flickrie 0.7.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +4 -0
  3. data/CHANGELOG.md +70 -30
  4. data/Gemfile +5 -4
  5. data/README.md +55 -53
  6. data/Rakefile +6 -9
  7. data/lib/flickrie/api_methods.rb +16 -3
  8. data/lib/flickrie/client.rb +11 -40
  9. data/lib/flickrie/instance.rb +0 -1
  10. data/lib/flickrie/location.rb +21 -18
  11. data/lib/flickrie/media.rb +5 -21
  12. data/lib/flickrie/media_count.rb +4 -0
  13. data/lib/flickrie/middleware.rb +71 -0
  14. data/lib/flickrie/oauth.rb +58 -49
  15. data/lib/flickrie/photo.rb +0 -2
  16. data/lib/flickrie/set.rb +0 -5
  17. data/lib/flickrie/upload_client.rb +45 -56
  18. data/lib/flickrie/user.rb +10 -10
  19. data/lib/flickrie/version.rb +1 -1
  20. data/lib/flickrie/video.rb +0 -2
  21. data/spec/files/photo.bla +0 -0
  22. data/spec/{api_methods_spec.rb → flickrie/api_methods_spec.rb} +14 -14
  23. data/spec/{error_spec.rb → flickrie/error_spec.rb} +1 -1
  24. data/spec/{instance_spec.rb → flickrie/instance_spec.rb} +2 -5
  25. data/spec/{license_spec.rb → flickrie/license_spec.rb} +1 -1
  26. data/spec/{location_spec.rb → flickrie/location_spec.rb} +12 -1
  27. data/spec/{media_count_spec.rb → flickrie/media_count_spec.rb} +7 -3
  28. data/spec/{media_spec.rb → flickrie/media_spec.rb} +25 -26
  29. data/spec/flickrie/oauth_spec.rb +25 -0
  30. data/spec/{photo_spec.rb → flickrie/photo_spec.rb} +1 -1
  31. data/spec/{set_spec.rb → flickrie/set_spec.rb} +2 -2
  32. data/spec/flickrie/upload_client_spec.rb +40 -0
  33. data/spec/flickrie/user_spec.rb +58 -0
  34. data/spec/{video_spec.rb → flickrie/video_spec.rb} +1 -1
  35. data/spec/spec_helper.rb +16 -13
  36. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/api_methods/asynchronous_upload.yml +60 -95
  37. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/api_methods/replace.yml +16 -16
  38. data/spec/{fixtures/vcr_cassettes/api_methods/tags.yml → vcr_cassettes/api_methods/tag_manipulation.yml} +24 -24
  39. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/api_methods/upload_and_delete.yml +21 -21
  40. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/error/a_request_was_made_and_failed.yml +9 -9
  41. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/instance/calling_api_methods.yml +32 -32
  42. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/license/get.yml +4 -4
  43. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/media/from_contacts.yml +8 -8
  44. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/media/from_set.yml +5 -5
  45. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/media/from_user.yml +5 -5
  46. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/media/get_context.yml +4 -4
  47. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/media/get_exif.yml +8 -8
  48. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/media/get_info.yml +18 -18
  49. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/media/public_from_user.yml +5 -5
  50. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/media/search.yml +5 -5
  51. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/media_count/get.yml +8 -8
  52. data/spec/vcr_cassettes/o_auth/incorrect_credentials.yml +249 -0
  53. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/photo/get_info.yml +6 -6
  54. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/photo/get_sizes.yml +12 -12
  55. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/photo/search.yml +5 -5
  56. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/set/from_user.yml +16 -16
  57. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/set/get_info.yml +32 -32
  58. data/spec/vcr_cassettes/upload_client/content_type.yml +117 -0
  59. data/spec/vcr_cassettes/upload_client/invalid_credentials.yml +208 -0
  60. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/user/find_by_username_or_email.yml +8 -8
  61. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/user/get_info.yml +8 -8
  62. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/video/get_info.yml +4 -4
  63. data/spec/{fixtures/vcr_cassettes → vcr_cassettes}/video/get_sizes.yml +8 -8
  64. metadata +105 -99
  65. data/spec/fixtures/vcr_cassettes/api_methods/tag_manipulation.yml +0 -178
  66. data/spec/fixtures/vcr_cassettes/error/code.yml +0 -84
  67. data/spec/fixtures/vcr_cassettes/error/was_raised.yml +0 -84
  68. data/spec/fixtures/vcr_cassettes/o_auth/incorrect_credentials.yml +0 -167
  69. data/spec/oauth_spec.rb +0 -22
  70. data/spec/user_spec.rb +0 -53
@@ -24,28 +24,22 @@ module Flickrie
24
24
  # photo.exif.get('X-Resolution', :data => 'raw') # => '180'
25
25
  # photo.exif.get('X-Resolution', :data => 'clean') # => '180 dpi'
26
26
  # photo.exif.get('X-Resolution') # => '180 dpi'
27
- #
28
27
  def exif() Exif.new(@info['exif']) rescue nil end
29
28
 
30
29
  def views_count() Integer(@info['views']) rescue nil end
31
30
  def comments_count() Integer(@info['comments_count']) rescue nil end
32
31
 
33
32
  # Returns an instance of Flickrie::Location
34
- #
35
33
  def location() Location.new(@info['location']) rescue nil end
36
34
  # Returns an instance of Flickrie::Media::Visibility
37
- #
38
35
  def geo_permissions() Visibility.new(@info['geoperms']) rescue nil end
39
36
 
40
37
  # Returns an array of Flickrie::Media::Tag
41
- #
42
38
  def tags() @info['tags'].map { |info| Tag.new(info) } rescue nil end
43
39
  # Returns an array of Flickrie::Media::Tag
44
- #
45
40
  def machine_tags() tags.select { |tag| tag.machine_tag? } rescue nil end
46
41
 
47
42
  # Returns an instance of Flickrie::License
48
- #
49
43
  def license() License.new(@info['license']) rescue nil end
50
44
 
51
45
  def posted_at() Time.at(Integer(@info['dates']['posted'])) rescue nil end
@@ -55,7 +49,6 @@ module Flickrie
55
49
  def taken_at_granularity() Integer(@info['dates']['takengranularity']) rescue nil end
56
50
 
57
51
  # Returns an instance of Flickrie::User
58
- #
59
52
  def owner() User.new(@info['owner']) rescue nil end
60
53
 
61
54
  def safety_level() Integer(@info['safety_level']) rescue nil end
@@ -75,7 +68,6 @@ module Flickrie
75
68
  end
76
69
 
77
70
  # Returns an instance of Flickrie::Media::Visibility
78
- #
79
71
  def visibility() Visibility.new(@info['visibility']) rescue nil end
80
72
 
81
73
  def primary?() Integer(@info['isprimary']) == 1 rescue nil end
@@ -98,11 +90,9 @@ module Flickrie
98
90
  def faved?() Integer(@info['is_faved']) == 1 rescue nil end
99
91
 
100
92
  # Returns an array of Flickrie::Media::Note
101
- #
102
93
  def notes() @info['notes']['note'].map { |hash| Note.new(hash) } rescue nil end
103
94
 
104
95
  # Returns an array of Flickrie::User
105
- #
106
96
  def favorites() @info['person'].map { |info| User.new(info) } rescue nil end
107
97
 
108
98
  def [](key) @info[key] end
@@ -221,17 +211,11 @@ module Flickrie
221
211
  end
222
212
 
223
213
  def from_context(hash)
224
- hash['count'] = hash['count']['_content'].to_i
225
-
226
- ['prevphoto', 'nextphoto'].each do |media|
227
- unless hash[media]['media'].nil?
228
- hash[media] = new(hash[media])
229
- else
230
- hash[media] = nil
231
- end
232
- end
233
-
234
- hash
214
+ count = hash['count']['_content'].to_i
215
+ previous_photo = new(hash['prevphoto']) rescue nil
216
+ next_photo = new(hash['nextphoto']) rescue nil
217
+ Struct.new(:count, :previous, :next).new \
218
+ count, previous_photo, next_photo
235
219
  end
