annict-rs
Annict API client library for Rust.
Annict is a web service to make and manage watching anime life.
Usage
Add this to your Cargo.toml
:
[dependencies]
annis = "0.0.3"
and this to your crate root:
extern crate annis;
Here is a example code that the process from obtaining access_token
until making a request for /v1/works.
extern crate annis;
use annis::{OAuth, Client, Works};
fn main(){
let auth = OAuth::client_id("client_id");
let url = &auth.authorize_url().redirect_uri("https://example.com").scope("read+write").build();
let access_token = auth
.access_token()
.client_secret("client_secret_key")
.code("certification code")
.build();
let client = Client::set_token(access_token);
let works = annis::works().params(vec![(Works::filter_title, "lain")]);
let json = client.call(works).unwrap();
assert_eq!(json["works"][0]["title"], "serial experiments lain".to_string());
}
Auth Requests were made two ways that methods or creating struct.
extern crate annis;
use annis::{OAuth, AuthorizeUri, AccessToken};
let auth = OAuth::client_id("client_id");
let instant = auth.authorize_url().build();
let manual = AuthorizeUrl{
client_id: "client_id".to_string(),
redirect_uri: "urn:ietf:wg:oauth:2.0:oob".to_string(),
scope: "read".to_string()
}.build();
assert_eq!(instant, manual);
let instant = auth
.access_token()
.client_secret("client_secret_key")
.code("certification code")
.build();
let manual = AccessToken{
client_id: "client_id".to_string(),
client_secret: "client_secret_key".to_string(),
code: "certification code".to_string(),
redirect_uri: "urn:ietf:wg:oauth:2.0:oob".into()
}.build();
assert_eq!(instant, manual);
Parameter arguments accept &str, String and Enum.
extern crate annis;
use annis::{OAuth, Client, Works::*};
let use_enum = annis::works().params(vec![(filter_title, "lain")]);
let use_string = annis::works().params(vec![("filter_title", "lain")]);
assert_eq!(use_enum.params, use_string.params);
License
MIT license
http://opensource.org/licenses/mit-license.php