Class: Aviary::ImageHost::Flickr
- Inherits:
-
Aviary::ImageHost
- Object
- Aviary::ImageHost
- Aviary::ImageHost::Flickr
- Defined in:
- lib/aviary/image_host/flickr.rb
Class Method Summary collapse
-
.api_key(key = nil) ⇒ Object
Get and set the API key.
-
.available? ⇒ Boolean
True if the API key has been set.
- .match_and_create(status) ⇒ Object
Instance Method Summary collapse
Methods inherited from Aviary::ImageHost
Class Method Details
.api_key(key = nil) ⇒ Object
Get and set the API key. Passing an argument sets the API key. Passing nothing gets the API key.
Returns api key.
12 13 14 15 |
# File 'lib/aviary/image_host/flickr.rb', line 12 def self.api_key(key = nil) @api_key = key if key @api_key end |
.available? ⇒ Boolean
True if the API key has been set.
Returns boolean.
20 21 22 |
# File 'lib/aviary/image_host/flickr.rb', line 20 def self.available? !api_key.nil? end |
.match_and_create(status) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/aviary/image_host/flickr.rb', line 24 def self.match_and_create(status) match(status.text).each do |capture| create :token => (capture =~ /^\d+$/ ? Base58.encode(capture.to_i) : capture), :status => status end end |
Instance Method Details
#href ⇒ Object
31 32 33 |
# File 'lib/aviary/image_host/flickr.rb', line 31 def href "http://flic.kr/p/#{self.token}" end |
#set_meta ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/aviary/image_host/flickr.rb', line 40 def uri = URI.parse "http://api.flickr.com/services/rest/?method=flickr" + ".photos.getInfo&api_key=#{self.class.api_key}" + "&photo_id=#{Base58.decode(self.token)}" photo = Nokogiri::XML(open(uri)).css('photo') self. = { :farm_id => photo.first['farm'], :server_id => photo.first['server'], :id => photo.first['id'], :secret => photo.first['secret'] } end |
#src ⇒ Object
35 36 37 38 |
# File 'lib/aviary/image_host/flickr.rb', line 35 def src "http://farm#{self.[:farm_id]}.static.flickr.com/" + "#{self.[:server_id]}/#{self.[:id]}_#{self.[:secret]}_z.jpg" end |