Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Ğ
Ğcli
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
clients
Rust
Ğcli
Commits
c2bfe48c
Commit
c2bfe48c
authored
4 years ago
by
Éloïs
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into 'master'
feat: add members count query See merge request
!1
parents
11d48a8f
45da934b
No related branches found
No related tags found
1 merge request
!1
feat: add members count query
Pipeline
#10515
passed
4 years ago
Stage: fmt
Stage: tests
Stage: quality
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
gql/gva_queries.gql
+6
-0
6 additions, 0 deletions
gql/gva_queries.gql
src/commands.rs
+41
-0
41 additions, 0 deletions
src/commands.rs
src/main.rs
+6
-1
6 additions, 1 deletion
src/main.rs
with
53 additions
and
1 deletion
gql/gva_queries.gql
+
6
−
0
View file @
c2bfe48c
...
...
@@ -12,3 +12,9 @@ query CurrentUd {
amount
}
}
query
MembersCount
{
currentBlock
{
membersCount
}
}
This diff is collapsed.
Click to expand it.
src/commands.rs
+
41
−
0
View file @
c2bfe48c
...
...
@@ -25,6 +25,8 @@ pub(crate) enum Command {
},
/// Get current UD value
CurrentUd
,
/// Get current number of WoT members
MembersCount
,
}
pub
(
crate
)
fn
balance
<
W
:
Write
>
(
...
...
@@ -83,6 +85,24 @@ pub(crate) fn current_ud<W: Write>(client: &Client, out: &mut W) -> anyhow::Resu
Ok
(())
}
pub
(
crate
)
fn
members_count
<
W
:
Write
>
(
client
:
&
Client
,
out
:
&
mut
W
)
->
anyhow
::
Result
<
()
>
{
let
request_body
=
MembersCount
::
build_query
(
members_count
::
Variables
);
let
members_count
::
ResponseData
{
current_block
:
members_count
::
MembersCountCurrentBlock
{
members_count
},
}
=
client
.send_gql_query
(
&
request_body
)
?
;
writeln!
(
out
,
"There is currently {} members in Ğ1 WoT!"
,
members_count
)
?
;
Ok
(())
}
// below are tests
#[cfg(test)]
mod
tests
{
use
super
::
*
;
...
...
@@ -145,4 +165,25 @@ mod tests {
Ok
(())
}
#[test]
fn
test_member_count
()
->
anyhow
::
Result
<
()
>
{
let
mut
client
=
Client
::
default
();
client
.expect_send_gql_query
::
<
graphql_client
::
QueryBody
<
members_count
::
Variables
>
,
_
>
()
.returning
(|
_
|
{
Ok
(
members_count
::
ResponseData
{
current_block
:
members_count
::
MembersCountCurrentBlock
{
members_count
:
10_000
,
},
})
});
let
mut
out
=
Vec
::
new
();
members_count
(
&
client
,
&
mut
out
)
?
;
let
output
=
std
::
str
::
from_utf8
(
&
out
)
?
;
assert_eq!
(
output
,
"There is currently 10000 members in Ğ1 WoT!
\n
"
);
Ok
(())
}
}
This diff is collapsed.
Click to expand it.
src/main.rs
+
6
−
1
View file @
c2bfe48c
...
...
@@ -32,7 +32,7 @@ use crate::client::Client;
#[cfg(test)]
use
crate
::
client
::
MockClient
as
Client
;
use
crate
::
commands
::
Command
;
use
commands
::{
balance
,
current_ud
};
use
commands
::{
balance
,
current_ud
,
members_count
};
use
graphql_client
::
GraphQLQuery
;
use
graphql_client
::
Response
;
use
std
::
io
::
Write
;
...
...
@@ -49,6 +49,10 @@ pub struct Balance;
#[graphql(schema_path
=
"gql/gva_schema.gql"
,
query_path
=
"gql/gva_queries.gql"
)]
pub
struct
CurrentUd
;
#[derive(Debug,
Clone,
Copy,
GraphQLQuery)]
#[graphql(schema_path
=
"gql/gva_schema.gql"
,
query_path
=
"gql/gva_queries.gql"
)]
pub
struct
MembersCount
;
#[derive(StructOpt)]
#[structopt(name
=
"rust-gva-client"
,
about
=
"Client use GVA API of Duniter."
)]
struct
CliArgs
{
...
...
@@ -71,6 +75,7 @@ fn main() -> anyhow::Result<()> {
ud_unit
,
}
=>
balance
(
&
client
,
&
mut
out
,
&
pubkey_or_script
,
ud_unit
)
?
,
Command
::
CurrentUd
=>
current_ud
(
&
client
,
&
mut
out
)
?
,
Command
::
MembersCount
=>
members_count
(
&
client
,
&
mut
out
)
?
,
}
Ok
(())
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment