How can I name an API (e.g. Flickr API) in Ruby on Rails? Question for beginners

I am building my first application on rails and I would like to call the Flickr API

I know that I can use flickr-fu, rflickr or another stone, but I want to do it myself from scratch to find out

Say, for example, I want to call flickr.photos.comments.getList, which returns comments on the photo. The arguments are api_key and photo_id. I have both.

I will get the answer as xml

<comments photo_id="109722179">
<comment id="6065-109722179-72057594077818641" author="35468159852@N01" authorname="Rev Dan Catt" datecreate="1141841470" permalink="http://www.flickr.com/photos/straup/109722179/#comment72057594077818641">
Umm, I'm not sure, can I get back to you on that one?</comment>
</comments>`

I want to save the received data by calling this method in a variable commentsso that I can access the data using, for example,

comments.all.first.author_name = "Rev Dan Catt"

or

comments.all.first.content = "Umm, I'm not sure, can I get back to..."

How can i do this? Please be patient (sorry for the question about noob)

+5
2
include 'rubygems'
include 'httparty'

class Flickr
  include HTTParty

  base_uri 'api.flickr.com'

  def self.getPhotos(uid)
    return get('/services/rest/', :query => {
      :method => 'flickr.people.getPublicPhotos',
      :api_key => 'api key goes here',
      :user_id => uid})
  end
end

Flickr.getPhotos('12345678')
+12

- XML- . Nokogiri - , . .

.

, , , () XML- . Ruby, , โ€‹โ€‹. - ( flickr-fu), , .

PS , , , , . , - !

+1

All Articles