flickr-objects 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +49 -63
- data/lib/flickr/api/abstract/params_processor.rb +68 -0
- data/lib/flickr/api/abstract.rb +113 -0
- data/lib/flickr/api/general.rb +75 -0
- data/lib/flickr/api/person.rb +91 -39
- data/lib/flickr/api/photo.rb +213 -108
- data/lib/flickr/api/set.rb +114 -55
- data/lib/flickr/api/upload_ticket.rb +17 -6
- data/lib/flickr/api.rb +90 -35
- data/lib/flickr/attributes.rb +200 -0
- data/lib/flickr/base_converter.rb +29 -0
- data/lib/flickr/client/data.rb +47 -0
- data/lib/flickr/client/oauth.rb +44 -0
- data/lib/flickr/client/upload.rb +55 -0
- data/lib/flickr/client.rb +77 -33
- data/lib/flickr/configuration.rb +85 -14
- data/lib/flickr/error.rb +58 -0
- data/lib/flickr/middleware.rb +52 -28
- data/lib/flickr/oauth.rb +89 -74
- data/lib/flickr/object/attribute_locations/list.rb +25 -0
- data/lib/flickr/object/attribute_locations/location.rb +29 -0
- data/lib/flickr/object/attribute_locations/permissions.rb +31 -0
- data/lib/flickr/object/attribute_locations/person/upload_status.rb +32 -0
- data/lib/flickr/object/attribute_locations/person.rb +78 -0
- data/lib/flickr/object/attribute_locations/photo/exif.rb +29 -0
- data/lib/flickr/object/attribute_locations/photo/note.rb +36 -0
- data/lib/flickr/object/attribute_locations/photo/tag.rb +23 -0
- data/lib/flickr/object/attribute_locations/photo.rb +164 -0
- data/lib/flickr/object/attribute_locations/set.rb +53 -0
- data/lib/flickr/object/attribute_locations/upload_ticket.rb +30 -0
- data/lib/flickr/object/attribute_locations/visibility.rb +24 -0
- data/lib/flickr/object/list/kaminari.rb +30 -0
- data/lib/flickr/object/list/normal.rb +27 -0
- data/lib/flickr/object/list/will_paginate.rb +31 -0
- data/lib/flickr/object/list.rb +87 -0
- data/lib/flickr/object/location.rb +35 -0
- data/lib/flickr/object/permissions.rb +18 -0
- data/lib/flickr/object/person/upload_status.rb +22 -0
- data/lib/flickr/object/person.rb +93 -0
- data/lib/flickr/object/photo/exif.rb +35 -0
- data/lib/flickr/object/photo/note.rb +20 -0
- data/lib/flickr/object/photo/size.rb +67 -0
- data/lib/flickr/object/photo/tag.rb +23 -0
- data/lib/flickr/object/photo.rb +349 -0
- data/lib/flickr/object/set.rb +114 -0
- data/lib/flickr/object/upload_ticket.rb +31 -0
- data/lib/flickr/object/visibility.rb +16 -0
- data/lib/flickr/object.rb +118 -27
- data/lib/flickr/sanitized_file.rb +70 -0
- data/lib/flickr/version.rb +4 -2
- data/lib/flickr.rb +69 -15
- metadata +89 -103
- data/lib/flickr/api/api_methods/flickr.rb +0 -5
- data/lib/flickr/api/api_methods/person.rb +0 -14
- data/lib/flickr/api/api_methods/photo.rb +0 -26
- data/lib/flickr/api/api_methods/set.rb +0 -18
- data/lib/flickr/api/api_methods/upload_ticket.rb +0 -5
- data/lib/flickr/api/flickr.rb +0 -35
- data/lib/flickr/api_caller.rb +0 -98
- data/lib/flickr/client/methods_client.rb +0 -22
- data/lib/flickr/client/upload_client.rb +0 -62
- data/lib/flickr/errors.rb +0 -19
- data/lib/flickr/helpers/base_58.rb +0 -15
- data/lib/flickr/helpers/boolean.rb +0 -4
- data/lib/flickr/helpers/core_ext.rb +0 -5
- data/lib/flickr/object/attribute/converter.rb +0 -49
- data/lib/flickr/object/attribute/finder.rb +0 -32
- data/lib/flickr/object/attribute.rb +0 -45
- data/lib/flickr/objects/attribute_values/list.rb +0 -10
- data/lib/flickr/objects/attribute_values/location.rb +0 -14
- data/lib/flickr/objects/attribute_values/note.rb +0 -11
- data/lib/flickr/objects/attribute_values/permissions.rb +0 -12
- data/lib/flickr/objects/attribute_values/person/upload_status.rb +0 -16
- data/lib/flickr/objects/attribute_values/person.rb +0 -24
- data/lib/flickr/objects/attribute_values/photo.rb +0 -84
- data/lib/flickr/objects/attribute_values/set.rb +0 -17
- data/lib/flickr/objects/attribute_values/tag.rb +0 -9
- data/lib/flickr/objects/attribute_values/upload_ticket.rb +0 -9
- data/lib/flickr/objects/attribute_values/visibility.rb +0 -10
- data/lib/flickr/objects/list.rb +0 -86
- data/lib/flickr/objects/location.rb +0 -26
- data/lib/flickr/objects/note.rb +0 -14
- data/lib/flickr/objects/permissions.rb +0 -14
- data/lib/flickr/objects/person/upload_status.rb +0 -14
- data/lib/flickr/objects/person.rb +0 -43
- data/lib/flickr/objects/photo.rb +0 -113
- data/lib/flickr/objects/set.rb +0 -29
- data/lib/flickr/objects/tag.rb +0 -17
- data/lib/flickr/objects/upload_ticket.rb +0 -18
- data/lib/flickr/objects/visibility.rb +0 -12
- data/lib/flickr/objects.rb +0 -25
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eebc705fe752afa94151b9a736292d266f37b15a
|
4
|
+
data.tar.gz: 70de81c78b4a5bdb9e575aa96b2aa5d069523ba8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4003856d98c98ddf1b9336b51452c846134d991b9e9cf230f1e4b75830cec0b60d354c2408db07a207133cef37438e8b351d7a9bc27bba09f7a1c52236047580
|
7
|
+
data.tar.gz: 4e4698dbc564b5efb8b496c48bccc6216239ae711b22ee4268216c25af2998c3449b3150e783db4817e3c105612d21fbade3bcff4df434c2fa8cb31a727c0bf4
|
data/README.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# Flickr Objects
|
2
2
|
|
3
3
|
This gem is an object-oriented wrapper for the [Flickr API](http://flickr.com/api).
|
4
|
-
To see its capability, take a look at this nice demonstration:
|
5
4
|
|
6
|
-
[http://janko-m.github.com/flickr-objects/](http://janko-m.github.com/flickr-objects/)
|
5
|
+
- Web page: [http://janko-m.github.com/flickr-objects/](http://janko-m.github.com/flickr-objects/)
|
6
|
+
- Home page: [https://github.com/janko-m/flickr-objects](https://github.com/janko-m/flickr-objects)
|
7
|
+
- API Documentation: [http://rubydoc.info/gems/flickr-objects/](http://rubydoc.info/gems/flickr-objects/)
|
7
8
|
|
8
9
|
## Installation and setup
|
9
10
|
|
@@ -17,34 +18,34 @@ Now create an initializer where you set your Flickr credentials.
|
|
17
18
|
|
18
19
|
```ruby
|
19
20
|
Flickr.configure do |config|
|
20
|
-
config.api_key
|
21
|
+
config.api_key = "API_KEY"
|
21
22
|
config.shared_secret = "SHARED_SECRET"
|
22
23
|
end
|
23
24
|
```
|
24
25
|
|
25
|
-
If you don't have them yet, you can apply for them
|
26
|
+
If you don't have them yet, you can apply for them
|
27
|
+
[here](http://www.flickr.com/services/apps/create/apply).
|
26
28
|
|
27
|
-
For list of possible configuration options, take a look at
|
28
|
-
|
29
|
+
For list of possible configuration options, take a look at
|
30
|
+
[`Flickr::Configuration`](http://rubydoc.info/gems/flickr-objects/Flickr/Configuration).
|
29
31
|
|
30
32
|
## Usage
|
31
33
|
|
32
|
-
This gem maps [Flickr's API methods](http://flickr.com/api) to methods
|
33
|
-
A handy reference for those mappings is in `Flickr.api_methods`:
|
34
|
+
This gem maps [Flickr's API methods](http://flickr.com/api) to Ruby methods.
|
34
35
|
|
35
36
|
```ruby
|
36
|
-
Flickr.
|
37
|
-
Flickr.
|
37
|
+
Flickr.photos.search(...) # flickr.photos.search
|
38
|
+
Flickr.person.get_sets(...) # flickr.photosets.getList
|
38
39
|
```
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
For the list of all API methods (and their related Flickr's methods), see the
|
42
|
+
[`Flickr::Api`](http://rubydoc.info/gems/flickr-objects/Flickr/Api) module.
|
43
|
+
These methods are included to the `Flickr` module.
|
43
44
|
|
44
|
-
|
45
|
+
Example:
|
45
46
|
|
46
47
|
```ruby
|
47
|
-
photos = Flickr.photos.search(user_id: "78733179@N04") #=> [#<Flickr::Photo: ...>, #<Flickr::Photo: ...>, ...]
|
48
|
+
photos = Flickr.photos.search(user_id: "78733179@N04") #=> [#<Flickr::Object::Photo: ...>, #<Flickr::Object::Photo: ...>, ...]
|
48
49
|
|
49
50
|
photo = photos.first
|
50
51
|
photo.id #=> "231233252"
|
@@ -52,45 +53,45 @@ photo.title #=> "My cat"
|
|
52
53
|
photo.visibility.public? #=> true
|
53
54
|
|
54
55
|
person = Flickr.people.find("78733179@N04")
|
55
|
-
|
56
|
-
|
57
|
-
set = sets.first
|
56
|
+
set = person.sets.first
|
58
57
|
set.id #=> "11243423"
|
59
58
|
set.photos_count #=> 40
|
60
59
|
```
|
61
60
|
|
62
|
-
|
61
|
+
Few notes here:
|
63
62
|
|
64
|
-
-
|
65
|
-
|
66
|
-
|
63
|
+
- flickr-objects distinguishes **instance** from **class** API methods. So,
|
64
|
+
`Flickr.photos.search` is a class API method. And `Flickr.people.get_sets`
|
65
|
+
is by its nature an **instance** API method, because we're finding sets
|
66
|
+
*from a person*; in that case we can call `#get_sets` on an instance of
|
67
|
+
person (so that our code looks better).
|
68
|
+
- Flickr objects can always be instantiated with `Flickr.<objects>.find(id)`
|
67
69
|
(in the above example we did `Flickr.people.find(id)`).
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
+
## Arguments to API methods
|
72
|
+
|
73
|
+
By its nature, API methods always accept a hash of parameters. Using that approach,
|
74
|
+
this would be the call for "flickr.people.findByEmail":
|
71
75
|
|
72
76
|
```ruby
|
73
77
|
Flickr.people.find_by_email(find_email: "janko.marohnic@gmail.com")
|
74
78
|
```
|
75
79
|
|
76
|
-
|
80
|
+
But that looks lame. Luckily, in these kind of methods flickr-objects improves
|
81
|
+
the argument list:
|
77
82
|
|
78
83
|
```ruby
|
79
84
|
Flickr.people.find_by_email("janko.marohnic@gmail.com")
|
80
85
|
```
|
81
86
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
For documentation on valid arguments, just look at the source code at
|
86
|
-
[`lib/flickr/api`](https://github.com/janko-m/flickr-objects/tree/master/lib/flickr/api),
|
87
|
-
under a specific object.
|
87
|
+
Of course, all parameters are documented:
|
88
|
+
[`Flickr::Api::Person#find_by_email`](http://rubydoc.info/gems/flickr-objects/Flickr/Api/Person#find_by_email-instance_method)
|
88
89
|
|
89
90
|
## Sizes
|
90
91
|
|
91
92
|
```ruby
|
92
|
-
person = Flickr.person.find(
|
93
|
-
photo = person.
|
93
|
+
person = Flickr.person.find("78733179@N04")
|
94
|
+
photo = person.public_photos(sizes: true).first
|
94
95
|
|
95
96
|
photo.small!(320)
|
96
97
|
photo.source_url #=> "http://farm9.staticflickr.com/8191/8130464513_780e01decd_n.jpg"
|
@@ -101,14 +102,14 @@ photo.medium!(500)
|
|
101
102
|
photo.width #=> 500
|
102
103
|
```
|
103
104
|
|
104
|
-
It is important here that you pass `sizes:
|
105
|
+
It is important here that you pass `sizes: true` to `Flickr::Person#public_photos`.
|
105
106
|
So, in your (Rails) application, one could use it like this:
|
106
107
|
|
107
108
|
```ruby
|
108
109
|
class PhotosController < ApplicationController
|
109
110
|
def index
|
110
111
|
person = Flickr.people.find("78733179@N04")
|
111
|
-
@photos = person.
|
112
|
+
@photos = person.public_photos(sizes: true).map(&:medium500!)
|
112
113
|
end
|
113
114
|
end
|
114
115
|
```
|
@@ -118,12 +119,11 @@ end
|
|
118
119
|
<% end %>
|
119
120
|
```
|
120
121
|
|
121
|
-
To find out more,
|
122
|
+
To find out more, see [`Flickr::Object::Photo`](http://rubydoc.info/gems/flickr-objects/Flickr/Object/Photo).
|
122
123
|
|
123
124
|
## Authentication
|
124
125
|
|
125
|
-
|
126
|
-
instance, assigning it the user's access token.
|
126
|
+
You may need to make authenticated API requests, using an access token.
|
127
127
|
|
128
128
|
```ruby
|
129
129
|
flickr = Flickr.new("ACCESS_TOKEN_KEY", "ACCESS_TOKEN_SECRET")
|
@@ -133,10 +133,10 @@ flickr.test_login #=> {"id" => "78733179@N04", "username" => ...}
|
|
133
133
|
flickr.people.find("78733179@N04").get_photos #=> [#<Flickr::Photo ...>, #<Flickr::Photo, ...>, ...]
|
134
134
|
```
|
135
135
|
|
136
|
-
For details on how to authenticate
|
137
|
-
[
|
136
|
+
For details on how to authenticate, i.e. obtain the access token, see
|
137
|
+
[`Flickr::OAuth`](http://rubydoc.info/gems/flickr-objects/Flickr/OAuth).
|
138
138
|
|
139
|
-
|
139
|
+
If you want, you can also assign the access token globally in your configuration.
|
140
140
|
|
141
141
|
```ruby
|
142
142
|
Flickr.configure do |config|
|
@@ -145,6 +145,8 @@ Flickr.configure do |config|
|
|
145
145
|
end
|
146
146
|
```
|
147
147
|
|
148
|
+
Naturally, this way you don't need to create an instance like above.
|
149
|
+
|
148
150
|
## Upload
|
149
151
|
|
150
152
|
```ruby
|
@@ -153,30 +155,14 @@ photo = Flickr.photos.find(photo_id).get_info!
|
|
153
155
|
photo.title #=> "Dandelions"
|
154
156
|
```
|
155
157
|
|
156
|
-
|
157
|
-
For the details on the additional options you can pass in, check out Flickr's [upload
|
158
|
-
documentation](http://www.flickr.com/services/api/upload.api.html).
|
159
|
-
|
160
|
-
For asynchronous upload take a look at [this wiki](https://github.com/janko-m/flickr-objects/wiki/Upload).
|
161
|
-
|
162
|
-
## Attributes and methods
|
163
|
-
|
164
|
-
For the list of attributes and methods that Flickr objects have, the best place to look at
|
165
|
-
is the source code. The source code is written in such a simple way that it acts as its
|
166
|
-
own documentation, so don't be discouraged if you haven't had experience in looking into other
|
167
|
-
people's code yet :)
|
168
|
-
|
169
|
-
For example, list of `Flickr::Photo`'s attributes can be found in
|
170
|
-
[`lib/flickr/objects/photo.rb`](https://github.com/janko-m/flickr-objects/blob/master/lib/flickr/objects/photo.rb).
|
171
|
-
Take a look just to see how it looks like :)
|
158
|
+
See [`Flickr.upload`](http://rubydoc.info/gems/flickr-objects/Flickr/Api/General#upload-instance_method)
|
172
159
|
|
173
160
|
## Few words
|
174
161
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
[Twitter](https://twitter.com/m_janko). Pull requests are also very welcome :)
|
162
|
+
Many of the API methods are not covered yet (because they are so many).
|
163
|
+
I believe I covered all the important ones, but if you wish for me to
|
164
|
+
cover certain new ones, feel free to contact me via [Twitter](https://twitter.com/m_janko).
|
165
|
+
I also wouldn't mind getting a pull request ;)
|
180
166
|
|
181
167
|
## Social
|
182
168
|
|
@@ -184,4 +170,4 @@ You can follow me on Twitter, I'm [@m_janko](https://twitter.com/m_janko).
|
|
184
170
|
|
185
171
|
## License
|
186
172
|
|
187
|
-
This project is released under the [MIT license](
|
173
|
+
This project is released under the [MIT license](LICENSE).
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Flickr
|
2
|
+
module Api
|
3
|
+
class Abstract
|
4
|
+
|
5
|
+
##
|
6
|
+
# Does processing of parameters passed to API requests, to enable nicer
|
7
|
+
# syntax.
|
8
|
+
#
|
9
|
+
class ParamsProcessor
|
10
|
+
|
11
|
+
attr_reader :params
|
12
|
+
|
13
|
+
def initialize(params)
|
14
|
+
@params = params
|
15
|
+
end
|
16
|
+
|
17
|
+
def process_for(flickr_method)
|
18
|
+
add_sizes! if add_sizes?(flickr_method)
|
19
|
+
|
20
|
+
@params
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
##
|
26
|
+
# @example
|
27
|
+
# processor = ParamsProcessor.new({sizes: true})
|
28
|
+
# processor.add_sizes!
|
29
|
+
# processor.params #=> {extras: "url_sq,url_t,url_q,url_s,url_n,url_m,url_z,url_c,url_l,url_h,url_k,url_o"}
|
30
|
+
#
|
31
|
+
# processor = ParamsProcessor.new({sizes: ["Square 75", "Thumbnail"]})
|
32
|
+
# processor.add_sizes!
|
33
|
+
# processor.params #=> {extras: "url_sq,url_t"}
|
34
|
+
#
|
35
|
+
def add_sizes!
|
36
|
+
if [true, :all].include? @params[:sizes]
|
37
|
+
@params[:sizes] = Flickr::Object::Photo::SIZES
|
38
|
+
end
|
39
|
+
|
40
|
+
sizes = Array(@params[:sizes])
|
41
|
+
.map { |name| Flickr::Object::Photo::Size.new(name) }
|
42
|
+
.map { |size| "url_#{size.abbreviation}" }
|
43
|
+
existing_extras = String(@params[:extras]).split(",")
|
44
|
+
|
45
|
+
@params[:extras] = (existing_extras + sizes).join(",")
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_sizes?(flickr_method)
|
49
|
+
[ "photos.getContactsPhotos",
|
50
|
+
"photos.search",
|
51
|
+
"photos.getNotInSet",
|
52
|
+
"photos.getRecent",
|
53
|
+
"photos.getUntagged",
|
54
|
+
"photos.getWithGeoData",
|
55
|
+
"photos.getWithoutGeoData",
|
56
|
+
"photos.RecentlyUpdated",
|
57
|
+
"photosets.getPhotos",
|
58
|
+
"people.getPhotos",
|
59
|
+
"people.getPhotosOf",
|
60
|
+
"people.getPublicPhotos",
|
61
|
+
"people.getContactsPublicPhotos" ].include?(flickr_method)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module Flickr
|
2
|
+
module Api
|
3
|
+
|
4
|
+
##
|
5
|
+
# This class abstracts the interface for communication with the Flickr API.
|
6
|
+
#
|
7
|
+
# @see Flickr::ApiError
|
8
|
+
#
|
9
|
+
class Abstract
|
10
|
+
|
11
|
+
extend Flickr::AutoloadHelper
|
12
|
+
|
13
|
+
autoload_names :ParamsProcessor
|
14
|
+
|
15
|
+
##
|
16
|
+
# @private
|
17
|
+
#
|
18
|
+
def self.object_class
|
19
|
+
Flickr::Object.const_get(name.match(/^Flickr::Api::/).post_match)
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# @private
|
24
|
+
#
|
25
|
+
def initialize(access_token = nil)
|
26
|
+
@access_token = access_token
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# @param id [String] ID of the object to be instantiated
|
31
|
+
# @example
|
32
|
+
# person = Flickr.photos.find("1")
|
33
|
+
# person.photos.each do |photo|
|
34
|
+
# # ...
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
def find(id)
|
38
|
+
object_class = self.class.object_class
|
39
|
+
object_class.new({"id" => id}, @access_token)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def get(flickr_method, params = {})
|
45
|
+
make_request(:get, flickr_method, params)
|
46
|
+
end
|
47
|
+
|
48
|
+
def post(flickr_method, params = {})
|
49
|
+
make_request(:post, flickr_method, params)
|
50
|
+
end
|
51
|
+
|
52
|
+
def make_request(http_method, flickr_method, params = {})
|
53
|
+
process_params(params, flickr_method)
|
54
|
+
client[:data].send(http_method, "flickr.#{flickr_method}", params)
|
55
|
+
end
|
56
|
+
|
57
|
+
def upload(params = {})
|
58
|
+
client[:upload].upload(params)
|
59
|
+
end
|
60
|
+
|
61
|
+
def replace(params = {})
|
62
|
+
client[:upload].replace(params)
|
63
|
+
end
|
64
|
+
|
65
|
+
def client
|
66
|
+
{
|
67
|
+
data: Flickr::Client::Data.new(@access_token),
|
68
|
+
upload: Flickr::Client::Upload.new(@access_token),
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# Enhances params, allowing nicer syntax.
|
74
|
+
#
|
75
|
+
# @example
|
76
|
+
# params = {sizes: ["Thumbnail", "Medium 500"]}
|
77
|
+
# process_params(params, "flickr.photos.search")
|
78
|
+
# params #=> {extras: "url_t,url_m"}
|
79
|
+
# @see Flickr::Api::Abstract::ParamsProcessor
|
80
|
+
#
|
81
|
+
def process_params(params, flickr_method)
|
82
|
+
ParamsProcessor.new(params).process_for(flickr_method)
|
83
|
+
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# @example
|
87
|
+
# photo = new_object(:Photo, {"id" => "1"})
|
88
|
+
# photo #=> #<Flickr::Object::Photo:0x007fcb9e08dee8 id="1">
|
89
|
+
#
|
90
|
+
def new_object(class_name, attributes)
|
91
|
+
object_class = self.class.object_class.const_get(class_name)
|
92
|
+
object_class.new(attributes, @access_token)
|
93
|
+
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# @example
|
97
|
+
# photos = new_list(:Photo, [{"id" => "1"}], {"page" => 1})
|
98
|
+
# photos #=> #<Flickr::Object::List:0x007ffe6b51d468
|
99
|
+
# # @attributes={"page"=>1},
|
100
|
+
# # @objects=
|
101
|
+
# # [#<Flickr::Object::Photo:0x007ffe6b4ff760 owner=#<Flickr::Object::Person:0x007ffe6b52d408 >>,
|
102
|
+
# # #<Flickr::Object::Photo:0x007ffe6b4fdcd0 owner=#<Flickr::Object::Person:0x007ffe6b556ab0 >>]>
|
103
|
+
#
|
104
|
+
def new_list(class_name, attributes_list, list_attributes)
|
105
|
+
objects = attributes_list.map { |attributes| new_object(class_name, attributes) }
|
106
|
+
list = Flickr::Object::List.new(list_attributes)
|
107
|
+
list.populate(objects)
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require "flickr/sanitized_file"
|
2
|
+
|
3
|
+
module Flickr
|
4
|
+
module Api
|
5
|
+
|
6
|
+
class General < Abstract
|
7
|
+
|
8
|
+
##
|
9
|
+
# @example
|
10
|
+
# photo = File.open("/path/to/dandelions.jpg")
|
11
|
+
# Flickr.upload(photo, title: "Dandelions")
|
12
|
+
# @param photo [String, File, Rails, Sinatra] Photo to upload
|
13
|
+
# @param params [Hash] See documentation below
|
14
|
+
# @return [String] ID of the uploaded photo (if synchronous)
|
15
|
+
# @return [String] ID of the upload ticket (if asynchronous). See {Flickr::Api::UploadTicket#check}.
|
16
|
+
# @docs [Upload API](http://www.flickr.com/services/api/upload.api.html)
|
17
|
+
#
|
18
|
+
def upload(photo, params = {})
|
19
|
+
response = super params.merge(photo: SanitizedFile.new(photo))
|
20
|
+
params[:async] == 1 ? response["ticketid"] : response["photoid"]
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# @example
|
25
|
+
# photo = File.open("/path/to/dandelions.jpg")
|
26
|
+
# Flickr.replace(photo, photo_id, title: "Dandelions")
|
27
|
+
# @param photo [String, File, Rails, Sinatra] Photo to upload
|
28
|
+
# @param photo_id [String] ID of the photo which will be replaced
|
29
|
+
# @param params [Hash] See documentation below
|
30
|
+
# @return [String] ID of the uploaded photo (if synchronous)
|
31
|
+
# @return [String] ID of the upload ticket (if asynchronous)
|
32
|
+
# @docs [Replace API](http://www.flickr.com/services/api/replace.api.html)
|
33
|
+
#
|
34
|
+
def replace(photo, photo_id, params = {})
|
35
|
+
response = super params.merge(photo: SanitizedFile.new(photo), photo_id: photo_id)
|
36
|
+
params[:async] == 1 ? response["ticketid"] : response["photoid"]["__content__"]
|
37
|
+
end
|
38
|
+
|
39
|
+
##
|
40
|
+
# @return [Array<String>]
|
41
|
+
# @docs [flickr.reflection.getMethods](http://www.flickr.com/services/api/flickr.reflection.getMethods.html)
|
42
|
+
#
|
43
|
+
def get_methods(params = {})
|
44
|
+
response = get "reflection.getMethods", params
|
45
|
+
response["methods"]["method"].map { |hash| hash["_content"] }
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# @return [Hash]
|
50
|
+
# @docs [flickr.test.login](http://www.flickr.com/services/api/flickr.test.login.html)
|
51
|
+
#
|
52
|
+
def test_login(params = {})
|
53
|
+
get "test.login", params
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# @return [Hash]
|
58
|
+
# @docs [flickr.test.echo](http://www.flickr.com/services/api/flickr.test.echo.html)
|
59
|
+
#
|
60
|
+
def test_echo(params = {})
|
61
|
+
get "test.echo", params
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# @return [Hash]
|
66
|
+
# @docs [flickr.test.null](http://www.flickr.com/services/api/flickr.test.null.html)
|
67
|
+
#
|
68
|
+
def test_null(params = {})
|
69
|
+
get "test.null", params
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
data/lib/flickr/api/person.rb
CHANGED
@@ -1,51 +1,103 @@
|
|
1
|
-
|
1
|
+
module Flickr
|
2
|
+
module Api
|
2
3
|
|
3
|
-
class
|
4
|
-
class Person < Object
|
5
|
-
def self.find_by_email(email, params = {})
|
6
|
-
response = client.get f(__method__), params.merge(find_email: email)
|
7
|
-
new(response["user"], client)
|
8
|
-
end
|
4
|
+
class Person < Abstract
|
9
5
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
##
|
7
|
+
# @param email [String]
|
8
|
+
# @return [Flickr::Object::Person]
|
9
|
+
# @docs [flickr.people.findByEmail](http://www.flickr.com/services/api/flickr.people.findByEmail.html)
|
10
|
+
#
|
11
|
+
def find_by_email(email, params = {})
|
12
|
+
response = get "people.findByEmail", params.merge(find_email: email)
|
13
|
+
new_object(:Person, response["user"])
|
14
|
+
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
##
|
17
|
+
# @param username [String]
|
18
|
+
# @return [Flickr::Object::Person]
|
19
|
+
# @docs [flickr.people.findByUsername](http://www.flickr.com/services/api/flickr.people.findByUsername.html)
|
20
|
+
#
|
21
|
+
def find_by_username(username, params = {})
|
22
|
+
response = get "people.findByUsername", params.merge(username: username)
|
23
|
+
new_object(:Person, response["user"])
|
24
|
+
end
|
19
25
|
|
20
|
-
|
21
|
-
|
22
|
-
@
|
23
|
-
|
24
|
-
|
26
|
+
##
|
27
|
+
# @return [Flickr::Object::Person::UploadStatus]
|
28
|
+
# @docs [flickr.people.getUploadStatus](http://www.flickr.com/services/api/flickr.people.getUploadStatus.html)
|
29
|
+
#
|
30
|
+
def get_upload_status(params = {})
|
31
|
+
response = get "people.getUploadStatus", params
|
32
|
+
new_object(:UploadStatus, response["user"])
|
33
|
+
end
|
25
34
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
35
|
+
##
|
36
|
+
# @param person_id [String]
|
37
|
+
# @return [Flickr::Object::Person]
|
38
|
+
# @docs [flickr.people.getInfo](http://www.flickr.com/services/api/flickr.people.getInfo.html)
|
39
|
+
#
|
40
|
+
def get_info(person_id, params = {})
|
41
|
+
response = get "people.getInfo", params.merge(user_id: person_id)
|
42
|
+
new_object(:Person, response["person"])
|
43
|
+
end
|
30
44
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
45
|
+
##
|
46
|
+
# @param person_id [String]
|
47
|
+
# @param params [Hash] See documentation below
|
48
|
+
# @return [Flickr::Object::List<Flickr::Object::Photo>]
|
49
|
+
# @docs [flickr.people.getPhotos](http://www.flickr.com/services/api/flickr.people.getPhotos.html)
|
50
|
+
#
|
51
|
+
def get_photos(person_id, params = {})
|
52
|
+
response = get "people.getPhotos", params.merge(user_id: person_id)
|
53
|
+
new_list(:Photo, response["photos"].delete("photo"), response["photos"])
|
54
|
+
end
|
35
55
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
56
|
+
##
|
57
|
+
# @param person_id [String]
|
58
|
+
# @param params [Hash] See documentation below
|
59
|
+
# @return [Flickr::Object::List<Flickr::Object::Photo>]
|
60
|
+
# @docs [flickr.people.getPhotosOf](http://www.flickr.com/services/api/flickr.people.getPhotosOf.html)
|
61
|
+
#
|
62
|
+
def get_photos_of(person_id, params = {})
|
63
|
+
response = get "people.getPhotosOf", params.merge(user_id: person_id)
|
64
|
+
new_list(:Photo, response["photos"].delete("photo"), response["photos"])
|
65
|
+
end
|
40
66
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
67
|
+
##
|
68
|
+
# @param person_id [String]
|
69
|
+
# @param params [Hash] See documentation below
|
70
|
+
# @return [Flickr::Object::List<Flickr::Object::Photo>]
|
71
|
+
# @docs [flickr.people.getPublicPhotos](http://www.flickr.com/services/api/flickr.people.getPublicPhotos.html)
|
72
|
+
#
|
73
|
+
def get_public_photos(person_id, params = {})
|
74
|
+
response = get "people.getPublicPhotos", params.merge(user_id: person_id)
|
75
|
+
new_list(:Photo, response["photos"].delete("photo"), response["photos"])
|
76
|
+
end
|
77
|
+
|
78
|
+
##
|
79
|
+
# @param person_id [String]
|
80
|
+
# @param params [Hash] See documentation below
|
81
|
+
# @return [Flickr::Object::List<Flickr::Object::Photo>]
|
82
|
+
# @docs [flickr.photos.getContactsPublicPhotos](http://www.flickr.com/services/api/flickr.photos.getContactsPublicPhotos.html)
|
83
|
+
#
|
84
|
+
def get_public_photos_from_contacts(person_id, params = {})
|
85
|
+
response = get "photos.getContactsPublicPhotos", params.merge(user_id: person_id)
|
86
|
+
new_list(:Photo, response["photos"].delete("photo"), response["photos"])
|
87
|
+
end
|
88
|
+
|
89
|
+
##
|
90
|
+
# @param person_id [String]
|
91
|
+
# @param params [Hash] See documentation below
|
92
|
+
# @return [Flickr::Object::List<Flickr::Object::Set>]
|
93
|
+
# @docs [flickr.photosets.getList](http://www.flickr.com/services/api/flickr.photosets.getList.html)
|
94
|
+
#
|
95
|
+
def get_sets(person_id, params = {})
|
96
|
+
response = get "photosets.getList", params.merge(user_id: person_id)
|
97
|
+
new_list(:Set, response["photosets"].delete("photoset"), response["photosets"])
|
98
|
+
end
|
45
99
|
|
46
|
-
def get_sets(params = {})
|
47
|
-
response = client.get f(__method__), params.merge(user_id: id)
|
48
|
-
Set.new_list(response["photosets"].delete("photoset"), client, response["photosets"])
|
49
100
|
end
|
101
|
+
|
50
102
|
end
|
51
103
|
end
|