flickr-objects 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.md +95 -49
- data/lib/flickr/api/api_methods/collection.rb +4 -0
- data/lib/flickr/api/api_methods/flickr.rb +6 -0
- data/lib/flickr/api/api_methods/location.rb +4 -0
- data/lib/flickr/api/api_methods/media.rb +14 -0
- data/lib/flickr/api/api_methods/note.rb +4 -0
- data/lib/flickr/api/api_methods/permissions.rb +4 -0
- data/lib/flickr/api/api_methods/person.rb +12 -0
- data/lib/flickr/api/api_methods/photo.rb +4 -0
- data/lib/flickr/api/api_methods/set.rb +13 -0
- data/lib/flickr/api/api_methods/tag.rb +4 -0
- data/lib/flickr/api/api_methods/upload_ticket.rb +5 -0
- data/lib/flickr/api/api_methods/video.rb +4 -0
- data/lib/flickr/api/api_methods/visibility.rb +4 -0
- data/lib/flickr/api/collection.rb +4 -0
- data/lib/flickr/api/flickr.rb +2 -7
- data/lib/flickr/api/location.rb +4 -0
- data/lib/flickr/api/media.rb +0 -11
- data/lib/flickr/api/note.rb +4 -0
- data/lib/flickr/api/permissions.rb +4 -0
- data/lib/flickr/api/person.rb +0 -13
- data/lib/flickr/api/set.rb +0 -18
- data/lib/flickr/api/tag.rb +4 -0
- data/lib/flickr/api/upload_ticket.rb +8 -0
- data/lib/flickr/api/visibility.rb +4 -0
- data/lib/flickr/api.rb +6 -5
- data/lib/flickr/api_caller.rb +13 -4
- data/lib/flickr/client/middleware/retry.rb +0 -9
- data/lib/flickr/client/upload_client.rb +5 -6
- data/lib/flickr/client.rb +2 -2
- data/lib/flickr/objects/collection.rb +0 -2
- data/lib/flickr/objects/location.rb +0 -2
- data/lib/flickr/objects/media.rb +0 -2
- data/lib/flickr/objects/note.rb +0 -2
- data/lib/flickr/objects/permissions.rb +0 -2
- data/lib/flickr/objects/person.rb +0 -3
- data/lib/flickr/objects/photo.rb +0 -3
- data/lib/flickr/objects/set.rb +0 -3
- data/lib/flickr/objects/tag.rb +0 -2
- data/lib/flickr/objects/upload_ticket.rb +0 -2
- data/lib/flickr/objects/video.rb +0 -3
- data/lib/flickr/objects/visibility.rb +0 -2
- data/lib/flickr/objects.rb +7 -6
- data/lib/flickr/version.rb +1 -1
- metadata +40 -3
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Janko Marohnić
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -30,46 +30,77 @@ If you don't have your API key and shared secret yet, you can apply for them
|
|
30
30
|
Let's start with a general example.
|
31
31
|
|
32
32
|
```ruby
|
33
|
-
|
34
|
-
person = Flickr.people.find(preson_id)
|
35
|
-
photos = person.get_public_photos #=> API request
|
33
|
+
photos = Flickr.photos.search(user_id: "78733179@N04") #=> [#<Flickr::Photo: ...>, #<Flickr::Photo: ...>, ...]
|
36
34
|
|
37
35
|
photo = photos.first
|
38
|
-
photo.id
|
39
|
-
photo.title
|
40
|
-
photo.visibility.public?
|
41
|
-
photo.
|
42
|
-
photo.get_info!
|
43
|
-
photo.
|
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"
|
44
42
|
```
|
45
43
|
|
46
|
-
|
44
|
+
Methods like `Flickr.photos.search` are **class** API methods, and methods like `photo.tags=` and
|
45
|
+
`photo.get_info!` are **instance** API methods.
|
47
46
|
|
48
|
-
- `
|
49
|
-
- `photo.
|
47
|
+
- `Flickr.photos.search` <=> `Flickr::Photo.search`
|
48
|
+
- `photo.tags=` <=> `Flickr::Photo#tags=`
|
49
|
+
- `photo.get_info!` <=> `Flickr::Photo#get_info!`
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
`Flickr::Photo#get_info!` corresponds to `flickr.photos.getInfo`.
|
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:
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
54
|
+
- `Flickr::Photo.search` <=> flickr.photos.search
|
55
|
+
- `Flickr::Photo#tags=` <=> flickr.photos.setTags
|
56
|
+
- `Flickr::Photo#get_info!` <=> flickr.photos.getInfo
|
57
|
+
|
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:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
Flickr.people.find_by_email(find_email: "janko.marohnic@gmail.com")
|
64
|
+
```
|
65
|
+
|
66
|
+
you can rather call it like this:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
Flickr.people.find_by_email("janko.marohnic@gmail.com")
|
70
|
+
```
|
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:
|
58
81
|
|
59
82
|
```ruby
|
60
83
|
Flickr.api_methods["flickr.photosets.getList"] #=> ["Flickr::Person#get_sets"]
|
61
84
|
```
|
62
85
|
|
63
|
-
Now you found out that it
|
64
|
-
you can call it like this:
|
86
|
+
Now you found out that it is located in `Flickr::Person#get_sets`.
|
65
87
|
|
66
88
|
```ruby
|
89
|
+
# You can now call it like this:
|
67
90
|
sets = Flickr.people.find(person_id).get_sets
|
68
91
|
sets.first.id #=> "12312324"
|
92
|
+
|
93
|
+
# Or like this:
|
94
|
+
sets = Flickr.find_by_username("josh").get_sets
|
95
|
+
sets.first.id #=> "12312324"
|
69
96
|
```
|
70
97
|
|
71
98
|
## Sizes
|
72
99
|
|
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
|
+
|
73
104
|
```ruby
|
74
105
|
person = Flickr.person.find(person_id)
|
75
106
|
photo = person.get_public_photos(sizes: :all).first
|
@@ -81,19 +112,39 @@ photo.height #=> 280
|
|
81
112
|
|
82
113
|
photo.medium!(500)
|
83
114
|
photo.width #=> 500
|
115
|
+
|
116
|
+
# You can also call it like this:
|
117
|
+
photo.small240!
|
118
|
+
photo.width #=> 240
|
119
|
+
```
|
120
|
+
|
121
|
+
It is important here that you pass `sizes: :all` to `Flickr::Person#get_public_photos`.
|
122
|
+
So, in your (Rails) application, one could use it like this:
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
class PhotosController < ApplicationController
|
126
|
+
def index
|
127
|
+
person = Flickr.people.find("78733179@N04")
|
128
|
+
@photos = person.get_public_photos(sizes: :all).map(&:medium500!)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
```
|
132
|
+
```erb
|
133
|
+
<% @photos.each do |photo| %>
|
134
|
+
<%= image_tag photo.source_url, size: "#{photo.width}x#{photo.height}" %>
|
135
|
+
<% end %>
|
84
136
|
```
|
85
137
|
|
86
138
|
## Authenticated requests
|
87
139
|
|
88
|
-
If you need to make authenticated API requests (which you'll often want), you can create a kind
|
89
|
-
of a instance, assigning to it user's access token. That instance then has the same interface as `Flickr`.
|
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`.
|
90
142
|
|
91
143
|
```ruby
|
92
144
|
flickr = Flickr.new("ACCESS_TOKEN_KEY", "ACCESS_TOKEN_SECRET")
|
93
145
|
|
94
146
|
flickr.test_login #=> {"id" => "78733179@N04", "username" => ...}
|
95
|
-
flickr.people.find(
|
96
|
-
# ...
|
147
|
+
flickr.people.find("78733179@N04").get_photos #=> [#<Flickr::Photo ...>, #<Flickr::Photo, ...>, ...]
|
97
148
|
```
|
98
149
|
|
99
150
|
If you're in a Rails application, probably the best solution for authenticating
|
@@ -105,14 +156,12 @@ You can also assign the access token globally in your configuration.
|
|
105
156
|
|
106
157
|
```ruby
|
107
158
|
Flickr.configure do |config|
|
108
|
-
config.api_key = "API_KEY"
|
109
|
-
config.shared_secret = "SHARED_SECRET"
|
110
159
|
config.access_token_key = "ACCESS_TOKEN_KEY"
|
111
160
|
config.access_token_secret = "ACCESS_TOKEN_SECRET"
|
112
161
|
end
|
113
162
|
```
|
114
163
|
|
115
|
-
This is useful if you're, for example, using Flickr as a photo storage in your
|
164
|
+
This is especially useful if you're, for example, using Flickr as a photo storage in your
|
116
165
|
application, and that access token is actually yours.
|
117
166
|
|
118
167
|
|
@@ -124,26 +173,21 @@ photo = Flickr.photos.find(photo_id).get_info!
|
|
124
173
|
photo.title #=> "Dandelions"
|
125
174
|
```
|
126
175
|
|
127
|
-
|
128
|
-
you can
|
129
|
-
|
130
|
-
```ruby
|
131
|
-
ticket_id = Flickr.upload("/path/to/photo.jpg", title: "Dandelions", ansync: true)
|
132
|
-
ticket = Flickr.check_upload_tickets(ticket_id).first
|
133
|
-
ticket.complete? #=> false
|
176
|
+
In the first argument you can pass in either a string (path to the file) or an open file.
|
177
|
+
For the details on the additional options you can pass in, check out Flickr's [upload
|
178
|
+
documentation](http://www.flickr.com/services/api/upload.api.html).
|
134
179
|
|
135
|
-
|
180
|
+
For asynchronous upload take a look at [this wiki](https://github.com/janko-m/flickr-objects/wiki/Upload).
|
136
181
|
|
137
|
-
|
138
|
-
ticket.complete? #=> true
|
139
|
-
ticket.photo.id #=> "232594385"
|
140
|
-
```
|
182
|
+
## Attributes and methods
|
141
183
|
|
142
|
-
|
184
|
+
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.
|
143
188
|
|
144
|
-
For
|
145
|
-
|
146
|
-
and `Flickr::Video` have can be found in `lib/flickr/objects/media.rb`.
|
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").
|
147
191
|
|
148
192
|
![Flickr::Media](http://farm9.staticflickr.com/8195/8133340670_38c60aaca7.jpg)
|
149
193
|
|
@@ -151,12 +195,14 @@ As you can see, it is very readable ;)
|
|
151
195
|
|
152
196
|
## Few words
|
153
197
|
|
154
|
-
Most of the API methods are not covered yet (because they are so many
|
155
|
-
|
156
|
-
with normal demands should have everything he needs.
|
157
|
-
|
158
|
-
|
159
|
-
|
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.
|
201
|
+
|
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 :)
|
160
206
|
|
161
207
|
## Social
|
162
208
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Flickr
|
2
|
+
class Media < Object
|
3
|
+
class_api_method :get_from_contacts, "flickr.photos.getContactsPhotos"
|
4
|
+
class_api_method :search, "flickr.photos.search"
|
5
|
+
|
6
|
+
instance_api_method :add_tags, "flickr.photos.addTags"
|
7
|
+
instance_api_method :delete, "flickr.photos.delete"
|
8
|
+
instance_api_method :get_info!, "flickr.photos.getInfo"
|
9
|
+
instance_api_method :get_sizes!, "flickr.photos.getSizes"
|
10
|
+
instance_api_method :remove_tag, "flickr.photos.removeTag"
|
11
|
+
instance_api_method :set_content_type, "flickr.photos.setContentType", aliases: [:content_type=]
|
12
|
+
instance_api_method :set_tags, "flickr.photos.setTags", aliases: [:tags=]
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Flickr
|
2
|
+
class Person < Object
|
3
|
+
class_api_method :find_by_email, "flickr.people.findByEmail"
|
4
|
+
class_api_method :find_by_username, "flickr.people.findByUsername"
|
5
|
+
|
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]
|
10
|
+
instance_api_method :get_sets, "flickr.photosets.getList"
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Flickr
|
2
|
+
class Set < Object
|
3
|
+
class_api_method :create, "flickr.photosets.create"
|
4
|
+
|
5
|
+
instance_api_method :add_photo, "flickr.photosets.addPhoto", aliases: [:add_video, :add_media]
|
6
|
+
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 :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]
|
12
|
+
end
|
13
|
+
end
|
data/lib/flickr/api/flickr.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative "api_methods/flickr"
|
2
|
+
|
1
3
|
class Flickr
|
2
4
|
api_methods = proc do
|
3
5
|
def upload(media, params = {})
|
@@ -14,27 +16,20 @@ class Flickr
|
|
14
16
|
response = client.get flickr_method(__method__), params.merge(tickets: tickets.to_s)
|
15
17
|
Collection.new(response["uploader"].delete("ticket"), UploadTicket, response["uploader"], client)
|
16
18
|
end
|
17
|
-
api_method :check_upload_tickets, "flickr.photos.upload.checkTickets"
|
18
19
|
|
19
20
|
def test_login(params = {})
|
20
21
|
client.get flickr_method(__method__), params
|
21
22
|
end
|
22
|
-
api_method :test_login, "flickr.test.login"
|
23
23
|
|
24
24
|
def test_echo(params = {})
|
25
25
|
client.get flickr_method(__method__), params
|
26
26
|
end
|
27
|
-
api_method :test_echo, "flickr.test.echo"
|
28
27
|
|
29
28
|
def test_null(params = {})
|
30
29
|
client.get flickr_method(__method__), params
|
31
30
|
end
|
32
|
-
api_method :test_null, "flickr.test.null"
|
33
31
|
end
|
34
32
|
|
35
|
-
def self.api_method(*args) class_api_method(*args) end
|
36
33
|
instance_eval(&api_methods)
|
37
|
-
|
38
|
-
def self.api_method(*args) instance_api_method(*args) end
|
39
34
|
class_eval(&api_methods)
|
40
35
|
end
|
data/lib/flickr/api/media.rb
CHANGED
@@ -4,60 +4,49 @@ class Flickr
|
|
4
4
|
client.post flickr_method(__method__), params.merge(photo_id: id, tags: tags)
|
5
5
|
tags
|
6
6
|
end
|
7
|
-
instance_api_method :add_tags, "flickr.photos.addTags"
|
8
7
|
|
9
8
|
def delete(params = {})
|
10
9
|
client.post flickr_method(__method__), params.merge(photo_id: id)
|
11
10
|
self
|
12
11
|
end
|
13
|
-
instance_api_method :delete, "flickr.photos.delete"
|
14
12
|
|
15
13
|
def self.get_from_contacts(params = {})
|
16
14
|
response = client.get flickr_method(__method__), handle_extras(params)
|
17
15
|
Collection.new(response["photos"].delete("photo"), Media, response["photos"], client)
|
18
16
|
end
|
19
|
-
class_api_method :get_from_contacts, "flickr.photos.getContactsPhotos"
|
20
17
|
|
21
18
|
def get_info!(params = {})
|
22
19
|
response = client.get flickr_method(__method__), params.merge(photo_id: id)
|
23
20
|
@hash.update(response["photo"])
|
24
21
|
self
|
25
22
|
end
|
26
|
-
instance_api_method :get_info!, "flickr.photos.getInfo"
|
27
23
|
|
28
24
|
def get_sizes!(params = {})
|
29
25
|
response = client.get flickr_method(__method__), params.merge(photo_id: id)
|
30
26
|
@hash.update(response["sizes"])
|
31
27
|
self
|
32
28
|
end
|
33
|
-
instance_api_method :get_sizes!, "flickr.photos.getSizes"
|
34
29
|
|
35
30
|
def remove_tag(tag_id, params = {})
|
36
31
|
client.post flickr_method(__method__), params.merge(photo_id: id, tag_id: tag_id)
|
37
32
|
tag_id
|
38
33
|
end
|
39
|
-
instance_api_method :remove_tag, "flickr.photos.removeTag"
|
40
34
|
|
41
35
|
def self.search(params = {})
|
42
36
|
response = client.get flickr_method(__method__), handle_extras(params)
|
43
37
|
Collection.new(response["photos"].delete("photo"), self, response["photos"], client)
|
44
38
|
end
|
45
|
-
class_api_method :search, "flickr.photos.search"
|
46
39
|
|
47
40
|
def set_content_type(content_type, params = {})
|
48
41
|
client.post flickr_method(__method__), params.merge(photo_id: id, content_type: content_type)
|
49
42
|
content_type
|
50
43
|
end
|
51
|
-
instance_api_method :set_content_type, "flickr.photos.setContentType"
|
52
44
|
alias content_type= set_content_type
|
53
|
-
instance_api_method :content_type=, "flickr.photos.setContentType"
|
54
45
|
|
55
46
|
def set_tags(tags, params = {})
|
56
47
|
client.post flickr_method(__method__), params.merge(photo_id: id, tags: tags)
|
57
48
|
tags
|
58
49
|
end
|
59
|
-
instance_api_method :set_tags, "flickr.photos.setTags"
|
60
50
|
alias tags= set_tags
|
61
|
-
instance_api_method :tags=, "flickr.photos.setTags"
|
62
51
|
end
|
63
52
|
end
|
data/lib/flickr/api/person.rb
CHANGED
@@ -4,67 +4,54 @@ class Flickr
|
|
4
4
|
response = client.get flickr_method(__method__), params.merge(find_email: email)
|
5
5
|
new(response["user"], client)
|
6
6
|
end
|
7
|
-
class_api_method :find_by_email, "flickr.people.findByEmail"
|
8
7
|
|
9
8
|
def self.find_by_username(username, params = {})
|
10
9
|
response = client.get flickr_method(__method__), params.merge(username: username)
|
11
10
|
new(response["user"], client)
|
12
11
|
end
|
13
|
-
class_api_method :find_by_username, "flickr.people.findByUsername"
|
14
12
|
|
15
13
|
def get_info!(params = {})
|
16
14
|
response = client.get flickr_method(__method__), params.merge(user_id: id)
|
17
15
|
@hash.update(response["person"])
|
18
16
|
self
|
19
17
|
end
|
20
|
-
instance_api_method :get_info!, "flickr.people.getInfo"
|
21
18
|
|
22
19
|
def get_photos(params = {})
|
23
20
|
get_media(params).select { |object| object.is_a?(Flickr::Photo) }
|
24
21
|
end
|
25
|
-
instance_api_method :get_photos, "flickr.people.getPhotos"
|
26
22
|
def get_videos(params = {})
|
27
23
|
get_media(params).select { |object| object.is_a?(Flickr::Video) }
|
28
24
|
end
|
29
|
-
instance_api_method :get_videos, "flickr.people.getPhotos"
|
30
25
|
def get_media(params = {})
|
31
26
|
response = client.get flickr_method(__method__), handle_extras(params.merge(user_id: id))
|
32
27
|
Collection.new(response["photos"].delete("photo"), Media, response["photos"], client)
|
33
28
|
end
|
34
|
-
instance_api_method :get_media, "flickr.people.getPhotos"
|
35
29
|
|
36
30
|
def get_public_photos(params = {})
|
37
31
|
get_public_media(params).select { |object| object.is_a?(Flickr::Photo) }
|
38
32
|
end
|
39
|
-
instance_api_method :get_public_photos, "flickr.people.getPublicPhotos"
|
40
33
|
def get_public_videos(params = {})
|
41
34
|
get_public_media(params).select { |object| object.is_a?(Flickr::Video) }
|
42
35
|
end
|
43
|
-
instance_api_method :get_public_videos, "flickr.people.getPublicPhotos"
|
44
36
|
def get_public_media(params = {})
|
45
37
|
response = client.get flickr_method(__method__), handle_extras(params.merge(user_id: id))
|
46
38
|
Collection.new(response["photos"].delete("photo"), Media, response["photos"], client)
|
47
39
|
end
|
48
|
-
instance_api_method :get_public_media, "flickr.people.getPublicPhotos"
|
49
40
|
|
50
41
|
def get_public_photos_from_contacts(params = {})
|
51
42
|
get_public_media_from_contacts(params).select {|object| object.is_a?(Flickr::Photo) }
|
52
43
|
end
|
53
|
-
instance_api_method :get_public_photos_from_contacts, "flickr.photos.getContactsPublicPhotos"
|
54
44
|
def get_public_videos_from_contacts(params = {})
|
55
45
|
get_public_media_from_contacts(params).select {|object| object.is_a?(Flickr::Video) }
|
56
46
|
end
|
57
|
-
instance_api_method :get_public_videos_from_contacts, "flickr.photos.getContactsPublicPhotos"
|
58
47
|
def get_public_media_from_contacts(params = {})
|
59
48
|
response = client.get flickr_method(__method__), handle_extras(params.merge(user_id: id))
|
60
49
|
Collection.new(response["photos"].delete("photo"), Media, response["photos"], client)
|
61
50
|
end
|
62
|
-
instance_api_method :get_public_media_from_contacts, "flickr.photos.getContactsPublicPhotos"
|
63
51
|
|
64
52
|
def get_sets(params = {})
|
65
53
|
response = client.get flickr_method(__method__), params.merge(user_id: id)
|
66
54
|
Collection.new(response["photosets"].delete("photoset"), Set, response["photosets"], client)
|
67
55
|
end
|
68
|
-
instance_api_method :get_sets, "flickr.photosets.getList"
|
69
56
|
end
|
70
57
|
end
|
data/lib/flickr/api/set.rb
CHANGED
@@ -3,68 +3,50 @@ class Flickr
|
|
3
3
|
def add_photo(media_id, params = {})
|
4
4
|
client.post flickr_method(__method__), params.merge(photoset_id: id, photo_id: media_id)
|
5
5
|
end
|
6
|
-
instance_api_method :add_photo, "flickr.photosets.addPhoto"
|
7
6
|
alias add_video add_photo
|
8
|
-
instance_api_method :add_video, "flickr.photosets.addPhoto"
|
9
7
|
alias add_media add_photo
|
10
|
-
instance_api_method :add_media, "flickr.photosets.addPhoto"
|
11
8
|
|
12
9
|
def self.create(params = {})
|
13
10
|
response = client.post flickr_method(__method__), params
|
14
11
|
new(response["photoset"], client)
|
15
12
|
end
|
16
|
-
class_api_method :create, "flickr.photosets.create"
|
17
13
|
|
18
14
|
def delete(params = {})
|
19
15
|
client.post flickr_method(__method__), params.merge(photoset_id: id)
|
20
16
|
self
|
21
17
|
end
|
22
|
-
instance_api_method :delete, "flickr.photosets.delete"
|
23
18
|
|
24
19
|
def edit_photos(params = {})
|
25
20
|
client.post flickr_method(__method__), params.merge(photoset_id: id)
|
26
21
|
self
|
27
22
|
end
|
28
|
-
instance_api_method :edit_photos, "flickr.photosets.editPhotos"
|
29
23
|
alias edit_videos edit_photos
|
30
|
-
instance_api_method :edit_videos, "flickr.photosets.editPhotos"
|
31
24
|
alias edit_media edit_photos
|
32
|
-
instance_api_method :edit_media, "flickr.photosets.editPhotos"
|
33
25
|
|
34
26
|
def get_info!(params = {})
|
35
27
|
response = client.get flickr_method(__method__), params.merge(photoset_id: id)
|
36
28
|
@hash.update(response["photoset"])
|
37
29
|
self
|
38
30
|
end
|
39
|
-
instance_api_method :get_info!, "flickr.photosets.getInfo"
|
40
31
|
|
41
32
|
def get_photos(params = {})
|
42
33
|
get_media(params.merge(media: "photos"))
|
43
34
|
end
|
44
|
-
instance_api_method :get_photos, "flickr.photosets.getPhotos"
|
45
35
|
def get_videos(params = {})
|
46
36
|
get_media(params.merge(media: "videos"))
|
47
37
|
end
|
48
|
-
instance_api_method :get_videos, "flickr.photosets.getPhotos"
|
49
38
|
def get_media(params = {})
|
50
39
|
response = client.get flickr_method(__method__), handle_extras(params.merge(photoset_id: id))
|
51
40
|
Collection.new(response["photoset"].delete("photo"), Media, response["photoset"], client)
|
52
41
|
end
|
53
|
-
instance_api_method :get_media, "flickr.photosets.getPhotos"
|
54
42
|
|
55
43
|
def remove_photos(media_id, params = {})
|
56
44
|
client.post flickr_method(__method__), params.merge(photoset_id: id, photo_ids: media_id)
|
57
45
|
end
|
58
|
-
instance_api_method :remove_photos, "flickr.photosets.removePhotos"
|
59
46
|
alias remove_videos remove_photos
|
60
|
-
instance_api_method :remove_videos, "flickr.photosets.removePhotos"
|
61
47
|
alias remove_media remove_photos
|
62
|
-
instance_api_method :remove_media, "flickr.photosets.removePhotos"
|
63
48
|
|
64
|
-
instance_api_method :remove_media, "flickr.photosets.removePhoto"
|
65
49
|
alias remove_photo remove_photos
|
66
|
-
instance_api_method :remove_photo, "flickr.photosets.removePhoto"
|
67
50
|
alias remove_video remove_photos
|
68
|
-
instance_api_method :remove_video, "flickr.photosets.removePhoto"
|
69
51
|
end
|
70
52
|
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
class Flickr
|
2
|
+
class UploadTicket < Object
|
3
|
+
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
|
+
end
|
7
|
+
end
|
8
|
+
end
|
data/lib/flickr/api.rb
CHANGED
@@ -42,9 +42,10 @@ class Flickr
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
map_interface :media,
|
46
|
-
map_interface :photos,
|
47
|
-
map_interface :videos,
|
48
|
-
map_interface :people,
|
49
|
-
map_interface :sets,
|
45
|
+
map_interface :media, Media
|
46
|
+
map_interface :photos, Photo
|
47
|
+
map_interface :videos, Video
|
48
|
+
map_interface :people, Person
|
49
|
+
map_interface :sets, Set
|
50
|
+
map_interface :upload_tickets, UploadTicket
|
50
51
|
end
|
data/lib/flickr/api_caller.rb
CHANGED
@@ -25,16 +25,25 @@ class Flickr
|
|
25
25
|
end
|
26
26
|
|
27
27
|
module ClassMethods
|
28
|
-
def instance_api_method(method, flickr_method)
|
29
|
-
|
28
|
+
def instance_api_method(method, flickr_method, options = {})
|
29
|
+
[method, *options[:aliases]].each do |method|
|
30
|
+
Flickr.api_methods[flickr_method] << "#{self.name}##{method}"
|
31
|
+
end
|
30
32
|
children.each { |child| Flickr.api_methods[flickr_method] << "#{child.name}##{method}" } if respond_to?(:children)
|
31
33
|
end
|
32
34
|
|
33
|
-
def class_api_method(method, flickr_method)
|
34
|
-
|
35
|
+
def class_api_method(method, flickr_method, options = {})
|
36
|
+
[method, *options[:aliases]].each do |method|
|
37
|
+
Flickr.api_methods[flickr_method] << "#{self.name}.#{method}"
|
38
|
+
end
|
35
39
|
children.each { |child| Flickr.api_methods[flickr_method] << "#{child.name}.#{method}" } if respond_to?(:children)
|
36
40
|
end
|
37
41
|
|
42
|
+
def api_method(*args)
|
43
|
+
instance_api_method(*args)
|
44
|
+
class_api_method(*args)
|
45
|
+
end
|
46
|
+
|
38
47
|
def flickr_method(method_name)
|
39
48
|
resolve_flickr_method("#{self.name}.#{method_name}")
|
40
49
|
end
|
@@ -1,16 +1,7 @@
|
|
1
1
|
class Flickr
|
2
2
|
class Client < Faraday::Connection
|
3
3
|
module Middleware
|
4
|
-
# A copy-paste from Faraday's master branch
|
5
4
|
class Retry < Faraday::Middleware
|
6
|
-
# Public: Initialize middleware
|
7
|
-
#
|
8
|
-
# Options:
|
9
|
-
# max - Maximum number of retries (default: 2).
|
10
|
-
# interval - Pause in seconds between retries (default: 0).
|
11
|
-
# exceptions - The list of exceptions to handle. Exceptions can be
|
12
|
-
# given as Class, Module, or String. (default:
|
13
|
-
# [Errno::ETIMEDOUT, Timeout::Error, Error::TimeoutError])
|
14
5
|
def initialize(app, options = {})
|
15
6
|
super(app)
|
16
7
|
@retries, options = options, {} if options.is_a? Integer
|
@@ -26,14 +26,13 @@ class Flickr
|
|
26
26
|
|
27
27
|
def get_file(object)
|
28
28
|
file, content_type, file_path =
|
29
|
-
|
30
|
-
when "String"
|
29
|
+
if object.is_a?(String)
|
31
30
|
[File.open(object), determine_content_type(object), object]
|
32
|
-
|
33
|
-
[object, determine_content_type(object.path), object.path]
|
34
|
-
when "ActionDispatch::Http::UploadedFile"
|
31
|
+
elsif object.class.name == "ActionDispatch::Http::UploadedFile"
|
35
32
|
[object, object.content_type, object.tempfile]
|
36
|
-
|
33
|
+
elsif object.respond_to?(:read) and object.respond_to?(:path)
|
34
|
+
[object, (object.respond_to?(:content_type) && object.content_type) || determine_content_type(object.path), object.path]
|
35
|
+
elsif object.is_a?(Hash) && defined?(Sinatra)
|
37
36
|
[object[:tempfile], object[:type], object[:tempfile].path]
|
38
37
|
else
|
39
38
|
raise Error, "invalid file format"
|
data/lib/flickr/client.rb
CHANGED
data/lib/flickr/objects/media.rb
CHANGED
data/lib/flickr/objects/note.rb
CHANGED
data/lib/flickr/objects/photo.rb
CHANGED
data/lib/flickr/objects/set.rb
CHANGED
data/lib/flickr/objects/tag.rb
CHANGED
data/lib/flickr/objects/video.rb
CHANGED
data/lib/flickr/objects.rb
CHANGED
@@ -19,10 +19,11 @@ class Flickr
|
|
19
19
|
class Collection < Object; end
|
20
20
|
end
|
21
21
|
|
22
|
-
Flickr::Object.children.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
objects = Flickr::Object.children.dup
|
23
|
+
objects.each do |object|
|
24
|
+
underscored_name = object.name.split("::").last.split(/(?<=\w)(?=[A-Z])/).map(&:downcase).join("_")
|
25
|
+
require "flickr/objects/#{underscored_name}"
|
26
|
+
require "flickr/objects/attribute_values/#{underscored_name}"
|
27
|
+
require "flickr/api/#{underscored_name}"
|
28
|
+
require "flickr/api/api_methods/#{underscored_name}"
|
28
29
|
end
|
data/lib/flickr/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flickr-objects
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -123,6 +123,22 @@ dependencies:
|
|
123
123
|
- - ! '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '2.0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rack-test
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
126
142
|
description: This gem is an object-oriented wrapper for the Flickr API.
|
127
143
|
email:
|
128
144
|
- janko.marohnic@gmail.com
|
@@ -131,12 +147,33 @@ extensions: []
|
|
131
147
|
extra_rdoc_files: []
|
132
148
|
files:
|
133
149
|
- README.md
|
150
|
+
- LICENSE
|
151
|
+
- lib/flickr/api/api_methods/collection.rb
|
152
|
+
- lib/flickr/api/api_methods/flickr.rb
|
153
|
+
- lib/flickr/api/api_methods/location.rb
|
154
|
+
- lib/flickr/api/api_methods/media.rb
|
155
|
+
- lib/flickr/api/api_methods/note.rb
|
156
|
+
- lib/flickr/api/api_methods/permissions.rb
|
157
|
+
- lib/flickr/api/api_methods/person.rb
|
158
|
+
- lib/flickr/api/api_methods/photo.rb
|
159
|
+
- lib/flickr/api/api_methods/set.rb
|
160
|
+
- lib/flickr/api/api_methods/tag.rb
|
161
|
+
- lib/flickr/api/api_methods/upload_ticket.rb
|
162
|
+
- lib/flickr/api/api_methods/video.rb
|
163
|
+
- lib/flickr/api/api_methods/visibility.rb
|
164
|
+
- lib/flickr/api/collection.rb
|
134
165
|
- lib/flickr/api/flickr.rb
|
166
|
+
- lib/flickr/api/location.rb
|
135
167
|
- lib/flickr/api/media.rb
|
168
|
+
- lib/flickr/api/note.rb
|
169
|
+
- lib/flickr/api/permissions.rb
|
136
170
|
- lib/flickr/api/person.rb
|
137
171
|
- lib/flickr/api/photo.rb
|
138
172
|
- lib/flickr/api/set.rb
|
173
|
+
- lib/flickr/api/tag.rb
|
174
|
+
- lib/flickr/api/upload_ticket.rb
|
139
175
|
- lib/flickr/api/video.rb
|
176
|
+
- lib/flickr/api/visibility.rb
|
140
177
|
- lib/flickr/api.rb
|
141
178
|
- lib/flickr/api_caller.rb
|
142
179
|
- lib/flickr/client/methods_client.rb
|
@@ -202,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
239
|
version: '0'
|
203
240
|
segments:
|
204
241
|
- 0
|
205
|
-
hash:
|
242
|
+
hash: -2444191243502827259
|
206
243
|
requirements: []
|
207
244
|
rubyforge_project:
|
208
245
|
rubygems_version: 1.8.23
|