Class: FlickrAuthentication
- Inherits:
-
Object
- Object
- FlickrAuthentication
- Defined in:
- lib/flickr_authentication.rb,
lib/flickr_authentication/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Attribute Summary collapse
-
#auth_file ⇒ Object
Returns the value of attribute auth_file.
-
#key ⇒ Object
Returns the value of attribute key.
-
#shared_secret ⇒ Object
Returns the value of attribute shared_secret.
Instance Method Summary collapse
- #authenticate ⇒ Object
-
#initialize(options = {}) ⇒ FlickrAuthentication
constructor
A new instance of FlickrAuthentication.
Constructor Details
#initialize(options = {}) ⇒ FlickrAuthentication
Returns a new instance of FlickrAuthentication.
10 11 12 13 14 |
# File 'lib/flickr_authentication.rb', line 10 def initialize( = {}) @key = [:key] @shared_secret = [:shared_secret] @auth_file = [:auth_file] end |
Instance Attribute Details
#auth_file ⇒ Object
Returns the value of attribute auth_file.
8 9 10 |
# File 'lib/flickr_authentication.rb', line 8 def auth_file @auth_file end |
#key ⇒ Object
Returns the value of attribute key.
8 9 10 |
# File 'lib/flickr_authentication.rb', line 8 def key @key end |
#shared_secret ⇒ Object
Returns the value of attribute shared_secret.
8 9 10 |
# File 'lib/flickr_authentication.rb', line 8 def shared_secret @shared_secret end |
Instance Method Details
#authenticate ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/flickr_authentication.rb', line 16 def authenticate FlickRaw.api_key = key FlickRaw.shared_secret = shared_secret if File.exists?(auth_file) puts "authenticating with #{auth_file}" data = YAML.load_file(auth_file) auth = flickr.auth.checkToken :auth_token => data["api_token"] else frob = flickr.auth.getFrob auth_url = FlickRaw.auth_url :frob => frob, :perms => "write" puts " " puts "opening your browser..." sleep 1 puts "Come back and press Enter when you are finished" sleep 2 Launchy.open(auth_url) STDIN.getc # Authentication auth = flickr.auth.getToken :frob => frob login = flickr.test.login puts auth.token data = {} data["api_token"] = auth.token File.open(auth_file, "w"){|f| YAML.dump(data, f) } end flickr #return the flickr object end |