Giter VIP home page Giter VIP logo

letterboxd-rs's Issues

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.

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).

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.