flickr-objects 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -8
- data/lib/flickr/api/api_methods/person.rb +4 -2
- data/lib/flickr/api/api_methods/photo.rb +14 -3
- data/lib/flickr/api/api_methods/set.rb +11 -7
- data/lib/flickr/api/person.rb +10 -0
- data/lib/flickr/api/photo.rb +55 -0
- data/lib/flickr/api/set.rb +24 -0
- data/lib/flickr/object.rb +1 -2
- data/lib/flickr/objects.rb +9 -8
- data/lib/flickr/objects/attribute_values/person.rb +1 -0
- data/lib/flickr/objects/attribute_values/person/upload_status.rb +16 -0
- data/lib/flickr/objects/attribute_values/photo.rb +1 -1
- data/lib/flickr/objects/person.rb +1 -0
- data/lib/flickr/objects/person/upload_status.rb +14 -0
- data/lib/flickr/version.rb +1 -1
- metadata +5 -3
data/README.md
CHANGED
@@ -59,8 +59,12 @@ set.id #=> "11243423"
|
|
59
59
|
set.photos_count #=> 40
|
60
60
|
```
|
61
61
|
|
62
|
-
|
63
|
-
|
62
|
+
We can learn few things here:
|
63
|
+
|
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)`
|
67
|
+
(in the above example we did `Flickr.people.find(id)`).
|
64
68
|
|
65
69
|
Parameters to API methods are not always passed as a hash. For example, instead
|
66
70
|
of calling "flickr.people.findByEmail" like this:
|
@@ -75,12 +79,12 @@ this gem has the convention of calling it like this:
|
|
75
79
|
Flickr.people.find_by_email("janko.marohnic@gmail.com")
|
76
80
|
```
|
77
81
|
|
78
|
-
|
79
|
-
other parameters as the last argument.
|
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.
|
80
84
|
|
81
|
-
For documentation on valid arguments, just look at the source code
|
82
|
-
[`lib/flickr/api`](https://github.com/janko-m/flickr-objects/
|
83
|
-
|
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.
|
84
88
|
|
85
89
|
## Sizes
|
86
90
|
|
@@ -163,7 +167,7 @@ own documentation, so don't be discouraged if you haven't had experience in look
|
|
163
167
|
people's code yet :)
|
164
168
|
|
165
169
|
For example, list of `Flickr::Photo`'s attributes can be found in
|
166
|
-
[`lib/flickr/objects/
|
170
|
+
[`lib/flickr/objects/photo.rb`](https://github.com/janko-m/flickr-objects/blob/master/lib/flickr/objects/photo.rb).
|
167
171
|
Take a look just to see how it looks like :)
|
168
172
|
|
169
173
|
## Few words
|
@@ -1,10 +1,12 @@
|
|
1
1
|
class Flickr
|
2
2
|
class Person < Object
|
3
|
-
class_api_method :find_by_email,
|
4
|
-
class_api_method :find_by_username,
|
3
|
+
class_api_method :find_by_email, "flickr.people.findByEmail"
|
4
|
+
class_api_method :find_by_username, "flickr.people.findByUsername"
|
5
|
+
class_api_method :get_upload_status, "flickr.people.getUploadStatus"
|
5
6
|
|
6
7
|
instance_api_method :get_info!, "flickr.people.getInfo"
|
7
8
|
instance_api_method :get_photos, "flickr.people.getPhotos"
|
9
|
+
instance_api_method :get_photos_of, "flickr.people.getPhotosOf"
|
8
10
|
instance_api_method :get_public_photos, "flickr.people.getPublicPhotos"
|
9
11
|
instance_api_method :get_public_photos_from_contacts, "flickr.photos.getContactsPublicPhotos"
|
10
12
|
instance_api_method :get_sets, "flickr.photosets.getList"
|
@@ -1,15 +1,26 @@
|
|
1
1
|
class Flickr
|
2
2
|
class Photo < Object
|
3
|
-
class_api_method :get_from_contacts,
|
4
|
-
class_api_method :search,
|
5
|
-
class_api_method :delete,
|
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
|
+
class_api_method :get_not_in_set, "flickr.photos.getNotInSet"
|
7
|
+
class_api_method :get_recent, "flickr.photos.getRecent"
|
8
|
+
class_api_method :get_untagged, "flickr.photos.getUntagged"
|
9
|
+
class_api_method :get_with_geo_data, "flickr.photos.getWithGeoData"
|
10
|
+
class_api_method :get_without_geo_data, "flickr.photos.getWithoutGeoData"
|
11
|
+
class_api_method :get_recently_updated, "flickr.photos.RecentlyUpdated"
|
6
12
|
|
7
13
|
instance_api_method :add_tags, "flickr.photos.addTags"
|
8
14
|
instance_api_method :delete, "flickr.photos.delete"
|
9
15
|
instance_api_method :get_info!, "flickr.photos.getInfo"
|
10
16
|
instance_api_method :get_sizes!, "flickr.photos.getSizes"
|
17
|
+
instance_api_method :get_favorites, "flickr.photos.getFavorites"
|
11
18
|
instance_api_method :remove_tag, "flickr.photos.removeTag"
|
12
19
|
instance_api_method :set_content_type, "flickr.photos.setContentType", aliases: [:content_type=]
|
13
20
|
instance_api_method :set_tags, "flickr.photos.setTags", aliases: [:tags=]
|
21
|
+
instance_api_method :set_dates, "flickr.photos.setDates"
|
22
|
+
instance_api_method :set_meta, "flickr.photos.setMeta"
|
23
|
+
instance_api_method :set_permissions, "flickr.photos.setPerms"
|
24
|
+
instance_api_method :set_safety_level, "flickr.photos.setSafetyLevel"
|
14
25
|
end
|
15
26
|
end
|
@@ -2,13 +2,17 @@ class Flickr
|
|
2
2
|
class Set < Object
|
3
3
|
class_api_method :create, "flickr.photosets.create"
|
4
4
|
class_api_method :delete, "flickr.photosets.delete"
|
5
|
+
class_api_method :order, "flickr.photosets.orderSets"
|
5
6
|
|
6
|
-
instance_api_method :add_photo,
|
7
|
-
instance_api_method :delete,
|
8
|
-
instance_api_method :edit_photos,
|
9
|
-
instance_api_method :get_info!,
|
10
|
-
instance_api_method :get_photos,
|
11
|
-
instance_api_method :remove_photos,
|
12
|
-
instance_api_method :remove_photo,
|
7
|
+
instance_api_method :add_photo, "flickr.photosets.addPhoto"
|
8
|
+
instance_api_method :delete, "flickr.photosets.delete"
|
9
|
+
instance_api_method :edit_photos, "flickr.photosets.editPhotos"
|
10
|
+
instance_api_method :get_info!, "flickr.photosets.getInfo"
|
11
|
+
instance_api_method :get_photos, "flickr.photosets.getPhotos"
|
12
|
+
instance_api_method :remove_photos, "flickr.photosets.removePhotos"
|
13
|
+
instance_api_method :remove_photo, "flickr.photosets.removePhoto"
|
14
|
+
instance_api_method :edit_meta, "flickr.photosets.editMeta"
|
15
|
+
instance_api_method :reorder_photos, "flickr.photosets.reorderPhotos"
|
16
|
+
instance_api_method :set_primary_photo, "flickr.photosets.setPrimaryPhoto", aliases: [:primary_photo=]
|
13
17
|
end
|
14
18
|
end
|
data/lib/flickr/api/person.rb
CHANGED
@@ -12,6 +12,11 @@ class Flickr
|
|
12
12
|
new(response["user"], client)
|
13
13
|
end
|
14
14
|
|
15
|
+
def self.get_upload_status(params = {})
|
16
|
+
response = client.get f(__method__), params
|
17
|
+
UploadStatus.new(response["user"], client)
|
18
|
+
end
|
19
|
+
|
15
20
|
def get_info!(params = {})
|
16
21
|
response = client.get f(__method__), params.merge(user_id: id)
|
17
22
|
@hash.update(response["person"])
|
@@ -23,6 +28,11 @@ class Flickr
|
|
23
28
|
Photo.new_list(response["photos"].delete("photo"), client, response["photos"])
|
24
29
|
end
|
25
30
|
|
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
|
35
|
+
|
26
36
|
def get_public_photos(params = {})
|
27
37
|
response = client.get f(__method__), handle_extras(params.merge(user_id: id))
|
28
38
|
Photo.new_list(response["photos"].delete("photo"), client, response["photos"])
|
data/lib/flickr/api/photo.rb
CHANGED
@@ -16,6 +16,36 @@ class Flickr
|
|
16
16
|
find(id).delete(params)
|
17
17
|
end
|
18
18
|
|
19
|
+
def self.get_not_in_set(params = {})
|
20
|
+
response = client.get f(__method__), handle_extras(params)
|
21
|
+
new_list(response["photos"].delete("photo"), client, response["photos"])
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.get_recent(params = {})
|
25
|
+
response = client.get f(__method__), handle_extras(params)
|
26
|
+
new_list(response["photos"].delete("photo"), client, response["photos"])
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.get_untagged(params = {})
|
30
|
+
response = client.get f(__method__), handle_extras(params)
|
31
|
+
new_list(response["photos"].delete("photo"), client, response["photos"])
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.get_with_geo_data(params = {})
|
35
|
+
response = client.get f(__method__), handle_extras(params)
|
36
|
+
new_list(response["photos"].delete("photo"), client, response["photos"])
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.get_without_geo_data(params = {})
|
40
|
+
response = client.get f(__method__), handle_extras(params)
|
41
|
+
new_list(response["photos"].delete("photo"), client, response["photos"])
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.get_recently_updated(params = {})
|
45
|
+
response = client.get f(__method__), handle_extras(params)
|
46
|
+
new_list(response["photos"].delete("photo"), client, response["photos"])
|
47
|
+
end
|
48
|
+
|
19
49
|
def get_info!(params = {})
|
20
50
|
response = client.get f(__method__), params.merge(photo_id: id)
|
21
51
|
@hash.update(response["photo"])
|
@@ -28,6 +58,11 @@ class Flickr
|
|
28
58
|
self
|
29
59
|
end
|
30
60
|
|
61
|
+
def get_favorites(params = {})
|
62
|
+
response = client.get f(__method__), params.merge(photo_id: id)
|
63
|
+
Person.new_list(response["photo"].delete("person"), client, response["photo"])
|
64
|
+
end
|
65
|
+
|
31
66
|
def delete(params = {})
|
32
67
|
client.post f(__method__), params.merge(photo_id: id)
|
33
68
|
self
|
@@ -54,5 +89,25 @@ class Flickr
|
|
54
89
|
client.post f(__method__), params.merge(photo_id: id, tag_id: tag_id)
|
55
90
|
tag_id
|
56
91
|
end
|
92
|
+
|
93
|
+
def set_dates(params = {})
|
94
|
+
client.post f(__method__), params.merge(photo_id: id)
|
95
|
+
params
|
96
|
+
end
|
97
|
+
|
98
|
+
def set_meta(params = {})
|
99
|
+
client.post f(__method__), params.merge(photo_id: id)
|
100
|
+
params
|
101
|
+
end
|
102
|
+
|
103
|
+
def set_permissions(params = {})
|
104
|
+
client.post f(__method__), params.merge(photo_id: id)
|
105
|
+
params
|
106
|
+
end
|
107
|
+
|
108
|
+
def set_safety_level(params = {})
|
109
|
+
client.post f(__method__), params.merge(photo_id: id)
|
110
|
+
params
|
111
|
+
end
|
57
112
|
end
|
58
113
|
end
|
data/lib/flickr/api/set.rb
CHANGED
@@ -11,6 +11,11 @@ class Flickr
|
|
11
11
|
find(id).delete(params)
|
12
12
|
end
|
13
13
|
|
14
|
+
def self.order(set_ids, params = {})
|
15
|
+
client.post f(__method__), params.merge(photoset_ids: set_ids)
|
16
|
+
set_ids
|
17
|
+
end
|
18
|
+
|
14
19
|
def delete(params = {})
|
15
20
|
client.post f(__method__), params.merge(photoset_id: id)
|
16
21
|
self
|
@@ -34,14 +39,33 @@ class Flickr
|
|
34
39
|
|
35
40
|
def add_photo(photo_id, params = {})
|
36
41
|
client.post f(__method__), params.merge(photoset_id: id, photo_id: photo_id)
|
42
|
+
photo_id
|
37
43
|
end
|
38
44
|
|
39
45
|
def remove_photos(photo_ids, params = {})
|
40
46
|
client.post f(__method__), params.merge(photoset_id: id, photo_ids: photo_ids)
|
47
|
+
photo_ids
|
41
48
|
end
|
42
49
|
|
43
50
|
def remove_photo(photo_id, params = {})
|
44
51
|
client.post f(__method__), params.merge(photoset_id: id, photo_id: photo_id)
|
52
|
+
photo_id
|
53
|
+
end
|
54
|
+
|
55
|
+
def edit_meta(params = {})
|
56
|
+
client.post f(__method__), params.merge(photoset_id: id)
|
57
|
+
params
|
58
|
+
end
|
59
|
+
|
60
|
+
def reorder_photos(photo_ids, params = {})
|
61
|
+
client.post f(__method__), params.merge(photoset_id: id, photo_ids: photo_ids)
|
62
|
+
photo_ids
|
63
|
+
end
|
64
|
+
|
65
|
+
def set_primary_photo(photo, params = {})
|
66
|
+
client.post f(__method__), params.merge(photoset_id: id, photo_id: (photo.is_a?(Photo) ? photo.id : photo))
|
67
|
+
photo
|
45
68
|
end
|
69
|
+
alias primary_photo= set_primary_photo
|
46
70
|
end
|
47
71
|
end
|
data/lib/flickr/object.rb
CHANGED
@@ -28,8 +28,7 @@ class Flickr
|
|
28
28
|
attribute_values[name] = send(name) unless send(name).nil?
|
29
29
|
end
|
30
30
|
class_name = self.class.name
|
31
|
-
|
32
|
-
"#<#{class_name}:#{id} #{attribute_values.map { |k, v| "#{k}=#{v.inspect}" }.join(" ")}>"
|
31
|
+
"#<#{class_name}: #{attribute_values.map { |k, v| "#{k}=#{v.inspect}" }.join(" ")}>"
|
33
32
|
end
|
34
33
|
|
35
34
|
def ==(other)
|
data/lib/flickr/objects.rb
CHANGED
@@ -7,18 +7,19 @@ class Flickr
|
|
7
7
|
class Set < Object; end
|
8
8
|
|
9
9
|
# Meta objects
|
10
|
-
class Visibility
|
11
|
-
class Permissions
|
12
|
-
class Note
|
13
|
-
class Tag
|
14
|
-
class Location
|
15
|
-
class UploadTicket
|
10
|
+
class Visibility < Object; end
|
11
|
+
class Permissions < Object; end
|
12
|
+
class Note < Object; end
|
13
|
+
class Tag < Object; end
|
14
|
+
class Location < Object; end
|
15
|
+
class UploadTicket < Object; end
|
16
|
+
class Person::UploadStatus < Object; end
|
16
17
|
|
17
18
|
autoload :List, "flickr/objects/list"
|
18
19
|
end
|
19
20
|
|
20
21
|
objects = Flickr::Object.children.dup
|
21
22
|
objects.each do |object|
|
22
|
-
underscored_name = object.name.split("::").
|
23
|
-
require "flickr/objects/#{underscored_name}"
|
23
|
+
underscored_name = object.name.split("::")[1..-1].map { |s| s.split(/(?<=\w)(?=[A-Z])/).map(&:downcase).join("_") }
|
24
|
+
require "flickr/objects/#{underscored_name.join("/")}"
|
24
25
|
end
|
@@ -16,6 +16,7 @@ class Flickr
|
|
16
16
|
mobile_url: [->{ @hash["mobileurl"]["_content"] }],
|
17
17
|
first_photo_taken: [->{ @hash["photos"]["firstdatetaken"]["_content"] }],
|
18
18
|
first_photo_uploaded: [->{ @hash["photos"]["firstdate"]["_content"] }],
|
19
|
+
favorited_at: [->{ @hash["favedate"] }],
|
19
20
|
photos_count: [->{ @hash["photos"]["count"]["_content"] }],
|
20
21
|
photo_views_count: [->{ @hash["photos"]["views"]["_content"] }],
|
21
22
|
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Flickr
|
2
|
+
class Person::UploadStatus < Object
|
3
|
+
class Month < Object
|
4
|
+
self.attribute_values = {
|
5
|
+
maximum: [->{ @hash["maxkb"] / 1024 }],
|
6
|
+
used: [->{ @hash["usedkb"] / 1024 }],
|
7
|
+
remaining: [->{ @hash["remainingkb"] / 1024 }],
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
self.attribute_values = {
|
12
|
+
current_month: [->{ @hash["bandwidth"].slice("maxkb", "usedkb", "remainingkb") }],
|
13
|
+
maximum_photo_size: [->{ @hash["filesize"]["maxmb"] }],
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative "../attribute_values/person/upload_status"
|
2
|
+
|
3
|
+
class Flickr
|
4
|
+
class Person::UploadStatus < Object
|
5
|
+
class Month < Object
|
6
|
+
attribute :maximum, Integer
|
7
|
+
attribute :used, Integer
|
8
|
+
attribute :remaining, Integer
|
9
|
+
end
|
10
|
+
|
11
|
+
attribute :current_month, Month
|
12
|
+
attribute :maximum_photo_size, Integer
|
13
|
+
end
|
14
|
+
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.
|
4
|
+
version: 0.2.0
|
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:
|
12
|
+
date: 2013-01-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -226,6 +226,7 @@ files:
|
|
226
226
|
- lib/flickr/objects/attribute_values/location.rb
|
227
227
|
- lib/flickr/objects/attribute_values/note.rb
|
228
228
|
- lib/flickr/objects/attribute_values/permissions.rb
|
229
|
+
- lib/flickr/objects/attribute_values/person/upload_status.rb
|
229
230
|
- lib/flickr/objects/attribute_values/person.rb
|
230
231
|
- lib/flickr/objects/attribute_values/photo.rb
|
231
232
|
- lib/flickr/objects/attribute_values/set.rb
|
@@ -236,6 +237,7 @@ files:
|
|
236
237
|
- lib/flickr/objects/location.rb
|
237
238
|
- lib/flickr/objects/note.rb
|
238
239
|
- lib/flickr/objects/permissions.rb
|
240
|
+
- lib/flickr/objects/person/upload_status.rb
|
239
241
|
- lib/flickr/objects/person.rb
|
240
242
|
- lib/flickr/objects/photo.rb
|
241
243
|
- lib/flickr/objects/set.rb
|
@@ -267,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
267
269
|
version: '0'
|
268
270
|
segments:
|
269
271
|
- 0
|
270
|
-
hash: -
|
272
|
+
hash: -3989441013380527644
|
271
273
|
requirements: []
|
272
274
|
rubyforge_project:
|
273
275
|
rubygems_version: 1.8.23
|