iamfmjk / etsy

A friendly Ruby interface to the Etsy API
https://github.com/kytrinyx/etsy
MIT License
171 stars 113 forks source link

Getting Listings for one section #101

Closed gdhgdhgdh closed 9 years ago

gdhgdhgdh commented 9 years ago

Hi,

Thanks for writing this gem! :) Can you tell me how to get the Listings for a single section of a single shop? I have the section I want but can't figure out how to work with it...

https://www.etsy.com/developers/documentation/reference/listing#method_findallshopsectionlistings says I need to pass at least shop_id and shop_section_id - is the below the correct syntax for that? I'm hoping that I'm just missing something from *identifiers_and_options but I don't know what it is. Can you help?

irb(main):044:0> user.shop.id
=> 5308141

irb(main):045:0> sect
=> #<Etsy::Section:0x00000001af7728 @result={"shop_section_id"=>7794481, "title"=>"Cabochons", "rank"=>5, "user_id"=>5569833, "active_listing_count"=>15}, @token=nil, @secret=nil>

irb(main):046:0> Etsy::Listing.find({:shop_id => user.shop.id, :shop_section_id => sect})
Etsy::EtsyJSONInvalid: Etsy::EtsyJSONInvalid
    from /var/lib/gems/1.9.1/gems/etsy-0.3.0/lib/etsy/response.rb:92:in `validate!'
    from /var/lib/gems/1.9.1/gems/etsy-0.3.0/lib/etsy/response.rb:58:in `result'
    from /var/lib/gems/1.9.1/gems/etsy-0.3.0/lib/etsy/model.rb:67:in `get_all'
    from /var/lib/gems/1.9.1/gems/etsy-0.3.0/lib/etsy/model.rb:24:in `get'
    from /var/lib/gems/1.9.1/gems/etsy-0.3.0/lib/etsy/model.rb:96:in `find_one_or_more'
    from /var/lib/gems/1.9.1/gems/etsy-0.3.0/lib/etsy/listing.rb:75:in `find'
    from (irb):46
    from /usr/bin/irb:12:in `<main>'

Cheers, Gavin.

gdhgdhgdh commented 9 years ago

Hm,

I got this to work using:

irb(main):077:0> listings = Etsy::Request.get("/shops/#{user.shop.id}/sections/#{sect.id}/listings")
=> #<Etsy::Response:0x000000020b8388 @raw_response=#<Net::HTTPOK 200 OK readbody=true>>

Is this the most optimal way?

Cheers, Gavin.

kytrinyx commented 9 years ago

I don't use the "models" (e.g. Listing), I always just use the requests directly. It might not be the most optimal way, but it's certainly how I would do it :)

gdhgdhgdh commented 9 years ago

Nice - then it's good enough for me, too - thanks for the response!