236
220
 
237
221
  def from_exif(info)
@@ -17,6 +17,10 @@ module Flickrie
17
17
 
18
18
  dates.first..dates.last
19
19
  end
20
+ alias time_interval date_range
21
+
22
+ def from() date_range.begin end
23
+ def to() date_range.end end
20
24
 
21
25
  def [](key) @info[key] end
22
26
  def hash() @info end
@@ -0,0 +1,71 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware/response_middleware'
3
+
4
+ module Flickrie
5
+ class Error < StandardError
6
+ attr_reader :code
7
+
8
+ def initialize(message, code = nil)
9
+ super(message)
10
+ @code = code.to_i
11
+ end
12
+ end
13
+
14
+ # Internal
15
+ module Middleware # :nodoc:
16
+ class StatusCheck < Faraday::Response::Middleware
17
+ def on_complete(env)
18
+ if env[:body]['stat'] != 'ok'
19
+ raise Error.new(env[:body]['message'], env[:body]['code'])
20
+ end
21
+ end
22
+ end
23
+
24
+ class UploadStatusCheck < Faraday::Response::Middleware
25
+ def on_complete(env)
26
+ if env[:body]['rsp']['stat'] != 'ok'
27
+ error = env[:body]['rsp']['err']
28
+ raise Error.new(error['msg'], error['code'])
29
+ end
30
+ end
31
+ end
32
+
33
+ class OAuthCheck < Faraday::Response::Middleware
34
+ def on_complete(env)
35
+ if env[:status] != 200
36
+ message = env[:body][/(?<=oauth_problem=)[^&]+/]
37
+ pretty_message = message.gsub('_', ' ').capitalize
38
+ raise Error.new(pretty_message)
39
+ end
40
+ end
41
+ end
42
+
43
+ class Retry < Faraday::Middleware
44
+ def initialize(app, retries = 2)
45
+ @retries = retries
46
+ super(app)
47
+ end
48
+
49
+ def call(env)
50
+ retries = @retries
51
+ begin
52
+ @app.call(env)
53
+ rescue Faraday::Error::TimeoutError
54
+ if retries > 0
55
+ retries -= 1
56
+ retry
57
+ end
58
+ raise
59
+ end
60
+ end
61
+ end
62
+
63
+ class ParseOAuthParams < FaradayMiddleware::ResponseMiddleware
64
+ define_parser do |body|
65
+ CGI.parse(body).inject({}) do |hash, (key, value)|
66
+ hash.update(key.to_sym => value.first)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -1,92 +1,101 @@
1
1
  require 'faraday_middleware'
2
- require 'faraday_middleware/response_middleware'
3
2
 
4
3
  module Flickrie
5
4
  module OAuth
6
5
  URL = 'http://www.flickr.com/services/oauth'.freeze
7
6
  NO_CALLBACK = 'oob'.freeze
8
7
 
9
- # :nodoc:
10
- def self.new_connection(additional_oauth_params = {})
11
- Faraday.new(URL) do |conn|
12
- conn.use FaradayMiddleware::OAuth, {
13
- :consumer_key => Flickrie.api_key,
14
- :consumer_secret => Flickrie.shared_secret
15
- }.merge(additional_oauth_params)
8
+ private
16
9
 
17
- conn.use StatusCheck
18
- conn.use ParseResponseParams
10
+ def self.new_connection(request_token = nil) # :nodoc:
11
+ Faraday.new(params) do |b|
12
+ b.use Middleware::Retry
13
+ b.use FaradayMiddleware::OAuth,
14
+ :consumer_key => Flickrie.api_key,
15
+ :consumer_secret => Flickrie.shared_secret,
16
+ :token => request_token.to_a.first,
17
+ :token_secret => request_token.to_a.last
19
18
 
