flickrie 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,3 +2,4 @@ TODO.md
2
2
  Gemfile.lock
3
3
  *.gem
4
4
  pkg/
5
+ credentials.rb
data/CHANGELOG.md CHANGED
@@ -1,10 +1,16 @@
1
1
  # Flickrie changelog
2
2
 
3
- ## Version 0.4.0 (Unreleased)
3
+ ## Version 0.4.0
4
4
 
5
5
  - covered `flickr.photos.getContactsPhotos`
6
6
  - covered `flickr.photos.getContactsPublicPhotos`
7
7
  - covered `flickr.photos.getContext`
8
+ - implemented uploading photos
9
+ - covered `flickr.photos.upload.checkTickets`
10
+
11
+ ## Version 0.3.2
12
+
13
+ - enabled passing params to `Flickrie::Set#photos`
8
14
 
9
15
  ## Version 0.3.1
10
16
 
@@ -19,4 +25,4 @@
19
25
 
20
26
  ## Version 0.2.2
21
27
 
22
- - removed `addressable` gem as dependency
28
+ - removed `addressable` gem as a dependency
data/Gemfile CHANGED
@@ -3,10 +3,10 @@ source :rubygems
3
3
  gemspec
4
4
 
5
5
  group :development, :test do
6
- gem "rake"
7
6
  gem "activesupport"
8
7
  gem "flickrie", :path => "~/Projects/flickrie"
9
8
  gem "pry"
9
+ gem "debugger"
10
10
  end
11
11
 
12
12
  group :test do
data/README.md CHANGED
@@ -35,13 +35,13 @@ You first need to install the gem.
35
35
  [sudo] gem install flickrie
36
36
  ```
37
37
 
38
- Then in your app you set the API key and secret (if you don't have them
38
+ Then in your app you set the API key and shared secret (if you don't have them
39
39
  already, you can apply for them [here](http://www.flickr.com/services/apps/create/apply)).
40
40
 
41
41
  ```ruby
42
42
  require 'flickrie'
43
- Flickrie.api_key = "your api key"
44
- Flickrie.shared_secret = "your shared secret"
43
+ Flickrie.api_key = "API_KEY"
44
+ Flickrie.shared_secret = "SHARED_SECRET"
45
45
  ```
46
46
 
47
47
  Then you can search for stuff.
@@ -122,8 +122,8 @@ be sure to check the [wiki](https://github.com/janko-m/flickrie/wiki) for some a
122
122
  ```ruby
123
123
  require 'flickrie'
124
124
 
125
- Flickrie.api_key = "your api key"
126
- Flickrie.shared_secret = "your shared secret"
125
+ Flickrie.api_key = "API_KEY"
126
+ Flickrie.shared_secret = "SHARED_SECRET"
127
127
 
128
128
  request_token = Flickrie::OAuth.get_request_token
129
129
  url = request_token.get_authorization_url
