flickrie 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG.md +22 -0
- data/Gemfile +0 -6
- data/README.md +15 -1
- data/Rakefile +8 -13
- data/api_methods.md +1 -1
- data/flickrie.gemspec +2 -3
- data/lib/flickrie/api_methods.rb +17 -0
- data/lib/flickrie/client.rb +21 -5
- data/lib/flickrie/instance.rb +7 -2
- data/lib/flickrie/license.rb +2 -0
- data/lib/flickrie/location.rb +10 -8
- data/lib/flickrie/media/exif.rb +3 -1
- data/lib/flickrie/media/tag.rb +3 -3
- data/lib/flickrie/media/visibility.rb +6 -4
- data/lib/flickrie/media.rb +69 -84
- data/lib/flickrie/media_count.rb +3 -5
- data/lib/flickrie/photo.rb +55 -54
- data/lib/flickrie/set.rb +31 -25
- data/lib/flickrie/ticket.rb +4 -8
- data/lib/flickrie/upload_client.rb +7 -2
- data/lib/flickrie/user.rb +33 -34
- data/lib/flickrie/version.rb +1 -1
- data/lib/flickrie/video.rb +13 -12
- data/spec/api_methods_spec.rb +43 -0
- data/spec/error_spec.rb +32 -0
- data/{test → spec/files}/photo.jpg +0 -0
- data/{test → spec/files}/video.mov +0 -0
- data/spec/instance_spec.rb +22 -0
- data/spec/license_spec.rb +15 -0
- data/spec/location_spec.rb +11 -0
- data/spec/media_count_spec.rb +18 -0
- data/spec/media_spec.rb +271 -0
- data/spec/oauth_spec.rb +22 -0
- data/spec/photo_spec.rb +137 -0
- data/spec/set_spec.rb +68 -0
- data/spec/spec_helper.rb +68 -0
- data/spec/user_spec.rb +56 -0
- data/spec/video_spec.rb +54 -0
- metadata +47 -132
- data/test/error_test.rb +0 -20
- data/test/instance_test.rb +0 -20
- data/test/license_test.rb +0 -19
- data/test/location_test.rb +0 -29
- data/test/media_count_test.rb +0 -25
- data/test/media_test.rb +0 -432
- data/test/oauth_test.rb +0 -25
- data/test/photo_test.rb +0 -212
- data/test/set_test.rb +0 -92
- data/test/test_helper.rb +0 -14
- data/test/user_test.rb +0 -70
- data/test/vcr_cassettes/error/code.yml +0 -1165
- data/test/vcr_cassettes/instance/calling_api_methods.yml +0 -182
- data/test/vcr_cassettes/license/get_licenses.yml +0 -73
- data/test/vcr_cassettes/location/square_brackets.yml +0 -85
- data/test/vcr_cassettes/media/delete.yml +0 -1380
- data/test/vcr_cassettes/media/from_contacts.yml +0 -155
- data/test/vcr_cassettes/media/from_set.yml +0 -276
- data/test/vcr_cassettes/media/from_user.yml +0 -275
- data/test/vcr_cassettes/media/get_context.yml +0 -73
- data/test/vcr_cassettes/media/get_info.yml +0 -167
- data/test/vcr_cassettes/media/remove_tag.yml +0 -264
- data/test/vcr_cassettes/media/replace.yml +0 -2252
- data/test/vcr_cassettes/media/search.yml +0 -275
- data/test/vcr_cassettes/media/tags.yml +0 -346
- data/test/vcr_cassettes/media_count/get.yml +0 -135
- data/test/vcr_cassettes/media_count/square_brackets.yml +0 -69
- data/test/vcr_cassettes/oauth/tokens.yml +0 -400
- data/test/vcr_cassettes/photo/asynchronous_upload.yml +0 -1693
- data/test/vcr_cassettes/photo/from_set.yml +0 -273
- data/test/vcr_cassettes/photo/from_user.yml +0 -275
- data/test/vcr_cassettes/photo/get_exif.yml +0 -239
- data/test/vcr_cassettes/photo/get_sizes.yml +0 -147
- data/test/vcr_cassettes/photo/other_api_calls.yml +0 -506
- data/test/vcr_cassettes/photo/search.yml +0 -271
- data/test/vcr_cassettes/photo/square_brackets.yml +0 -85
- data/test/vcr_cassettes/photo/upload.yml +0 -1229
- data/test/vcr_cassettes/set/from_user.yml +0 -477
- data/test/vcr_cassettes/set/get_info.yml +0 -951
- data/test/vcr_cassettes/set/square_brackets.yml +0 -73
- data/test/vcr_cassettes/user/find_by_email_or_username.yml +0 -135
- data/test/vcr_cassettes/user/get_info.yml +0 -151
- data/test/vcr_cassettes/user/square_brackets.yml +0 -77
- data/test/vcr_cassettes/video/get_exif.yml +0 -135
- data/test/vcr_cassettes/video/get_info.yml +0 -86
- data/test/vcr_cassettes/video/get_sizes.yml +0 -151
- data/test/vcr_cassettes/video/other_api_calls.yml +0 -643
- data/test/vcr_cassettes/video/square_brackets.yml +0 -86
- data/test/vcr_cassettes/video/upload.yml +0 -308
- data/test/video_test.rb +0 -118
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,27 @@
|
|
1
1
|
# Flickrie changelog
|
2
2
|
|
3
|
+
## Version 1.0.0
|
4
|
+
|
5
|
+
- cover `flickr.photos.getFavorites` and `flickr.test.login`
|
6
|
+
- change the way `flickr.photos.getContext` works (this is the part that is NOT backwards compatible)
|
7
|
+
|
8
|
+
Before:
|
9
|
+
```ruby
|
10
|
+
context = Flickrie.get_photo_context(712472397)
|
11
|
+
context['count'] # => 12
|
12
|
+
context['prevphoto'] # => #<Photo: ...>
|
13
|
+
context['nexphoto'] # => #<Photo: ...>
|
14
|
+
```
|
15
|
+
Now:
|
16
|
+
```ruby
|
17
|
+
context = Flickrie.get_photo_context(712472397)
|
18
|
+
context.count # => 12
|
19
|
+
context.previous # => #<Photo: ...>
|
20
|
+
context.next # => #<Photo: ...>
|
21
|
+
```
|
22
|
+
|
23
|
+
- bug fixes (especially regarding the `Flickr::Instance`)
|
24
|
+
|
3
25
|
## Version 0.6.1
|
4
26
|
|
5
27
|
- `Flickrie::Media::Ticket` is now called just `Flickrie::Ticket`
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -138,7 +138,7 @@ puts "Visit this url to authenticate: #{url}"
|
|
138
138
|
|
139
139
|
print "If you agreed, the code was displayed afterwards. Enter it: "
|
140
140
|
code = gets.strip
|
141
|
-
access_token = Flickrie::OAuth.get_access_token(code)
|
141
|
+
access_token = Flickrie::OAuth.get_access_token(code, request_token)
|
142
142
|
Flickrie.access_token = access_token.token
|
143
143
|
Flickrie.access_secret = access_token.secret
|
144
144
|
puts "You successfully authenticated!"
|
@@ -214,6 +214,19 @@ default.
|
|
214
214
|
Please, feel free to post any issues that you're having, I will be happy
|
215
215
|
to help. I will also be happy if you let me know about any bugs.
|
216
216
|
|
217
|
+
## How to contribute
|
218
|
+
|
219
|
+
I will be happy if you want to contribute. The procedure is nothing
|
220
|
+
special, you just fork the project and send me a pull request.
|
221
|
+
|
222
|
+
For your tests to be able to run, you should make a Flickr account, and
|
223
|
+
get the API key and secret. You can get them [here](http://www.flickr.com/services/apps/create/apply).
|
224
|
+
You also have to get the access token. You can do that by using my
|
225
|
+
authentication system. After you have these four things, you have to
|
226
|
+
assign them to environment variables named `FLICKR_API_KEY`,
|
227
|
+
`FLICKR_SHARED_SECRET`, `FLICKR_ACCESS_TOKEN`, `FLICKR_ACCESS_SECRET`.
|
228
|
+
Once you do that, you should be able to run tests.
|
229
|
+
|
217
230
|
## Cedits
|
218
231
|
|
219
232
|
Special thanks to @**mislav**, my brother, he helped me really a lot
|
@@ -237,6 +250,7 @@ basis of this gem.
|
|
237
250
|
"flickr.photos.getContext" -> Flickrie.get_photo_context
|
238
251
|
"flickr.photos.getCounts" -> Flickrie.get_photos_counts
|
239
252
|
"flickr.photos.getExif" -> Flickrie.get_photo_exif
|
253
|
+
"flickr.photos.getFavorites" -> Flickrie.get_photo_favorites
|
240
254
|
"flickr.photos.getInfo" -> Flickrie.get_photo_info
|
241
255
|
"flickr.photos.getSizes" -> Flickrie.get_photo_sizes
|
242
256
|
"flickr.photos.removeTag" -> Flickrie.remove_photo_tag
|
data/Rakefile
CHANGED
@@ -1,22 +1,17 @@
|
|
1
1
|
require 'bundler'
|
2
2
|
Bundler::GemHelper.install_tasks
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
task :spec, :spec do |task, args|
|
5
|
+
command = "bundle exec rspec -I spec --require 'spec_helper'"
|
6
|
+
if args['spec'].nil?
|
7
|
+
system(command)
|
8
|
+
else
|
9
|
+
system(command + " spec/#{args['spec']}_spec.rb")
|
9
10
|
end
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
map { |t| [File.basename(t).chomp('_test.rb').to_sym, t] }.
|
15
|
-
each do |test_name, test_file|
|
16
|
-
task(test_name) do
|
17
|
-
system "bundle exec turn -Itest --require=test_helper #{test_file}"
|
18
|
-
end
|
19
|
-
end
|
13
|
+
task :console do
|
14
|
+
system "bundle exec pry -I. --require 'flickrie' --require 'credentials'"
|
20
15
|
end
|
21
16
|
|
22
17
|
task :rdoc do
|
data/api_methods.md
CHANGED
@@ -115,7 +115,7 @@
|
|
115
115
|
- ~~flickr.photos.getContext~~
|
116
116
|
- ~~flickr.photos.getCounts~~
|
117
117
|
- ~~flickr.photos.getExif~~
|
118
|
-
- flickr.photos.getFavorites
|
118
|
+
- ~~flickr.photos.getFavorites~~
|
119
119
|
- ~~flickr.photos.getInfo~~
|
120
120
|
- flickr.photos.getNotInSet
|
121
121
|
- flickr.photos.getPerms
|
data/flickrie.gemspec
CHANGED
@@ -20,8 +20,7 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.add_dependency "simple_oauth", '~> 0.1'
|
21
21
|
gem.add_dependency "multi_xml", '~> 0.4'
|
22
22
|
|
23
|
-
gem.add_development_dependency "activesupport"
|
24
|
-
gem.add_development_dependency "
|
23
|
+
gem.add_development_dependency "activesupport", '>= 3'
|
24
|
+
gem.add_development_dependency "rspec", '>= 2'
|
25
25
|
gem.add_development_dependency "vcr"
|
26
|
-
gem.add_development_dependency "webmock"
|
27
26
|
end
|
data/lib/flickrie/api_methods.rb
CHANGED
@@ -124,10 +124,20 @@ module Flickrie
|
|
124
124
|
Video.from_exif(response.body['photo'])
|
125
125
|
end
|
126
126
|
|
127
|
+
def get_photo_favorites(photo_id, params = {})
|
128
|
+
response = client.get_media_favorites(photo_id, params)
|
129
|
+
Photo.new(response.body['photo'])
|
130
|
+
end
|
131
|
+
def get_video_favorites(video_id, params = {})
|
132
|
+
response = client.get_media_favorites(video_id, params)
|
133
|
+
Video.new(response.body['photo'])
|
134
|
+
end
|
135
|
+
|
127
136
|
def get_media_info(media_id, params = {})
|
128
137
|
response = client.get_media_info(media_id, params)
|
129
138
|
Media.from_info(response.body['photo'])
|
130
139
|
end
|
140
|
+
|
131
141
|
alias get_photo_info get_media_info
|
132
142
|
alias get_video_info get_media_info
|
133
143
|
|
@@ -195,5 +205,12 @@ module Flickrie
|
|
195
205
|
def videos_from_set(set_id, params = {})
|
196
206
|
media_from_set(set_id, params.merge(:media => 'videos'))
|
197
207
|
end
|
208
|
+
|
209
|
+
#--
|
210
|
+
# test
|
211
|
+
def test_login(params = {})
|
212
|
+
response = client.test_login(params)
|
213
|
+
User.from_test(response.body['user'])
|
214
|
+
end
|
198
215
|
end
|
199
216
|
end
|
data/lib/flickrie/client.rb
CHANGED
@@ -9,7 +9,7 @@ module Flickrie
|
|
9
9
|
attributes.each do |attribute|
|
10
10
|
define_method "#{attribute}=" do |value|
|
11
11
|
instance_variable_set "@#{attribute}", value
|
12
|
-
@client = nil
|
12
|
+
@client = @upload_client = nil
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -18,8 +18,12 @@ module Flickrie
|
|
18
18
|
attr_accessor_with_client_reset :api_key, :shared_secret,
|
19
19
|
:timeout, :open_timeout, :access_token, :access_secret
|
20
20
|
|
21
|
-
def client
|
22
|
-
@client ||=
|
21
|
+
def client
|
22
|
+
@client ||= new_client
|
23
|
+
end
|
24
|
+
|
25
|
+
def new_client(access_token_hash = {})
|
26
|
+
Client.new(params) do |conn|
|
23
27
|
conn.use FaradayMiddleware::OAuth,
|
24
28
|
:consumer_key => api_key,
|
25
29
|
:consumer_secret => shared_secret,
|
@@ -154,6 +158,11 @@ module Flickrie
|
|
154
158
|
{:photo_id => media_id}.merge(params)
|
155
159
|
end
|
156
160
|
|
161
|
+
def get_media_favorites(media_id, params = {})
|
162
|
+
get 'flickr.photos.getFavorites',
|
163
|
+
{:photo_id => media_id}.merge(params)
|
164
|
+
end
|
165
|
+
|
157
166
|
def get_media_info(media_id, params = {})
|
158
167
|
get 'flickr.photos.getInfo',
|
159
168
|
{:photo_id => media_id}.merge(params)
|
@@ -203,11 +212,18 @@ module Flickrie
|
|
203
212
|
ensure_media({:photoset_id => set_id}.merge(params))
|
204
213
|
end
|
205
214
|
|
215
|
+
#--
|
216
|
+
# test
|
217
|
+
def test_login(params = {})
|
218
|
+
get 'flickr.test.login', params
|
219
|
+
end
|
220
|
+
|
206
221
|
private
|
207
222
|
|
208
223
|
def ensure_media(params)
|
209
|
-
params
|
210
|
-
|
224
|
+
params.dup.tap do |dup_params|
|
225
|
+
dup_params[:extras] = [dup_params[:extras], 'media'].compact.join(',')
|
226
|
+
end
|
211
227
|
end
|
212
228
|
end
|
213
229
|
end
|
data/lib/flickrie/instance.rb
CHANGED
@@ -6,8 +6,13 @@ module Flickrie
|
|
6
6
|
@access_token, @access_secret = access_token, access_secret
|
7
7
|
end
|
8
8
|
|
9
|
-
def client
|
10
|
-
|
9
|
+
def client
|
10
|
+
@client ||= Flickrie.new_client(access_token_hash)
|
11
|
+
end
|
12
|
+
|
13
|
+
def upload_client
|
14
|
+
@upload_client ||= Flickrie.new_upload_client(access_token_hash)
|
15
|
+
end
|
11
16
|
|
12
17
|
include ApiMethods
|
13
18
|
|
data/lib/flickrie/license.rb
CHANGED
data/lib/flickrie/location.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
module Flickrie
|
2
2
|
class Location
|
3
|
-
attr_reader :latitude, :longitude, :accuracy, :context, :place_id,
|
4
|
-
:woeid
|
3
|
+
attr_reader :latitude, :longitude, :accuracy, :context, :place_id, :woeid
|
5
4
|
|
6
|
-
def neighbourhood
|
7
|
-
def locality
|
8
|
-
def county
|
9
|
-
def region
|
10
|
-
def country
|
5
|
+
def neighbourhood() place('neighbourhood') end
|
6
|
+
def locality() place('locality') end
|
7
|
+
def county() place('county') end
|
8
|
+
def region() place('region') end
|
9
|
+
def country() place('country') end
|
11
10
|
|
12
11
|
def [](key)
|
13
12
|
@info[key]
|
@@ -16,11 +15,14 @@ module Flickrie
|
|
16
15
|
private
|
17
16
|
|
18
17
|
def initialize(info = {})
|
18
|
+
raise ArgumentError if info.nil?
|
19
|
+
|
19
20
|
@info = info
|
20
21
|
|
21
|
-
%w[latitude longitude accuracy
|
22
|
+
%w[latitude longitude accuracy place_id woeid].each do |attribute|
|
22
23
|
instance_variable_set "@#{attribute}", @info[attribute]
|
23
24
|
end
|
25
|
+
@context = Integer(@info['context']) rescue nil
|
24
26
|
end
|
25
27
|
|
26
28
|
def place(place_name)
|
data/lib/flickrie/media/exif.rb
CHANGED
@@ -7,7 +7,7 @@ module Flickrie
|
|
7
7
|
data['_content']
|
8
8
|
|
9
9
|
rescue NoMethodError
|
10
|
-
|
10
|
+
nil
|
11
11
|
end
|
12
12
|
|
13
13
|
def [](key)
|
@@ -15,6 +15,8 @@ module Flickrie
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def initialize(info)
|
18
|
+
raise ArgumentError if info.nil?
|
19
|
+
|
18
20
|
@info = info
|
19
21
|
end
|
20
22
|
end
|
data/lib/flickrie/media/tag.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Flickrie
|
2
2
|
module Media
|
3
3
|
class Tag
|
4
|
-
def id
|
5
|
-
def raw
|
6
|
-
def content
|
4
|
+
def id() @info['id'] end
|
5
|
+
def raw() @info['raw'] end
|
6
|
+
def content() @info['_content'] end
|
7
7
|
|
8
8
|
def machine_tag?
|
9
9
|
@info['machine_tag'].to_i == 1 if @info['machine_tag']
|
@@ -1,16 +1,18 @@
|
|
1
1
|
module Flickrie
|
2
2
|
module Media
|
3
3
|
class Visibility
|
4
|
-
def public
|
5
|
-
def friends
|
6
|
-
def family
|
7
|
-
def contacts
|
4
|
+
def public?() @info['ispublic'].to_i == 1 if @info['ispublic'] end
|
5
|
+
def friends?() @info['isfriend'].to_i == 1 if @info['isfriend'] end
|
6
|
+
def family?() @info['isfamily'].to_i == 1 if @info['isfamily'] end
|
7
|
+
def contacts?() @info['iscontact'].to_i == 1 if @info['iscontact'] end
|
8
8
|
|
9
9
|
def [](key)
|
10
10
|
@info[key]
|
11
11
|
end
|
12
12
|
|
13
13
|
def initialize(info)
|
14
|
+
raise ArgumentError if info.nil?
|
15
|
+
|
14
16
|
@info = info
|
15
17
|
end
|
16
18
|
end
|
data/lib/flickrie/media.rb
CHANGED
@@ -7,16 +7,16 @@ require 'date'
|
|
7
7
|
|
8
8
|
module Flickrie
|
9
9
|
module Media
|
10
|
-
def id
|
11
|
-
def secret
|
12
|
-
def server
|
13
|
-
def farm
|
14
|
-
def title
|
15
|
-
def description
|
16
|
-
def
|
17
|
-
def
|
18
|
-
|
19
|
-
def camera
|
10
|
+
def id() @info['id'] end
|
11
|
+
def secret() @info['secret'] end
|
12
|
+
def server() @info['server'] end
|
13
|
+
def farm() @info['farm'] end
|
14
|
+
def title() @info['title'] end
|
15
|
+
def description() @info['description'] end
|
16
|
+
def media_status() @info['media_status'] end
|
17
|
+
def path_alias() @info['pathalias'] end
|
18
|
+
|
19
|
+
def camera() @info['camera'] end
|
20
20
|
# ==== Example
|
21
21
|
#
|
22
22
|
# photo.exif.get('Model') # => 'Canon PowerShot G12'
|
@@ -25,51 +25,34 @@ module Flickrie
|
|
25
25
|
# photo.exif.get('X-Resolution', :data => 'clean') # => '180 dpi'
|
26
26
|
# photo.exif.get('X-Resolution') # => '180 dpi'
|
27
27
|
#
|
28
|
-
def exif
|
28
|
+
def exif() Exif.new(@info['exif']) rescue nil end
|
29
29
|
|
30
|
-
def views_count
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
def comments_count
|
35
|
-
@info['comments_count'].to_i if @info['comments_count']
|
36
|
-
end
|
37
|
-
|
38
|
-
def location
|
39
|
-
Location.new(@info['location']) if @info['location']
|
40
|
-
end
|
41
|
-
|
42
|
-
def machine_tags
|
43
|
-
tags.select { |tag| tag.machine_tag? } if tags
|
44
|
-
end
|
30
|
+
def views_count() Integer(@info['views']) rescue nil end
|
31
|
+
def comments_count() Integer(@info['comments_count']) rescue nil end
|
45
32
|
|
46
|
-
def
|
47
|
-
|
48
|
-
end
|
33
|
+
def location() Location.new(@info['location']) rescue nil end
|
34
|
+
def geo_permissions() Visibility.new(@info['geoperms']) rescue nil end
|
49
35
|
|
50
|
-
def
|
51
|
-
|
52
|
-
end
|
36
|
+
def tags() @info['tags'].map { |info| Tag.new(info) } rescue nil end
|
37
|
+
def machine_tags() tags.select { |tag| tag.machine_tag? } rescue nil end
|
53
38
|
|
54
|
-
def
|
55
|
-
def uploaded_at; Time.at(@info['dates']['uploaded'].to_i) if @info['dates']['uploaded'] end
|
56
|
-
def updated_at; Time.at(@info['dates']['lastupdate'].to_i) if @info['dates']['lastupdate'] end
|
57
|
-
def taken_at; DateTime.parse(@info['dates']['taken']).to_time if @info['dates']['taken'] end
|
39
|
+
def license() License.new(@info['license']) rescue nil end
|
58
40
|
|
59
|
-
def
|
60
|
-
|
61
|
-
end
|
41
|
+
def posted_at() Time.at(Integer(@info['dates']['posted'])) rescue nil end
|
42
|
+
def uploaded_at() Time.at(Integer(@info['dates']['uploaded'])) rescue nil end
|
43
|
+
def updated_at() Time.at(Integer(@info['dates']['lastupdate'])) rescue nil end
|
44
|
+
def taken_at() DateTime.parse(@info['dates']['taken']).to_time rescue nil end
|
45
|
+
def taken_at_granularity() Integer(@info['dates']['takengranularity']) rescue nil end
|
62
46
|
|
63
|
-
def owner
|
64
|
-
User.new(@info['owner']) if @info['owner']
|
65
|
-
end
|
47
|
+
def owner() User.new(@info['owner']) rescue nil end
|
66
48
|
|
67
|
-
def safety_level
|
49
|
+
def safety_level() Integer(@info['safety_level']) rescue nil end
|
68
50
|
|
69
|
-
def safe
|
70
|
-
def moderate
|
71
|
-
def restricted
|
51
|
+
def safe?() safety_level <= 1 if safety_level end
|
52
|
+
def moderate?() safety_level == 2 if safety_level end
|
53
|
+
def restricted?() safety_level == 3 if safety_level end
|
72
54
|
|
55
|
+
# TODO: Take care about the url from #get_info
|
73
56
|
def url
|
74
57
|
if owner and id
|
75
58
|
"http://www.flickr.com/photos/#{owner.nsid}/#{id}"
|
@@ -78,68 +61,65 @@ module Flickrie
|
|
78
61
|
end
|
79
62
|
end
|
80
63
|
|
81
|
-
def visibility
|
82
|
-
Visibility.new(@info['visibility']) if @info['visibility']
|
83
|
-
end
|
64
|
+
def visibility() Visibility.new(@info['visibility']) rescue nil end
|
84
65
|
|
85
|
-
def primary
|
66
|
+
def primary?() Integer(@info['isprimary']) == 1 rescue nil end
|
86
67
|
|
87
|
-
def favorite
|
68
|
+
def favorite?() Integer(@info['isfavorite']) == 1 rescue nil end
|
88
69
|
|
89
|
-
def can_comment
|
90
|
-
def can_add_meta
|
70
|
+
def can_comment?() Integer(@info['editability']['cancomment']) == 1 rescue nil end
|
71
|
+
def can_add_meta?() Integer(@info['editability']['canaddmeta']) == 1 rescue nil end
|
91
72
|
|
92
|
-
def can_everyone_comment?
|
93
|
-
|
94
|
-
end
|
73
|
+
def can_everyone_comment?() Integer(@info['publiceditability']['cancomment']) == 1 rescue nil end
|
74
|
+
def can_everyone_add_meta?() Integer(@info['publiceditability']['canaddmeta']) == 1 rescue nil end
|
95
75
|
|
96
|
-
def
|
97
|
-
|
98
|
-
end
|
76
|
+
def can_download?() Integer(@info['usage']['candownload']) == 1 rescue nil end
|
77
|
+
def can_blog?() Integer(@info['usage']['canblog']) == 1 rescue nil end
|
78
|
+
def can_print?() Integer(@info['usage']['canprint']) == 1 rescue nil end
|
79
|
+
def can_share?() Integer(@info['usage']['canshare']) == 1 rescue nil end
|
99
80
|
|
100
|
-
def
|
101
|
-
def can_blog?; @info['usage']['canblog'].to_i == 1 if @info['usage']['canblog'] end
|
102
|
-
def can_print?; @info['usage']['canprint'].to_i == 1 if @info['usage']['canprint'] end
|
103
|
-
def can_share?; @info['usage']['canshare'].to_i == 1 if @info['usage']['canshare'] end
|
81
|
+
def has_people?() Integer(@info['people']['haspeople']) == 1 rescue nil end
|
104
82
|
|
105
|
-
def
|
83
|
+
def faved?() Integer(@info['is_faved']) == 1 rescue nil end
|
106
84
|
|
107
|
-
def
|
85
|
+
def notes() @info['notes']['note'].map { |hash| Note.new(hash) } rescue nil end
|
108
86
|
|
109
|
-
def
|
110
|
-
@info['notes']['note'].map { |hash| Note.new(hash) } if @info['notes']
|
111
|
-
end
|
87
|
+
def favorites() @info['person'].map { |info| User.new(info) } rescue nil end
|
112
88
|
|
113
89
|
def [](key)
|
114
90
|
@info[key]
|
115
91
|
end
|
116
92
|
|
117
|
-
def get_info(info = nil)
|
118
|
-
info ||= Flickrie.client.get_media_info(id).body['photo']
|
93
|
+
def get_info(params = {}, info = nil)
|
94
|
+
info ||= Flickrie.client.get_media_info(id, params).body['photo']
|
95
|
+
@info.update(info)
|
119
96
|
|
120
|
-
|
121
|
-
info['
|
122
|
-
info['
|
123
|
-
info['
|
124
|
-
info['
|
97
|
+
# Fixes
|
98
|
+
@info['title'] = @info['title']['_content']
|
99
|
+
@info['description'] = @info['description']['_content']
|
100
|
+
@info['comments_count'] = @info.delete('comments')['_content']
|
101
|
+
@info['dates']['uploaded'] = @info.delete('dateuploaded')
|
102
|
+
@info['tags'] = @info['tags']['tag']
|
125
103
|
|
126
|
-
@info.update(info)
|
127
104
|
self
|
128
105
|
end
|
129
106
|
|
130
107
|
def get_exif(params = {}, info = nil)
|
131
108
|
info ||= Flickrie.client.get_media_exif(id, params).body['photo']
|
109
|
+
@info.update(info)
|
132
110
|
|
133
|
-
|
134
|
-
|
111
|
+
self
|
112
|
+
end
|
113
|
+
|
114
|
+
def get_favorites(params = {}, info = nil)
|
115
|
+
info ||= Flickrie.client.get_media_favorites(id, params).body['photo']
|
116
|
+
@info.update(info)
|
135
117
|
|
136
118
|
self
|
137
119
|
end
|
138
120
|
|
139
121
|
def initialize(info = {})
|
140
122
|
@info = info
|
141
|
-
@info['dates'] ||= {}
|
142
|
-
@info['usage'] ||= {}
|
143
123
|
end
|
144
124
|
|
145
125
|
module ClassMethods # :nodoc:
|
@@ -169,11 +149,16 @@ module Flickrie
|
|
169
149
|
'taken' => info.delete('datetaken'),
|
170
150
|
'takengranularity' => info.delete('datetakengranularity'),
|
171
151
|
}
|
172
|
-
info['usage'] = {}
|
173
152
|
|
174
153
|
unless info['tags'].nil?
|
175
154
|
info['tags'] = info['tags'].split(' ').map do |tag_content|
|
176
|
-
|
155
|
+
{'_content' => tag_content, 'machine_tag' => 0}
|
156
|
+
end
|
157
|
+
end
|
158
|
+
unless info['machine_tags'].nil?
|
159
|
+
info['tags'] ||= []
|
160
|
+
info['tags'] += info.delete('machine_tags').split(' ').map do |tag_content|
|
161
|
+
{'_content' => tag_content, 'machine_tag' => 1}
|
177
162
|
end
|
178
163
|
end
|
179
164
|
|
@@ -182,7 +167,7 @@ module Flickrie
|
|
182
167
|
end
|
183
168
|
|
184
169
|
def from_info(info)
|
185
|
-
new('media' => info['media']).get_info(info)
|
170
|
+
new('media' => info['media']).get_info({}, info)
|
186
171
|
end
|
187
172
|
|
188
173
|
def from_user(hash)
|
@@ -202,7 +187,7 @@ module Flickrie
|
|
202
187
|
end
|
203
188
|
|
204
189
|
def from_sizes(info)
|
205
|
-
new.get_sizes(info)
|
190
|
+
new.get_sizes({}, info)
|
206
191
|
end
|
207
192
|
|
208
193
|
def from_search(hash)
|
data/lib/flickrie/media_count.rb
CHANGED
@@ -2,9 +2,7 @@ require 'date'
|
|
2
2
|
|
3
3
|
module Flickrie
|
4
4
|
class MediaCount
|
5
|
-
def value
|
6
|
-
@info['count'].to_i
|
7
|
-
end
|
5
|
+
def value() Integer(@info['count']) rescue nil end
|
8
6
|
|
9
7
|
def date_range
|
10
8
|
dates =
|
@@ -13,8 +11,8 @@ module Flickrie
|
|
13
11
|
[DateTime.parse(@info['fromdate']).to_time,
|
14
12
|
DateTime.parse(@info['todate']).to_time]
|
15
13
|
when "unix timestamp"
|
16
|
-
[Time.at(@info['fromdate']
|
17
|
-
Time.at(@info['todate']
|
14
|
+
[Time.at(Integer(@info['fromdate'])),
|
15
|
+
Time.at(Integer(@info['todate']))]
|
18
16
|
end
|
19
17
|
|
20
18
|
dates.first..dates.last
|