Class: FlickrVision
- Inherits:
-
Object
- Object
- FlickrVision
- Defined in:
- lib/flickr_vision.rb
Constant Summary collapse
- API_URL =
"https://api.flickr.com/services/rest/?"
Instance Attribute Summary collapse
-
#app_id ⇒ Object
readonly
Returns the value of attribute app_id.
-
#user_id ⇒ Object
readonly
Returns the value of attribute user_id.
Instance Method Summary collapse
- #get_all_photosets ⇒ Object
- #get_photo(photo_id) ⇒ Object
- #get_photos(photoset_id, per_page, page) ⇒ Object
-
#initialize(user_id, app_id) ⇒ FlickrVision
constructor
A new instance of FlickrVision.
Constructor Details
#initialize(user_id, app_id) ⇒ FlickrVision
12 13 14 15 |
# File 'lib/flickr_vision.rb', line 12 def initialize(user_id, app_id) @user_id = user_id @app_id = app_id end |
Instance Attribute Details
#app_id ⇒ Object (readonly)
Returns the value of attribute app_id.
10 11 12 |
# File 'lib/flickr_vision.rb', line 10 def app_id @app_id end |
#user_id ⇒ Object (readonly)
Returns the value of attribute user_id.
10 11 12 |
# File 'lib/flickr_vision.rb', line 10 def user_id @user_id end |
Instance Method Details
#get_all_photosets ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/flickr_vision.rb', line 17 def get_all_photosets() uri = URI(API_URL + "method=flickr.photosets.getList" + "&api_key=" + self.app_id + "&user_id=" + self.user_id) response = Net::HTTP.start(uri.host, uri.port,:use_ssl => uri.scheme == 'https',:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https| request = Net::HTTP::Get.new uri.request_uri https.request(request) end doc = REXML::Document.new(response.body) result = Array.new doc.elements.each('rsp/photosets/photoset') do |photo_set| photoset_id = photo_set.attributes["id"] title = photo_set.elements["title"].text description = photo_set.elements["description"].text result.push(FlickrPhotoset.new(photoset_id, title, description)) end return result end |
#get_photo(photo_id) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/flickr_vision.rb', line 36 def get_photo(photo_id) uri = URI(API_URL + "method=flickr.photos.getInfo" + "&api_key=" + self.app_id + "&photo_id=" + photo_id + "&user_id=" + self.user_id) response = Net::HTTP.start(uri.host, uri.port,:use_ssl => uri.scheme == 'https',:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https| request = Net::HTTP::Get.new uri.request_uri https.request(request) end flickrPhoto = FlickrPhoto.new doc = REXML::Document.new(response.body) doc.elements.each('rsp/photo') do |photo| flickrPhoto.id = photo.attributes["id"] flickrPhoto.farm_id = photo.attributes["farm"] flickrPhoto.server_id = photo.attributes["server"] flickrPhoto.secret = photo.attributes["secret"] flickrPhoto.title = photo.elements["title"] flickrPhoto.description = photo.elements["description"] end return flickrPhoto end |
#get_photos(photoset_id, per_page, page) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/flickr_vision.rb', line 57 def get_photos(photoset_id, per_page, page) if per_page == nil url = API_URL + "method=flickr.photosets.getPhotos" + "&api_key=" + self.app_id + "&photoset_id=" + photoset_id + "&extras=date_upload" else url = API_URL + "method=flickr.photosets.getPhotos" + "&api_key=" + self.app_id + "&photoset_id=" + photoset_id + "&extras=date_upload" + "&per_page=" + per_page.to_s + "&page=" + page.to_s end uri = URI(url) response = Net::HTTP.start(uri.host, uri.port,:use_ssl => uri.scheme == 'https',:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https| request = Net::HTTP::Get.new uri.request_uri https.request(request) end doc = REXML::Document.new(response.body) photos = Array.new doc.elements.each('rsp/photoset/photo') do |photo| flickrPhoto = FlickrPhoto.new flickrPhoto.id = photo.attributes["id"] flickrPhoto.farm_id = photo.attributes["farm"] flickrPhoto.server_id = photo.attributes["server"] flickrPhoto.secret = photo.attributes["secret"] flickrPhoto.title = photo.attributes["title"] flickrPhoto.primary = photo.attributes["isprimary"] # omschrijving ophalen via andere rest call flickrPhoto.description = get_description(flickrPhoto.id) photos.push(flickrPhoto) end #photos.keys.sort return photos end |