flickrie 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,9 +1,9 @@
1
1
  TODO.md
2
2
  Gemfile.lock
3
3
  pkg/
4
- doc/
5
4
  wiki/
6
5
  .DS_Store
7
6
  api_methods.md
8
7
  .bundle/
9
8
  .rspec
9
+ .yardoc/
data/.yardopts ADDED
@@ -0,0 +1,11 @@
1
+ --charset utf-8
2
+ --readme README.md
3
+ --markup markdown
4
+ --title "Flickrie documentation"
5
+ --exclude "lib/flickrie/middleware.rb"
6
+ --exclude "lib/flickrie/client.rb"
7
+ --exclude "lib/flickrie/upload_client.rb"
8
+ --tag api_method:"Flickr API method"
9
+ --tag comment
10
+ --hide-tag comment
11
+ --no-private
data/CHANGELOG.md CHANGED
@@ -1,44 +1,48 @@
1
1
  # Flickrie changelog
2
2
 
3
+ ## Version 1.0.1
4
+
5
+ - Transfered the documentation to YARD. See the readme for the updated link.
6
+
3
7
  ## Version 1.0.0
4
8
 
5
- - Changes that are backwards compatible:
9
+ ### Changes that are backwards compatible
6
10
 
7
- -- Fixed content type not being passed to the file you're uploading
11
+ - Fixed content type not being passed to the file you're uploading
8
12
  if you specified it directly.
9
13
 
10
- -- The request will now be retried once more if it timeouts
14
+ - The request will now be retried once more if it timeouts
11
15
 
12
- -- In authentication:
13
- --- you can now call `request_token.authorize_url` instead of `request_token.get_authorization_url`.
14
- --- you can now call `request_token.get_access_token(code)` instead of `Flickrie::OAuth.get_access_token(code, request_token)`.
15
- --- you also get the infomation about the user who just authenticated,
16
+ - In authentication:
17
+ ** you can now call `request_token.authorize_url` instead of `request_token.get_authorization_url`.
18
+ ** you can now call `request_token.get_access_token(code)` instead of `Flickrie::OAuth.get_access_token(code, request_token)`.
19
+ ** you also get the infomation about the user who just authenticated,
16
20
  which you can then access with `access_token.user_info`
