flickrie 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,68 +1,7 @@
1
- require 'faraday_middleware'
1
+ require 'faraday'
2
2
 
3
3
  module Flickrie
4
- OPEN_TIMEOUT = 4
5
- TIMEOUT = 6
6
-
7
- class << self
8
- def self.attr_accessor_with_client_reset(*attributes) # :nodoc:
9
- attr_reader *attributes
10
-
11
- attributes.each do |attribute|
12
- define_method "#{attribute}=" do |value|
13
- instance_variable_set "@#{attribute}", value
14
- @client = @upload_client = nil
15
- end
16
- end
17
- end
18
-
19
- attr_accessor_with_client_reset :api_key, :shared_secret,
20
- :timeout, :open_timeout, :access_token, :access_secret
21
-
22
- # ==== Example
23
- #
24
- # Flickrie.client.get "flickr.photos.licenses.getInfo"
25
- # Flickrie.client.post "flickr.photos.licenses.setLicense", :photo_id => 1241497, :license_id => 2
26
- def client
27
- @client ||= new_client
28
- end
29
-
30
- def new_client(access_token_hash = {}) # :nodoc:
31
- Client.new(params) do |b|
32
- b.use Middleware::Retry
33
- b.use FaradayMiddleware::OAuth,
34
- :consumer_key => api_key,
35
- :consumer_secret => shared_secret,
36
- :token => access_token_hash[:token] || access_token,
37
- :token_secret => access_token_hash[:secret] || access_secret
38
-
39
- b.use Middleware::StatusCheck
40
- b.use FaradayMiddleware::ParseJson
41
- b.use Middleware::OAuthCheck
42
-
43
- b.adapter :net_http
44
- end
45
- end
46
-
47
- private
48
-
49
- def params
50
- {
51
- :url => 'http://api.flickr.com/services/rest',
52
- :params => {
53
- :format => 'json',
54
- :nojsoncallback => '1',
55
- :api_key => api_key
56
- },
57
- :request => {
58
- :open_timeout => open_timeout || OPEN_TIMEOUT,
59
- :timeout => timeout || TIMEOUT
60
- }
61
- }
62
- end
63
- end
64
-
65
- class Client < Faraday::Connection # :nodoc:
4
+ class Client < Faraday::Connection
66
5
  def get(method, params = {})
67
6
  super() do |req|
68
7
  req.params[:method] = method
@@ -77,7 +16,6 @@ module Flickrie
77
16
  end
78
17
  end
79
18
 
80
- #--
81
19
  # people
82
20
  def find_user_by_email(email, params = {})
83
21
  get 'flickr.people.findByEmail',
@@ -89,22 +27,21 @@ module Flickrie
89
27
  {:username => username}.merge(params)
90
28
  end
91
29
 
92
- def get_user_info(user_nsid, params = {})
30
+ def get_user_info(nsid, params = {})
93
31
  get 'flickr.people.getInfo',
94
- {:user_id => user_nsid}.merge(params)
32
+ {:user_id => nsid}.merge(params)
95
33
  end
96
34
 
97
- def media_from_user(user_nsid, params = {})
35
+ def media_from_user(nsid, params = {})
98
36
  get 'flickr.people.getPhotos',
99
- ensure_media({:user_id => user_nsid}.merge(params))
37
+ ensure_media({:user_id => nsid}.merge(params))
100
38
  end
101
39
 
102
- def public_media_from_user(user_nsid, params = {})
40
+ def public_media_from_user(nsid, params = {})
103
41
  get 'flickr.people.getPublicPhotos',
104
- ensure_media({:user_id => user_nsid}.merge(params))
42
+ ensure_media({:user_id => nsid}.merge(params))
105
43
  end
106
44
 
107
- #--
108
45
  # photos
109
46
  def add_media_tags(media_id, tags, params = {})
110
47
  post 'flickr.photos.addTags',
@@ -120,9 +57,9 @@ module Flickrie
120
57
  get 'flickr.photos.getContactsPhotos', ensure_media(params)
121
58
  end
122
59
 
123
- def public_media_from_user_contacts(user_nsid, params = {})
60
+ def public_media_from_user_contacts(nsid, params = {})
124
61
  get 'flickr.photos.getContactsPublicPhotos',
125
- ensure_media({:user_id => user_nsid}.merge(params))
62
+ ensure_media({:user_id => nsid}.merge(params))
126
63
  end
127
64
 
128
65
  def get_media_context(media_id, params = {})
@@ -163,29 +100,26 @@ module Flickrie
163
100
  get 'flickr.photos.search', ensure_media(params)
164
101
  end
165
102
 
166
- #--
167
103
  # photos.upload
168
104
  def check_upload_tickets(tickets, params = {})
169
105
  get 'flickr.photos.upload.checkTickets',
170
106
  {:tickets => tickets}.merge(params)
171
107
  end
172
108
 
173
- #--
174
109
  # photos.licenses
175
110
  def get_licenses(params = {})
176
111
  get 'flickr.photos.licenses.getInfo', params
177
112
  end
178
113
 
179
- #--
180
114
  # photosets
181
115
  def get_set_info(set_id, params = {})
182
116
  get 'flickr.photosets.getInfo',
183
117
  {:photoset_id => set_id}.merge(params)
184
118
  end
185
119
 
186
- def sets_from_user(user_nsid, params = {})
120
+ def sets_from_user(nsid, params = {})
187
121
  get 'flickr.photosets.getList',
188
- {:user_id => user_nsid}.merge(params)
122
+ {:user_id => nsid}.merge(params)
189
123
  end
190
124
 
191
125
  def media_from_set(set_id, params = {})
@@ -193,7 +127,6 @@ module Flickrie
193
127
  ensure_media({:photoset_id => set_id}.merge(params))
194
128
  end
195
129
 
196
- #--
197
130
  # test
198
131
  def test_login(params = {})
199
132
  get 'flickr.test.login', params
@@ -2,28 +2,27 @@ module Flickrie
2
2
  class Instance
3
3
  attr_reader :access_token, :access_secret
4
4
 
5
+ # Initializes a new authenticated instance. Example:
6
+ #
7
+ # flickrie = Flickrie::Instance.new("ACCESS_TOKEN", "ACCESS_SECRET")
8
+ # flickrie.find_user_by_email("...")
5
9
  def initialize(access_token, access_secret)
6
10
  @access_token, @access_secret = access_token, access_secret
7
11
  end
8
12
 
9
- # ==== Example
10
- #
11
- # flickrie = Flickrie::Instance.new("ACCESS_TOKEN", "ACCESS_SECRET")
12
- #
13
- # flickrie.client.get "flickr.photos.licenses.getInfo"
14
- # flickrie.client.post "flickr.photos.licenses.setLicense", :photo_id => 1241497, :license_id => 2
13
+ # See {Flickrie.client} for more info.
15
14
  def client
16
15
  @client ||= Flickrie.new_client(access_token_hash)
17
16
  end
18
17
 
19
- def upload_client
20
- @upload_client ||= Flickrie.new_upload_client(access_token_hash)
21
- end
22
-
23
18
  include ApiMethods
24
19
 
25
20
  private
26
21
 
22
+ def upload_client
23
+ @upload_client ||= Flickrie.new_upload_client(access_token_hash)
24
+ end
25
+
27
26
  def access_token_hash
28
27
  {:token => access_token, :secret => access_secret}
29
28
  end
@@ -1,20 +1,32 @@
1
1
  module Flickrie
2
2
  class Location
3
+ # @!parse attr_reader :latitude
3
4
  def latitude() @info['latitude'] end
5
+ # @!parse attr_reader :longitude
4
6
  def longitude() @info['longitude'] end
7
+ # @!parse attr_reader :accuracy
5
8
  def accuracy() @info['accuracy'] end
9
+ # @!parse attr_reader :context
6
10
  def context() Integer(@info['context']) rescue nil end
7
11
 
12
+ # @!parse attr_reader :neighbourhood
8
13
  def neighbourhood() new_area('neighbourhood') end
