flickrie 0.5.2 → 0.6.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 (71) hide show
  1. data/.gitignore +0 -1
  2. data/CHANGELOG.md +10 -0
  3. data/Gemfile +3 -2
  4. data/Rakefile +7 -2
  5. data/flickrie.gemspec +3 -0
  6. data/lib/flickrie/api_methods.rb +5 -0
  7. data/lib/flickrie/client.rb +17 -4
  8. data/lib/flickrie/location.rb +23 -50
  9. data/lib/flickrie/media/exif.rb +4 -0
  10. data/lib/flickrie/media/tag.rb +4 -0
  11. data/lib/flickrie/media/ticket.rb +4 -0
  12. data/lib/flickrie/media/visibility.rb +10 -6
  13. data/lib/flickrie/media.rb +7 -70
  14. data/lib/flickrie/media_count.rb +4 -0
  15. data/lib/flickrie/oauth.rb +5 -3
  16. data/lib/flickrie/set.rb +5 -21
  17. data/lib/flickrie/upload_client.rb +4 -2
  18. data/lib/flickrie/user.rb +4 -1
  19. data/lib/flickrie/version.rb +1 -1
  20. data/lib/flickrie/video.rb +0 -13
  21. data/test/error_test.rb +20 -0
  22. data/test/instance_test.rb +13 -14
  23. data/test/license_test.rb +7 -13
  24. data/test/location_test.rb +11 -2
  25. data/test/media_count_test.rb +20 -12
  26. data/test/media_test.rb +319 -311
  27. data/test/oauth_test.rb +17 -18
  28. data/test/photo_test.rb +78 -60
  29. data/test/set_test.rb +72 -63
  30. data/test/{test.rb → test_helper.rb} +7 -0
  31. data/test/user_test.rb +43 -34
  32. data/test/vcr_cassettes/error/code.yml +1165 -0
  33. data/test/vcr_cassettes/instance/calling_api_methods.yml +182 -0
  34. data/test/vcr_cassettes/license/get_licenses.yml +73 -0
  35. data/test/vcr_cassettes/location/square_brackets.yml +85 -0
  36. data/test/vcr_cassettes/media/delete.yml +1380 -0
  37. data/test/vcr_cassettes/media/from_contacts.yml +155 -0
  38. data/test/vcr_cassettes/media/from_set.yml +276 -0
  39. data/test/vcr_cassettes/media/from_user.yml +275 -0
  40. data/test/vcr_cassettes/media/get_context.yml +73 -0
  41. data/test/vcr_cassettes/media/get_info.yml +167 -0
  42. data/test/vcr_cassettes/media/remove_tag.yml +264 -0
  43. data/test/vcr_cassettes/media/replace.yml +2252 -0
  44. data/test/vcr_cassettes/media/search.yml +275 -0
  45. data/test/vcr_cassettes/media/tags.yml +346 -0
  46. data/test/vcr_cassettes/media_count/get.yml +135 -0
  47. data/test/vcr_cassettes/media_count/square_brackets.yml +69 -0
  48. data/test/vcr_cassettes/oauth/tokens.yml +400 -0
  49. data/test/vcr_cassettes/photo/asynchronous_upload.yml +1693 -0
  50. data/test/vcr_cassettes/photo/from_set.yml +273 -0
  51. data/test/vcr_cassettes/photo/from_user.yml +275 -0
  52. data/test/vcr_cassettes/photo/get_exif.yml +239 -0
  53. data/test/vcr_cassettes/photo/get_sizes.yml +147 -0
  54. data/test/vcr_cassettes/photo/other_api_calls.yml +506 -0
  55. data/test/vcr_cassettes/photo/search.yml +271 -0
  56. data/test/vcr_cassettes/photo/square_brackets.yml +85 -0
  57. data/test/vcr_cassettes/photo/upload.yml +1229 -0
  58. data/test/vcr_cassettes/set/from_user.yml +477 -0
  59. data/test/vcr_cassettes/set/get_info.yml +951 -0
  60. data/test/vcr_cassettes/set/square_brackets.yml +73 -0
  61. data/test/vcr_cassettes/user/find_by_email_or_username.yml +135 -0
  62. data/test/vcr_cassettes/user/get_info.yml +151 -0
  63. data/test/vcr_cassettes/user/square_brackets.yml +77 -0
  64. data/test/vcr_cassettes/video/get_exif.yml +135 -0
  65. data/test/vcr_cassettes/video/get_info.yml +86 -0
  66. data/test/vcr_cassettes/video/get_sizes.yml +151 -0
  67. data/test/vcr_cassettes/video/other_api_calls.yml +643 -0
  68. data/test/vcr_cassettes/video/square_brackets.yml +86 -0
  69. data/test/vcr_cassettes/video/upload.yml +308 -0
  70. data/test/video_test.rb +66 -53
  71. metadata +123 -12
