flickr-objects 0.0.2 → 0.1.0

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.
Files changed (63) hide show
  1. data/README.md +55 -85
  2. data/lib/flickr/api/api_methods/flickr.rb +0 -1
  3. data/lib/flickr/api/api_methods/person.rb +3 -3
  4. data/lib/flickr/api/api_methods/photo.rb +12 -1
  5. data/lib/flickr/api/api_methods/set.rb +6 -5
  6. data/lib/flickr/api/flickr.rb +9 -9
  7. data/lib/flickr/api/person.rb +13 -29
  8. data/lib/flickr/api/photo.rb +51 -4
  9. data/lib/flickr/api/set.rb +20 -25
  10. data/lib/flickr/api/upload_ticket.rb +4 -2
  11. data/lib/flickr/api.rb +0 -2
  12. data/lib/flickr/api_caller.rb +5 -11
  13. data/lib/flickr/client/upload_client.rb +4 -16
  14. data/lib/flickr/client.rb +1 -1
  15. data/lib/flickr/configuration.rb +2 -0
  16. data/lib/flickr/errors.rb +19 -0
  17. data/lib/flickr/middleware.rb +63 -0
  18. data/lib/flickr/oauth.rb +109 -0
  19. data/lib/flickr/object/attribute/finder.rb +2 -2
  20. data/lib/flickr/object/attribute.rb +8 -8
  21. data/lib/flickr/object.rb +13 -2
  22. data/lib/flickr/objects/attribute_values/{collection.rb → list.rb} +1 -1
  23. data/lib/flickr/objects/attribute_values/photo.rb +81 -16
  24. data/lib/flickr/objects/attribute_values/set.rb +1 -5
  25. data/lib/flickr/objects/attribute_values/upload_ticket.rb +3 -5
  26. data/lib/flickr/objects/list.rb +86 -0
  27. data/lib/flickr/objects/location.rb +2 -0
  28. data/lib/flickr/objects/note.rb +3 -1
  29. data/lib/flickr/objects/permissions.rb +2 -0
  30. data/lib/flickr/objects/person.rb +8 -5
  31. data/lib/flickr/objects/photo.rb +98 -30
  32. data/lib/flickr/objects/set.rb +4 -5
  33. data/lib/flickr/objects/tag.rb +2 -0
  34. data/lib/flickr/objects/upload_ticket.rb +8 -6
  35. data/lib/flickr/objects/visibility.rb +2 -0
  36. data/lib/flickr/objects.rb +2 -7
  37. data/lib/flickr/version.rb +1 -1
  38. data/lib/flickr.rb +5 -0
  39. metadata +60 -32
  40. data/lib/flickr/api/api_methods/collection.rb +0 -4
  41. data/lib/flickr/api/api_methods/location.rb +0 -4
  42. data/lib/flickr/api/api_methods/media.rb +0 -14
  43. data/lib/flickr/api/api_methods/note.rb +0 -4
  44. data/lib/flickr/api/api_methods/permissions.rb +0 -4
  45. data/lib/flickr/api/api_methods/tag.rb +0 -4
  46. data/lib/flickr/api/api_methods/video.rb +0 -4
  47. data/lib/flickr/api/api_methods/visibility.rb +0 -4
  48. data/lib/flickr/api/collection.rb +0 -4
  49. data/lib/flickr/api/location.rb +0 -4
  50. data/lib/flickr/api/media.rb +0 -52
  51. data/lib/flickr/api/note.rb +0 -4
  52. data/lib/flickr/api/permissions.rb +0 -4
  53. data/lib/flickr/api/tag.rb +0 -4
  54. data/lib/flickr/api/video.rb +0 -11
  55. data/lib/flickr/api/visibility.rb +0 -4
  56. data/lib/flickr/client/middleware/retry.rb +0 -29
  57. data/lib/flickr/client/middleware.rb +0 -42
  58. data/lib/flickr/helpers/inheritable_attr_accessor.rb +0 -18
  59. data/lib/flickr/objects/attribute_values/media.rb +0 -70
  60. data/lib/flickr/objects/attribute_values/video.rb +0 -27
  61. data/lib/flickr/objects/collection.rb +0 -56
  62. data/lib/flickr/objects/media.rb +0 -72
  63. data/lib/flickr/objects/video.rb +0 -21
data/README.md CHANGED
@@ -22,85 +22,68 @@ Flickr.configure do |config|
22
22
  end