14
+ # @!parse attr_reader :locality
9
15
  def locality() new_area('locality') end
16
+ # @!parse attr_reader :county
10
17
  def county() new_area('county') end
18
+ # @!parse attr_reader :region
11
19
  def region() new_area('region') end
20
+ # @!parse attr_reader :country
12
21
  def country() new_area('country') end
13
22
 
23
+ # @!parse attr_reader :place_id
14
24
  def place_id() @info['place_id'] end
25
+ # @!parse attr_reader :woeid
15
26
  def woeid() @info['woeid'] end
16
27
 
17
28
  def [](key) @info[key] end
29
+ # @!parse attr_reader :hash
18
30
  def hash() @info end
19
31
 
20
32
  private
@@ -7,58 +7,94 @@ require 'date'
7
7
 
8
8
  module Flickrie
9
9
  module Media
10
+ # @!parse attr_reader :id
10
11
  def id() @info['id'] end
12
+ # @!parse attr_reader :secret
11
13
  def secret() @info['secret'] end
14
+ # @!parse attr_reader :server
12
15
  def server() @info['server'] end
16
+ # @!parse attr_reader :farm
13
17
  def farm() @info['farm'] end
18
+ # @!parse attr_reader :title
14
19
  def title() @info['title'] end
20
+ # @!parse attr_reader :description
15
21
  def description() @info['description'] end
22
+ # @!parse attr_reader :media_status
16
23
  def media_status() @info['media_status'] end
24
+ # @!parse attr_reader :path_alias
17
25
  def path_alias() @info['pathalias'] end
18
26
 
27
+ # @!parse attr_reader :camera
19
28
  def camera() @info['camera'] end
20
- # ==== Example
29
+ # Returns exif of the photo/video. Example:
21
30
  #
22
- # photo.exif.get('Model') # => 'Canon PowerShot G12'
31
+ # photo.exif.get('Model') # => 'Canon PowerShot G12'
23
32
  #
24
- # photo.exif.get('X-Resolution', :data => 'raw') # => '180'
25
- # photo.exif.get('X-Resolution', :data => 'clean') # => '180 dpi'
26
- # photo.exif.get('X-Resolution') # => '180 dpi'
33
+ # photo.exif.get('X-Resolution', :data => 'raw') # => '180'
34
+ # photo.exif.get('X-Resolution', :data => 'clean') # => '180 dpi'
35
+ # photo.exif.get('X-Resolution') # => '180 dpi'
36
+ #
37
+ # @return [Flickrie::Media::Exif]
38
+ #
39
+ # @!parse attr_reader :exif
27
40
  def exif() Exif.new(@info['exif']) rescue nil end
28
41
 
42
+ # @!parse attr_reader :views_count
29
43
  def views_count() Integer(@info['views']) rescue nil end
44
+ # @!parse attr_reader :comments_count
30
45
  def comments_count() Integer(@info['comments_count']) rescue nil end
31
46
 
32
- # Returns an instance of Flickrie::Location
47
+ # @return [Flickrie::Location]
48
+ #
49
+ # @!parse attr_reader :location
33
50
  def location() Location.new(@info['location']) rescue nil end
34
- # Returns an instance of Flickrie::Media::Visibility
51
+ # @return [Flickrie::Media::Visibility]
52
+ #
53
+ # @!parse attr_reader :geo_permissions
35
54
  def geo_permissions() Visibility.new(@info['geoperms']) rescue nil end
36
55
 
37
- # Returns an array of Flickrie::Media::Tag
56
+ # @return [Array<Flickrie::Media::Tag>]
57
+ #
58
+ # @!parse attr_reader :tags
38
59
  def tags() @info['tags'].map { |info| Tag.new(info) } rescue nil end
39
- # Returns an array of Flickrie::Media::Tag
60
+ # @return [Array<Flickrie::Media::Tag>]
61
+ #
62
+ # @!parse attr_reader :machine_tags
40
63
  def machine_tags() tags.select { |tag| tag.machine_tag? } rescue nil end
41
64
 
