Class: FlickRaw::Flickr
Overview
Root class of the flickr api hierarchy.
Instance Attribute Summary collapse
-
#access_secret ⇒ Object
Authenticated access token secret.
-
#access_token ⇒ Object
Authenticated access token.
Class Method Summary collapse
Instance Method Summary collapse
-
#call(req, args = {}, &block) ⇒ Object
This is the central method.
-
#get_access_token(token, secret, verify) ⇒ Object
Get an oauth access token.
-
#get_authorize_url(token, args = {}) ⇒ Object
Get the oauth authorize url.
-
#get_request_token(args = {}) ⇒ Object
Get an oauth request token.
-
#initialize ⇒ Flickr
constructor
:nodoc:.
-
#replace_photo(file, args = {}) ⇒ Object
Use this to replace the photo with :photo_id with the photo in file.
-
#upload_photo(file, args = {}) ⇒ Object
Use this to upload the photo in file.
Methods inherited from Request
build_request, flickr_methods, flickr_objects, request_name
Constructor Details
#initialize ⇒ Flickr
:nodoc:
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/flickraw/api.rb', line 37 def initialize # :nodoc: raise "No API key or secret defined !" if FlickRaw.api_key.nil? or FlickRaw.shared_secret.nil? @oauth_consumer = OAuthClient.new(FlickRaw.api_key, FlickRaw.shared_secret) @oauth_consumer.proxy = FlickRaw.proxy @oauth_consumer.user_agent = USER_AGENT @access_token = @access_secret = nil Flickr.build(call('flickr.reflection.getMethods')) if Flickr.flickr_objects.empty? super self end |
Instance Attribute Details
#access_secret ⇒ Object
Authenticated access token secret
33 34 35 |
# File 'lib/flickraw/api.rb', line 33 def access_secret @access_secret end |
#access_token ⇒ Object
Authenticated access token
30 31 32 |
# File 'lib/flickraw/api.rb', line 30 def access_token @access_token end |
Class Method Details
.build(methods) ⇒ Object
35 |
# File 'lib/flickraw/api.rb', line 35 def self.build(methods); methods.each { |m| build_request m } end |
Instance Method Details
#call(req, args = {}, &block) ⇒ Object
This is the central method. It does the actual request to the flickr server.
Raises FailedResponse if the response status is failed.
51 52 53 54 55 |
# File 'lib/flickraw/api.rb', line 51 def call(req, args={}, &block) rest_path = FlickRaw.secure ? REST_PATH_SECURE : REST_PATH http_response = @oauth_consumer.post_form(rest_path, @access_secret, {:oauth_token => @access_token}, build_args(args, req)) process_response(req, http_response.body) end |
#get_access_token(token, secret, verify) ⇒ Object
Get an oauth access token.
flickr.get_access_token(token['oauth_token'], token['oauth_token_secret'], oauth_verifier)
76 77 78 79 80 81 |
# File 'lib/flickraw/api.rb', line 76 def get_access_token(token, secret, verify) flickr_oauth_access_token = FlickRaw.secure ? FLICKR_OAUTH_ACCESS_TOKEN_SECURE : FLICKR_OAUTH_ACCESS_TOKEN access_token = @oauth_consumer.access_token(flickr_oauth_access_token, secret, :oauth_token => token, :oauth_verifier => verify) @access_token, @access_secret = access_token['oauth_token'], access_token['oauth_token_secret'] access_token end |
#get_authorize_url(token, args = {}) ⇒ Object
Get the oauth authorize url.
auth_url = flickr.(token['oauth_token'], :perms => 'delete')
68 69 70 71 |
# File 'lib/flickraw/api.rb', line 68 def (token, args = {}) = FlickRaw.secure ? FLICKR_OAUTH_AUTHORIZE_SECURE : FLICKR_OAUTH_AUTHORIZE @oauth_consumer.(, args.merge(:oauth_token => token)) end |
#get_request_token(args = {}) ⇒ Object
Get an oauth request token.
token = flickr.get_request_token(:oauth_callback => "http://example.com")
60 61 62 63 |
# File 'lib/flickraw/api.rb', line 60 def get_request_token(args = {}) flickr_oauth_request_token = FlickRaw.secure ? FLICKR_OAUTH_REQUEST_TOKEN_SECURE : FLICKR_OAUTH_REQUEST_TOKEN @oauth_consumer.request_token(flickr_oauth_request_token, args) end |
#replace_photo(file, args = {}) ⇒ Object
Use this to replace the photo with :photo_id with the photo in file.
flickr.replace_photo '/path/to/the/photo', :photo_id => id
See www.flickr.com/services/api/replace.api.html for more information on the arguments.
98 99 100 101 |
# File 'lib/flickraw/api.rb', line 98 def replace_photo(file, args={}) replace_path = FlickRaw.secure ? REPLACE_PATH_SECURE : REPLACE_PATH upload_flickr(replace_path, file, args) end |
#upload_photo(file, args = {}) ⇒ Object
Use this to upload the photo in file.
flickr.upload_photo '/path/to/the/photo', :title => 'Title', :description => 'This is the description'
See www.flickr.com/services/api/upload.api.html for more information on the arguments.
88 89 90 91 |
# File 'lib/flickraw/api.rb', line 88 def upload_photo(file, args={}) upload_path = FlickRaw.secure ? UPLOAD_PATH_SECURE : UPLOAD_PATH upload_flickr(upload_path, file, args) end |