23
23
  ```
24
24
 
25
- If you don't have your API key and shared secret yet, you can apply for them
26
- [here](http://www.flickr.com/services/apps/create/apply).
25
+ If you don't have them yet, you can apply for them [here](http://www.flickr.com/services/apps/create/apply).
26
+
27
+ For list of possible configuration options, take a look at [this
28
+ wiki](https://github.com/janko-m/flickr-objects/wiki/Configuration).
27
29
 
28
30
  ## Usage
29
31
 
30
- Let's start with a general example.
32
+ This gem maps [Flickr's API methods](http://flickr.com/api) to methods on objects.
33
+ A handy reference for those mappings is in `Flickr.api_methods`:
31
34
 
32
35
  ```ruby
33
- photos = Flickr.photos.search(user_id: "78733179@N04") #=> [#<Flickr::Photo: ...>, #<Flickr::Photo: ...>, ...]
34
-
35
- photo = photos.first
36
- photo.id #=> "231233252"
37
- photo.title #=> "My cat"
38
- photo.visibility.public? #=> true
39
- photo.tags = "cats funny" # API request
40
- photo.get_info! # API request
41
- photo.tags.join(" ") #=> "cats funny"
36
+ Flickr.api_methods["flickr.photos.search"] #=> ["Flickr::Photo.search"]
37
+ Flickr.api_methods["flickr.photosets.getList"] #=> ["Flickr::Person#get_sets"]
42
38
  ```
43
39
 
44
- Methods like `Flickr.photos.search` are **class** API methods, and methods like `photo.tags=` and
45
- `photo.get_info!` are **instance** API methods.
40
+ As you see, sometimes names can differ, but you can always find out this way.
41
+ So, `Flickr::Photo.search` is a **class** API method, and
42
+ `Flickr::Person#get_sets` is an **instance** API method.
46
43
 
47
- - `Flickr.photos.search` <=> `Flickr::Photo.search`
48
- - `photo.tags=` <=> `Flickr::Photo#tags=`
49
- - `photo.get_info!` <=> `Flickr::Photo#get_info!`
44
+ Here's an example:
50
45
 
51
- API methods under the hood call methods described on Flickr's official [API page](http://flickr.com/api).
52
- In our example, we have this correspondence:
46
+ ```ruby
47
+ photos = Flickr.photos.search(user_id: "78733179@N04") #=> [#<Flickr::Photo: ...>, #<Flickr::Photo: ...>, ...]
53
48
 
54
- - `Flickr::Photo.search` <=> flickr.photos.search
55
- - `Flickr::Photo#tags=` <=> flickr.photos.setTags
56
- - `Flickr::Photo#get_info!` <=> flickr.photos.getInfo
49
+ photo = photos.first
50
+ photo.id #=> "231233252"
51
+ photo.title #=> "My cat"
52
+ photo.visibility.public? #=> true
57
53
 
58
- Raw Flickr's API methods always take a hash of parameters. So, for example,
59
- flickr.people.findByEmail takes the `:find_email` parameter. But this gem
60
- implies these kind of obvious parameters, so instead of having to call it like this:
54
+ person = Flickr.people.find("78733179@N04")
55
+ sets = person.get_sets #=> [#<Flickr::Set: ...>, #<Flickr::Set: ...>, ...]
61
56
 
62
- ```ruby
63
- Flickr.people.find_by_email(find_email: "janko.marohnic@gmail.com")
57
+ set = sets.first
58
+ set.id #=> "11243423"
59
+ set.photos_count #=> 40
64
60
  ```
65
61
 
66
- you can rather call it like this:
62
+ You can always manually instantiate objects with `Flickr.objects.find(id)`
63
+ (in the above example we called `Flickr.people.find(id)`).
64
+
65
+ Parameters to API methods are not always passed as a hash. For example, instead
66
+ of calling "flickr.people.findByEmail" like this:
67
67
 
68
68
  ```ruby
69
- Flickr.people.find_by_email("janko.marohnic@gmail.com")
69
+ Flickr.people.find_by_email(find_email: "janko.marohnic@gmail.com")
70
70
  ```
71
71
 