20
- conn.adapter :net_http
21
- end
22
- end
19
+ b.use Middleware::ParseOAuthParams
20
+ b.use Middleware::OAuthCheck
23
21
 
24
- class StatusCheck < Faraday::Response::Middleware # :nodoc:
25
- def on_complete(env)
26
- if env[:status] != 200
27
- raise Error, env[:body]['oauth_problem'].gsub('_', ' ').capitalize
22
+ b.adapter :net_http
28
23
  end
29
24
  end
30
- end
31
25
 
32
- class Error < StandardError
33
- end
34
-
35
- class ParseResponseParams < FaradayMiddleware::ResponseMiddleware # :nodoc:
36
- define_parser do |body|
37
- params_array = body.split('&').map { |param| param.split('=') }
38
- params_array.map! { |params| params.count == 1 ? params << "" : params}
39
- Hash[*params_array.flatten]
26
+ def self.params
27
+ {
28
+ :url => URL,
29
+ :request => {
30
+ :open_timeout => Flickrie.open_timeout || OPEN_TIMEOUT,
31
+ :timeout => Flickrie.timeout || TIMEOUT
32
+ }
33
+ }
40
34
  end
41
- end
42
35
 
43
- # :doc:
36
+ public
37
+
44
38
  def self.get_request_token(options = {})
45
39
  connection = new_connection
46
-
47
40
  response = connection.get "request_token" do |req|
48
41
  req.params[:oauth_callback] = options[:callback_url] || NO_CALLBACK
49
42
  end
50
43
 
51
- RequestToken.from_response(response.body)
44
+ RequestToken.new(response.body)
52
45
  end
53
46
 
54
47
  def self.get_access_token(verifier, request_token)
55
- connection = new_connection \
56
- :token => request_token.token,
57
- :token_secret => request_token.secret
58
-
48
+ connection = new_connection(request_token)
59
49
  response = connection.get "access_token" do |req|
60
50
  req.params[:oauth_verifier] = verifier
61
51
  end
62
52
 
63
- AccessToken.from_response(response.body)
53
+ AccessToken.new(response.body)
64
54
  end
65
55
 
66
- module Token # :nodoc:
67
- def from_response(body)
68
- new(body['oauth_token'], body['oauth_token_secret'])
56
+ module Token
57
+ attr_reader :token, :secret
58
+
59
+ def initialize(info)
60
+ @token = info[:oauth_token]
61
+ @secret = info[:oauth_token_secret]
62
+ end
63
+
64
+ def to_a
65
+ [token, secret]
69
66
  end
70
67
  end
71
68
 
72
- class RequestToken < Struct.new(:token, :secret)
73
- extend Token
69
+ class RequestToken
70
+ include Token
74
71
 
75
- def get_authorization_url(options = {})
72
+ def get_authorization_url(params = {})
76
73
  require 'uri'
77
74
  url = URI.parse(URL)
78
- url.path += "/authorize"
79
- params = {
80
- :oauth_token => token,
81
- :perms => options[:permissions] || options[:perms]
82
- }
83
- url.query = params.map { |k, v| "#{k}=#{v}" }.join('&')
75
+ url.path += '/authorize'
76
+ query_params = {:oauth_token => token}.merge(params)
77
+ url.query = query_params.map { |k,v| "#{k}=#{v}" }.join('&')
84
78
  url.to_s
85
79
  end
80
+ alias authorize_url get_authorization_url
81
+
82
+ def get_access_token(verifier)
83
+ OAuth.get_access_token(verifier, self)
84
+ end
86
85
  end
87
86
 
88
- class AccessToken < Struct.new(:token, :secret)
89
- extend Token
87
+ class AccessToken
88
+ include Token
89
+
90
+ attr_reader :user_info
91
+
92
+ def initialize(info)
93
+ super
94
+ @user_info = info.tap do |info|
95
+ info.delete(:oauth_token)
96
+ info.delete(:oauth_token_secret)
97
+ end
98
+ end
90
99
  end
91
100
  end
92
101
  end
@@ -1,6 +1,5 @@
1
1
  module Flickrie
