Giter VIP home page Giter VIP logo

letterboxd-rs's Introduction

Letterboxd API for Rust

crates-badge docs-badge license-badge ci-badge

Letterboxd API client for accessing the data on the Letterboxd.com website in Rust.

Example

#[tokio::main]
async fn main() -> letterboxd::Result<()> {
    let api_key_pair = letterboxd::ApiKeyPair::from_env().unwrap();
    let client = letterboxd::Client::new(api_key_pair);

    let req = letterboxd::SearchRequest {
        input: "Fight Club".to_string(),
        per_page: Some(1),
        ..Default::default()
    };
    let resp = client.search(&req).await?;
    println!("{:?}", resp);

    Ok(())
}

For more examples cf. tests/integration.rs.

Note: Not all APIs are implemented. Feel free to contribute missing implementation, usually these are very straight forward.

License

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this document by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

letterboxd-rs's People

Contributors

boxdot avatar jeschkies avatar vn-ki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

letterboxd-rs's Issues

Split out client code and defs by endpoint type

It might be worth splitting up client.rs and defs.rs into sub-paths based on the endpoint type. I think that as the number of supported endpoints grows, keeping all the client code and struct definitions in single large files will start to get in the way: defs.rs is already ~3k lines long.

The best way to do this IMO would be to pull out the client functions and struct defs into sub-paths based on the endpoint type (film, list, etc).

Implement film/report endpoint

The endpoint is a POST request without reponse body, which is different to other requests normally heaving a body reponse. Therefore, it does not fit to the POST macro. Also it is quite hard to write an integration test for this request without being banned from letterboxd.

Abstract get, post, patch and delete in macro

Example implementation

macro_rules! GET {
    ($func_name:ident, ($path:expr $(, $arg:ident:$T:ty)*), $ReqT:ty, $RespT:tt) => {
        pub fn $func_name(&self $( , $arg: $T)*, req: &$ReqT) -> $RespT {
            println!(
                concat!("Called `{}` for path `", $path, "`"), stringify!($func_name) $( , $arg)*);
            println!("{:?}", req);
            $RespT { body: String::from("empty") }
        }
    };
    ($func_name:ident, $path:expr, $ReqT:ty, $RespT:tt) => {
        GET!($func_name, ($path), $ReqT, $RespT);
    };
}

#[derive(Debug)]
pub struct Request {
    param: String,
}
pub struct Response {
    body: String,
}

pub struct Client;

impl Client {
    GET!(films, "/film", Request, Response);
    GET!(film, ("/film/{}/title/{}", id: i32, name: &str), Request, Response);
}

fn main() {
    Client.films(&Request { param: String::from("foo") });
    Client.film(1, "foo", &Request { param: String::from("foo") });
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.