3个版本

使用旧的Rust 2015

0.1.2 2021年4月2日
0.1.1 2018年11月30日
0.1.0 2018年11月5日

#740 in 认证

MIT许可

18KB
325

instapaper

Rust对Instapaper公共API的封装。官方API的文档可以在这里找到。注意,为了接收访问API的消费者密钥和密钥,您必须填写此表单。查看Client结构以获取所有可用的方法。

Rustdocs

安装

instapaper = "*" 添加到您的 Cargo.toml 文件中。

示例

extern crate dotenv;

use dotenv::dotenv;
use std::env;

dotenv().ok();

for (key, value) in env::vars() {
  println!("{}: {}", key, value);
}

// Instapaper uses the archaic Oauth1 which requires the username and password in order to
// receive an oauth token required for further operations.
let client = instapaper::authenticate(
    &env::var("INSTAPAPER_USERNAME").unwrap(),
    &env::var("INSTAPAPER_PASSWORD").unwrap(),
    &env::var("INSTAPAPER_CONSUMER_KEY").unwrap(),
    &env::var("INSTAPAPER_CONSUMER_SECRET").unwrap(),
).expect("failed to authenticate");

// Now the `oauth_key` and `oauth_secret` on `instapaper::Client` has been set to make it valid
// for API actions
client.add("https://sirupsen.com/read", "How I Read", "").unwrap();
println!("{:?}", client.bookmarks().unwrap());

println!("Client {{");
println!("  consumer_key: {}", client.consumer_key);
println!("  consumer_secret: {}", client.consumer_secret);
println!("  oauth_key: {}", client.oauth_key.as_ref().unwrap());
println!("  oauth_secret: {}", client.oauth_secret.as_ref().unwrap());
println!("}}");

// You can save the Oauth authentication details to e.g. an enviroment file or wherever you
// store secrets and discard the username and password.
let client2 = instapaper::Client {
    consumer_key: env::var("INSTAPAPER_CONSUMER_KEY").unwrap().to_owned(),
    consumer_secret: env::var("INSTAPAPER_CONSUMER_SECRET").unwrap().to_owned(),
    oauth_key: client.oauth_key,
    oauth_secret: client.oauth_secret,
};

println!("{:?}", client2.bookmarks().unwrap());

许可证:MIT

依赖项

~26MB
~647K SLoC