data/.gitignore CHANGED
@@ -1,5 +1,4 @@
1
1
  TODO.md
2
2
  Gemfile.lock
3
- *.gem
4
3
  pkg/
5
4
  credentials.rb
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Flickrie changelog
2
2
 
3
+ ## Version 0.6.0
4
+
5
+ - you can access the raw response hash with square brackets, if you notice I
6
+ didn't cover some part of it with methods. So, for example, `photo['id']`
7
+ will access the photo's ID.
8
+
9
+ - when `Flickrie::Error` is raises, you can now access its `#code`
10
+ attribute. This makes better error handling, because error code
11
+ is (supposed to be) unique, unlike the error message
12
+
3
13
  ## Version 0.5.2
4
14
 
5
15
  - the gem now also works with Faraday 0.7 (I apologize for not
data/Gemfile CHANGED
@@ -5,12 +5,13 @@ gemspec
5
5
  gem "faraday", "~> 0.7.6"
6
6
 
7
7
  group :development, :test do
8
- gem "activesupport"
9
8
  gem "flickrie", :path => "~/Projects/flickrie"
10
9
  gem "pry"
11
10
  gem "debugger"
12
11
  end
13
12
 
14
13
  group :test do
15
- gem "turn"
14
+ # This is to get rid of 'gem install minitest' messages
15
+ # in the tests
16
+ gem "minitest"
16
17
  end
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ CURRENT_DIR = File.expand_path(File.dirname(__FILE__))
5
5
 
6
6
  task :test do
7
7
  Dir["#{CURRENT_DIR}/test/**/*_test.rb"].each do |test_file|
8
- system "bundle exec turn -Itest #{test_file}"
8
+ system "bundle exec turn -Itest --require=test_helper #{test_file}"
9
9
  end
10
10
  end
11
11
 
@@ -14,7 +14,12 @@ namespace :test do
14
14
  map { |t| [File.basename(t).chomp('_test.rb').to_sym, t] }.
15
15
  each do |test_name, test_file|
16
16
  task(test_name) do
17
- system "bundle exec turn -Itest #{test_file}"
17
+ system "bundle exec turn -Itest --require=test_helper #{test_file}"
18
18
  end
19
19
  end
20
20
  end
21
+
22
+ task :rdoc do
23
+ system "rm -rf doc/"
24
+ system "rdoc lib/"
25
+ end
data/flickrie.gemspec CHANGED
@@ -21,4 +21,7 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency "multi_xml", '~> 0.4'
22
22
 
23
23
  gem.add_development_dependency "activesupport"
24
+ gem.add_development_dependency "turn"
25
+ gem.add_development_dependency "vcr"
26
+ gem.add_development_dependency "webmock"
24
27
  end
@@ -29,6 +29,7 @@ module Flickrie
29
29
  end
30
30
  end
31
31
 
32
+ #--
32
33
  # people
33
34
  def find_user_by_email(email)
34
35
  response = client.find_user_by_email(email)
@@ -58,6 +59,7 @@ module Flickrie
58
59
  select { |media| media.is_a?(Video) }
59
60
  end
60
61
 
62
+ #--
61
63
  # photos
62
64
  def add_media_tags(media_id, tags)
63
65
  client.add_media_tags(media_id, tags)
@@ -160,6 +162,7 @@ module Flickrie
160
162
  search_media(search_params.merge(:media => 'videos'))
161
163
  end
162
164
 
165
+ #--
163
166
  # photos.upload
164
167
  def check_upload_tickets(tickets)
165
168
  tickets = tickets.join(',') if tickets.respond_to?(:join)
@@ -168,12 +171,14 @@ module Flickrie
168
171
  map { |info| Media::Ticket.new(info) }
169
172
  end
170
173
 
174
+ #--
171
175
  # licenses
172
176
  def get_licenses
173
177
  response = client.get_licenses
174
178
  License.from_hash(response.body['licenses']['license'])
175
179
  end
176
180
 
181
+ #--
177
182
  # photosets
178
183
  def get_set_info(set_id)
179
184
  response = client.get_set_info(set_id)
@@ -2,6 +2,7 @@ require 'faraday_middleware'
2
2
 
3
3
  module Flickrie
4
4
  class << self
5
+ # :nodoc:
5
6
  def self.attr_accessor_with_client_reset(*attributes)
6
7
  attr_reader *attributes
7
8
 
@@ -54,17 +55,24 @@ module Flickrie
54
55
  end
55
56
 
56
57
  class Error < StandardError
58
+ attr_reader :code
59
+
60
+ def initialize(message, code = nil)
61
+ super(message)
62
+ @code = code.to_i
63
+ end
57
64
  end
58
65
 
59
- class StatusCheck < Faraday::Response::Middleware
66
+ class StatusCheck < Faraday::Response::Middleware # :nodoc:
60
67
  def on_complete(env)
61
68
  if env[:body]['stat'] != 'ok'
62
- raise Error, env[:body]['message']
69
+ raise Error.new(env[:body]['message'], env[:body]['code']),
70
+ env[:body]['message']
63
71
  end
64
72
  end
65
73
  end
66
74
 
67
- class OAuthStatusCheck < Faraday::Response::Middleware
75
+ class OAuthStatusCheck < Faraday::Response::Middleware # :nodoc:
68
76
  def on_complete(env)
69
77
  if env[:status] != 200
70
78
  message = env[:body][/(?<=oauth_problem=)[^&]+/]
@@ -88,6 +96,7 @@ module Flickrie
88
96
  end
89
97
  end
90
98
 
99
+ #--
91
100
  # people
92
101
  def find_user_by_email(email)
93
102
  get 'flickr.people.findByEmail', :find_email => email
@@ -106,6 +115,7 @@ module Flickrie
106
115
  get 'flickr.people.getPublicPhotos', ensure_media(params)
107
116
  end
108
117
 
118
+ #--
109
119
  # photos
110
120
  def add_media_tags(media_id, tags)
111
121
  post 'flickr.photos.addTags', :photo_id => media_id, :tags => tags
@@ -152,16 +162,19 @@ module Flickrie
152
162
  get 'flickr.photos.search', ensure_media(params)
153
163
  end
154
164
 
165
+ #--
155
166
  # photos.upload
156
167
  def check_upload_tickets(tickets)
157
168
  get 'flickr.photos.upload.checkTickets', :tickets => tickets
158
169
  end
159
170
 
160
- # licenses
171
+ #--
172
+ # photos.licenses
161
173
  def get_licenses
162
174
  get 'flickr.photos.licenses.getInfo'
163
175
  end
164
176
 
177
+ #--
165
178
  # photosets
166
179
  def get_set_info(set_id)
167
180
  get 'flickr.photosets.getInfo', :photoset_id => set_id
@@ -1,62 +1,35 @@
1
1
  module Flickrie
2
2
  class Location
3
- %w[latitude longitude accuracy context place_id woeid].each do |attr_name|
4
- define_method(attr_name) do
5
- @info[attr_name]
6
- end
7
- end
3
+ attr_reader :latitude, :longitude, :accuracy, :context, :place_id,
4
+ :woeid
8
5
 
9
- %w[neighbourhood locality county region country].each do |place_name|
10
- define_method(place_name) do
11
- if @info[place_name]
12
- Struct.new(:name, :place_id, :woeid).new \
13
- @info[place_name]['_content'],
14
- @info[place_name]['place_id'],
15
- @info[place_name]['woeid']
16
- end
17
- end
6
+ def neighbourhood; place('neighbourhood') end
7
+ def locality; place('locality') end
8
+ def county; place('county') end
9
+ def region; place('region') end
10
+ def country; place('country') end
11
+
12
+ def [](key)
13
+ @info[key]
18
14
  end
19
15
 
20
16
  private
21
17
 
22
18
  def initialize(info = {})
23
19
  @info = info
20
+
21
+ %w[latitude longitude accuracy context place_id woeid].each do |attribute|
22
+ instance_variable_set "@#{attribute}", @info[attribute]
23
+ end
24
+ end
25
+
26
+ def place(place_name)
27
+ if @info[place_name]
28
+ Struct.new(:name, :place_id, :woeid).new \
29
+ @info[place_name]['_content'],
30
+ @info[place_name]['place_id'],
31
+ @info[place_name]['woeid']
32
+ end
24
33
  end
25
34
  end
26
35
  end
27
-
28
- __END__
29
-
30
- {
31
- "latitude" => 37.792608,
32
- "longitude" => -122.402672,
33
- "accuracy" => "14",
34
- "context" => "0",
35
- "neighbourhood" => {
36
- "_content" => "Financial District",
37
- "place_id" => "GddgqTpTUb8LgT93hw",
38
- "woeid" => "23512022"
39
- },
40
- "locality" => {
41
- "_content" => "San Francisco",
42
- "place_id" => "7.MJR8tTVrIO1EgB",
43
- "woeid" => "2487956"
44
- },
45
- "county" => {
46
- "_content" => "San Francisco",
47
- "place_id" => ".7sOmlRQUL9nK.kMzA",
48
- "woeid" => "12587707"
49
- },
50
- "region" => {
51
- "_content" => "California",
52
- "place_id" => "NsbUWfBTUb4mbyVu",
53
- "woeid" => "2347563"
54
- },
55
- "country" => {
56
- "_content" => "United States",
57
- "place_id" => "nz.gsghTUb4c2WAecA",
58
- "woeid" => "23424977"
59
- },
60
- "place_id" =>"GddgqTpTUb8LgT93hw",
61
- "woeid" =>"23512022"
62
- }
@@ -10,6 +10,10 @@ module Flickrie
10
10
  raise Error, "The information about '#{key}' doesn't exist"
11
11
  end
12
12
 
13
+ def [](key)
14
+ @info[key]
15
+ end
16
+
13
17
  def initialize(info)
14
18
  @info = info
15
19
  end
@@ -13,6 +13,10 @@ module Flickrie
13
13
  User.new('nsid' => @info['author']) if @info['author']
14
14
  end
15
15
 
16
+ def [](key)
17
+ @info[key]
18
+ end
19
+
16
20
  def initialize(info)
17
21
  @info = info
18
22
  end
@@ -14,6 +14,10 @@ module Flickrie
14
14
  Time.at(@info['imported'].to_i)
15
15
  end
16
16
 
17
+ def [](key)
18
+ @info[key]
19
+ end
20
+
17
21
  def initialize(info)
18
22
  @info = info
19
23
  end
@@ -1,13 +1,17 @@
1
1
  module Flickrie
2
2
  module Media
3
3
  class Visibility
4
- def public?; @visibility[0].to_i == 1 if @visibility[0] end
5
- def friends?; @visibility[1].to_i == 1 if @visibility[1] end
6
- def family?; @visibility[2].to_i == 1 if @visibility[2] end
7
- def contacts?; @visibility[3].to_i == 1 if @visibility[3] end
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
- def initialize(*visibility)
10
- @visibility = visibility.flatten
9
+ def [](key)
10
+ @info[key]
11
+ end
12
+
13
+ def initialize(info)
14
+ @info = info
11
15
  end
12
16
  end
13
17
  end
@@ -45,13 +45,7 @@ module Flickrie
45
45
  end
46
46
 
47
47
  def geo_permissions
48
- if @info['geoperms']
49
- Visibility.new \
50
- *[@info['geoperms']['ispublic'],
51
- @info['geoperms']['isfriend'],
52
- @info['geoperms']['isfamily'],
53
- @info['geoperms']['iscontact']]
54
- end
48
+ Visibility.new(@info['geoperms']) if @info['geoperms']
55
49
  end
56
50
 
57
51
  def license
@@ -86,12 +80,7 @@ module Flickrie
86
80
  end
87
81
 
88
82
  def visibility
89
- if @info['visibility']
90
- Visibility.new \
91
- *[@info['visibility']['ispublic'],
92
- @info['visibility']['isfriend'],
93
- @info['visibility']['isfamily']]
94
- end
83
+ Visibility.new(@info['visibility']) if @info['visibility']
95
84
  end
96
85
 
97
86
  def primary?; @info['isprimary'].to_i == 1 if @info['isprimary'] end
@@ -122,10 +111,13 @@ module Flickrie
122
111
  @info['notes']['note'].map { |hash| Note.new(hash) } if @info['notes']
123
112
  end
124
113
 
114
+ def [](key)
115
+ @info[key]
116
+ end
117
+
125
118
  def get_info(info = nil)
126
119
  info ||= Flickrie.client.get_media_info(id).body['photo']
127
120
 
128
- # Fixes
129
121
  info['title'] = info['title']['_content']
130
122
  info['description'] = info['description']['_content']
131
123
  info['comments_count'] = info.delete('comments')['_content']
@@ -151,7 +143,7 @@ module Flickrie
151
143
  @info['usage'] ||= {}
152
144
  end
153
145
 
154
- module ClassMethods
146
+ module ClassMethods # :nodoc:
155
147
  def from_set(hash)
156
148
  hash['photo'].map do |info|
157
149
  info['owner'] = {
@@ -253,58 +245,3 @@ module Flickrie
253
245
  end
254
246
  end
255
247
  end
256
-
257
- __END__
258
-
259
-
260
- {
261
- "id"=>"6923154272",
262
- "secret"=>"5519fab554",
263
- "server"=>"5279",
264
- "farm"=>6,
265
- "dateuploaded"=>"1334189525",
266
- "isfavorite"=>0,
267
- "license"=>"0",
268
- "safety_level"=>"0",
269
- "rotation"=>0,
270
- "owner"=>
271
- {"nsid"=>"67131352@N04",
272
- "username"=>"Janko Marohnić",
273
- "realname"=>"",
274
- "location"=>"",
275
- "iconserver"=>"0",
276
- "iconfarm"=>0},
277
- "title"=>{"_content"=>"David Belle - Canon commercial"},
278
- "description"=>{"_content"=>""},
279
- "visibility"=>{"ispublic"=>1, "isfriend"=>0, "isfamily"=>0},
280
- "dates"=>
281
- {"posted"=>"1334189525",
282
- "taken"=>"2012-04-11 17:12:05",
283
- "takengranularity"=>"0",
284
- "lastupdate"=>"1334259651"},
285
- "views"=>"1",
286
- "editability"=>{"cancomment"=>0, "canaddmeta"=>0},
287
- "publiceditability"=>{"cancomment"=>1, "canaddmeta"=>0},
288
- "usage"=>{"candownload"=>1, "canblog"=>0, "canprint"=>0, "canshare"=>0},
289
- "comments"=>{"_content"=>"0"},
290
- "notes"=>{"note"=>[]},
291
- "people"=>{"haspeople"=>0},
292
- "tags"=>
293
- {"tag"=>
294
- [{"id"=>"67099213-6923154272-471",
295
- "author"=>"67131352@N04",
296
- "raw"=>"David",
297
- "_content"=>"david",
298
- "machine_tag"=>0},
299
- {"id"=>"67099213-6923154272-18012",
300
- "author"=>"67131352@N04",
301
- "raw"=>"Belle",
302
- "_content"=>"belle",
303
- "machine_tag"=>0}]},
304
- "location"=> {...}
305
- "geoperms"=>{"ispublic"=>1, "iscontact"=>0, "isfriend"=>0, "isfamily"=>0},
306
- "urls"=>
307
- {"url"=>
308
- [{"type"=>"photopage",
309
- "_content"=>"http://www.flickr.com/photos/67131352@N04/6923154272/"}]},
310
- }
@@ -20,6 +20,10 @@ module Flickrie
20
20
  dates.first..dates.last
21
21
  end
22
22
 
23
+ def [](key)
24
+ @info[key]
25
+ end
26
+
23
27
  def initialize(info, params)
24
28
  @info = info
25
29
  @dates_kind = (params[:dates].nil? ? "mysql timestamp" : "unix timestamp")
@@ -6,6 +6,7 @@ module Flickrie
6
6
  URL = 'http://www.flickr.com/services/oauth'.freeze
7
7
  NO_CALLBACK = 'oob'.freeze
8
8
 
9
+ # :nodoc:
9
10
  def self.new_connection(additional_oauth_params = {})
10
11
  oauth_params = {
11
12
  :consumer_key => Flickrie.api_key,
@@ -22,7 +23,7 @@ module Flickrie
22
23
  end
23
24
  end
24
25
 
25
- class StatusCheck < Faraday::Response::Middleware
26
+ class StatusCheck < Faraday::Response::Middleware # :nodoc:
26
27
  def on_complete(env)
27
28
  if env[:status] != 200
28
29
  raise Error, env[:body]['oauth_problem'].gsub('_', ' ').capitalize
@@ -33,13 +34,14 @@ module Flickrie
33
34
  class Error < StandardError
34
35
  end
35
36
 
36
- class ParseResponseParams < FaradayMiddleware::ResponseMiddleware
37
+ class ParseResponseParams < FaradayMiddleware::ResponseMiddleware # :nodoc:
37
38
  define_parser do |body|
38
39
  params_array = body.split('&').map { |param| param.split('=') }
39
40
  Hash[*params_array.flatten]
40
41
  end
41
42
  end
42
43
 
44
+ # :doc:
43
45
  def self.get_request_token(options = {})
44
46
  connection = new_connection
45
47
 
@@ -62,7 +64,7 @@ module Flickrie
62
64
  AccessToken.from_response(response.body)
63
65
  end
64
66
 
65
- module Token
67
+ module Token # :nodoc:
66
68
  def from_response(body)
67
69
  new(body['oauth_token'], body['oauth_token_secret'])
68
70
  end
data/lib/flickrie/set.rb CHANGED
@@ -25,6 +25,7 @@ module Flickrie
25
25
 
26
26
  def can_comment?; @info['can_comment'].to_i == 1 if @info['can_comment'] end
27
27
 
28
+ #--
28
29
  # TODO: Figure out what this is
29
30
  def needs_interstitial?; @info['needs_interstitial'].to_i == 1 end
30
31
  def visibility_can_see_set?; @info['visibility_can_see_set'].to_i == 1 end
@@ -34,6 +35,10 @@ module Flickrie
34
35
 
35
36
  def url; "http://www.flickr.com/photos/#{owner.nsid}/sets/#{id}" end
36
37
 
38
+ def [](key)
39
+ @info[key]
40
+ end
41
+
37
42
  def get_info(info = nil)
38
43
  info ||= Flickrie.client.get_set_info(id).body['photoset']
39
44
  info['title'] = info['title']['_content']
@@ -66,24 +71,3 @@ module Flickrie
66
71
  end
67
72
  end
68
73
  end
69
-
70
- __END__
71
-
72
- {
73
- "id"=>"72157629443464020",
74
- "primary"=>"6913731566",
75
- "secret"=>"23879c079a",
76
- "server"=>"7130",
77
- "farm"=>8,
78
- "photos"=>"1",
79
- "videos"=>0,
80
- "title"=>{"_content"=>"Bla"},
81
- "description"=>{"_content"=>""},
82
- "needs_interstitial"=>0,
83
- "visibility_can_see_set"=>1,
84
- "count_views"=>"0",
85
- "count_comments"=>"0",
86
- "can_comment"=>0,
87
- "date_create"=>"1334331151",
88
- "date_update"=>"1334331155
89
- }
@@ -28,10 +28,12 @@ module Flickrie
28
28
  end
29
29
  end
30
30
 
31
- class UploadStatusCheck < Faraday::Response::Middleware
31
+ class UploadStatusCheck < Faraday::Response::Middleware # :nodoc:
32
32
  def on_complete(env)
33
33
  if env[:body]['rsp']['stat'] != 'ok'
34
- raise Error, env[:body]['rsp']['err']['msg']
34
+ error = env[:body]['rsp']['err']
35
+ raise Error.new(error['msg'], error['code']),
36
+ error['msg']
35
37
  end
36
38
  end
37
39
  end
data/lib/flickrie/user.rb CHANGED
@@ -50,11 +50,14 @@ module Flickrie
50
50
  @info['ispro'].to_i == 1 if @info['ispro']
51
51
  end
52
52
 
53
+ def [](key)
54
+ @info[key]
55
+ end
56
+
53
57
  def get_info(info = nil)
54
58
  info ||= Flickrie.client.get_user_info(nsid).body['person']
55
59
  @info.update(info)
56
60
 
57
- # Fixes
58
61
  %w[username realname location description profileurl
59
62
  mobileurl photosurl].each do |attribute|
60
63
  @info[attribute] = @info[attribute]['_content']
@@ -1,3 +1,3 @@
1
1
  module Flickrie
2
- VERSION = '0.5.2'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -47,16 +47,3 @@ module Flickrie
47
47
  end
48
48
  end
49
49
  end
50
-
51
- __END__
52
-
53
- {
54
- ...
55
- "video"=>
56
- {"ready"=>1,
57
- "failed"=>0,
58
- "pending"=>0,
59
- "duration"=>"34",
60
- "width"=>"480",
61
- "height"=>"360"}
62
- }
@@ -0,0 +1,20 @@
1
+ class ErrorTest < Test::Unit::TestCase
2
+ def test_code
3
+ VCR.use_cassette 'error/code' do
4
+ begin
5
+ Flickrie.api_key = nil
6
+ Flickrie.client.get_licenses
7
+ rescue Flickrie::Error => error
8
+ assert_equal 100, error.code
9
+ end
10
+
11
+ begin
12
+ Flickrie.api_key = nil
13
+ Flickrie.upload_client.upload \
14
+ File.expand_path(File.join(File.dirname(__FILE__), 'photo.jpg'))
15
+ rescue Flickrie::Error => error
16
+ assert_equal 100, error.code
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,21 +1,20 @@
1
- require 'test/unit'
2
- require 'flickrie'
3
-
4
1
  class InstanceTest < Test::Unit::TestCase
5
- def test_if_it_works
6
- Flickrie.api_key = ENV['FLICKR_API_KEY']
7
- Flickrie.shared_secret = ENV['FLICKR_SHARED_SECRET']
2
+ def test_calling_api_methods
3
+ VCR.use_cassette 'instance/calling_api_methods' do
4
+ Flickrie.access_token = nil
5
+ Flickrie.access_secret = nil
8
6
 
9
- flickr = Flickrie::Instance.new \
10
- ENV['FLICKR_ACCESS_TOKEN'], ENV['FLICKR_ACCESS_SECRET']
7
+ flickr = Flickrie::Instance.new \
8
+ ENV['FLICKR_ACCESS_TOKEN'], ENV['FLICKR_ACCESS_SECRET']
11
9
 
12
- photo_id = 6946979188
13
- flickr.add_photo_tags(photo_id, "janko")
14
- photo = flickr.get_photo_info(photo_id)
10
+ photo_id = 6946979188
11
+ flickr.add_photo_tags(photo_id, "janko")
12
+ photo = flickr.get_photo_info(photo_id)
15
13
 
16
- tag = photo.tags.find { |tag| tag.content == "janko" }
17
- assert_not_nil tag
14
+ tag = photo.tags.find { |tag| tag.content == "janko" }
15
+ assert_not_nil tag
18
16
 
19
- flickr.remove_photo_tag tag.id
17
+ flickr.remove_photo_tag tag.id
18
+ end
20
19
  end
21
20
  end