72
- You can still pass a hash of other parameters as the last argument. For the
73
- documentation on valid arguments, just look at the source code under
74
- `lib/flickr/api/`. In our example, because `.find_by_email` belongs to `people`,
75
- the method is located in [`lib/flickr/api/person.rb`](https://github.com/janko-m/flickr-objects/blob/master/lib/flickr/api/person.rb#L3-6).
76
-
77
- Now, let's say that you want to use a method that fetches all sets from a
78
- person. And you find out that this method is "flickr.photosets.getList".
79
- How can you now find out where it is located in this gem? Well, that's where
80
- `Flickr.api_methods` comes in handy. You can call it in the console:
72
+ this gem has the convention of calling it like this:
81
73
 
82
74
  ```ruby
83
- Flickr.api_methods["flickr.photosets.getList"] #=> ["Flickr::Person#get_sets"]
75
+ Flickr.people.find_by_email("janko.marohnic@gmail.com")
84
76
  ```
85
77
 
86
- Now you found out that it is located in `Flickr::Person#get_sets`.
78
+ Obvious parameters will always be passed like this. You can still pass a hash of
79
+ other parameters as the last argument.
87
80
 
88
- ```ruby
89
- # You can now call it like this:
90
- sets = Flickr.people.find(person_id).get_sets
91
- sets.first.id #=> "12312324"
92
-
93
- # Or like this:
94
- sets = Flickr.find_by_username("josh").get_sets
95
- sets.first.id #=> "12312324"
96
- ```
81
+ For documentation on valid arguments, just look at the source code under
82
+ [`lib/flickr/api`](https://github.com/janko-m/flickr-objects/blob/master/lib/flickr/api).
83
+ There you will find listed all the API methods of a specific object.
97
84
 
98
85
  ## Sizes
99
86
 
100
- When you upload photos to Flickr, Flickr automatically makes different versions
101
- (sizes) of your photo. So, for example you have "Medium 500", "Small 320", and
102
- so on. Here's how you use this in the gem:
103
-
104
87
  ```ruby
105
88
  person = Flickr.person.find(person_id)
106
89
  photo = person.get_public_photos(sizes: :all).first
@@ -112,10 +95,6 @@ photo.height #=> 280
112
95
 
113
96
  photo.medium!(500)
114
97
  photo.width #=> 500
115
-
116
- # You can also call it like this:
117
- photo.small240!
118
- photo.width #=> 240
119
98
  ```
120
99
 
121
100
  It is important here that you pass `sizes: :all` to `Flickr::Person#get_public_photos`.
@@ -125,7 +104,7 @@ So, in your (Rails) application, one could use it like this:
125
104
  class PhotosController < ApplicationController
126
105
  def index
127
106
  person = Flickr.people.find("78733179@N04")
128
- @photos = person.get_public_photos(sizes: :all).map(&:medium500!)
107
+ @photos = person.get_public_photos(sizes: :all).map { |photo| photo.medium!(500) }
129
108
  end
130
109
  end
131
110
  ```
@@ -135,22 +114,23 @@ end
135
114
  <% end %>
136
115
  ```
137
116
 
138
- ## Authenticated requests
117
+ To find out more, take a look at [this wiki](https://github.com/janko-m/flickr-objects/wiki/Sizes).
118
+
119
+ ## Authentication
139
120
 
140
- If you need to make authenticated API requests (which you'll probably often want), you can create a kind
141
- of a instance, assigning to it the user's access token. That instance then has the same interface as `Flickr`.
121
+ If you need to make authenticated API requests (which you'll probably often want), you should create an
122
+ instance, assigning it the user's access token.
142
123
 
143
124
  ```ruby
144
125
  flickr = Flickr.new("ACCESS_TOKEN_KEY", "ACCESS_TOKEN_SECRET")
145
126
 
127
+ # It has the same interface as `Flickr`
146
128
  flickr.test_login #=> {"id" => "78733179@N04", "username" => ...}
147
129
  flickr.people.find("78733179@N04").get_photos #=> [#<Flickr::Photo ...>, #<Flickr::Photo, ...>, ...]
148
130
  ```
149
131
 
150
- If you're in a Rails application, probably the best solution for authenticating
151
- users through Flickr (thus obtaining their access tokens) is the
152
- [omniauth-flickr](https://github.com/timbreitkreutz/omniauth-flickr) gem.
153
- Another (more lightweight) solution would be [flickr-login](https://github.com/janko-m/flickr-login).
132
+ For details on how to authenticate (obtain the access token) take a look at
133
+ [this wiki](http://github.com/janko-m/flickr-objects/wiki/Authentication).
154
134
 
155
135
  You can also assign the access token globally in your configuration.
156
136
 
@@ -161,10 +141,6 @@ Flickr.configure do |config|
161
141
  end
162
142
  ```
163
143
 
164
- This is especially useful if you're, for example, using Flickr as a photo storage in your
165
- application, and that access token is actually yours.
166
-
167
-
168
144
  ## Upload
169
145
 
170
146
  ```ruby
@@ -182,27 +158,21 @@ For asynchronous upload take a look at [this wiki](https://github.com/janko-m/fl
182
158
  ## Attributes and methods
183
159
 
184
160
  For the list of attributes and methods that Flickr objects have, the best place to look at
185
- is the source code. The source code is delibarately written in a way that it's
186
- really easy to read, even for someone who doesn't have experience in looking into other
187
- people's code.
188
-
189
- For example, list of common attributes that `Flickr::Photo`
190
- and `Flickr::Video` have can be found in [`lib/flickr/objects/media.rb`]("https://github.com/janko-m/flickr-objects/blob/master/lib/flickr/objects/media.rb").
191
-
192
- ![Flickr::Media](http://farm9.staticflickr.com/8195/8133340670_38c60aaca7.jpg)
161
+ is the source code. The source code is written in such a simple way that it acts as its
162
+ own documentation, so don't be discouraged if you haven't had experience in looking into other
163
+ people's code yet :)
193
164
 
194
- As you can see, it is very readable ;)
165
+ For example, list of `Flickr::Photo`'s attributes can be found in
166
+ [`lib/flickr/objects/media.rb`](https://github.com/janko-m/flickr-objects/blob/master/lib/flickr/objects/media.rb).
167
+ Take a look just to see how it looks like :)
195
168
 
196
169
  ## Few words
197
170
 
198
- Most of the API methods are not covered yet (because they are so many).
199
- The most important API methods should be already implemented, so a person
200
- with normal demands should have everything he needs.
171
+ Most of the API methods are not covered yet (because they are so many). I will
172
+ be covering new ones regularly.
201
173
 
202
- If you feel like some API methods (that are not yet covered) should have
203
- a higher priority to be covered, feel free to let me know (maybe best via
204
- [Twitter](https://twitter.com/m_janko)), and I will try to get them covered
205
- in the next version. Pull requests are also very welcome :)
174
+ Feel free to speed up covering certain API methods by contacting me through
175
+ [Twitter](https://twitter.com/m_janko). Pull requests are also very welcome :)
206
176
 
207
177
  ## Social
208
178
 
@@ -1,5 +1,4 @@
1
1
  class Flickr
2
- api_method :check_upload_tickets, "flickr.photos.upload.checkTickets"
3
2
  api_method :test_login, "flickr.test.login"
4
3
  api_method :test_echo, "flickr.test.echo"
5
4
  api_method :test_null, "flickr.test.null"
@@ -4,9 +4,9 @@ class Flickr
4
4
  class_api_method :find_by_username, "flickr.people.findByUsername"
5
5
 
6
6
  instance_api_method :get_info!, "flickr.people.getInfo"
7
- instance_api_method :get_photos, "flickr.people.getPhotos", aliases: [:get_videos, :get_media]
8
- instance_api_method :get_public_photos, "flickr.people.getPublicPhotos", aliases: [:get_public_videos, :get_public_media]
9
- instance_api_method :get_public_photos_from_contacts, "flickr.photos.getContactsPublicPhotos", aliases: [:get_public_videos_from_contacts, :get_public_media_from_contacts]
7
+ instance_api_method :get_photos, "flickr.people.getPhotos"
8
+ instance_api_method :get_public_photos, "flickr.people.getPublicPhotos"
9
+ instance_api_method :get_public_photos_from_contacts, "flickr.photos.getContactsPublicPhotos"
10
10
  instance_api_method :get_sets, "flickr.photosets.getList"
11
11
  end
12
12
  end
@@ -1,4 +1,15 @@
1
1
  class Flickr
2
- class Photo < Media
2
+ class Photo < Object
3
+ class_api_method :get_from_contacts, "flickr.photos.getContactsPhotos"
4
+ class_api_method :search, "flickr.photos.search"
5
+ class_api_method :delete, "flickr.photos.delete"
6
+
7
+ instance_api_method :add_tags, "flickr.photos.addTags"
8
+ instance_api_method :delete, "flickr.photos.delete"
9
+ instance_api_method :get_info!, "flickr.photos.getInfo"
10
+ instance_api_method :get_sizes!, "flickr.photos.getSizes"
11
+ instance_api_method :remove_tag, "flickr.photos.removeTag"
12
+ instance_api_method :set_content_type, "flickr.photos.setContentType", aliases: [:content_type=]
13
+ instance_api_method :set_tags, "flickr.photos.setTags", aliases: [:tags=]
3
14
  end
4
15
  end
@@ -1,13 +1,14 @@
1
1
  class Flickr
2
2
  class Set < Object
3
3
  class_api_method :create, "flickr.photosets.create"
4
+ class_api_method :delete, "flickr.photosets.delete"
4
5
 
5
- instance_api_method :add_photo, "flickr.photosets.addPhoto", aliases: [:add_video, :add_media]
6
+ instance_api_method :add_photo, "flickr.photosets.addPhoto"
6
7
  instance_api_method :delete, "flickr.photosets.delete"
7
- instance_api_method :edit_photos, "flickr.photosets.editPhotos", aliases: [:edit_videos, :edit_media]
8
+ instance_api_method :edit_photos, "flickr.photosets.editPhotos"
8
9
  instance_api_method :get_info!, "flickr.photosets.getInfo"
9
- instance_api_method :get_photos, "flickr.photosets.getPhotos", aliases: [:get_videos, :get_media]
10
- instance_api_method :remove_photos, "flickr.photosets.removePhotos", aliases: [:remove_videos, :remove_media]
11
- instance_api_method :remove_photo, "flickr.photosets.removePhoto", aliases: [:remove_video, :remove_media]
10
+ instance_api_method :get_photos, "flickr.photosets.getPhotos"
11
+ instance_api_method :remove_photos, "flickr.photosets.removePhotos"
12
+ instance_api_method :remove_photo, "flickr.photosets.removePhoto"
12
13
  end
13
14
  end
@@ -2,31 +2,31 @@ require_relative "api_methods/flickr"
2
2
 
3
3
  class Flickr
4
4
  api_methods = proc do
5
- def upload(media, params = {})
6
- response = upload_client.upload(media, params)
5
+ def upload(photo, params = {})
6
+ response = upload_client.upload(photo, params)
7
7
  params[:async] == 1 ? response["ticketid"] : response["photoid"]
8
8
  end
9
9
 
10
- def replace(media, id, params = {})
11
- response = upload_client.replace(media, id, params)
10
+ def replace(photo, id, params = {})
11
+ response = upload_client.replace(photo, id, params)
12
12
  params[:async] == 1 ? response["ticketid"] : response["photoid"]
13
13
  end
14
14
 
15
15
  def check_upload_tickets(tickets, params = {})
16
- response = client.get flickr_method(__method__), params.merge(tickets: tickets.to_s)
17
- Collection.new(response["uploader"].delete("ticket"), UploadTicket, response["uploader"], client)
16
+ Flickr.deprecation_warn "`Flickr.check_upload_tickets` is deprecated. Use `Flickr.upload_tickets.check` instead."
17
+ upload_tickets.check(tickets, params)
18
18
  end
19
19
 
20
20
  def test_login(params = {})
21
- client.get flickr_method(__method__), params
21
+ client.get f(__method__), params
22
22
  end
23
23
 
24
24
  def test_echo(params = {})
25
- client.get flickr_method(__method__), params
25
+ client.get f(__method__), params
26
26
  end
27
27
 
28
28
  def test_null(params = {})
29
- client.get flickr_method(__method__), params
29
+ client.get f(__method__), params
30
30
  end
31
31
  end
32
32
 
@@ -1,57 +1,41 @@
1
+ require_relative "api_methods/person"
2
+
1
3
  class Flickr
2
4
  class Person < Object
3
5
  def self.find_by_email(email, params = {})
4
- response = client.get flickr_method(__method__), params.merge(find_email: email)
6
+ response = client.get f(__method__), params.merge(find_email: email)
5
7
  new(response["user"], client)
6
8
  end
7
9
 
8
10
  def self.find_by_username(username, params = {})
9
- response = client.get flickr_method(__method__), params.merge(username: username)
11
+ response = client.get f(__method__), params.merge(username: username)
10
12
  new(response["user"], client)
11
13
  end
12
14
 
13
15
  def get_info!(params = {})
14
- response = client.get flickr_method(__method__), params.merge(user_id: id)
16
+ response = client.get f(__method__), params.merge(user_id: id)
15
17
  @hash.update(response["person"])
16
18
  self
17
19
  end
18
20
 
19
21
  def get_photos(params = {})
20
- get_media(params).select { |object| object.is_a?(Flickr::Photo) }
21
- end
22
- def get_videos(params = {})
23
- get_media(params).select { |object| object.is_a?(Flickr::Video) }
24
- end
25
- def get_media(params = {})
26
- response = client.get flickr_method(__method__), handle_extras(params.merge(user_id: id))
27
- Collection.new(response["photos"].delete("photo"), Media, response["photos"], client)
22
+ response = client.get f(__method__), handle_extras(params.merge(user_id: id))
23
+ Photo.new_list(response["photos"].delete("photo"), client, response["photos"])
28
24
  end
29
25
 
30
26
  def get_public_photos(params = {})
31
- get_public_media(params).select { |object| object.is_a?(Flickr::Photo) }
32
- end
33
- def get_public_videos(params = {})
34
- get_public_media(params).select { |object| object.is_a?(Flickr::Video) }
35
- end
36
- def get_public_media(params = {})
37
- response = client.get flickr_method(__method__), handle_extras(params.merge(user_id: id))
38
- Collection.new(response["photos"].delete("photo"), Media, response["photos"], client)
27
+ response = client.get f(__method__), handle_extras(params.merge(user_id: id))
28
+ Photo.new_list(response["photos"].delete("photo"), client, response["photos"])
39
29
  end
40
30
 
41
31
  def get_public_photos_from_contacts(params = {})
42
- get_public_media_from_contacts(params).select {|object| object.is_a?(Flickr::Photo) }
43
- end
44
- def get_public_videos_from_contacts(params = {})
45
- get_public_media_from_contacts(params).select {|object| object.is_a?(Flickr::Video) }
46
- end
47
- def get_public_media_from_contacts(params = {})
48
- response = client.get flickr_method(__method__), handle_extras(params.merge(user_id: id))
49
- Collection.new(response["photos"].delete("photo"), Media, response["photos"], client)
32
+ response = client.get f(__method__), handle_extras(params.merge(user_id: id))
33
+ Photo.new_list(response["photos"].delete("photo"), client, response["photos"])
50
34
  end
51
35
 
52
36
  def get_sets(params = {})
53
- response = client.get flickr_method(__method__), params.merge(user_id: id)
54
- Collection.new(response["photosets"].delete("photoset"), Set, response["photosets"], client)
37
+ response = client.get f(__method__), params.merge(user_id: id)
38
+ Set.new_list(response["photosets"].delete("photoset"), client, response["photosets"])
55
39
  end
56
40
  end
57
41
  end
@@ -1,11 +1,58 @@
1
+ require_relative "api_methods/photo"
2
+
1
3
  class Flickr
2
- class Photo < Media
4
+ class Photo < Object
5
+ def self.search(params = {})
6
+ response = client.get f(__method__), handle_extras(params)
7
+ new_list(response["photos"].delete("photo"), client, response["photos"])
8
+ end
9
+
3
10
  def self.get_from_contacts(params = {})
4
- super(params).select { |media| media.is_a?(self) }
11
+ response = client.get f(__method__), handle_extras(params)
12
+ new_list(response["photos"].delete("photo"), client, response["photos"])
5
13
  end
6
14
 
7
- def self.search(params = {})
8
- super(params.merge(media: "photos"))
15
+ def self.delete(id, params = {})
16
+ find(id).delete(params)
17
+ end
18
+
19
+ def get_info!(params = {})
20
+ response = client.get f(__method__), params.merge(photo_id: id)
21
+ @hash.update(response["photo"])
22
+ self
23
+ end
24
+
25
+ def get_sizes!(params = {})
26
+ response = client.get f(__method__), params.merge(photo_id: id)
27
+ @hash.update(response["sizes"])
28
+ self
29
+ end
30
+
31
+ def delete(params = {})
32
+ client.post f(__method__), params.merge(photo_id: id)
33
+ self
34
+ end
35
+
36
+ def set_content_type(content_type, params = {})
37
+ client.post f(__method__), params.merge(photo_id: id, content_type: content_type)
38
+ content_type
39
+ end
40
+ alias content_type= set_content_type
41
+
42
+ def set_tags(tags, params = {})
43
+ client.post f(__method__), params.merge(photo_id: id, tags: tags)
44
+ tags
45
+ end
46
+ alias tags= set_tags
47
+
48
+ def add_tags(tags, params = {})
49
+ client.post f(__method__), params.merge(photo_id: id, tags: tags)
50
+ tags
51
+ end
52
+
53
+ def remove_tag(tag_id, params = {})
54
+ client.post f(__method__), params.merge(photo_id: id, tag_id: tag_id)
55
+ tag_id
9
56
  end
10
57
  end
11
58
  end
@@ -1,52 +1,47 @@
1
+ require_relative "api_methods/set"
2
+
1
3
  class Flickr
2
4
  class Set < Object
3
- def add_photo(media_id, params = {})
4
- client.post flickr_method(__method__), params.merge(photoset_id: id, photo_id: media_id)
5
- end
6
- alias add_video add_photo
7
- alias add_media add_photo
8
-
9
5
  def self.create(params = {})
10
- response = client.post flickr_method(__method__), params
6
+ response = client.post f(__method__), params
11
7
  new(response["photoset"], client)
12
8
  end
13
9
 
10
+ def self.delete(id, params = {})
11
+ find(id).delete(params)
12
+ end
13
+
14
14
  def delete(params = {})
15
- client.post flickr_method(__method__), params.merge(photoset_id: id)
15
+ client.post f(__method__), params.merge(photoset_id: id)
16
16
  self
17
17
  end
18
18
 
19
19
  def edit_photos(params = {})
20
- client.post flickr_method(__method__), params.merge(photoset_id: id)
20
+ client.post f(__method__), params.merge(photoset_id: id)
21
21
  self
22
22
  end
23
- alias edit_videos edit_photos
24
- alias edit_media edit_photos
25
23
 
26
24
  def get_info!(params = {})
27
- response = client.get flickr_method(__method__), params.merge(photoset_id: id)
25
+ response = client.get f(__method__), params.merge(photoset_id: id)
28
26
  @hash.update(response["photoset"])
29
27
  self
30
28
  end
31
29
 
32
30
  def get_photos(params = {})
33
- get_media(params.merge(media: "photos"))
34
- end
35
- def get_videos(params = {})
36
- get_media(params.merge(media: "videos"))
31
+ response = client.get f(__method__), handle_extras(params.merge(photoset_id: id))
32
+ Photo.new_list(response["photoset"].delete("photo"), client, response["photoset"])
37
33
  end
38
- def get_media(params = {})
39
- response = client.get flickr_method(__method__), handle_extras(params.merge(photoset_id: id))
40
- Collection.new(response["photoset"].delete("photo"), Media, response["photoset"], client)
34
+
35
+ def add_photo(photo_id, params = {})
36
+ client.post f(__method__), params.merge(photoset_id: id, photo_id: photo_id)
41
37
  end
42
38
 
43
- def remove_photos(media_id, params = {})
44
- client.post flickr_method(__method__), params.merge(photoset_id: id, photo_ids: media_id)
39
+ def remove_photos(photo_ids, params = {})
40
+ client.post f(__method__), params.merge(photoset_id: id, photo_ids: photo_ids)
45
41
  end
46
- alias remove_videos remove_photos
47
- alias remove_media remove_photos
48
42
 
49
- alias remove_photo remove_photos
50
- alias remove_video remove_photos
43
+ def remove_photo(photo_id, params = {})
44
+ client.post f(__method__), params.merge(photoset_id: id, photo_id: photo_id)
45
+ end
51
46
  end
52
47
  end
@@ -1,8 +1,10 @@
1
+ require_relative "api_methods/upload_ticket"
2
+
1
3
  class Flickr
2
4
  class UploadTicket < Object
3
5
  def self.check(tickets, params = {})
4
- response = client.get flickr_method(__method__), params.merge(tickets: tickets)
5
- Collection.new(response["uploader"].delete("ticket"), self, response["uploader"], client)
6
+ response = client.get f(__method__), params.merge(tickets: tickets)
7
+ new_list(response["uploader"].delete("ticket"), client, response["uploader"])
6
8
  end
7
9
  end
8
10
  end
data/lib/flickr/api.rb CHANGED
@@ -42,9 +42,7 @@ class Flickr
42
42
  end
43
43
  end
44
44
 
45
- map_interface :media, Media
46
45
  map_interface :photos, Photo
47
- map_interface :videos, Video
48
46
  map_interface :people, Person
49
47
  map_interface :sets, Set
50
48
  map_interface :upload_tickets, UploadTicket
@@ -29,14 +29,12 @@ class Flickr
29
29
  [method, *options[:aliases]].each do |method|
30
30
  Flickr.api_methods[flickr_method] << "#{self.name}##{method}"
31
31
  end
32
- children.each { |child| Flickr.api_methods[flickr_method] << "#{child.name}##{method}" } if respond_to?(:children)
33
32
  end
34
33
 
35
34
  def class_api_method(method, flickr_method, options = {})
36
35
  [method, *options[:aliases]].each do |method|
37
36
  Flickr.api_methods[flickr_method] << "#{self.name}.#{method}"
38
37
  end
39
- children.each { |child| Flickr.api_methods[flickr_method] << "#{child.name}.#{method}" } if respond_to?(:children)
40
38
  end
41
39
 
42
40
  def api_method(*args)
@@ -44,7 +42,7 @@ class Flickr
44
42
  class_api_method(*args)
45
43
  end
46
44
 
47
- def flickr_method(method_name)
45
+ def f(method_name)
48
46
  resolve_flickr_method("#{self.name}.#{method_name}")
49
47
  end
50
48
 
@@ -58,7 +56,7 @@ class Flickr
58
56
  end
59
57
 
60
58
  module InstanceMethods
61
- def flickr_method(method_name)
59
+ def f(method_name)
62
60
  self.class.resolve_flickr_method("#{self.class.name}##{method_name}")
63
61
  end
64
62
  end
@@ -72,11 +70,7 @@ class Flickr
72
70
 
73
71
  module Methods
74
72
  def handle_extras(params)
75
- include_sizes(include_media(params))
76
- end
77
-
78
- def include_media(params)
79
- include_in_extras(params, "media")
73
+ include_sizes(params)
80
74
  end
81
75
 
82
76
  def include_sizes(params)
@@ -84,9 +78,9 @@ class Flickr
84
78
 
85
79
  abbrs = case params[:sizes]
86
80
  when :all
87
- Media::SIZES.values
81
+ Photo::SIZES.values
88
82
  else
89
- params[:sizes].map { |size| Media::SIZES[size] }
83
+ params[:sizes].map { |size| Photo::SIZES[size] }
90
84
  end
91
85
  urls = abbrs.map { |abbr| "url_#{abbr}" }.join(",")
92
86
  include_in_extras(params, urls)
@@ -6,15 +6,13 @@ class Flickr
6
6
  end
7
7
  end
8
8
 
9
- def upload(media, params = {})
10
- file = get_file(media)
11
- response = post "upload", {photo: file}.merge(params)
9
+ def upload(photo, params = {})
10
+ response = post "upload", {photo: get_file(photo)}.merge(params)
12
11
  response.body
13
12
  end
14
13
 
15
- def replace(media, id, params = {})
16
- file = get_file(media)
17
- response = post "replace", {photo: file, photo_id: id}.merge(params)
14
+ def replace(photo, id, params = {})
15
+ response = post "replace", {photo: get_file(photo), photo_id: id}.merge(params)
18
16
  response.body
19
17
  end
20
18
 
@@ -59,16 +57,6 @@ class Flickr
59
57
  %w[.svg .svgz] => 'image/svg+xml',
60
58
  %w[.tiff .tif] => 'image/tiff',
61
59
  %w[.ico] => 'image/vnd.microsoft.icon',
62
-
63
- %w[.mpg .mpeg .m1v .m1a .m2a .mpa .mpv] => 'video/mpeg',
64
- %w[.mp4 .m4a .m4p .m4b .m4r .m4v] => 'video/mp4',
65
- %w[.ogv .oga .ogx .ogg .spx] => 'video/ogg',
66
- %w[.mov .qt] => 'video/quicktime',
67
- %w[.webm] => 'video/webm',
68
- %w[.mkv .mk3d .mka .mks] => 'video/x-matroska',
69
- %w[.wmv] => 'video/x-ms-wmv',
70
- %w[.flv .f4v .f4p .f4a .f4b] => 'video/x-flv',
71
- %w[.avi] => 'video/avi'
72
60
  }
73
61
  end
74
62
  end