@@ -147,6 +147,24 @@ are "read", "write" and "delete".
147
147
  If you want to make authentication in your web application, check out my [flickr_auth](https://github.com/janko-m/flickr_auth) gem.
148
148
  Or, if you want to do it manually, check out [this wiki](https://github.com/janko-m/flickrie/wiki/Authentication-in-web-applications) for instructions.
149
149
 
150
+ ## Photo upload
151
+
152
+ ```ruby
153
+ photo_id = Flickrie.upload("/path/to/photo.jpg", :title => "A cow")
154
+ photo = Flickrie.get_photo_info(photo_id)
155
+ photo.title # => "A cow"
156
+ ```
157
+
158
+ For the list of parameters you can pass in when uploading a photo, see
159
+ [this page](http://www.flickr.com/services/api/upload.api.html).
160
+
161
+ Few notes:
162
+ - Photo uploads require authentication with "write" permissions.
163
+ - Path to the photo has to be absolute.
164
+
165
+ See [this wiki](https://github.com/janko-m/flickrie/wiki/Asynchronous_photo_upload) for an example
166
+ of an asynchronous photo upload.
167
+
150
168
  ## A few words
151
169
 
152
170
  Now, I covered only a few out of many Flickr's API methods using this approach,
@@ -199,26 +217,32 @@ basis of this gem.
199
217
 
200
218
  ```ruby
201
219
  # people
202
- "flickr.people.findByEmail" -> Flickrie.find_user_by_email
203
- "flickr.people.findByUsername" -> Flickrie.find_user_by_username
204
- "flickr.people.getInfo" -> Flickrie.get_user_info
205
- "flickr.people.getPublicPhotos" -> Flickrie.public_photos_from_user
220
+ "flickr.people.findByEmail" -> Flickrie.find_user_by_email
221
+ "flickr.people.findByUsername" -> Flickrie.find_user_by_username
222
+ "flickr.people.getInfo" -> Flickrie.get_user_info
223
+ "flickr.people.getPublicPhotos" -> Flickrie.public_photos_from_user
206
224
 
207
225
  # photos
208
- "flickr.photos.addTags" -> Flickrie.add_photo_tags
209
- "flickr.photos.delete" -> Flickrie.delete_photo
210
- "flickr.photos.getInfo" -> Flickrie.get_photo_info
211
- "flickr.photos.getSizes" -> Flickrie.get_photo_sizes
212
- "flickr.photos.removeTag" -> Flickrie.remove_photo_tag
213
- "flickr.photos.search" -> Flickrie.search_photos
226
+ "flickr.photos.addTags" -> Flickrie.add_photo_tags
227
+ "flickr.photos.delete" -> Flickrie.delete_photo
228
+ "flickr.photos.getContactsPhotos" -> Flickrie.photos_from_contacts
229
+ "flickr.photos.getContactsPublicPhotos" -> Flickrie.public_photos_from_user_contacts
230
+ "flickr.photos.getContext" -> Flickrie.get_photo_context
231
+ "flickr.photos.getInfo" -> Flickrie.get_photo_info
232
+ "flickr.photos.getSizes" -> Flickrie.get_photo_sizes
233
+ "flickr.photos.removeTag" -> Flickrie.remove_photo_tag
234
+ "flickr.photos.search" -> Flickrie.search_photos
235
+
236
+ # photos.upload
237
+ "flickr.photos.upload.checkTickets" -> Flickrie.check_upload_tickets
214
238
 
215
239
  # photos.licenses
216
- "flickr.photos.licenses.getInfo" -> Flickrie.get_licenses
240
+ "flickr.photos.licenses.getInfo" -> Flickrie.get_licenses
217
241
 
218
242
  # photosets
219
- "flickr.photosets.getInfo" -> Flickrie.get_set_info
220
- "flickr.photosets.getList" -> Flickrie.sets_from_user
221
- "flickr.photosets.getPhotos" -> Flickrie.photos_from_set
243
+ "flickr.photosets.getInfo" -> Flickrie.get_set_info
244
+ "flickr.photosets.getList" -> Flickrie.sets_from_user
245
+ "flickr.photosets.getPhotos" -> Flickrie.photos_from_set
222
246
  ```
223
247
 
224
248
  ## Changelog
data/flickrie.gemspec CHANGED
@@ -17,4 +17,7 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency 'faraday_middleware'
19
19
  gem.add_dependency 'simple_oauth'
20
+ gem.add_dependency 'multi_xml'
21
+
22
+ gem.add_development_dependency "activesupport"
20
23
  end
@@ -1,4 +1,5 @@
1
1
  require 'flickrie/client'
2
+ require 'flickrie/upload_client'
2
3
  require 'flickrie/oauth'
3
4
  require 'flickrie/license'
4
5
  require 'flickrie/user'
@@ -9,6 +10,24 @@ require 'flickrie/set'
9
10
 
10
11
  module Flickrie
11
12
  module ApiMethods
13
+ def upload(media, params = {})
14
+ response = upload_client.upload(media, params)
15
+ if params[:async] == 1
16
+ response.body['rsp']['ticketid']
17
+ else
18
+ response.body['rsp']['photoid']
19
+ end
20
+ end
21
+
22
+ def replace(media, media_id, params = {})
23
+ response = upload_client.replace(media, media_id, params)
24
+ if params[:async] == 1
25
+ response.body['rsp']['ticketid']
26
+ else
27
+ response.body['rsp']['photoid']
28
+ end
29
+ end
30
+
12
31
  # people
13
32
  def find_user_by_email(email)
14
33
  response = client.find_user_by_email(email)
@@ -47,10 +66,42 @@ module Flickrie
47
66
 
48
67
  def delete_media(media_id)
49
68
  client.delete_media(media_id)
69
+ media_id
50
70
  end
51
71
  alias delete_photo delete_media
52
72
  alias delete_video delete_media
53
73
 
74
+ def media_from_contacts(params = {})
75
+ response = client.media_from_contacts(params)
76
+ Media.from_contacts(response.body['photos'])
77
+ end
78
+ def photos_from_contacts(params = {})
79
+ media_from_contacts(params).select { |media| media.is_a?(Photo) }
80
+ end
81
+ def videos_from_contacts(params = {})
82
+ media_from_contacts(params).select { |media| media.is_a?(Video) }
83
+ end
84
+
85
+ def public_media_from_user_contacts(user_nsid, params = {})
86
+ response = client.public_media_from_user_contacts(user_nsid, params)
87
+ Media.from_contacts(response.body['photos'])
88
+ end
89
+ def public_photos_from_user_contacts(user_nsid, params = {})
90
+ public_media_from_user_contacts(user_nsid, params).
91
+ select { |media| media.is_a?(Photo) }
92
+ end
93
+ def public_videos_from_user_contacts(user_nsid, params = {})
94
+ public_media_from_user_contacts(user_nsid, params).
95
+ select { |media| media.is_a?(Photo) }
96
+ end
97
+
98
+ def get_media_context(media_id)
99
+ response = client.get_media_context(media_id)
100
+ Media.from_context(response.body)
101
+ end
102
+ alias get_photo_context get_media_context
103
+ alias get_video_context get_media_context
104
+
54
105
  def get_media_info(media_id)
55
106
  response = client.get_media_info(media_id)
56
107
  Media.from_info(response.body['photo'])
@@ -84,6 +135,14 @@ module Flickrie
84
135
  search_media(search_params.merge(:media => 'videos'))
85
136
  end
86
137
 
138
+ # photos.upload
139
+ def check_upload_tickets(tickets)
140
+ tickets = tickets.join(',') if tickets.is_a?(Array)
141
+ response = client.check_upload_tickets(tickets)
142
+ response.body['uploader']['ticket'].
143
+ map { |info| Media::Ticket.new(info) }
144
+ end
145
+
87
146
  # licenses
88
147
  def get_licenses
89
148
  response = client.get_licenses
@@ -17,36 +17,37 @@ module Flickrie
17
17
  :timeout, :open_timeout, :access_token, :access_secret
18
18
 
19
19
  def client(access_token_hash = {})
20
- @client ||= begin
21
- client = Client.new(params) do |conn|
22
- conn.request :oauth,
23
- :consumer_key => api_key,
24
- :consumer_secret => shared_secret,
25
- :token => access_token_hash[:token] || access_token,
26
- :token_secret => access_token_hash[:secret] || access_secret
27
- conn.response :json, :content_type => /(text\/plain)|(json)$/
28
- conn.adapter Faraday.default_adapter
29
- end
30
-
31
- client.builder.insert_after FaradayMiddleware::ParseJson, OAuthStatusCheck
32
- client.builder.insert_before FaradayMiddleware::ParseJson, StatusCheck
33
- client
20
+ @client ||= Client.new(params) do |conn|
21
+ conn.request :oauth,
22
+ :consumer_key => api_key,
23
+ :consumer_secret => shared_secret,
24
+ :token => access_token_hash[:token] || access_token,
25
+ :token_secret => access_token_hash[:secret] || access_secret
26
+
27
+ conn.use StatusCheck
28
+ conn.response :json, :content_type => /(text\/plain)|(json)$/
29
+ conn.use OAuthStatusCheck
30
+
31
+ conn.adapter Faraday.default_adapter
34
32
  end
35
33
  end
36
34
 
37
35
  private
38
36
 
37
+ OPEN_TIMEOUT = 4
38
+ TIMEOUT = 6
39
+
39
40
  def params
40
41
  {
41
- :url => 'http://api.flickr.com/services/rest/',
42
+ :url => 'http://api.flickr.com/services/rest',
42
43
  :params => {
43
44
  :format => 'json',
44
45
  :nojsoncallback => '1',
45
46
  :api_key => api_key
46
47
  },
47
48
  :request => {
48
- :open_timeout => open_timeout || 8,
49
- :timeout => timeout || 8
49
+ :open_timeout => open_timeout || OPEN_TIMEOUT,
50
+ :timeout => timeout || TIMEOUT
50
51
  }
51
52
  }
52
53
  end
@@ -114,6 +115,19 @@ module Flickrie
114
115
  post 'flickr.photos.delete', :photo_id => media_id
115
116
  end
116
117
 
118
+ def media_from_contacts(params = {})
119
+ get 'flickr.photos.getContactsPhotos', ensure_media(params)
120
+ end
121
+
122
+ def public_media_from_user_contacts(user_nsid, params = {})
123
+ params = {:user_id => user_nsid}.merge(params)
124
+ get 'flickr.photos.getContactsPublicPhotos', ensure_media(params)
125
+ end
126
+
127
+ def get_media_context(media_id)
128
+ get 'flickr.photos.getContext', :photo_id => media_id
129
+ end
130
+
117
131
  def get_media_info(media_id)
118
132
  get 'flickr.photos.getInfo', :photo_id => media_id
119
133
  end
@@ -130,6 +144,11 @@ module Flickrie
130
144
  get 'flickr.photos.search', ensure_media(params)
131
145
  end
132
146
 
147
+ # photos.upload
148
+ def check_upload_tickets(tickets)
149
+ get 'flickr.photos.upload.checkTickets', :tickets => tickets
150
+ end
151
+
133
152
  # licenses
134
153
  def get_licenses
135
154
  get 'flickr.photos.licenses.getInfo'
@@ -6,10 +6,15 @@ module Flickrie
6
6
  @access_token, @access_secret = access_token, access_secret
7
7
  end
8
8
 
9
- def client
10
- Flickrie.client(:token => access_token, :secret => access_secret)
11
- end
9
+ def client; Flickrie.client(access_token_hash) end
10
+ def upload_client; Flickrie.upload_client(access_token_hash) end
12
11
 
13
12
  include ApiMethods
13
+
14
+ private
15
+
16
+ def access_token_hash
17
+ {:token => access_token, :secret => access_secret}
18
+ end
14
19
  end
15
20
  end
@@ -0,0 +1,22 @@
1
+ module Flickrie
2
+ module Media
3
+ class Ticket
4
+ def id; @info['id'] end
5
+ def media_id; @info['photoid'] end
6
+ alias photo_id media_id
7
+ alias video_id media_id
8
+
9
+ def complete?
10
+ @info['complete'].to_i == 1
11
+ end
12
+
13
+ def imported_at
14
+ Time.at(@info['imported'].to_i)
15
+ end
16
+
17
+ def initialize(info)
18
+ @info = info
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,6 +1,7 @@
1
1
  require 'flickrie/media/visibility'
2
2
  require 'flickrie/media/note'
3
3
  require 'flickrie/media/tag'
4
+ require 'flickrie/media/ticket'
4
5
  require 'flickrie/location'
5
6
  require 'date'
6
7
 
@@ -68,6 +69,8 @@ module Flickrie
68
69
  def url
69
70
  if owner and id
70
71
  "http://www.flickr.com/photos/#{owner.nsid}/#{id}"
72
+ elsif @info['url']
73
+ "http://www.flickr.com" + @info['url']
71
74
  end
72
75
  end
73
76
 
@@ -102,6 +105,8 @@ module Flickrie
102
105
 
103
106
  def has_people?; @info['people']['haspeople'].to_i == 1 if @info['people'] end
104
107
 
108
+ def faved?; @info['is_faved'].to_i == 1 if @info['is_faved'] end
109
+
105
110
  def notes
106
111
  @info['notes']['note'].map { |hash| Note.new(hash) } if @info['notes']
107
112
  end
@@ -190,6 +195,28 @@ module Flickrie
190
195
  def from_search(hash)
191
196
  from_user(hash)
192
197
  end
198
+
199
+ def from_contacts(hash)
200
+ hash['photo'].each do |info|
201
+ info['ownername'] = info.delete('username')
202
+ end
203
+
204
+ from_user(hash)
205
+ end
206
+
207
+ def from_context(hash)
208
+ hash['count'] = hash['count']['_content'].to_i
209
+
210
+ ['prevphoto', 'nextphoto'].each do |media|
211
+ unless hash[media]['media'].nil?
212
+ hash[media] = new(hash[media])
213
+ else
214
+ hash[media] = nil
215
+ end
216
+ end
217
+
218
+ hash
219
+ end
193
220
  end
194
221
  extend(ClassMethods)
195
222
 
@@ -0,0 +1,88 @@
1
+ module Flickrie
2
+ class << self
3
+ def upload_client(access_token_hash = {})
4
+ @upload_client ||= UploadClient.new(upload_params) do |conn|
5
+ conn.request :oauth,
6
+ :consumer_key => api_key,
7
+ :consumer_secret => shared_secret,
8
+ :token => access_token_hash[:token] || access_token,
9
+ :token_secret => access_token_hash[:secret] || access_secret
10
+ conn.request :multipart
11
+
12
+ conn.use UploadStatusCheck
13
+ conn.response :xml
14
+
15
+ conn.adapter Faraday.default_adapter
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def upload_params
22
+ {
23
+ :url => 'http://api.flickr.com/services',
24
+ :request => {
25
+ :open_timeout => open_timeout || OPEN_TIMEOUT
26
+ }
27
+ }
28
+ end
29
+ end
30
+
31
+ class UploadStatusCheck < Faraday::Response::Middleware
32
+ def on_complete(env)
33
+ if env[:body]['rsp']['stat'] != 'ok'
34
+ raise Error, env[:body]['rsp']['err']['msg']
35
+ end
36
+ end
37
+ end
38
+
39
+ class UploadClient < Faraday::Connection
40
+ def upload(media, params = {})
41
+ media_file = get_file(media, params[:mime_type])
42
+ post "upload", {:photo => media_file}.merge(params)
43
+ end
44
+
45
+ def replace(media, media_id, params = {})
46
+ media_file = get_file(media)
47
+ post "replace", {:photo => media_file,
48
+ :photo_id => media_id}.merge(params)
49
+ end
50
+
51
+ private
52
+
53
+ MIME_TYPES = {
54
+ %w[.jpg .jpeg .jpe .jif .jfif .jfi] => 'image/jpeg',
55
+ %w[.gif] => 'image/gif',
56
+ %w[.png] => 'image/png',
57
+ %w[.svg .svgz] => 'image/svg+xml',
58
+ %w[.tiff .tif] => 'image/tiff',
59
+ %w[.ico] => 'image/vnd.microsoft.icon',
60
+
61
+ %w[.mpg .mpeg .m1v .m1a .m2a .mpa .mpv] => 'video/mpeg',
62
+ %w[.mp4 .m4a .m4p .m4b .m4r .m4v] => 'video/mp4',
63
+ %w[.ogv .oga .ogx .ogg .spx] => 'video/ogg',
64
+ %w[.mov .qt] => 'video/quicktime',
65
+ %w[.webm] => 'video/webm',
66
+ %w[.mkv .mk3d .mka .mks] => 'video/x-matroska',
67
+ %w[.wmv] => 'video/x-ms-wmv',
68
+ %w[.flv .f4v .f4p .f4a .f4b] => 'video/x-flv',
69
+ %w[.avi] => 'video/avi'
70
+ }.freeze
71
+
72
+ def get_file(object, mime_type = nil)
73
+ if object.is_a?(String)
74
+ Faraday::UploadIO.new(object, mime_type || get_mime_type(object))
75
+ else
76
+ object
77
+ end
78
+ end
79
+
80
+ def get_mime_type(file_path)
81
+ extension = file_path[/\.\w{3,4}$/]
82
+ mime_type = MIME_TYPES.find { |k,v| k.include?(extension) }.last
83
+
84
+ rescue NoMethodError
85
+ raise Error, "Don't know mime type for this extension (#{extension})"
86
+ end
87
+ end
88
+ end
@@ -1,3 +1,3 @@
1
1
  module Flickrie
2
- VERSION = '0.3.2'
2
+ VERSION = '0.4.0'
3
3
  end
data/test/media_test.rb CHANGED
@@ -286,6 +286,98 @@ class MediaTest < Test::Unit::TestCase
286
286
  assert_equal media.tags.join(' '), tags_before_change.chomp("janko").rstrip
287
287
  end
288
288
 
289
+ def test_delete_media
290
+ media_path = File.join(File.expand_path(File.dirname(__FILE__)), 'photo.jpg')
291
+ media_id = Flickrie.upload(media_path)
292
+ assert_includes Flickrie.public_media_from_user(@user_nsid).map(&:id), media_id
293
+ Flickrie.delete_media(media_id)
294
+ refute_includes Flickrie.public_media_from_user(@user_nsid).map(&:id), media_id
295
+ end
296
+
297
+ def test_media_from_contacts
298
+ medias = [
299
+ Flickrie.media_from_contacts(
300
+ :include_self => 1, :single_photo => 1, :extras => @all_extras).first,
301
+ Flickrie.public_media_from_user_contacts(@user_nsid,
302
+ :include_self => 1, :single_photo => 1, :extras => @all_extras).first
303
+ ]
304
+
305
+ medias.each do |media|
306
+ assert_equal '7093101501', media.id
307
+ assert_equal '9337f28800', media.secret
308
+ assert_equal '7090', media.server
309
+ assert_equal 8, media.farm
310
+ assert_equal 'IMG_0917', media.title
311
+ assert_equal '', media.tags.join(' ')
312
+ assert_equal '', media.machine_tags.join(' ')
313
+ assert_equal 0, media.views_count
314
+ assert_equal '0', media.license.id
315
+ assert_not_nil media.url
316
+ assert_equal 'ready', media.media_status
317
+
318
+ # Time
319
+ assert_instance_of Time, media.uploaded_at
320
+ assert_instance_of Time, media.updated_at
321
+ assert_instance_of Time, media.taken_at
322
+ assert_equal 0, media.taken_at_granularity
323
+
324
+ # Location
325
+ assert_nil media.location
326
+
327
+ # Owner
328
+ assert_equal '67131352@N04', media.owner.nsid
329
+ assert_equal 'Janko Marohnić', media.owner.username
330
+ assert_equal '5464', media.owner.icon_server
331
+ assert_equal 6, media.owner.icon_farm
332
+ refute media.owner.buddy_icon_url.empty?
333
+
334
+ # Visibility (This is the difference from Flickrie.media_from_set)
335
+ assert_equal true, media.visibility.public?
336
+ assert_equal false, media.visibility.friends?
337
+ assert_equal false, media.visibility.family?
338
+ assert_equal nil, media.visibility.contacts?
339
+ end
340
+ end
341
+
342
+ def test_get_media_context
343
+ context = Flickrie.get_media_context(@media_id)
344
+
345
+ assert_equal 98, context['count']
346
+
347
+ previous_media = context['prevphoto']
348
+ assert_equal '6946978706', previous_media.id
349
+ assert_equal 'b38270bbd6', previous_media.secret
350
+ assert_equal '7216', previous_media.server
351
+ assert_equal 8, previous_media.farm
352
+ assert_equal 'IMG_0795', previous_media.title
353
+ refute previous_media.url.empty?
354
+ assert_equal '0', previous_media.license.id
355
+ assert_equal false, previous_media.faved?
356
+
357
+ next_media = context['nextphoto']
358
+ assert_equal '6946979704', next_media.id
359
+ assert_equal '74513ff732', next_media.secret
360
+ assert_equal '7234', next_media.server
361
+ assert_equal 8, next_media.farm
362
+ assert_equal 'IMG_0797', next_media.title
363
+ refute next_media.url.empty?
364
+ assert_equal '0', next_media.license.id
365
+ assert_equal false, next_media.faved?
366
+ end
367
+
368
+ def test_media_replace
369
+ media_path = File.join(File.expand_path(File.dirname(__FILE__)), 'photo.jpg')
370
+ begin
371
+ media_id = Flickrie.upload(media_path)
372
+ Flickrie.replace(media_path, media_id)
373
+ flunk
374
+ rescue => exception
375
+ assert_equal "Not a pro account", exception.message
376
+ ensure
377
+ Flickrie.delete_media(media_id)
378
+ end
379
+ end
380
+
289
381
  def test_methods_returning_nil
290
382
  media = Flickrie::Photo.new
291
383
 
data/test/photo.jpg ADDED
Binary file
data/test/photo_test.rb CHANGED
@@ -146,6 +146,24 @@ class PhotoTest < Test::Unit::TestCase
146
146
  end
147
147
  end
148
148
 
149
+ def test_photo_upload
150
+ photo_path = File.join(File.expand_path(File.dirname(__FILE__)), 'photo.jpg')
151
+ photo_id = Flickrie.upload(photo_path)
152
+ assert_nothing_raised(Flickrie::Error) { Flickrie.get_photo_info(photo_id) }
153
+ Flickrie.delete_photo(photo_id)
154
+ end
155
+
156
+ def test_asynchronous_photo_upload
157
+ photo_path = File.join(File.expand_path(File.dirname(__FILE__)), 'photo.jpg')
158
+ ticket_id = Flickrie.upload(photo_path, :async => 1)
159
+ begin
160
+ ticket = Flickrie.check_upload_tickets([ticket_id]).first
161
+ end until ticket.complete?
162
+ photo_id = ticket.photo_id
163
+ assert_nothing_raised(Flickrie::Error) { Flickrie.get_photo_info(photo_id) }
164
+ Flickrie.delete_photo(photo_id)
165
+ end
166
+
149
167
  def test_other_api_calls
150
168
  # add_photo_tags, get_photo_info, remove_photo_tag,
151
169
  # search_photos, photos_from_contacts
@@ -155,6 +173,9 @@ class PhotoTest < Test::Unit::TestCase
155
173
  photo = Flickrie.get_photo_info(@photo_id)
156
174
  tag = photo.tags.find { |tag| tag.content == "janko" }
157
175
  Flickrie.remove_photo_tag(tag.id)
176
+ Flickrie.photos_from_contacts(:include_self => 1)
177
+ Flickrie.public_photos_from_user_contacts(@user_nsid, :include_self => 1)
178
+ Flickrie.get_photo_context(@photo_id)
158
179
  Flickrie.search_photos(:user_id => @user_nsid)
159
180
  end
160
181
  end
data/test/test.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  require 'test/unit'
2
2
  require 'flickrie/client'
3
3
 
4
- Flickrie.timeout = 20
5
- Flickrie.open_timeout = 20
6
4
  Flickrie.api_key = ENV['FLICKR_API_KEY']
7
5
  Flickrie.shared_secret = ENV['FLICKR_SHARED_SECRET']
8
6
  Flickrie.access_token = ENV['FLICKR_ACCESS_TOKEN']
data/test/video.mov ADDED
Binary file
data/test/video_test.rb CHANGED
@@ -66,6 +66,13 @@ class VideoTest < Test::Unit::TestCase
66
66
  assert_nil video.mobile_download_url
67
67
  end
68
68
 
69
+ def test_video_upload
70
+ video_path = File.join(File.expand_path(File.dirname(__FILE__)), 'video.mov')
71
+ video_id = Flickrie.upload(video_path)
72
+ assert_nothing_raised(Flickrie::Error) { Flickrie.get_video_info(video_id) }
73
+ Flickrie.delete_video(video_id)
74
+ end
75
+
69
76
  def test_other_api_calls
70
77
  # add_video_tags, remove_video_tag,
71
78
  # search_videos, videos_from_contacts,
@@ -76,9 +83,12 @@ class VideoTest < Test::Unit::TestCase
76
83
  video = Flickrie.get_video_info(@video_id)
77
84
  tag = video.tags.find { |tag| tag.content == "janko" }
78
85
  Flickrie.remove_video_tag(tag.id)
79
- Flickrie.search_videos(:user_id => @user_nsid)
86
+ Flickrie.videos_from_contacts(:include_self => 1)
87
+ Flickrie.public_videos_from_user_contacts(@user_nsid, :include_self => 1)
80
88
  Flickrie.public_videos_from_user(@user_nsid)
81
89
  Flickrie.videos_from_set(@set_id)
90
+ Flickrie.get_video_context(@video_id)
91
+ Flickrie.search_videos(:user_id => @user_nsid)
82
92
  end
83
93
  end
84
94
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flickrie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-02 00:00:00.000000000 Z
12
+ date: 2012-05-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday_middleware
16
- requirement: &70189173611560 !ruby/object:Gem::Requirement
16
+ requirement: &70095977665920 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70189173611560
24
+ version_requirements: *70095977665920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: simple_oauth
27
- requirement: &70189173466820 !ruby/object:Gem::Requirement
27
+ requirement: &70095977665300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,29 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70189173466820
35
+ version_requirements: *70095977665300
36
+ - !ruby/object:Gem::Dependency
37
+ name: multi_xml
38
+ requirement: &70095977664520 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70095977664520
47
+ - !ruby/object:Gem::Dependency
48
+ name: activesupport
49
+ requirement: &70095977662960 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70095977662960
36
58
  description: This gem is a nice wrapper for the Flickr API with an intuitive interface.
37
59
  email:
38
60
  - janko.marohnic@gmail.com
@@ -56,10 +78,12 @@ files:
56
78
  - lib/flickrie/media.rb
57
79
  - lib/flickrie/media/note.rb
58
80
  - lib/flickrie/media/tag.rb
81
+ - lib/flickrie/media/ticket.rb
59
82
  - lib/flickrie/media/visibility.rb
60
83
  - lib/flickrie/oauth.rb
61
84
  - lib/flickrie/photo.rb
62
85
  - lib/flickrie/set.rb
86
+ - lib/flickrie/upload_client.rb
63
87
  - lib/flickrie/user.rb
64
88
  - lib/flickrie/version.rb
65
89
  - lib/flickrie/video.rb
@@ -68,10 +92,12 @@ files:
68
92
  - test/location_test.rb
69
93
  - test/media_test.rb
70
94
  - test/oauth_test.rb
95
+ - test/photo.jpg
71
96
  - test/photo_test.rb
72
97
  - test/set_test.rb
73
98
  - test/test.rb
74
99
  - test/user_test.rb
100
+ - test/video.mov
75
101
  - test/video_test.rb
76
102
  homepage: https://github.com/janko-m/flickrie
77
103
  licenses: []
@@ -106,9 +132,11 @@ test_files:
106
132
  - test/location_test.rb
107
133
  - test/media_test.rb
108
134
  - test/oauth_test.rb
135
+ - test/photo.jpg
109
136
  - test/photo_test.rb
110
137
  - test/set_test.rb
111
138
  - test/test.rb
112
139
  - test/user_test.rb
140
+ - test/video.mov
113
141
  - test/video_test.rb
114
142
  has_rdoc: