Giter Club home page Giter Club logo

genius-rs's Introduction

genius-rs's People

Contributors

alt-art avatar vrobweis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

genius-rs's Issues

Refactor Hit struct to be an enum?

Love this crate. API wrappers are the unsung heroes of any application ecosystem, and I'm glad to see any improvements to Rust's application-level situation. Having said that, I'm curious if this library can map to some common Rust idioms.

In this case, as of version 0.4.0, this library still uses a struct to represent a Hit, or search result from the Genius API.

genius-rs/src/search.rs

Lines 5 to 11 in 283c082

#[derive(Deserialize, Debug)]
pub struct Hit {
pub index: String,
#[serde(rename = "type")]
pub hit_type: String,
pub result: Song,
}

Can this be changed? serde allows the deserialization of enums, and if there are even types other than "song" that would appear in the type field, an enum could be used to represent them. It would certainly be much easier to use than having to read all the public fields of each type.

I couldn't find a complete list of "type"s that Genius search hits can have, but since they seem to only currently support a song type, it is likely they may simply have future proofed, intending to update their database later on to distinguish between music videos and songs, which they currently do not do. For the time being, a single-variant, #[non-exhaustive] enum could represent this perfectly.

Rename "type" field in Hit struct to hit_type to avoid keyword collision

pub r#type: String,

The type field of the Hit struct is currently explicitly escaped in the code to allow the keyword to line up with the API response. It's consistent with the rest of the design, which is nice, but causes issues for a user of the crate if they want to match against that type. Renaming it to something functionally identical that doesn't collide with the type keyword would be a good first step to making the library hide the details of the API responses and make it a little easier to use. :)

The ergonomics are already a little weird, but when having to escape the type keyword, it makes it almost too weird to use:

let search_result = Genius::new(token).search(artist_name.as_str()).await;
if let Ok(result) = search_result {
    if (result.meta.status == 200) {
        let hits = result.response.hits;
        for hit in hits {
            (hit.r#type == "song".to_string());
        }
    }
}

get_lyrics function returning nothing

code:

let lyrics = genius.get_lyrics("https://genius.com/Marty-robbins-big-iron-lyrics").await.unwrap();
    println!("{:#?}", lyrics);

result:
[]

maybe a i did something wrong? Using the code provided on the readme doesnt seems to help.

Library methods shouldn't use tokio::main attribute

pub async fn get_lyrics(&self, url: &str) -> Result<Vec<String>, reqwest::Error> {

#[tokio::main]

Making the Genius methods both labeled with ![tokio::main] is problematic, since effectively it makes them unusable as library calls. They're async functions that can't be executed by the user's runtime, you reproduce the tokio runtime with every call of those methods. It dodges compiler issues, okay, but in practice this barely works for performance, and makes using the methods more unwieldy. Try instead making your test methods use the tokio test attribute.

ParseError: error decoding response body

use genius_rs::Genius;

#[tokio::main]
async fn main() {
    let genius = Genius::new(dotenv::var("TOKEN").unwrap());
    let response = genius.search("Sia").await;

    match response {
      Ok(resp) => println!("{:?}", resp),
      Err(e) => println!("{:?}", e),
    }
    
}

I was checking the examples listed in the readme, but I couldn't reproduce them since the error says that the response can't be parsed because it's not a valid. The error is the following:

ParseError("error decoding response body: missing field `response` at line 1 column 134")

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.