class Flickr::Client
This abstract class is the base for the client classes which communicate with the Flickr
API. For example, the part of Flickr
API for uploading photos need requests to be marked as multipart, while the part for querying data of photos doesn’t need it. So it’s obvious that we need separate classes.
This class just extracts the common behaviour, like including the API key in requests.
@private
Public Class Methods
new() { |builder| ... }
click to toggle source
# File lib/flickr/client.rb, line 27 def initialize @connection = Faraday.new(url, connection_options) do |builder| builder.use Flickr::Middleware::CatchTimeout yield builder if block_given? builder.use FaradayMiddleware::Caching, Flickr.cache if Flickr.cache builder.adapter :net_http end end
Public Instance Methods
get(*args, &block)
click to toggle source
# File lib/flickr/client.rb, line 37 def get(*args, &block) do_request(:get, *args, &block) end
post(*args, &block)
click to toggle source
# File lib/flickr/client.rb, line 41 def post(*args, &block) do_request(:post, *args, &block) end
Private Instance Methods
api_key()
click to toggle source
# File lib/flickr/client.rb, line 71 def api_key Flickr.api_key end
connection_options()
click to toggle source
# File lib/flickr/client.rb, line 47 def connection_options { params: { format: "json", nojsoncallback: 1, api_key: api_key, }, request: { open_timeout: open_timeout, timeout: timeout, }, proxy: proxy, } end
do_request(http_method, *args, &block)
click to toggle source
# File lib/flickr/client.rb, line 66 def do_request(http_method, *args, &block) response = @connection.send(http_method, *args, &block) response.body end
open_timeout()
click to toggle source
# File lib/flickr/client.rb, line 79 def open_timeout Flickr.open_timeout end
proxy()
click to toggle source
# File lib/flickr/client.rb, line 91 def proxy Flickr.proxy end
timeout()
click to toggle source
# File lib/flickr/client.rb, line 83 def timeout Flickr.timeout end
url()
click to toggle source
# File lib/flickr/client.rb, line 62 def url # Should be implemented in subclasses end
use_ssl?()
click to toggle source
# File lib/flickr/client.rb, line 87 def use_ssl? !!Flickr.use_ssl end