Class: Flickr::Client
- Inherits:
-
Object
show all
- Defined in:
- lib/flickr/client.rb
Constant Summary
collapse
- DEFAULT_ENDPOINT =
'http://api.flickr.com'.freeze
- SECURE_ENDPOINT =
'https://secure.flickr.com'.freeze
- REST_PATH =
'/services/rest'.freeze
- UPLOAD_PATH =
'/services/upload'.freeze
- REPLACE_PATH =
'/services/resplace'.freeze
- CONFIGURATION_KEYS =
[
:consumer_key,
:consumer_secret,
:token,
:token_secret,
:secure,
:format,
:enable_logging
]
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
26
27
28
29
30
|
# File 'lib/flickr/client.rb', line 26
def initialize(options = {})
CONFIGURATION_KEYS.each do |key|
send("#{key}=", options[key])
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
70
71
72
|
# File 'lib/flickr/client.rb', line 70
def method_missing(method_name, *args)
args.empty? ? Flickr::Node.new(self, ['flickr', method_name].join('.')) : super
end
|
Instance Method Details
#adapter ⇒ Object
45
46
47
|
# File 'lib/flickr/client.rb', line 45
def adapter
@adapter || Faraday.default_adapter
end
|
#authentication(options = {}) ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'lib/flickr/client.rb', line 36
def authentication(options = {})
{
:consumer_key => consumer_key,
:consumer_secret => consumer_secret,
:token => token,
:token_secret => token_secret
}.merge(options.select{|k,v| [:consumer_key, :consumer_secret, :token, :token_secret].include?(k.to_sym)})
end
|
#connection(options = {}) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/flickr/client.rb', line 49
def connection(options = {})
@connection = Faraday.new(:url => endpoint(options[:secure])) do |builder|
builder.use Faraday::Request::OAuth, authentication(options)
builder.use Faraday::Request::Multipart
builder.use Faraday::Request::UrlEncoded
builder.use Faraday::Response::RaiseFlickrError
if (options[:format] or format).to_s == 'json'
builder.use Faraday::Response::ParseJson
else
builder.use Faraday::Response::ParseXml
end
builder.use Faraday::Response::RaiseError
builder.use Faraday::Response::Logger if options[:enable_logging] or enable_logging
builder.adapter adapter
end
end
|
#endpoint(secure = false) ⇒ Object