2
2
  # See Flickrie::Media for the other methods.
3
- #
4
3
  class Photo
5
4
  include Media
6
5
 
@@ -66,7 +65,6 @@ module Flickrie
66
65
  def rotation() Integer(@info['rotation']) rescue nil end
67
66
 
68
67
  # Same as calling <tt>Flickrie.get_photo_sizes(photo.id)</tt>
69
- #
70
68
  def get_sizes(params = {}, info = nil)
71
69
  info ||= Flickrie.client.get_media_sizes(id, params).body['sizes']
72
70
  @info['usage'] ||= {}
data/lib/flickrie/set.rb CHANGED
@@ -20,17 +20,13 @@ module Flickrie
20
20
  end
21
21
 
22
22
  # Returns an instance of Flickrie::User
23
- #
24
23
  def owner() User.new('nsid' => @info['owner']) if @info['owner'] end
25
24
 
26
25
  # Same as calling <tt>Flickrie.photos_from_set(set.id)</tt>
27
- #
28
26
  def photos(params = {}) Flickrie.photos_from_set(id, params) end
29
27
  # Same as calling <tt>Flickrie.videos_from_set(set.id)</tt>
30
- #
31
28
  def videos(params = {}) Flickrie.videos_from_set(id, params) end
32
29
  # Same as calling <tt>Flickrie.media_from_set(set.id)</tt>
33
- #
34
30
  def media(params = {}) Flickrie.media_from_set(id, params) end
35
31
 
36
32
  def can_comment?() Integer(@info['can_comment']) == 1 rescue nil end
@@ -51,7 +47,6 @@ module Flickrie
51
47
  def hash() @info end
52
48
 
53
49
  # Same as calling <tt>Flickrie.get_set_info(set.id)</tt>
54
- #
55
50
  def get_info(info = nil)
56
51
  info ||= Flickrie.client.get_set_info(id).body['photoset']
57
52
  @info.update(info)
@@ -1,3 +1,5 @@
1
+ require 'faraday_middleware'
2
+
1
3
  module Flickrie
2
4
  class << self
3
5
  # :nodoc:
@@ -6,19 +8,20 @@ module Flickrie
6
8
  end
7
9
 
8
10
  def new_upload_client(access_token_hash = {})
9
- UploadClient.new(upload_params) do |conn|
10
- conn.use FaradayMiddleware::OAuth,
11
+ UploadClient.new(upload_params) do |b|
12
+ b.use Middleware::Retry
13
+ b.use FaradayMiddleware::OAuth,
11
14
  :consumer_key => api_key,
12
15
  :consumer_secret => shared_secret,
13
16
  :token => access_token_hash[:token] || access_token,
14
17
  :token_secret => access_token_hash[:secret] || access_secret
15
- conn.request :multipart
18
+ b.request :multipart
16
19
 
17
- conn.use UploadStatusCheck
18
- conn.use FaradayMiddleware::ParseXml
19
- conn.use OAuthStatusCheck
20
+ b.use Middleware::UploadStatusCheck
21
+ b.use FaradayMiddleware::ParseXml
22
+ b.use Middleware::OAuthCheck
20
23
 
21
- conn.adapter :net_http
24
+ b.adapter :net_http
22
25
  end
23
26
  end
24
27
 
@@ -28,40 +31,35 @@ module Flickrie
28
31
  {
29
32
  :url => 'http://api.flickr.com/services',
30
33
  :request => {
31
- :open_timeout => open_timeout || DEFAULTS[:open_timeout]
34
+ :open_timeout => open_timeout || OPEN_TIMEOUT
32
35
  }
33
36
  }
34
37
  end
35
38
  end
36
39
 
37
- class UploadStatusCheck < Faraday::Response::Middleware # :nodoc:
38
- def on_complete(env)
39
- if env[:body]['rsp']['stat'] != 'ok'
40
- error = env[:body]['rsp']['err']
41
- raise Error.new(error['msg'], error['code']),
42
- error['msg']
43
- end
44
- end
45
- end
46
-
47
40
  class UploadClient < Faraday::Connection # :nodoc:
48
41
  def upload(media, params = {})
49
- media_file = get_file(media, params[:mime_type])
50
- media_title = get_title(media)
51
- post "upload", {:photo => media_file,
52
- :title => media_title}.merge(params)
42
+ file = get_file(media, params[:content_type])
43
+ title = file.original_filename.match(/\.\w{3,4}$/).pre_match
44
+ post "upload", {
45
+ :photo => file,
46
+ :title => title
47
+ }.merge(params)
53
48
  end
54
49
 
55
50
  def replace(media, media_id, params = {})
56
- media_file = get_file(media, params[:mime_type])
57
- media_title = get_title(media)
58
- post "replace", {:photo => media_file,
59
- :photo_id => media_id, :title => media_title}.merge(params)
51
+ file = get_file(media, params[:content_type])
52
+ title = file.original_filename.match(/\.\w{3,4}$/).pre_match
53
+ post "replace", {
54
+ :photo => file,
55
+ :photo_id => media_id,
56
+ :title => title
57
+ }.merge(params)
60
58
  end
61
59
 
62
60
  private
63
61
 
64
- MIME_TYPES = {
62
+ CONTENT_TYPES = {
65
63
  %w[.jpg .jpeg .jpe .jif .jfif .jfi] => 'image/jpeg',
66
64
  %w[.gif] => 'image/gif',
67
65
  %w[.png] => 'image/png',
@@ -80,40 +78,31 @@ module Flickrie
80
78
  %w[.avi] => 'video/avi'
81
79
  }.freeze
82
80
 
83
- def get_file(object, mime_type = nil)
84
- if object.class.name == "String" # file path
85
- file_path = object
86
- mime_type ||= get_mime_type(file_path)
87
- elsif object.class.name == "ActionDispatch::Http::UploadedFile" # Rails
88
- file_path = object.tempfile
89
- mime_type ||= object.content_type
90
- elsif object.class.name == "Hash" # Sinatra
91
- file_path = object[:tempfile].path
92
- mime_type ||= object[:type]
93
- end
81
+ def get_file(object, content_type = nil)
82
+ file, content_type, file_path =
83
+ case object.class.name
84
+ when "String"
85
+ # file path
86
+ [File.open(object), content_type || determine_content_type(object), object]
87
+ when "ActionDispatch::Http::UploadedFile"
88
+ # file from Rails
89
+ [object, object.content_type, object.tempfile]
90
+ when "Hash"
91
+ # file from Sinatra
92
+ [object[:tempfile], object[:type], object[:tempfile].path]
93
+ else
94
+ raise Error, "Invalid file format"
95
+ end
94
96
 
95
- Faraday::UploadIO.new(file_path, mime_type)
97
+ Faraday::UploadIO.new(file, content_type, file_path)
96
98
  end
97
99
 
98
- def get_mime_type(file_path)
99
- extension = file_path[/\.\w{3,4}$/]
100
- mime_type = MIME_TYPES.find { |k,v| k.include?(extension) }.last
100
+ def determine_content_type(file_path)
101
+ extension = file_path[/\.\w+$/]
102
+ content_type = CONTENT_TYPES.find { |k,v| k.include?(extension) }.last
101
103
 
102
104
  rescue NoMethodError
103
- raise Error, "Don't know mime type for this extension (#{extension})"
104
- end
105
-
106
- def get_title(object)
107
- filename =
108
- if object.class.name == "String" # file path
109
- File.basename(object)
110
- elsif object.class.name == "ActionDispatch::Http::UploadedFile" # Rails
111
- object.original_filename
112
- elsif object.class.name == "Hash" # Sinatra
113
- object[:filename]
114
- end
115
-
116
- filename.match(/\.\w{3,4}$/).pre_match
105
+ raise Error, "Don't know the content type for this extension (#{extension})"
117
106
  end
118
107
  end
119
108
  end
data/lib/flickrie/user.rb CHANGED
@@ -7,11 +7,7 @@ module Flickrie
7
7
  def username() @info['username'] end
8
8
  def real_name() @info['realname'] end
9
9
  def location() @info['location'] end
10
- def time_zone() @info['timezone'] end
11
10
  def description() @info['description'] end
12
- def profile_url() @info['profileurl'] end
13
- def mobile_url() @info['mobileurl'] end
14
- def photos_url() @info['photosurl'] end
15
11
  def path_alias() @info['path_alias'] end
16
12
  def icon_server() @info['iconserver'] end
17
13
  def icon_farm() @info['iconfarm'] end
@@ -26,21 +22,26 @@ module Flickrie
26
22
  end
27
23
  end
28
24
 
25
+ # ==== Example
26
+ #
27
+ # user.time_zone.offset # => "+01:00"
28
+ # user.time_zone.label # => "Sarajevo, Skopje, Warsaw, Zagreb"
29
+ def time_zone() Struct.new(:label, :offset).new(*@info['timezone'].values) rescue nil end
30
+
31
+ def photos_url() @info['photosurl'] || "http://www.flickr.com/photos/#{nsid || id}" end
32
+ def profile_url() @info['profileurl'] || "http://www.flickr.com/people/#{nsid || id}" end
33
+ def mobile_url() @info['mobileurl'] end
34
+
29
35
  def first_taken() DateTime.parse(@info['photos']['firstdatetaken']).to_time rescue nil end
30
36
  def first_uploaded() Time.at(Integer(@info['photos']['firstdate'])) rescue nil end
31
37
 
32
38
  def favorited_at() Time.at(Integer(@info['favedate'])) rescue nil end
33
39
 
34
- def favorited_at
35
- Time.at(@info['favedate'].to_i)
36
- end
37
-
38
40
  def media_count() Integer(@info['photos']['count']) rescue nil end
39
41
  alias photos_count media_count
40
42
  alias videos_count media_count
41
43
 
42
44
  # The same as calling <tt>Flickrie.public_photos_from_user(user.nsid)</tt>
43
- #
44
45
  def public_photos() Flickrie.public_photos_from_user(nsid || id) end
45
46
 
46
47
  def pro?() Integer(@info['ispro']) == 1 rescue nil end
@@ -49,7 +50,6 @@ module Flickrie
49
50
  def hash() @info end
50
51
 
51
52
  # The same as calling <tt>Flickrie.get_user_info(user.nsid)</tt>
52
- #
53
53
  def get_info(params = {}, info = nil)
54
54
  info ||= Flickrie.client.get_user_info(nsid || id, params).body['person']
55
55
  @info.update(info)
@@ -1,3 +1,3 @@
1
1
  module Flickrie
2
- VERSION = "0.7.3"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,6 +1,5 @@
1
1
  module Flickrie
2
2
  # See Flickrie::Media for the other methods.
3
- #
4
3
  class Video
5
4
  include Media
6
5
 
@@ -18,7 +17,6 @@ module Flickrie
18
17
  def mobile_download_url() @video['mobile_download_url'] end
19
18
 
20
19
  # This fetches the #source_url, #download_url and the #mobile_download_url
21
- #
22
20
  def get_sizes(params = {}, info = nil)
23
21
  info ||= Flickrie.client.get_media_sizes(id, params).body['sizes']
24
22
  @info['usage'] ||= {}
Binary file
@@ -1,42 +1,42 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
1
+ require 'spec_helper'
2
2
 
3
3
  describe Flickrie::ApiMethods do
4
4
  it "should upload and delete correctly", :vcr, :cassette => "upload and delete" do
5
- media_id = @flickrie.upload(PHOTO_PATH)
6
- @flickrie.public_media_from_user(USER_NSID).map(&:id).should include(media_id)
7
- @flickrie.delete_media(media_id)
8
- @flickrie.public_media_from_user(USER_NSID).map(&:id).should_not include(media_id)
5
+ media_id = Flickrie.upload(PHOTO_PATH)
6
+ Flickrie.public_media_from_user(USER_NSID).map(&:id).should include(media_id)
7
+ Flickrie.delete_media(media_id)
8
+ Flickrie.public_media_from_user(USER_NSID).map(&:id).should_not include(media_id)
9
9
  end
10
10
 
11
11
  it "should upload asynchronously correctly", :vcr, :cassette => "asynchronous upload" do
12
- ticket_id = @flickrie.upload(PHOTO_PATH, :async => 1)
12
+ ticket_id = Flickrie.upload(PHOTO_PATH, :async => 1)
13
13
  begin
14
- ticket = @flickrie.check_upload_tickets([ticket_id]).first
14
+ ticket = Flickrie.check_upload_tickets([ticket_id]).first
15
15
  end until ticket.complete?
16
16
  photo_id = ticket.photo_id
17
17
  Flickrie.get_photo_info(photo_id).id.should eq(photo_id)
18
- @flickrie.delete_photo(photo_id)
18
+ Flickrie.delete_photo(photo_id)
19
19
  end
20
20
 
21
21
  it "should replace correctly", :vcr, :cassette => "replace" do
22
22
  begin
23
- id = @flickrie.upload(PHOTO_PATH)
24
- @flickrie.replace(PHOTO_PATH, id)
23
+ id = Flickrie.upload(PHOTO_PATH)
24
+ Flickrie.replace(PHOTO_PATH, id)
25
25
  rescue => exception
26
26
  exception.code.should eq(1) # Not a pro account
27
27
  ensure
28
- @flickrie.delete_media(id)
28
+ Flickrie.delete_media(id)
29
29
  end
30
30
  end
31
31
 
32
32
  it "should manipulate tags correctly", :vcr, :cassette => "tag manipulation" do
33
- media = @flickrie.get_media_info(PHOTO_ID)
33
+ media = Flickrie.get_media_info(PHOTO_ID)
34
34
  tags_before_change = media.tags.join(' ')
35
- @flickrie.add_media_tags(PHOTO_ID, "janko")
35
+ Flickrie.add_media_tags(PHOTO_ID, "janko")
36
36
  media.get_info
37
37
  media.tags.join(' ').should eq([tags_before_change, "janko"].join(' '))
38
38
  tag_id = media.tags.find { |tag| tag.content == "janko" }.id
39
- @flickrie.remove_media_tag(tag_id)
39
+ Flickrie.remove_media_tag(tag_id)
40
40
  media.get_info
41
41
  media.tags.join(' ').should eq(tags_before_change)
42
42
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
1
+ require 'spec_helper'
2
2
 
3
3
  describe Flickrie::Error do
4
4
  before(:all) do
@@ -1,19 +1,16 @@
1
- # encoding: utf-8
2
- require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
1
+ require 'spec_helper'
3
2
 
4
3
  describe Flickrie::Instance do
5
4
  it "should be able to call API methods", :vcr, :cassette => "calling api methods" do
6
5
  # this is to see if the client and upload_client were reset
7
6
  Flickrie.get_photo_info(PHOTO_ID)
8
- Flickrie.access_token = ENV['FLICKR_ACCESS_TOKEN']
9
- Flickrie.access_secret = ENV['FLICKR_ACCESS_SECRET']
10
7
  id = Flickrie.upload(PHOTO_PATH)
11
8
  Flickrie.delete_photo(id)
12
9
  Flickrie.access_token = Flickrie.access_secret = nil
13
10
 
14
11
  instance = Flickrie::Instance.new(ENV['FLICKR_ACCESS_TOKEN'], ENV['FLICKR_ACCESS_SECRET'])
15
12
  user = instance.test_login
16
- user.username.should eq("Janko Marohnić")
13
+ user.username.should eq(USER_USERNAME)
17
14
  id = instance.upload(PHOTO_PATH)
18
15
  instance.delete_photo(id)
19
16
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
1
+ require 'spec_helper'
2
2
 
3
3
  describe Flickrie::License do
4
4
  context "get" do