flickr_vision 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ class FlickrPhoto
2
+
3
+ attr_accessor :id, :farm_id, :server_id, :secret
4
+
5
+ def small_square()
6
+ return build_photo_url(@farm_id,@server_id,@id,@secret).gsub(".jpg","") + "_s" + ".jpg"
7
+ end
8
+
9
+ def thumbnail()
10
+ return build_photo_url(@farm_id,@server_id,@id,@secret).gsub(".jpg","") + "_t" + ".jpg"
11
+ end
12
+
13
+ # 240 px
14
+ def small()
15
+ return build_photo_url(@farm_id,@server_id,@id,@secret).gsub(".jpg","") + "_m" + ".jpg"
16
+ end
17
+
18
+ # 640 px
19
+ def medium()
20
+ return build_photo_url(@farm_id,@server_id,@id,@secret).gsub(".jpg","") + "_z" + ".jpg"
21
+ end
22
+
23
+ def large()
24
+ return build_photo_url(@farm_id,@server_id,@id,@secret).gsub(".jpg","") + "_b" + ".jpg"
25
+ end
26
+
27
+ def original()
28
+ return build_photo_url(@farm_id,@server_id,@id,@secret).gsub(".jpg","") + "_o" + ".jpg"
29
+ end
30
+
31
+ private
32
+
33
+ def build_photo_url(farm_id,server_id,photo_id,secret)
34
+ return "http://farm#{farm_id}.static.flickr.com/#{server_id}/#{photo_id}_#{secret}.jpg"
35
+ end
36
+
37
+ end
@@ -0,0 +1,10 @@
1
+ class FlickrPhotoset
2
+
3
+ attr_reader :id, :title
4
+
5
+ def initialize(id, title)
6
+ @id = id
7
+ @title = title
8
+ end
9
+
10
+ end
@@ -0,0 +1,64 @@
1
+ require 'net/http'
2
+ require 'rexml/document'
3
+ require 'flickr_vision/flickr_photoset'
4
+ require 'flickr_vision/flickr_photo'
5
+
6
+ class FlickrVision
7
+
8
+ API_URL = "https://api.flickr.com/services/rest/?"
9
+
10
+ attr_reader :user_id, :app_id
11
+
12
+ def initialize(user_id, app_id)
13
+ @user_id = user_id
14
+ @app_id = app_id
15
+ end
16
+
17
+ def get_all_photosets()
18
+ uri = URI(API_URL + "method=flickr.photosets.getList" + "&api_key=" + self.app_id + "&user_id=" + self.user_id)
19
+
20
+ response = Net::HTTP.start(uri.host, uri.port,:use_ssl => uri.scheme == 'https',:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
21
+ request = Net::HTTP::Get.new uri.request_uri
22
+ https.request(request)
23
+ end
24
+
25
+ doc = REXML::Document.new(response.body)
26
+ result = Array.new
27
+ doc.elements.each('rsp/photosets/photoset') do |photo_set|
28
+ photoset_id = photo_set.attributes["id"]
29
+ title = photo_set.elements["title"].text
30
+ result.push(FlickrPhotoset.new(photoset_id, title))
31
+ end
32
+ return result
33
+ end
34
+
35
+ def get_photos(photoset_id, per_page, page)
36
+ if per_page == nil
37
+ url = API_URL + "method=flickr.photosets.getPhotos" + "&api_key=" + self.app_id + "&photoset_id=" + photoset_id + "&extras=date_upload"
38
+ else
39
+ 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
40
+ end
41
+
42
+ uri = URI(url)
43
+ response = Net::HTTP.start(uri.host, uri.port,:use_ssl => uri.scheme == 'https',:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |https|
44
+ request = Net::HTTP::Get.new uri.request_uri
45
+ https.request(request)
46
+ end
47
+
48
+ doc = REXML::Document.new(response.body)
49
+ photos = Array.new
50
+ doc.elements.each('rsp/photoset/photo') do |photo|
51
+ flickrPhoto = FlickrPhoto.new
52
+ flickrPhoto.id = photo.attributes["id"]
53
+ flickrPhoto.farm_id = photo.attributes["farm"]
54
+ flickrPhoto.server_id = photo.attributes["server"]
55
+ flickrPhoto.secret = photo.attributes["secret"]
56
+ photos.push(flickrPhoto)
57
+ end
58
+
59
+ #photos.keys.sort
60
+
61
+ return photos
62
+ end
63
+
64
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flickr_vision
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Koen De Vuyst
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-10-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A gem to access flickr
15
+ email: koen@infovision.be
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/flickr_vision.rb
21
+ - lib/flickr_vision/flickr_photoset.rb
22
+ - lib/flickr_vision/flickr_photo.rb
23
+ homepage: http://www.infovision.be
24
+ licenses:
25
+ - MIT
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.8.15
45
+ signing_key:
46
+ specification_version: 3
47
+ summary: FlickrVision
48
+ test_files: []