42
- # Returns an instance of Flickrie::License
65
+ # @return [Flickrie::License]
66
+ # @!parse attr_reader :license
43
67
  def license() License.new(@info['license']) rescue nil end
44
68
 
69
+ # @!parse attr_reader :posted_at
45
70
  def posted_at() Time.at(Integer(@info['dates']['posted'])) rescue nil end
71
+ # @!parse attr_reader :uploaded_at
46
72
  def uploaded_at() Time.at(Integer(@info['dates']['uploaded'])) rescue nil end
73
+ # @!parse attr_reader :updated_at
47
74
  def updated_at() Time.at(Integer(@info['dates']['lastupdate'])) rescue nil end
75
+ # @!parse attr_reader :taken_at
48
76
  def taken_at() DateTime.parse(@info['dates']['taken']).to_time rescue nil end
77
+ # @!parse attr_reader :taken_at_granularity
49
78
  def taken_at_granularity() Integer(@info['dates']['takengranularity']) rescue nil end
50
79
 
51
- # Returns an instance of Flickrie::User
80
+ # @return [Flickrie::User]
81
+ #
82
+ # @!parse attr_reader :owner
52
83
  def owner() User.new(@info['owner']) rescue nil end
53
84
 
85
+ # @!parse attr_reader :safety_level
54
86
  def safety_level() Integer(@info['safety_level']) rescue nil end
55
87
 
88
+ # @!parse attr_reader :safe?
56
89
  def safe?() safety_level <= 1 if safety_level end
90
+ # @!parse attr_reader :moderate?
57
91
  def moderate?() safety_level == 2 if safety_level end
92
+ # @!parse attr_reader :restricted?
58
93
  def restricted?() safety_level == 3 if safety_level end
59
94
 
60
- #--
61
- # TODO: Take care about the url from #get_info
95
+ # @comment TODO: Take care about the url from #get_info
96
+ #
97
+ # @!parse attr_reader :url
62
98
  def url
63
99
  if owner and id
64
100
  "http://www.flickr.com/photos/#{owner.nsid}/#{id}"
@@ -67,37 +103,57 @@ module Flickrie
67
103
  end
68
104
  end
69
105
 
70
- # Returns an instance of Flickrie::Media::Visibility
106
+ # @return [Flickrie::Media::Visibility]
107
+ #
108
+ # @!parse attr_reader :visibility
71
109
  def visibility() Visibility.new(@info['visibility']) rescue nil end
72
110
 
111
+ # @!parse attr_reader :primary?
73
112
  def primary?() Integer(@info['isprimary']) == 1 rescue nil end
74
113
 
114
+ # @!parse attr_reader :favorite?
75
115
  def favorite?() Integer(@info['isfavorite']) == 1 rescue nil end
76
116
 
117
+ # @!parse attr_reader :can_comment?
77
118
  def can_comment?() Integer(@info['editability']['cancomment']) == 1 rescue nil end
119
+ # @!parse attr_reader :can_add_meta?
78
120
  def can_add_meta?() Integer(@info['editability']['canaddmeta']) == 1 rescue nil end
79
121
 
122
+ # @!parse attr_reader :can_everyone_comment?
80
123
  def can_everyone_comment?() Integer(@info['publiceditability']['cancomment']) == 1 rescue nil end
124
+ # @!parse attr_reader :can_everyone_add_meta?
81
125
  def can_everyone_add_meta?() Integer(@info['publiceditability']['canaddmeta']) == 1 rescue nil end
82
126
 
127
+ # @!parse attr_reader :can_download?
83
128
  def can_download?() Integer(@info['usage']['candownload']) == 1 rescue nil end
129
+ # @!parse attr_reader :can_blog?
84
130
  def can_blog?() Integer(@info['usage']['canblog']) == 1 rescue nil end
131
+ # @!parse attr_reader :can_print?
85
132
  def can_print?() Integer(@info['usage']['canprint']) == 1 rescue nil end
133
+ # @!parse attr_reader :can_share?
86
134
  def can_share?() Integer(@info['usage']['canshare']) == 1 rescue nil end
