Code Monkey home page Code Monkey logo

Comments (4)

Eonm avatar Eonm commented on June 30, 2024

Hi @ademasi ,

Thank you for your issue and welcome to the Rust community 🦀.

You should try something like this :

extern crate zotero;

use zotero::ZoteroInit;
use zotero::Get;

use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    let z = ZoteroInit::set_user("ID", "API_KEY");
    let items = z.get_items(None)?;
    
   for item in items.iter() {
     println!("{:?}", item);
   }

    Ok(())
}

The problem with your code is that z.get_items(None) returns a Result. A result holds a value or an Error. If you want to iter over a Result you need to get it's value first. To do so you can unwrap the Result whit : z.get_items(None).unwrap() or you can use ? operator as I did in my first example. Or You can also use pattern matching like this :

extern crate zotero;

use zotero::ZoteroInit;
use zotero::Get;

use std::error::Error;

fn main() {
    let z = ZoteroInit::set_user("ID", "API_KEY");
    let items = z.get_items(None);
    
    let items = z.get_items(None);
    
   match items {
     Ok(zotero_items) => println!("{:?}", zotero_items),
     Err(_) => panic!("API Error")
   }
}

If you want to check your API key privileges you should take a look at the doc.

let z = ZoteroInit::set_user("ID", "API_KEY");
let key_info = z.get_api_key_info("API_KEY");
println!("{:?}", key_info);

While looking to fix your issue I noticed other issues with my crate. Zotero API slightly change since I implemented it and I'm facing Derialization issues 😞. I need more time to fix this see #2.

Best regards

from zotero.

ademasi avatar ademasi commented on June 30, 2024

Hi @Eonm ,

Thank you for taking the time to reply to my issue.

Indeed, I was expecting something closer to what I am used to in Python or Java. I need to read the rust book ...
Anyway, I was able to access my API key details with get_api_key_info. But as you saw, if I am trying to access an item, even directly with its ID, I get this this error :

Err(
    Error("invalid type: map, expected a string", line: 0, column: 0),
)

What would be the first step to hep with with #2 ?

Regards, Alex.

from zotero.

Eonm avatar Eonm commented on June 30, 2024

I take a closer look at this deserialization issue this afternoon. I can provide a hot fix, but more work needs to be done. I need to implement proper unit test and add more documentation, maybe this week end.

Can you replace the zotero dependencies entry with the following in Cargo.toml :

zotero = { git = "https://github.com/Eonm/zotero", branch ="deserialization-fix"}

I won't touch anything on this branch for not braking your code.

Regards,

from zotero.

Eonm avatar Eonm commented on June 30, 2024

I didn't notice but the first code you used was in the documentation. It's my fault. The documentation is wrong.

from zotero.

Related Issues (5)

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.