How can I call an API (for example Flickr API) in Ruby on Rails? Newbie question

后端 未结 2 1057
心在旅途
心在旅途 2021-02-03 15:07

Im building my first app in rails and I would like to call Flickr\'s API

I know I can use flickr-fu, rflickr or other gem but I want to do it myself from scratch to lear

2条回答
  •  误落风尘
    2021-02-03 15:53

    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
    

    and then call

    Flickr.getPhotos('12345678')
    

提交回复
热议问题