87
135
 
136
+ # @!parse attr_reader :has_people?
88
137
  def has_people?() Integer(@info['people']['haspeople']) == 1 rescue nil end
89
138
 
139
+ # @!parse attr_reader :faved?
90
140
  def faved?() Integer(@info['is_faved']) == 1 rescue nil end
91
141
 
92
- # Returns an array of Flickrie::Media::Note
142
+ # @return [Array<Flickrie::Media::Note>]
143
+ #
144
+ # @!parse attr_reader :notes
93
145
  def notes() @info['notes']['note'].map { |hash| Note.new(hash) } rescue nil end
94
146
 
95
- # Returns an array of Flickrie::User
147
+ # @return [Array<Flickrie::User>]
148
+ #
149
+ # @!parse attr_reader :favorites
96
150
  def favorites() @info['person'].map { |info| User.new(info) } rescue nil end
97
151
 
98
152
  def [](key) @info[key] end
153
+ # @!parse attr_reader :hash
99
154
  def hash() @info end
100
155
 
156
+ # Same as calling `Flickrie.get_(photo|video)_info(id)`.
101
157
  def get_info(params = {}, info = nil)
102
158
  info ||= Flickrie.client.get_media_info(id, params).body['photo']
103
159
  @info.update(info)
@@ -112,6 +168,7 @@ module Flickrie
112
168
  self
113
169
  end
114
170
 
171
+ # Same as calling `Flickrie.get_(photo|video)_info(id)`.
115
172
  def get_exif(params = {}, info = nil)
116
173
  info ||= Flickrie.client.get_media_exif(id, params).body['photo']
117
174
  @info.update(info)
@@ -119,6 +176,7 @@ module Flickrie
119
176
  self
120
177
  end
121
178
 
179
+ # Same as calling `Flickrie.get_(photo|video)_info(id)`.
122
180
  def get_favorites(params = {}, info = nil)
123
181
  info ||= Flickrie.client.get_media_favorites(id, params).body['photo']
124
182
  @info.update(info)
@@ -130,7 +188,8 @@ module Flickrie
130
188
  @info = info
131
189
  end
132
190
 
133
- module ClassMethods # :nodoc:
191
+ # @private
192
+ module ClassMethods
134
193
  def from_set(hash)
135
194
  hash['photo'].map do |info|
136
195
  info['owner'] = {
@@ -224,10 +283,12 @@ module Flickrie
224
283
  end
225
284
  extend(ClassMethods)
226
285
 
286
+ # @private
227
287
  def self.included(klass)
228
288
  klass.extend(ClassMethods)
229
289
  end
230
290
 
291
+ # @private
231
292
  def self.new(info)
232
293
  eval(info['media'].capitalize).new(info)
233
294
  end
@@ -1,13 +1,14 @@
1
1
  module Flickrie
2
2
  module Media
3
3
  class Exif
4
- # ==== Example
4
+ # Gets exif. Example:
5
5
  #
6
- # photo.exif.get('Model') # => 'Canon PowerShot G12'
6
+ # photo.exif.get('Model') # => 'Canon PowerShot G12'
7
+ #
8
+ # photo.exif.get('X-Resolution', :data => 'raw') # => '180'
9
+ # photo.exif.get('X-Resolution', :data => 'clean') # => '180 dpi'
10
+ # photo.exif.get('X-Resolution') # => '180 dpi'
7
11
  #
8
- # photo.exif.get('X-Resolution', :data => 'raw') # => '180'
9
- # photo.exif.get('X-Resolution', :data => 'clean') # => '180 dpi'
10
- # photo.exif.get('X-Resolution') # => '180 dpi'
11
12
  #
12
13
  def get(key, options = {})
13
14
  hash = @info.find { |hash| hash['label'] == key }
@@ -19,6 +20,7 @@ module Flickrie
19
20
  end
20
21
 
21
22
  def [](key) @info[key] end
23
+ # @!parse attr_reader :hash
22
24
  def hash() @info end
23
25
 
24
26
  private