17
21
  (it's a Hash with keys `:fullname`, `:user_nsid` and `:username`)
18
22
 
19
- -- When calling `Flickrie.get_photos_counts`, the `Flickrie::MediaCount`
20
- now also has attributes `#time_interval` (alias for `#date_range`),
21
- `#from` and `#to`.
23
+ - When calling `Flickrie.get_photos_counts`, the `Flickrie::MediaCount`
24
+ now also has attributes `#time_interval` (alias for `#date_range`),
25
+ `#from` and `#to`.
22
26
 
23
- - Changes that are **not** backwards compatible:
27
+ ### Changes that are NOT backwards compatible
24
28
 
25
- -- If you're passing in the content type of the file you're uploading,
26
- the parameter is now called `:content_type`, not `:mime_type`.
29
+ - If you're passing in the content type of the file you're uploading,
30
+ the parameter is now called `:content_type`, not `:mime_type`.
27
31
 
28
- -- If there is a problem in obtaining the access token, `Flickrie::Error`
29
- is now raised, instead of `Flickrie::OAuth::Error`.
32
+ - If there is a problem in obtaining the access token, `Flickrie::Error`
33
+ is now raised, instead of `Flickrie::OAuth::Error`.
30
34
 
31
- -- When you're calling `request_token.get_authorization_url`, if you want to
32
- specifiy permissions, you now have to pass the `:perms` option,
33
- instead of `:permissions`. In this way you can pass any parameter,
34
- and it will be appended to the URL (in case Flickr adds a new parameter).
35
+ - When you're calling `request_token.get_authorization_url`, if you want to
36
+ specifiy permissions, you now have to pass the `:perms` option,
37
+ instead of `:permissions`. In this way you can pass any parameter,
38
+ and it will be appended to the URL (in case Flickr adds a new parameter).
35
39
 
36
- -- When you have a `Flickrie::User` instance, the
37
- `Flickrie::User#time_zone` now returns a struct with `#label` and
38
- `#offset` attributes (before it returned a `Hash` with those keys).
40
+ - When you have a `Flickrie::User` instance, the
41
+ `Flickrie::User#time_zone` now returns a struct with `#label` and
42
+ `#offset` attributes (before it returned a `Hash` with those keys).
39
43
 
40
- -- When you call `Flickrie.get_media_context`, the result is now a
41
- struct with attributes `#count`, `#previous`, `#next`.
44
+ - When you call `Flickrie.get_media_context`, the result is now a
45
+ struct with attributes `#count`, `#previous`, `#next`.
42
46
 
43
47
  ## Version 0.7.3
44
48
 
data/README.md CHANGED
@@ -45,7 +45,7 @@ You first need to install the gem.
45
45
  Then, if you're using Bundler in your project, put it into your `Gemfile`:
46
46
 
47
47
  ```ruby
48
- gem "flickrie"
48
+ gem "flickrie", "~> 1.0.0"
49
49
  ```
50
50
 
51
51
  Then in your app you set the API key and shared secret (if you don't have them
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ task :spec do |task, args|
8
8
  system "rspec -Ispec"
9
9
  end
10
10
 
11
- Dir["spec/*_spec.rb"].each do |spec|
11
+ Dir["spec/flickrie/*_spec.rb"].each do |spec|
12
12
  task_name = File.basename(spec)[/.+(?=_spec\.rb)/]
13
13
  task :"spec:#{task_name}" do
14
14
  system "rspec -Ispec #{spec}"
data/lib/flickrie.rb CHANGED
@@ -1,6 +1,161 @@
1
+ require 'flickrie/client'
2
+ require 'flickrie/upload_client'
3
+ require 'flickrie/middleware'
4
+ require 'faraday_middleware'
5
+
6
+ module Flickrie
7
+ DEFAULTS = {
8
+ :open_timeout => 3,
9
+ :timeout => 4
10
+ }
11
+
12
+ class << self
13
+ # Your API key. If you don't have one already, you can apply for it
14
+ # [here](http://www.flickr.com/services/apps/create/apply) (you first
15
+ # have to sign in).
16
+ attr_accessor :api_key
17
+
18
+ # Your shared secret. This goes in pair with your API key.
19
+ # If you don't have the API key already, you can apply for it
20
+ # [here](http://www.flickr.com/services/apps/create/apply) (you first
21
+ # have to sign in).
22
+ attr_accessor :shared_secret
23
+
24
+ # Time to wait for the connection to Flickr to open (in seconds).
25
+ # Otherwise `Faraday::Error::TimeoutError` is raised. If you're in a
26
+ # web application, you may want to rescue this exception and display
27
+ # some custom error page (telling the user to try to load the page again,
28
+ # for example).
29
+ #
30
+ # You may want to override this if you notice that your connection often
31
+ # timeouts.
32
+ #
33
+ # Defaults to 3 seconds.
34
+ attr_accessor :open_timeout
35
+
36
+ # Time to wait for the first block of response from Flickr to be read
37
+ # (in seconds). Otherwise `Faraday::Error::TimeoutError` is raised.
38
+ # If you're in a web application, you may want to rescue this exception
39
+ # and display some custom error page (telling the user to try to load
40
+ # the page again, for example).
41
+ #
42
+ # You may want to override this if you notice that your connection often
43
+ # timeouts.
44
+ #
45
+ # Defaults to 4 seconds.
46
+ attr_accessor :timeout
47
+
48
+ # Access token (token + secret) is used to make authenticated requests.
49
+ # Access tokens are unique for each Flickr user, and they last forever.
50
+ # So, if your app is of that kind that it asks users to authenticate through Flickr,
51
+ # after you get their access token, you can store it somewhere in the database,
52
+ # and you never have to ask that user to authenticate again.
53
+ #
54
+ # You can obtain the access token in various ways:
55
+ #
56
+ # - using this gem's [authentication proccess](https://github.com/janko-m/flickrie#authentication)
57
+ #
58
+ # - using my [flickr_auth](https://github.com/janko-m/flickr_auth) gem
59
+ #
60
+ # - using [omniauth](https://github.com/intridea/omniauth) with the
61
+ # [omniauth-flickr](https://github.com/timbreitkreutz/omniauth-flickr) strategy
62
+ attr_accessor :access_token, :access_secret
63
+
64
+ [
65
+ :api_key, :shared_secret, :timeout,
66
+ :open_timeout, :access_token, :access_secret
67
+ ].
68
+ each do |attribute|
69
+ define_method "#{attribute}=" do |value|
70
+ instance_variable_set "@#{attribute}", value
71
+ @client = @upload_client = nil
72
+ end
73
+ end
74
+
75
+ # This is for manual use (for example, if I haven't covered something yet, and you really need it).
76
+ # Here's an example:
77
+ #
78
+ # response = Flickrie.client.get "flickr.photos.getInfo", :photo_id => 8423943
79
+ # response.body['photo']['id'] # => 8423943
80
+ # response.body['photo']['description'] # => "..."
81
+ #
82
+ # Flickrie.client.post "flickr.photos.licenses.setLicense", :photo_id => 1241497, :license_id => 2
83
+ #
84
+ # For the full list of available API methods, see [this page](http://www.flickr.com/services/api/).
85
+ #
86
+ # @return [HTTP response] A Faraday HTTP response
87
+ def client
88
+ @client ||= new_client
89
+ end
90
+
91
+ # @private
92
+ def new_client(access_token = {})
93
+ params = {
94
+ :url => 'http://api.flickr.com/services/rest',
95
+ :params => {
96
+ :format => 'json',
97
+ :nojsoncallback => '1',
98
+ :api_key => api_key
99
+ },
100
+ :request => {
101
+ :open_timeout => open_timeout || DEFAULTS[:open_timeout],
102
+ :timeout => timeout || DEFAULTS[:timeout]
103
+ }
104
+ }
105
+
106
+ Client.new(params) do |b|
107
+ b.use Middleware::Retry
108
+ b.use FaradayMiddleware::OAuth,
109
+ :consumer_key => api_key,
110
+ :consumer_secret => shared_secret,
111
+ :token => access_token[:token] || self.access_token,
112
+ :token_secret => access_token[:secret] || self.access_secret
113
+
114
+ b.use Middleware::StatusCheck
115
+ b.use FaradayMiddleware::ParseJson
116
+ b.use Middleware::OAuthCheck
117
+
118
+ b.adapter :net_http
119
+ end
120
+ end
121
+
122
+ # @private
123
+ def upload_client
124
+ @upload_client ||= new_upload_client
125
+ end
126
+
127
+ # @private
128
+ def new_upload_client(access_token = {})
129
+ params = {
130
+ :url => 'http://api.flickr.com/services',
131
+ :request => {
132
+ :open_timeout => open_timeout || DEFAULTS[:open_timeout]
133
+ }
134
+ }
135
+
136
+ UploadClient.new(params) do |b|
137
+ b.use Middleware::Retry
138
+ b.use FaradayMiddleware::OAuth,
139
+ :consumer_key => api_key,
140
+ :consumer_secret => shared_secret,
141
+ :token => access_token[:token] || self.access_token,
142
+ :token_secret => access_token[:secret] || self.access_secret
143
+ b.request :multipart
144
+
145
+ b.use Middleware::UploadStatusCheck
146
+ b.use FaradayMiddleware::ParseXml
147
+ b.use Middleware::OAuthCheck
148
+
149
+ b.adapter :net_http
150
+ end
151
+ end
152
+ end
153
+ end
154
+
1
155
  require 'flickrie/api_methods'
2
- require 'flickrie/instance'
3
156
 
4
157
  module Flickrie
5
158
  extend ApiMethods
6
159
  end
160
+
161
+ require 'flickrie/instance'
@@ -13,14 +13,20 @@ require 'flickrie/ticket'
13
13
 
14
14
  module Flickrie
15
15
  module ApiMethods
16
- # ==== Example
16
+ # For uploading photos and videos to Flickr. Example:
17
17
  #
18
- # path = File.expand_path("photo.jpg")
19
- # id = Flickrie.upload(path, :title => "Me and Jessica", :description => "...")
20
- # photo = Flickrie.get_photo_info(id)
21
- # photo.title # => "Me and Jessica"
18
+ # path = File.expand_path("photo.jpg")
19
+ # photo_id = Flickrie.upload(path, :title => "Me and Jessica", :description => "...")
20
+ # photo = Flickrie.get_photo_info(photo_id)
21
+ # photo.title # => "Me and Jessica"
22
22
  #
23
- # If the <tt>:async => 1</tt> option is passed, returns the ticket ID.
23
+ # If the `:async => 1` option is passed, returns the ticket ID (see {#check\_upload\_tickets}).
24
+ #
25
+ # @param media [File, String] A file or a path to the file you want to upload
26
+ # @param params [Hash] Options for uploading (see [this page](http://www.flickr.com/services/api/upload.api.html))
27
+ # @return [String] New photo's ID, or ticket's ID, if `:async => 1` is passed
28
+ #
29
+ # @note This method requires authentication with "write" permissions.
24
30
  def upload(media, params = {})
25
31
  response = upload_client.upload(media, params)
26
32
  if params[:async] == 1
@@ -30,15 +36,20 @@ module Flickrie
30
36
  end
31
37
  end
32
38
 
33
- # ==== Example
39
+ # For replacing photos and videos on Flickr. Example:
40
+ #
41
+ # path = File.expand_path("photo.jpg")
42
+ # photo_id = 42374 # ID of the photo to be replaced
43
+ # id = Flickrie.replace(path, photo_id)
34
44
  #
35
- # path = File.expand_path("photo.jpg")
36
- # photo_id = 42374 # ID of the photo to be replaced
37
- # id = Flickrie.replace(path, photo_id, :title => "Me and Jessica", :description => "...")
38
- # photo = Flickrie.get_photo_info(id)
39
- # photo.title # => "Me and Jessica"
45
+ # If the `:async => 1` option is passed, returns the ticket ID (see {#check\_upload\_tickets}).
40
46
  #
41
- # If the <tt>:async => 1</tt> option is passed, returns the ticket ID.
47
+ # @param media [File, String] A file or a path to the file you want to upload
48
+ # @param media_id [String, Fixnum] The ID of the photo/video to be replaced
49
+ # @param params [Hash] Options for replacing (see [this page](http://www.flickr.com/services/api/replace.api.html))
50
+ # @return [String] New photo's ID, or ticket's ID, if `:async => 1` is passed
51
+ #
52
+ # @note This method requires authentication with "write" permissions.
42
53
  def replace(media, media_id, params = {})
43
54
  response = upload_client.replace(media, media_id, params)
44
55
  if params[:async] == 1
@@ -48,94 +59,199 @@ module Flickrie
48
59
  end
49
60
  end
50
61
 
51
- #--
52
- # people
62
+ # Fetches the Flickr user with the given email.
63
+ #
64
+ # @param email [String]
65
+ # @return [Flickrie::User]
66
+ # @api_method [flickr.people.findByEmail](http://www.flickr.com/services/api/flickr.people.findByEmail.html)
53
67
  def find_user_by_email(email, params = {})
54
68
  response = client.find_user_by_email(email, params)
55
69
  User.from_find(response.body['user'])
56
70
  end
57
71
 
72
+ # Fetches the Flickr user with the given username.
73
+ #
74
+ # @param username [String]
75
+ # @return [Flickrie::User]
76
+ # @api_method [flickr.people.findByUsername](http://www.flickr.com/services/api/flickr.people.findByUsername.html)
58
77
  def find_user_by_username(username, params = {})
59
78
  response = client.find_user_by_username(username, params)
60
79
  User.from_find(response.body['user'])
61
80
  end
62
81
 
63
- def get_user_info(user_nsid, params = {})
64
- response = client.get_user_info(user_nsid, params)
82
+ # Fetches the Flickr user with the given NSID.
83
+ #
84
+ # @param nsid [String]
85
+ # @return [Flickrie::User]
86
+ # @api_method [flickr.people.getInfo](http://www.flickr.com/services/api/flickr.people.getInfo.html)
87
+ def get_user_info(nsid, params = {})
88
+ response = client.get_user_info(nsid, params)
65
89
  User.from_info(response.body['person'])
66
90
  end
67
91
 
68
- def media_from_user(user_nsid, params = {})
69
- response = client.media_from_user(user_nsid, params)
92
+ # Fetches photos and videos from the Flickr user with the given NSID.
93
+ #
94
+ # @param nsid [String]
95
+ # @return [Array<Flickrie::Photo, Flickrie::Video>]
96
+ # @api_method [flickr.people.getPhotos](http://www.flickr.com/services/api/flickr.people.getPhotos.html)
97
+ #
98
+ # @note This method requires authentication with "read" permissions.
99
+ def media_from_user(nsid, params = {})
100
+ response = client.media_from_user(nsid, params)
70
101
  Media.from_user(response.body['photos'])
71
102
  end
72
- def photos_from_user(user_nsid, params = {})
73
- media_from_user(user_nsid, params).
103
+ # Fetches photos from the Flickr user with the given NSID.
104
+ #
105
+ # @param nsid [String]
106
+ # @return [Array<Flickrie::Photo>]
107
+ # @api_method [flickr.people.getPhotos](http://www.flickr.com/services/api/flickr.people.getPhotos.html)
108
+ #
109
+ # @note This method requires authentication with "read" permissions.
110
+ def photos_from_user(nsid, params = {})
111
+ media_from_user(nsid, params).
74
112
  select { |media| media.is_a?(Photo) }
75
113
  end
76
- def videos_from_user(user_nsid, params = {})
77
- media_from_user(user_nsid, params).
114
+ # Fetches videos from the Flickr user with the given NSID.
115
+ #
116
+ # @param nsid [String]
117
+ # @return [Array<Flickrie::Video>]
118
+ # @api_method [flickr.people.getPhotos](http://www.flickr.com/services/api/flickr.people.getPhotos.html)
119
+ #
120
+ # @note This method requires authentication with "read" permissions.
121
+ def videos_from_user(nsid, params = {})
122
+ media_from_user(nsid, params).
78
123
  select { |media| media.is_a?(Video) }
79
124
  end
80
125
 
81
- def public_media_from_user(user_nsid, params = {})
82
- response = client.public_media_from_user(user_nsid, params)
126
+ # Fetches public photos and videos from the Flickr user with the given
127
+ # NSID.
128
+ #
129
+ # @param nsid [String]
130
+ # @return [Array<Flickrie::Photo, Flickrie::Video>]
131
+ # @api_method [flickr.people.getPublicPhotos](http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html)
132
+ def public_media_from_user(nsid, params = {})
133
+ response = client.public_media_from_user(nsid, params)
83
134
  Media.from_user(response.body['photos'])
84
135
  end
85
- def public_photos_from_user(user_nsid, params = {})
86
- public_media_from_user(user_nsid, params).
136
+ # Fetches public photos from the Flickr user with the given NSID.
137
+ #
138
+ # @param nsid [String]
139
+ # @return [Array<Flickrie::Photo>]
140
+ # @api_method [flickr.people.getPublicPhotos](http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html)
141
+ def public_photos_from_user(nsid, params = {})
142
+ public_media_from_user(nsid, params).
87
143
  select { |media| media.is_a?(Photo) }
88
144
  end
89
- def public_videos_from_user(user_nsid, params = {})
90
- public_media_from_user(user_nsid, params).
145
+ # Fetches public videos from the Flickr user with the given NSID.
146
+ #
147
+ # @param nsid [String]
148
+ # @return [Array<Flickrie::Video>]
149
+ # @api_method [flickr.people.getPublicPhotos](http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html)
150
+ def public_videos_from_user(nsid, params = {})
151
+ public_media_from_user(nsid, params).
91
152
  select { |media| media.is_a?(Video) }
92
153
  end
93
154
 
94
- #--
95
- # photos
155
+ # Add tags to the photo/video with the given ID.
156
+ #
157
+ # @param media_id [String, Fixnum]
158
+ # @param tags [String] A space delimited string with tags
159
+ # @api_method [flickr.photos.addTags](http://www.flickr.com/services/api/flickr.photos.addTags.html)
160
+ #
161
+ # @note This method requires authentication with "write" permissions.
96
162
  def add_media_tags(media_id, tags, params = {})
97
163
  client.add_media_tags(media_id, tags, params)
164
+ nil
98
165
  end
99
166
  alias add_photo_tags add_media_tags
100
167
  alias add_video_tags add_media_tags
101
168
 
169
+ # Deletes the photo/video with the given ID.
170
+ #
171
+ # @param media_id [String, Fixnum]
172
+ # @api_method [flickr.photos.delete](http://www.flickr.com/services/api/flickr.photos.delete.html)
173
+ #
174
+ # @note This method requires authentication with "delete" permissions.
102
175
  def delete_media(media_id, params = {})
103
176
  client.delete_media(media_id, params)
104
- media_id
177
+ nil
105
178
  end
106
179
  alias delete_photo delete_media
107
180
  alias delete_video delete_media
108
181
 
182
+ # Fetches photos and videos from contacts of the user who authenticated.
183
+ #
184
+ # @param params [Hash] Options for this API method (see the link below)
185
+ # @return [Array<Flickrie::Photo, Flickrie::Video>]
186
+ # @api_method [flickr.photos.getContactsPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html)
187
+ #
188
+ # @note This method requires authentication with "read" permissions.
109
189
  def media_from_contacts(params = {})
110
190
  response = client.media_from_contacts(params)
111
191
  Media.from_contacts(response.body['photos'])
112
192
  end
193
+ # Fetches photos from contacts of the user who authenticated.
194
+ #
195
+ # @param params [Hash] Options for this API method (see the link below)
196
+ # @return [Array<Flickrie::Photo>]
197
+ # @api_method [flickr.photos.getContactsPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html)
198
+ #
199
+ # @note This method requires authentication with "read" permissions.
113
200
  def photos_from_contacts(params = {})
114
201
  media_from_contacts(params).select { |media| media.is_a?(Photo) }
115
202
  end
203
+ # Fetches videos from contacts of the user who authenticated.
204
+ #
205
+ # @param params [Hash] Options for this API method (see the link below)
206
+ # @return [Array<Flickrie::Video>]
207
+ # @api_method [flickr.photos.getContactsPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPhotos.html)
208
+ #
209
+ # @note This method requires authentication with "read" permissions.
116
210
  def videos_from_contacts(params = {})
117
211
  media_from_contacts(params).select { |media| media.is_a?(Video) }
118
212
  end
119
213
 
120
- def public_media_from_user_contacts(user_nsid, params = {})
121
- response = client.public_media_from_user_contacts(user_nsid, params)
214
+ # Fetches public photos and videos from contacts of the user with the
215
+ # given NSID.
216
+ #
217
+ # @param nsid [String]
218
+ # @param params [Hash] Options for this API method (see the link below)
219
+ # @api_method [flickr.photos.getContactsPublicPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html)
220
+ def public_media_from_user_contacts(nsid, params = {})
221
+ response = client.public_media_from_user_contacts(nsid, params)
122
222
  Media.from_contacts(response.body['photos'])
123
223
  end
124
- def public_photos_from_user_contacts(user_nsid, params = {})
125
- public_media_from_user_contacts(user_nsid, params).
224
+ # Fetches public photos from contacts of the user with the
225
+ # given NSID.
226
+ #
227
+ # @param nsid [String]
228
+ # @param params [Hash] Options for this API method (see the link below)
229
+ # @api_method [flickr.photos.getContactsPublicPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html)
230
+ def public_photos_from_user_contacts(nsid, params = {})
231
+ public_media_from_user_contacts(nsid, params).
126
232
  select { |media| media.is_a?(Photo) }
127
233
  end
128
- def public_videos_from_user_contacts(user_nsid, params = {})
129
- public_media_from_user_contacts(user_nsid, params).
234
+ # Fetches public videos from contacts of the user with the
235
+ # given NSID.
236
+ #
237
+ # @param nsid [String]
238
+ # @param params [Hash] Options for this API method (see the link below)
239
+ # @api_method [flickr.photos.getContactsPublicPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html)
240
+ def public_videos_from_user_contacts(nsid, params = {})
241
+ public_media_from_user_contacts(nsid, params).
130
242
  select { |media| media.is_a?(Photo) }
131
243
  end
132
244
 
133
- # ==== Example
245
+ # Fetches context of the photo/video with the given ID. Example:
246
+ #
247
+ # context = Flickrie.get_photo_context(37124234)
248
+ # context.count # => 23
249
+ # context.previous # => #<Photo: id=2433240, ...>
250
+ # context.next # => #<Video: id=1282404, ...>
134
251
  #
135
- # context = Flickrie.get_photo_context(37124234)
136
- # context.count # => 23
137
- # context.previous # => #<Photo: id=2433240, ...>
138
- # context.next # => #<Video: id=1282404, ...>
252
+ # @param media_id [String, Fixnum]
253
+ # @return [Struct]
254
+ # @api_method [flickr.photos.getContext](http://www.flickr.com/services/api/flickr.photos.getContext.html)
139
255
  def get_media_context(media_id, params = {})
140
256
  response = client.get_media_context(media_id, params)
141
257
  Media.from_context(response.body)
@@ -143,7 +259,21 @@ module Flickrie
143
259
  alias get_photo_context get_media_context
144
260
  alias get_video_context get_media_context
145
261
 
146
- # Returns instances of Flickrie::MediaCount
262
+ # Fetches numbers of photos and videos for given date ranges. Example:
263
+ #
264
+ # require 'date'
265
+ # dates = [DateTime.parse("3rd Jan 2011").to_time, DateTime.parse("11th Aug 2011").to_time]
266
+ # counts = Flickrie.get_media_counts(:taken_dates => dates.map(&:to_i).join(','))
267
+ #
268
+ # count = counts.first
269
+ # count.value # => 24
270
+ # count.date_range # => 2011-01-03 01:00:00 +0100..2011-08-11 02:00:00 +0200
271
+ # count.date_range.begin # => 2011-01-03 01:00:00 +0100
272
+ # count.from # => 2011-01-03 01:00:00 +0100
273
+ #
274
+ # @param params [Hash] Options for this API method (see the link below)
275
+ # @return [Flickrie::MediaCount]
276
+ # @api_method [flickr.photos.getCounts](http://www.flickr.com/services/api/flickr.photos.getCounts.html)
147
277
  def get_media_counts(params = {})
148
278
  response = client.get_media_counts \
149
279
  MediaCount.ensure_utc(params)
@@ -153,28 +283,71 @@ module Flickrie
153
283
  alias get_photos_counts get_media_counts
154
284
  alias get_videos_counts get_media_counts
155
285
 
156
- # See Flickrie::Media#exif for details
286
+ # Fetches the exif for the photo with the given ID. Example:
287
+ #
288
+ # photo = Flickrie.get_photo_exif(27234987)
289
+ # photo.exif.get('Model') # => 'Canon PowerShot G12'
290
+ #
291
+ # photo.exif.get('X-Resolution', :data => 'raw') # => '180'
292
+ # photo.exif.get('X-Resolution', :data => 'clean') # => '180 dpi'
293
+ # photo.exif.get('X-Resolution') # => '180 dpi'
294
+ #
295
+ # @param photo_id [String, Fixnum]
296
+ # @return [Flickrie::Photo]
297
+ # @api_method [flickr.photos.getExif](http://www.flickr.com/services/api/flickr.photos.getExif.html)
157
298
  def get_photo_exif(photo_id, params = {})
158
299
  response = client.get_media_exif(photo_id, params)
159
300
  Photo.from_exif(response.body['photo'])
160
301
  end
161
- # See Flickrie::Media#exif for details
302
+ # Fetches the exif for the video with the given ID. Example:
303
+ #
304
+ # video = Flickrie.get_video_exif(27234987)
305
+ # video.exif.get('Model') # => 'Canon PowerShot G12'
306
+ #
307
+ # video.exif.get('X-Resolution', :data => 'raw') # => '180'
308
+ # video.exif.get('X-Resolution', :data => 'clean') # => '180 dpi'
309
+ # video.exif.get('X-Resolution') # => '180 dpi'
310
+ #
311
+ # @param video_id [String, Fixnum]
312
+ # @return [Flickrie::Video]
313
+ # @api_method [flickr.photos.getExif](http://www.flickr.com/services/api/flickr.photos.getExif.html)
162
314
  def get_video_exif(video_id, params = {})
163
315
  response = client.get_media_exif(video_id, params)
164
316
  Video.from_exif(response.body['photo'])
165
317
  end
166
318
 
167
- # Returns instances of Flickrie::User
319
+ # Fetches the list of users who favorited the photo with the given ID.
320
+ # Example:
321
+ #
322
+ # photo = Flickrie.get_photo_favorites(24810948)
323
+ # photo.favorites.first.username # => "John Smith"
324
+ #
325
+ # @param photo_id [String, Fixnum]
326
+ # @return [Flickrie::Photo]
327
+ # @api_method [flickr.photos.getFavorites](http://www.flickr.com/services/api/flickr.photos.getFavorites.html)
168
328
  def get_photo_favorites(photo_id, params = {})
169
329
  response = client.get_media_favorites(photo_id, params)
170
330
  Photo.new(response.body['photo'])
171
331
  end
172
- # Returns instances of Flickrie::User
332
+ # Fetches the list of users who favorited the video with the given ID.
333
+ # Example:
334
+ #
335
+ # video = Flickrie.get_video_favorites(24810948)
336
+ # video.favorites.first.username # => "John Smith"
337
+ #
338
+ # @param video_id [String, Fixnum]
339
+ # @return [Flickrie::Video]
340
+ # @api_method [flickr.photos.getFavorites](http://www.flickr.com/services/api/flickr.photos.getFavorites.html)
173
341
  def get_video_favorites(video_id, params = {})
174
342
  response = client.get_media_favorites(video_id, params)
175
343
  Video.new(response.body['photo'])
176
344
  end
177
345
 
346
+ # Fetches info of the photo/video with the given ID.
347
+ #
348
+ # @param media_id [String, Fixnum]
349
+ # @return [Flickrie::Photo, Flickrie::Video]
350
+ # @api_method [flickr.photos.getInfo](http://www.flickr.com/services/api/flickr.photos.getInfo.html)
178
351
  def get_media_info(media_id, params = {})
179
352
  response = client.get_media_info(media_id, params)
180
353
  Media.from_info(response.body['photo'])
@@ -182,81 +355,158 @@ module Flickrie
182
355
  alias get_photo_info get_media_info
183
356
  alias get_video_info get_media_info
184
357
 
185
- # Returns an instance of Flickrie::Photo
358
+ # Fetches the sizes of the photo with the given ID. Example:
359
+ #
360
+ # photo = Flickrie.get_photo_sizes(242348)
361
+ # photo.medium!(500)
362
+ # photo.size # => "Medium 500"
363
+ # photo.source_url # => "http://farm8.staticflickr.com/7090/7093101501_9337f28800.jpg"
364
+ #
365
+ # @param photo_id [String, Fixnum]
366
+ # @return [Flickrie::Photo]
367
+ # @api_method [flickr.photos.getSizes](http://www.flickr.com/services/api/flickr.photos.getSizes.html)
186
368
  def get_photo_sizes(photo_id, params = {})
187
369
  response = client.get_media_sizes(photo_id, params)
188
370
  Photo.from_sizes(response.body['sizes'])
189
371
  end
190
- # Returns an instance of Flickrie::Video
372
+ # Fetches the sizes of the video with the given ID. Example:
373
+ #
374
+ # video = Flickrie.get_video_sizes(438492)
375
+ # video.download_url # => "..."
376
+ #
377
+ # @param video_id [String, Fixnum]
378
+ # @return [Flickrie::Video]
379
+ # @api_method [flickr.photos.getSizes](http://www.flickr.com/services/api/flickr.photos.getSizes.html)
191
380
  def get_video_sizes(video_id, params = {})
192
381
  response = client.get_media_sizes(video_id, params)
193
382
  Video.from_sizes(response.body['sizes'])
194
383
  end
195
384
 
385
+ # Remove the tag with the given ID
386
+ #
387
+ # @param tag_id [String]
388
+ # @api_method [flickr.photos.removeTag](http://www.flickr.com/services/api/flickr.photos.removeTag.html)
389
+ #
390
+ # @note This method requires authentication with "write" permissions.
196
391
  def remove_media_tag(tag_id, params = {})
197
392
  client.remove_media_tag(tag_id, params)
393
+ nil
198
394
  end
199
395
  alias remove_photo_tag remove_media_tag
200
396
  alias remove_video_tag remove_media_tag
201
397
 
398
+ # Fetches photos and videos matching a certain criteria.
399
+ #
400
+ # @param search_params [Hash] Options for searching (see the link below)
401
+ # @return [Array<Flickrie::Photo, Flickrie::Video>]
402
+ # @api_method [flickr.photos.search](http://www.flickr.com/services/api/flickr.photos.search.html)
202
403
  def search_media(search_params = {})
203
404
  response = client.search_media(search_params)
204
405
  Media.from_search(response.body['photos'])
205
406
  end
407
+ # Fetches photos matching a certain criteria.
408
+ #
409
+ # @param search_params [Hash] Options for searching (see the link below)
410
+ # @return [Array<Flickrie::Photo>]
411
+ # @api_method [flickr.photos.search](http://www.flickr.com/services/api/flickr.photos.search.html)
206
412
  def search_photos(search_params = {})
207
413
  search_media(search_params.merge(:media => 'photos'))
208
414
  end
415
+ # Fetches videos matching a certain criteria.
416
+ #
417
+ # @param search_params [Hash] Options for searching (see the link below)
418
+ # @return [Array<Flickrie::Video>]
419
+ # @api_method [flickr.photos.search](http://www.flickr.com/services/api/flickr.photos.search.html)
209
420
  def search_videos(search_params = {})
210
421
  search_media(search_params.merge(:media => 'videos'))
211
422
  end
212
423
 
213
- #--
214
- # photos.upload
215
- #++
216
- # Returns an array of Flickrie::Ticket
217
- def check_upload_tickets(tickets, params = {})
218
- tickets = tickets.join(',') if tickets.respond_to?(:join)
219
- response = client.check_upload_tickets(tickets, params)
220
- response.body['uploader']['ticket'].
221
- map { |info| Ticket.new(info) }
222
- end
223
-
224
- #--
225
- # licenses
226
- #++
227
- # Returns an array of Flickrie::License
424
+ # Fetches all available types of licenses.
425
+ #
426
+ # @return [Array<Flickrie::License>]
427
+ # @api_method [flickr.photos.licenses.getInfo](http://www.flickr.com/services/api/flickr.photos.licenses.getInfo.html)
228
428
  def get_licenses(params = {})
229
429
  response = client.get_licenses(params)
230
430
  License.from_hash(response.body['licenses']['license'])
231
431
  end
232
432
 
233
- #--
234
- # photosets
433
+ # Fetches upload tickets with given IDs. Example:
434
+ #
435
+ # photo = File.open("...")
436
+ # ticket_id = Flickrie.upload(photo)
437
+ # sleep(10)
438
+ #
439
+ # ticket = Flickrie.check_upload_tickects(ticket_id)
440
+ # if ticket.complete?
441
+ # puts "Photo was uploaded, and its ID is #{ticket.photo_id}"
442
+ # end
443
+ #
444
+ # @param tickets [String] A space delimited string with ticket IDs
445
+ # @return [Flickrie::Ticket]
446
+ # @api_method [flickr.photos.upload.checkTickets](http://www.flickr.com/services/api/flickr.photos.upload.checkTickets.html)
447
+ def check_upload_tickets(tickets, params = {})
448
+ ticket_ids = tickets.join(',') rescue tickets
449
+ response = client.check_upload_tickets(ticket_ids, params)
450
+ response.body['uploader']['ticket'].
451
+ map { |info| Ticket.new(info) }
452
+ end
453
+
454
+ # Fetches information about the set with the given ID.
455
+ #
456
+ # @param set_id [String, Fixnum]
457
+ # @return [Flickrie::Set]
458
+ # @api_method [flickr.photosets.getInfo](http://www.flickr.com/services/api/flickr.photosets.getInfo.html)
235
459
  def get_set_info(set_id, params = {})
236
460
  response = client.get_set_info(set_id, params)
237
461
  Set.from_info(response.body['photoset'])
238
462
  end
239
463
 
240
- def sets_from_user(user_nsid, params = {})
241
- response = client.sets_from_user(user_nsid, params)
242
- Set.from_user(response.body['photosets']['photoset'], user_nsid)
464
+ # Fetches sets from a user with the given NSID.
465
+ #
466
+ # @param nsid [String]
467
+ # @return [Array<Flickrie::Set>]
468
+ # @api_method [flickr.photosets.getList](http://www.flickr.com/services/api/flickr.photosets.getList.html)
469
+ def sets_from_user(nsid, params = {})
470
+ response = client.sets_from_user(nsid, params)
471
+ Set.from_user(response.body['photosets']['photoset'], nsid)
243
472
  end
244
473
 
474
+ # Fetches photos and videos from a set with the given ID.
475
+ #
476
+ # @param set_id [String]
477
+ # @param params [Hash] Options for this API method (see the link below)
478
+ # @return [Array<Flickrie::Photo, Flickrie::Video>]
479
+ # @api_method [flickr.photosets.getPhotos](http://www.flickr.com/services/api/flickr.photosets.getPhotos.html)
245
480
  def media_from_set(set_id, params = {})
246
481
  response = client.media_from_set(set_id, params)
247
482
  Media.from_set(response.body['photoset'])
248
483
  end
484
+ # Fetches photos from a set with the given ID.
485
+ #
486
+ # @param set_id [String]
487
+ # @param params [Hash] Options for this API method (see the link below)
488
+ # @return [Array<Flickrie::Photo>]
489
+ # @api_method [flickr.photosets.getPhotos](http://www.flickr.com/services/api/flickr.photosets.getPhotos.html)
249
490
  def photos_from_set(set_id, params = {})
250
491
  media_from_set(set_id, params.merge(:media => 'photos'))
251
492
  end
493
+ # Fetches videos from a set with the given ID.
494
+ #
495
+ # @param set_id [String]
496
+ # @param params [Hash] Options for this API method (see the link below)
497
+ # @return [Array<Flickrie::Video>]
498
+ # @api_method [flickr.photosets.getPhotos](http://www.flickr.com/services/api/flickr.photosets.getPhotos.html)
252
499
  def videos_from_set(set_id, params = {})
253
500
  media_from_set(set_id, params.merge(:media => 'videos'))
254
501
  end
255
502
 
256
- #--
257
- # test
258
- #++
259
- # Returns an instance of Flickrie::User
503
+ # Tests if the authentication was successful. If it was, it
504
+ # returns info of the user who just authenticated.
505
+ #
506
+ # @return [Flickrie::User]
507
+ # @api_method [flickr.test.login](http://www.flickr.com/services/api/flickr.test.login.html)
508
+ #
509
+ # @note This method requires authentication with "read" permissions.
260
510
  def test_login(params = {})
261
511
  response = client.test_login(params)
262
512
  User.from_test(response.body['user'])