Class: Ppds::Flickr

Inherits:
Object
  • Object
show all
Defined in:
lib/ppds/flickr.rb

Constant Summary collapse

API_URL =
'http://api.flickr.com/services/rest'
API_KEY =
'0282f93eb6da0425310bd5791f4c2fc0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFlickr

Returns a new instance of Flickr.



18
19
# File 'lib/ppds/flickr.rb', line 18

def initialize
end

Instance Attribute Details

#photosObject

Returns the value of attribute photos.



16
17
18
# File 'lib/ppds/flickr.rb', line 16

def photos
  @photos
end

Instance Method Details

#query(action, data) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ppds/flickr.rb', line 21

def query(action, data)
  data.update({
    :api_key => API_KEY,
    :method  => action
  })
  RestClient.post(API_URL, data)
rescue RestClient::RequestFailed
  raise 'Query failed: %s' % $!
rescue RestClient::RequestTimeout
  raise 'Timeout occured'
rescue Exception
  raise $!
end

#update(qty) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ppds/flickr.rb', line 35

def update(qty)
  data = {
    :extras       => 'date_upload,icon_server,license',
    :count        => qty,
    :user_id      => $cfg.get(:nsid).to_s,
    :single_photo => $cfg.get(:one_per_contact) ? 1 : 0,
    :just_friends => $cfg.get(:only_from_friends) ? 1 : 0,
    :include_self => $cfg.get(:include_self) ? 1 : 0
  }
  xml = query('flickr.photos.getContactsPublicPhotos', data)
  @xml = XML::Parser.string(xml).parse
  self.photos = @xml.find('//photos/photo').map do |node|
    Photo.new(node.attributes)
  end
end