Class: FlickrApiRequest
- Inherits:
-
Object
- Object
- FlickrApiRequest
- Defined in:
- lib/flickr/interaction/flickr_api_request.rb
Constant Summary collapse
- API_RSP =
'json'
- API_REQ =
'rest'
- API_URL =
"https://api.flickr.com/services/#{API_REQ}/"
Instance Attribute Summary collapse
-
#tokens ⇒ Object
readonly
Returns the value of attribute tokens.
Instance Method Summary collapse
- #call(method, arguments, authenticated, get) ⇒ Object
-
#initialize(tokens) ⇒ FlickrApiRequest
constructor
A new instance of FlickrApiRequest.
- #sign_request(arguments) ⇒ Object
Constructor Details
#initialize(tokens) ⇒ FlickrApiRequest
Returns a new instance of FlickrApiRequest.
14 15 16 17 |
# File 'lib/flickr/interaction/flickr_api_request.rb', line 14 def initialize(tokens) @tokens = tokens @arguments = { 'format' => API_RSP, 'api_key' => @tokens.api_key } end |
Instance Attribute Details
#tokens ⇒ Object (readonly)
Returns the value of attribute tokens.
12 13 14 |
# File 'lib/flickr/interaction/flickr_api_request.rb', line 12 def tokens @tokens end |
Instance Method Details
#call(method, arguments, authenticated, get) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/flickr/interaction/flickr_api_request.rb', line 19 def call(method, arguments, authenticated, get) arguments ? arguments = arguments.merge(@arguments) : arguments = @arguments arguments = arguments.merge({'method' => method}) arguments = objects_to_strings(arguments) arguments = remove_blank_args(arguments) if authenticated if !@tokens.auth_token return {'stat' => 'fail'} end arguments = arguments.merge({'auth_token' => @tokens.auth_token}) end arguments = sign_request(arguments) begin JSON.parse strip_function(Request.make(API_URL, arguments.class == Array ? arguments : arguments.to_a, get)) rescue JSON::ParserError nil end end |
#sign_request(arguments) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/flickr/interaction/flickr_api_request.rb', line 43 def sign_request(arguments) arguments = sort_arguments(arguments) api_sig = @tokens.shared_secret.clone arguments.each { |item| api_sig << item[0].to_s + item[1].to_s } sig_digest = Digest::MD5.hexdigest(api_sig) arguments.insert(0, ['api_sig', sig_digest]) arguments end |