flickr-objects 0.2.0 → 0.3.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 (92) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +49 -63
  3. data/lib/flickr/api/abstract/params_processor.rb +68 -0
  4. data/lib/flickr/api/abstract.rb +113 -0
  5. data/lib/flickr/api/general.rb +75 -0
  6. data/lib/flickr/api/person.rb +91 -39
  7. data/lib/flickr/api/photo.rb +213 -108
  8. data/lib/flickr/api/set.rb +114 -55
  9. data/lib/flickr/api/upload_ticket.rb +17 -6
  10. data/lib/flickr/api.rb +90 -35
  11. data/lib/flickr/attributes.rb +200 -0
  12. data/lib/flickr/base_converter.rb +29 -0
  13. data/lib/flickr/client/data.rb +47 -0
  14. data/lib/flickr/client/oauth.rb +44 -0
  15. data/lib/flickr/client/upload.rb +55 -0
  16. data/lib/flickr/client.rb +77 -33
  17. data/lib/flickr/configuration.rb +85 -14
  18. data/lib/flickr/error.rb +58 -0
  19. data/lib/flickr/middleware.rb +52 -28
  20. data/lib/flickr/oauth.rb +89 -74
  21. data/lib/flickr/object/attribute_locations/list.rb +25 -0
  22. data/lib/flickr/object/attribute_locations/location.rb +29 -0
  23. data/lib/flickr/object/attribute_locations/permissions.rb +31 -0
  24. data/lib/flickr/object/attribute_locations/person/upload_status.rb +32 -0
  25. data/lib/flickr/object/attribute_locations/person.rb +78 -0
  26. data/lib/flickr/object/attribute_locations/photo/exif.rb +29 -0
  27. data/lib/flickr/object/attribute_locations/photo/note.rb +36 -0
  28. data/lib/flickr/object/attribute_locations/photo/tag.rb +23 -0
  29. data/lib/flickr/object/attribute_locations/photo.rb +164 -0
  30. data/lib/flickr/object/attribute_locations/set.rb +53 -0
  31. data/lib/flickr/object/attribute_locations/upload_ticket.rb +30 -0
  32. data/lib/flickr/object/attribute_locations/visibility.rb +24 -0
  33. data/lib/flickr/object/list/kaminari.rb +30 -0
  34. data/lib/flickr/object/list/normal.rb +27 -0
  35. data/lib/flickr/object/list/will_paginate.rb +31 -0
  36. data/lib/flickr/object/list.rb +87 -0
  37. data/lib/flickr/object/location.rb +35 -0
  38. data/lib/flickr/object/permissions.rb +18 -0
  39. data/lib/flickr/object/person/upload_status.rb +22 -0
  40. data/lib/flickr/object/person.rb +93 -0
  41. data/lib/flickr/object/photo/exif.rb +35 -0
  42. data/lib/flickr/object/photo/note.rb +20 -0
  43. data/lib/flickr/object/photo/size.rb +67 -0
  44. data/lib/flickr/object/photo/tag.rb +23 -0
  45. data/lib/flickr/object/photo.rb +349 -0
  46. data/lib/flickr/object/set.rb +114 -0
  47. data/lib/flickr/object/upload_ticket.rb +31 -0
  48. data/lib/flickr/object/visibility.rb +16 -0
  49. data/lib/flickr/object.rb +118 -27
  50. data/lib/flickr/sanitized_file.rb +70 -0
  51. data/lib/flickr/version.rb +4 -2
  52. data/lib/flickr.rb +69 -15
  53. metadata +89 -103
  54. data/lib/flickr/api/api_methods/flickr.rb +0 -5
  55. data/lib/flickr/api/api_methods/person.rb +0 -14
  56. data/lib/flickr/api/api_methods/photo.rb +0 -26
  57. data/lib/flickr/api/api_methods/set.rb +0 -18
  58. data/lib/flickr/api/api_methods/upload_ticket.rb +0 -5
  59. data/lib/flickr/api/flickr.rb +0 -35
  60. data/lib/flickr/api_caller.rb +0 -98
  61. data/lib/flickr/client/methods_client.rb +0 -22
  62. data/lib/flickr/client/upload_client.rb +0 -62
  63. data/lib/flickr/errors.rb +0 -19
  64. data/lib/flickr/helpers/base_58.rb +0 -15
  65. data/lib/flickr/helpers/boolean.rb +0 -4
  66. data/lib/flickr/helpers/core_ext.rb +0 -5
  67. data/lib/flickr/object/attribute/converter.rb +0 -49
  68. data/lib/flickr/object/attribute/finder.rb +0 -32
  69. data/lib/flickr/object/attribute.rb +0 -45
  70. data/lib/flickr/objects/attribute_values/list.rb +0 -10
  71. data/lib/flickr/objects/attribute_values/location.rb +0 -14
  72. data/lib/flickr/objects/attribute_values/note.rb +0 -11
  73. data/lib/flickr/objects/attribute_values/permissions.rb +0 -12
  74. data/lib/flickr/objects/attribute_values/person/upload_status.rb +0 -16
  75. data/lib/flickr/objects/attribute_values/person.rb +0 -24
  76. data/lib/flickr/objects/attribute_values/photo.rb +0 -84
  77. data/lib/flickr/objects/attribute_values/set.rb +0 -17
  78. data/lib/flickr/objects/attribute_values/tag.rb +0 -9
  79. data/lib/flickr/objects/attribute_values/upload_ticket.rb +0 -9
  80. data/lib/flickr/objects/attribute_values/visibility.rb +0 -10
  81. data/lib/flickr/objects/list.rb +0 -86
  82. data/lib/flickr/objects/location.rb +0 -26
  83. data/lib/flickr/objects/note.rb +0 -14
  84. data/lib/flickr/objects/permissions.rb +0 -14
  85. data/lib/flickr/objects/person/upload_status.rb +0 -14
  86. data/lib/flickr/objects/person.rb +0 -43
  87. data/lib/flickr/objects/photo.rb +0 -113
  88. data/lib/flickr/objects/set.rb +0 -29
  89. data/lib/flickr/objects/tag.rb +0 -17
  90. data/lib/flickr/objects/upload_ticket.rb +0 -18
  91. data/lib/flickr/objects/visibility.rb +0 -12
  92. 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 = "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 [here](http://www.flickr.com/services/apps/create/apply).
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 [this
28
- wiki](https://github.com/janko-m/flickr-objects/wiki/Configuration).
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 on objects.
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.api_methods["flickr.photos.search"] #=> ["Flickr::Photo.search"]
37
- Flickr.api_methods["flickr.photosets.getList"] #=> ["Flickr::Person#get_sets"]
37
+ Flickr.photos.search(...) # flickr.photos.search
38
+ Flickr.person.get_sets(...) # flickr.photosets.getList
38
39
  ```
39
40
 
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.
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
- Here's an example:
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
- sets = person.get_sets #=> [#<Flickr::Set: ...>, #<Flickr::Set: ...>, ...]
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
- We can learn few things here:
61
+ Few notes here:
63
62
 
64
- - Interface to object's class methods is always the plural of object's name
65
- (above we called `Flickr::Photo.search` with `Flickr.photos.search`).
66
- - You can always manually instantiate objects with `Flickr.<objects>.find(id)`
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
- Parameters to API methods are not always passed as a hash. For example, instead
70
- of calling "flickr.people.findByEmail" like this:
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
- this gem has the convention of calling it like this:
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
- This is always the case with obvious (and required) parameters. You can still
83
- always pass a hash of other parameters as the last argument.
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(person_id)
93
- photo = person.get_public_photos(sizes: :all).first
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: :all` to `Flickr::Person#get_public_photos`.
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.get_public_photos(sizes: :all).map { |photo| photo.medium!(500) }
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, take a look at [this wiki](https://github.com/janko-m/flickr-objects/wiki/Sizes).
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
- If you need to make authenticated API requests (which you'll probably often want), you should create an
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 (obtain the access token) take a look at
137
- [this wiki](http://github.com/janko-m/flickr-objects/wiki/Authentication).
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
- You can also assign the access token globally in your configuration.
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
- In the first argument you can pass in either a string (path to the file) or an open file.
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
- Most of the API methods are not covered yet (because they are so many). I will
176
- be covering new ones regularly.
177
-
178
- Feel free to speed up covering certain API methods by contacting me through
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](https://github.com/janko-m/flickr-objects/blob/master/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
@@ -1,51 +1,103 @@
1
- require_relative "api_methods/person"
1
+ module Flickr
2
+ module Api
2
3
 
3
- class Flickr
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
- def self.find_by_username(username, params = {})
11
- response = client.get f(__method__), params.merge(username: username)
12
- new(response["user"], client)
13
- end
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
- def self.get_upload_status(params = {})
16
- response = client.get f(__method__), params
17
- UploadStatus.new(response["user"], client)
18
- end
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
- def get_info!(params = {})
21
- response = client.get f(__method__), params.merge(user_id: id)
22
- @hash.update(response["person"])
23
- self
24
- end
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
- def get_photos(params = {})
27
- response = client.get f(__method__), handle_extras(params.merge(user_id: id))
28
- Photo.new_list(response["photos"].delete("photo"), client, response["photos"])
29
- end
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
- def get_photos_of(params = {})
32
- response = client.get f(__method__), handle_extras(params.merge(user_id: id))
33
- Photo.new_list(response["photos"].delete("photo"), client, response["photos"])
34
- end
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
- def get_public_photos(params = {})
37
- response = client.get f(__method__), handle_extras(params.merge(user_id: id))
38
- Photo.new_list(response["photos"].delete("photo"), client, response["photos"])
39
- end
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
- def get_public_photos_from_contacts(params = {})
42
- response = client.get f(__method__), handle_extras(params.merge(user_id: id))
43
- Photo.new_list(response["photos"].delete("photo"), client, response["photos"])
44
- end
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