flickrie 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/.gitignore +2 -1
  2. data/CHANGELOG.md +9 -1
  3. data/Gemfile +7 -6
  4. data/README.md +18 -1
  5. data/Rakefile +47 -9
  6. data/flickrie.gemspec +19 -15
  7. data/lib/flickrie/api_methods.rb +23 -0
  8. data/lib/flickrie/client.rb +16 -11
  9. data/lib/flickrie/instance.rb +7 -0
  10. data/lib/flickrie/media/exif.rb +12 -3
  11. data/lib/flickrie/media/note.rb +5 -0
  12. data/lib/flickrie/media/tag.rb +4 -3
  13. data/lib/flickrie/media/visibility.rb +4 -3
  14. data/lib/flickrie/media.rb +19 -0
  15. data/lib/flickrie/oauth.rb +5 -7
  16. data/lib/flickrie/photo.rb +6 -2
  17. data/lib/flickrie/set.rb +10 -0
  18. data/lib/flickrie/upload_client.rb +10 -12
  19. data/lib/flickrie/user.rb +4 -0
  20. data/lib/flickrie/version.rb +1 -1
  21. data/lib/flickrie/video.rb +4 -0
  22. data/spec/api_methods_spec.rb +2 -0
  23. data/spec/error_spec.rb +2 -0
  24. data/spec/fixtures/vcr_cassettes/api_methods/asynchronous_upload.yml +397 -0
  25. data/spec/fixtures/vcr_cassettes/api_methods/replace.yml +126 -0
  26. data/spec/fixtures/vcr_cassettes/api_methods/tags.yml +178 -0
  27. data/spec/fixtures/vcr_cassettes/api_methods/upload_and_delete.yml +152 -0
  28. data/spec/fixtures/vcr_cassettes/error/code.yml +84 -0
  29. data/spec/fixtures/vcr_cassettes/error/was_raised.yml +84 -0
  30. data/spec/fixtures/vcr_cassettes/instance/calling_api_methods.yml +231 -0
  31. data/spec/fixtures/vcr_cassettes/license/get.yml +38 -0
  32. data/spec/fixtures/vcr_cassettes/media/from_contacts.yml +73 -0
  33. data/spec/fixtures/vcr_cassettes/media/from_set.yml +38 -0
  34. data/spec/fixtures/vcr_cassettes/media/get_context.yml +38 -0
  35. data/spec/fixtures/vcr_cassettes/media/get_exif.yml +73 -0
  36. data/spec/fixtures/vcr_cassettes/media/get_info.yml +108 -0
  37. data/spec/fixtures/vcr_cassettes/media/public_from_user.yml +38 -0
  38. data/spec/fixtures/vcr_cassettes/media/search.yml +38 -0
  39. data/spec/fixtures/vcr_cassettes/media_count/get.yml +73 -0
  40. data/spec/fixtures/vcr_cassettes/oauth/incorrect_credentials.yml +167 -0
  41. data/spec/fixtures/vcr_cassettes/photo/get_info.yml +38 -0
  42. data/spec/fixtures/vcr_cassettes/photo/get_sizes.yml +73 -0
  43. data/spec/fixtures/vcr_cassettes/photo/search.yml +38 -0
  44. data/spec/fixtures/vcr_cassettes/set/from_user.yml +143 -0
  45. data/spec/fixtures/vcr_cassettes/set/get_info.yml +283 -0
  46. data/spec/fixtures/vcr_cassettes/user/find_by_username_or_email.yml +73 -0
  47. data/spec/fixtures/vcr_cassettes/user/get_info.yml +73 -0
  48. data/spec/fixtures/vcr_cassettes/video/get_info.yml +38 -0
  49. data/spec/fixtures/vcr_cassettes/video/get_sizes.yml +73 -0
  50. data/spec/instance_spec.rb +2 -0
  51. data/spec/license_spec.rb +2 -0
  52. data/spec/location_spec.rb +2 -0
  53. data/spec/media_count_spec.rb +2 -0
  54. data/spec/media_spec.rb +1 -0
  55. data/spec/oauth_spec.rb +2 -0
  56. data/spec/photo_spec.rb +2 -0
  57. data/spec/set_spec.rb +1 -0
  58. data/spec/spec_helper.rb +20 -3
  59. data/spec/user_spec.rb +1 -0
  60. data/spec/video_spec.rb +2 -0
  61. metadata +92 -21
  62. data/credentials.rb +0 -4
data/.gitignore CHANGED
@@ -2,6 +2,7 @@ TODO.md
2
2
  Gemfile.lock
3
3
  pkg/
4
4
  doc/
5
+ wiki/
5
6
  .DS_Store
6
- spec/vcr_cassettes
7
7
  api_methods.md
8
+ .bundle/
data/CHANGELOG.md CHANGED
@@ -1,12 +1,20 @@
1
1
  # Flickrie changelog
2
2
 
3
+ ## Version 0.7.2
4
+
5
+ - specified versions of dependencies and Ruby accurately
6
+
3
7
  ## Version 0.7.1
4
8
 
5
9
  - fixed an oauth bug
10
+ - added `#hash` method to photos, sets etc. which you can call to get the
11
+ raw data (in Ruby hash). This is useful if I accidentally left something out,
12
+ or if Flickr added something new that I didn't cover yet, that you can
13
+ still get to the data. `#[]` reads from the same hash.
6
14
 
7
15
  ## Version 0.7.0
8
16
 
9
- - cover `flickr.photos.getFavorites` and `flickr.test.login`
17
+ - covered `flickr.photos.getFavorites` and `flickr.test.login`
10
18
  - bug fixes (especially regarding the `Flickr::Instance`)
11
19
 
12
20
  ## Version 0.6.1
data/Gemfile CHANGED
@@ -2,10 +2,11 @@ source :rubygems
2
2
 
3
3
  gemspec
4
4
 
5
- gem "faraday", "~> 0.7.6"
6
-
7
- group :development, :test do
8
- gem "flickrie", :path => "~/Projects/flickrie"
9
- gem "pry"
10
- gem "debugger"
5
+ group :test do
6
+ gem "faraday", '0.7.6'
11
7
  end
8
+
9
+ # You can run `bundle [install] --without debugger pry` if
10
+ # you don't want to install them
11
+ gem "debugger", :group => :debugger
12
+ gem "pry", :group => :pry
data/README.md CHANGED
@@ -117,7 +117,7 @@ So, in your ERB template you could do something like this (in Rails):
117
117
  ```
118
118
 
119
119
  You can see the full list of available methods and attributes in the
120
- [documentation](http://janko-m.github.com/flickrie/doc/Flickrie.html).
120
+ [documentation](http://janko-m.github.com/flickrie/Flickrie.html).
121
121
  For photos (and videos) have a look at the `Flickrie::Media` module,
122
122
  because it's included into `Flickrie::Photo` and `Flickrie::Video`, and most
123
123
  of the attributes are there.
@@ -214,6 +214,23 @@ 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
+ Nothing special, you just fork the project, and send me a pull request.
220
+ Don't forget to cover the change with tests. If you don't know how to
221
+ write tests, send the pull requests without them, it's ok.
222
+
223
+ An important note: if you want to add a line in the tests which makes a **new** HTTP request,
224
+ you'll have to get your own API key and access token. You can get the
225
+ API key and secret [here](http://www.flickr.com/services/apps/create/apply)
226
+ (assuming you already have a Flickr account), and you can then obtain an access token by using my
227
+ authentication system (described above). You then have to assign these
228
+ values to the environment variables `FLICKR_API_KEY`, `FLICKR_SHARED_SECRET`,
229
+ `FLICKR_ACCESS_TOKEN` and `FLICKR_ACCESS_SECRET`. That's it, you should
230
+ be able to run the tests normally now.
231
+
232
+ Feel free to email me if you have any problems.
233
+
217
234
  ## Cedits
218
235
 
219
236
  Special thanks to @**mislav**, my brother, he helped me really a lot
data/Rakefile CHANGED
@@ -1,25 +1,63 @@
1
1
  require 'bundler'
2
2
  Bundler::GemHelper.install_tasks
3
3
 
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")
4
+ desc "Run the specs (use spec:name to run a single spec)"
5
+ task :spec do |task, args|
6
+ system "bundle exec rspec --color"
7
+ end
8
+
9
+ Dir["spec/*_spec.rb"].each do |spec|
10
+ task_name = File.basename(spec)[/.+(?=_spec\.rb)/]
11
+ task :"spec:#{task_name}" do
12
+ system "bundle exec rspec #{spec} --color"
10
13
  end
11
14
  end
12
15
 
16
+ desc "Open the console with credentials (API key, secret etc.) already filled in"
13
17
  task :console do
18
+ File.open("credentials.rb", "w") do |f|
19
+ f.write <<-CREDENTIALS
20
+ Flickrie.api_key = ENV['FLICKR_API_KEY']
21
+ Flickrie.shared_secret = ENV['FLICKR_SHARED_SECRET']
22
+ Flickrie.access_token = ENV['FLICKR_ACCESS_TOKEN']
23
+ Flickrie.access_secret = ENV['FLICKR_ACCESS_SECRET']
24
+ CREDENTIALS
25
+ end
14
26
  begin
15
27
  require 'pry'
16
- system "bundle exec pry -I. --require 'flickrie' --require 'credentials'"
28
+ system "bundle exec pry --require 'flickrie' --require './credentials'"
17
29
  rescue LoadError
18
- system "bundle exec irb -I. -r 'flickrie' -r 'credentials'"
30
+ system "bundle exec irb -r 'flickrie' -r './credentials'"
19
31
  end
32
+ FileUtils.remove_file "credentials.rb"
20
33
  end
21
34
 
22
35
  task :rdoc do
23
- system "rm -rf doc/"
36
+ FileUtils.rm_rf "doc"
24
37
  system "rdoc lib/"
25
38
  end
39
+
40
+ # copied from Rails
41
+ begin
42
+ require 'rails/source_annotation_extractor'
43
+
44
+ desc "Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)"
45
+ task :notes do
46
+ SourceAnnotationExtractor.enumerate "OPTIMIZE|FIXME|TODO", :tag => true
47
+ end
48
+
49
+ namespace :notes do
50
+ ["OPTIMIZE", "FIXME", "TODO"].each do |annotation|
51
+ # desc "Enumerate all #{annotation} annotations"
52
+ task annotation.downcase.intern do
53
+ SourceAnnotationExtractor.enumerate annotation
54
+ end
55
+ end
56
+
57
+ desc "Enumerate a custom annotation, specify with ANNOTATION=CUSTOM"
58
+ task :custom do
59
+ SourceAnnotationExtractor.enumerate ENV['ANNOTATION']
60
+ end
61
+ end
62
+ rescue LoadError
63
+ end
data/flickrie.gemspec CHANGED
@@ -1,26 +1,30 @@
1
1
  # encoding: utf-8
2
- require File.expand_path('../lib/flickrie/version', __FILE__)
2
+ require File.expand_path("../lib/flickrie/version", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.author = "Janko Marohnić"
6
- gem.email = "janko.marohnic@gmail.com"
7
- gem.description = %q{This gem is a nice wrapper for the Flickr API with an intuitive interface.}
8
- gem.summary = %q{The reason why I did this gem is because the other ones either weren't well maintained, or they were too literal in the sense that the response from the API call wasn't processed almost at all. It doesn't seem too bad at first, but after a while you realize it's not pretty. So I wanted to make it pretty :)}
9
- gem.homepage = "https://github.com/janko-m/flickrie"
10
-
11
- gem.files = `git ls-files`.split($\)
12
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
- gem.name = "flickrie"
14
- gem.require_paths = ["lib"]
15
5
  gem.version = Flickrie::VERSION
16
6
 
17
- gem.license = "MIT"
7
+ gem.author = "Janko Marohnić"
8
+ gem.email = "janko.marohnic@gmail.com"
9
+ gem.description = %q{This gem is a nice wrapper for the Flickr API with an intuitive interface.}
10
+ gem.summary = %q{The reason why I did this gem is because the other ones either weren't well maintained, or they were too literal in the sense that the response from the API call wasn't processed almost at all. It doesn't seem too bad at first, but after a while you realize it's not pretty. So I wanted to make it pretty :)}
11
+ gem.homepage = "https://github.com/janko-m/flickrie"
12
+
13
+ gem.files = `git ls-files`.split($\)
14
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
15
+ gem.name = "flickrie"
16
+ gem.require_path = "lib"
17
+
18
+ gem.license = "MIT"
19
+
20
+ gem.required_ruby_version = ">= 1.9.2"
18
21
 
19
- gem.add_dependency "faraday_middleware"
22
+ gem.add_dependency "faraday_middleware", '>= 0.8.7', '< 0.9'
23
+ gem.add_dependency "faraday", '>= 0.7.6', '< 0.9'
20
24
  gem.add_dependency "simple_oauth", '~> 0.1'
21
25
  gem.add_dependency "multi_xml", '~> 0.4'
22
26
 
23
- gem.add_development_dependency "activesupport", '>= 3'
27
+ gem.add_development_dependency "rake", '~> 0.9'
24
28
  gem.add_development_dependency "rspec", '>= 2'
25
- gem.add_development_dependency "vcr"
29
+ gem.add_development_dependency "vcr", '>= 2', '< 3'
26
30
  end
@@ -12,6 +12,15 @@ require 'flickrie/ticket'
12
12
 
13
13
  module Flickrie
14
14
  module ApiMethods
15
+ # ==== Example
16
+ #
17
+ # path = File.expand_path("photo.jpg")
18
+ # id = Flickrie.upload(path, :title => "Me and Jessica", :description => "...")
19
+ # photo = Flickrie.get_photo_info(id)
20
+ # photo.title # => "Me and Jessica"
21
+ #
22
+ # If the <tt>:async => 1</tt> option is passed, returns the ticket ID.
23
+ #
15
24
  def upload(media, params = {})
16
25
  response = upload_client.upload(media, params)
17
26
  if params[:async] == 1
@@ -21,6 +30,16 @@ module Flickrie
21
30
  end
22
31
  end
23
32
 
33
+ # ==== Example
34
+ #
35
+ # path = File.expand_path("photo.jpg")
36
+ # photo_id = 42374 # ID of the photo to be replaced
37
+ # id = Flickrie.replace(path, photo_id, :title => "Me and Jessica", :description => "...")
38
+ # photo = Flickrie.get_photo_info(id)
39
+ # photo.title # => "Me and Jessica"
40
+ #
41
+ # If the <tt>:async => 1</tt> option is passed, returns the ticket ID.
42
+ #
24
43
  def replace(media, media_id, params = {})
25
44
  response = upload_client.replace(media, media_id, params)
26
45
  if params[:async] == 1
@@ -169,6 +188,8 @@ module Flickrie
169
188
 
170
189
  #--
171
190
  # photos.upload
191
+ #++
192
+ # Returns an array of Flickrie::Ticket
172
193
  def check_upload_tickets(tickets, params = {})
173
194
  tickets = tickets.join(',') if tickets.respond_to?(:join)
174
195
  response = client.check_upload_tickets(tickets, params)
@@ -178,6 +199,8 @@ module Flickrie
178
199
 
179
200
  #--
180
201
  # licenses
202
+ #++
203
+ # Returns an array of Flickrie::License
181
204
  def get_licenses(params = {})
182
205
  response = client.get_licenses(params)
183
206
  License.from_hash(response.body['licenses']['license'])
@@ -1,9 +1,13 @@
1
1
  require 'faraday_middleware'
2
2
 
3
3
  module Flickrie
4
+ DEFAULTS = {
5
+ :open_timeout => 4,
6
+ :timeout => 6
7
+ }.freeze
8
+
4
9
  class << self
5
- # :nodoc:
6
- def self.attr_accessor_with_client_reset(*attributes)
10
+ def self.attr_accessor_with_client_reset(*attributes) # :nodoc:
7
11
  attr_reader *attributes
8
12
 
9
13
  attributes.each do |attribute|
@@ -14,15 +18,19 @@ module Flickrie
14
18
  end
15
19
  end
16
20
 
17
- # :doc:
18
21
  attr_accessor_with_client_reset :api_key, :shared_secret,
19
22
  :timeout, :open_timeout, :access_token, :access_secret
20
23
 
24
+ # ==== Example
25
+ #
26
+ # Flickrie.client.get "flickr.photos.licenses.getInfo"
27
+ # Flickrie.client.post "flickr.photos.licenses.setLicense", :photo_id => 1241497, :license_id => 2
28
+ #
21
29
  def client
22
30
  @client ||= new_client
23
31
  end
24
32
 
25
- def new_client(access_token_hash = {})
33
+ def new_client(access_token_hash = {}) # :nodoc:
26
34
  Client.new(params) do |conn|
27
35
  conn.use FaradayMiddleware::OAuth,
28
36
  :consumer_key => api_key,
@@ -34,15 +42,12 @@ module Flickrie
34
42
  conn.use FaradayMiddleware::ParseJson, :content_type => /(text\/plain)|(json)$/
35
43
  conn.use OAuthStatusCheck
36
44
 
37
- conn.adapter Faraday.default_adapter
45
+ conn.adapter :net_http
38
46
  end
39
47
  end
40
48
 
41
49
  private
42
50
 
43
- OPEN_TIMEOUT = 4
44
- TIMEOUT = 6
45
-
46
51
  def params
47
52
  {
48
53
  :url => 'http://api.flickr.com/services/rest',
@@ -52,8 +57,8 @@ module Flickrie
52
57
  :api_key => api_key
53
58
  },
54
59
  :request => {
55
- :open_timeout => open_timeout || OPEN_TIMEOUT,
56
- :timeout => timeout || TIMEOUT
60
+ :open_timeout => open_timeout || DEFAULTS[:open_timeout],
61
+ :timeout => timeout || DEFAULTS[:timeout]
57
62
  }
58
63
  }
59
64
  end
@@ -86,7 +91,7 @@ module Flickrie
86
91
  end
87
92
  end
88
93
 
89
- class Client < Faraday::Connection
94
+ class Client < Faraday::Connection # :nodoc:
90
95
  def get(method, params = {})
91
96
  super() do |req|
92
97
  req.params[:method] = method
@@ -6,6 +6,13 @@ module Flickrie
6
6
  @access_token, @access_secret = access_token, access_secret
7
7
  end
8
8
 
9
+ # ==== Example
10
+ #
11
+ # flickrie = Flickrie::Instance.new("ACCESS_TOKEN", "ACCESS_SECRET")
12
+ #
13
+ # flickrie.client.get "flickr.photos.licenses.getInfo"
14
+ # flickrie.client.post "flickr.photos.licenses.setLicense", :photo_id => 1241497, :license_id => 2
15
+ #
9
16
  def client
10
17
  @client ||= Flickrie.new_client(access_token_hash)
11
18
  end
@@ -1,6 +1,14 @@
1
1
  module Flickrie
2
2
  module Media
3
3
  class Exif
4
+ # ==== Example
5
+ #
6
+ # photo.exif.get('Model') # => 'Canon PowerShot G12'
7
+ #
8
+ # photo.exif.get('X-Resolution', :data => 'raw') # => '180'
9
+ # photo.exif.get('X-Resolution', :data => 'clean') # => '180 dpi'
10
+ # photo.exif.get('X-Resolution') # => '180 dpi'
11
+ #
4
12
  def get(key, options = {})
5
13
  hash = @info.find { |hash| hash['label'] == key }
6
14
  data = hash[options[:data]] || hash['clean'] || hash['raw']
@@ -10,9 +18,10 @@ module Flickrie
10
18
  nil
11
19
  end
12
20
 
13
- def [](key)
14
- @info[key]
15
- end
21
+ def [](key) @info[key] end
22
+ def hash() @info end
23
+
24
+ private
16
25
 
17
26
  def initialize(info)
18
27
  raise ArgumentError if info.nil?
@@ -8,6 +8,11 @@ module Flickrie
8
8
  @content
9
9
  end
10
10
 
11
+ def [](key) @info[key] end
12
+ def hash() @info end
13
+
14
+ private
15
+
11
16
  def initialize(hash)
12
17
  @id = hash['id']
13
18
  @author = User.new \
@@ -13,9 +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
16
+ def [](key) @info[key] end
17
+ def hash() @info end
18
+
19
+ private
19
20
 
20
21
  def initialize(info)
21
22
  @info = info
@@ -6,9 +6,10 @@ module Flickrie
6
6
  def family?() @info['isfamily'].to_i == 1 if @info['isfamily'] end
7
7
  def contacts?() @info['iscontact'].to_i == 1 if @info['iscontact'] end
8
8
 
9
- def [](key)
10
- @info[key]
11
- end
9
+ def [](key) @info[key] end
10
+ def hash() @info end
11
+
12
+ private
12
13
 
13
14
  def initialize(info)
14
15
  raise ArgumentError if info.nil?
@@ -30,12 +30,22 @@ module Flickrie
30
30
  def views_count() Integer(@info['views']) rescue nil end
31
31
  def comments_count() Integer(@info['comments_count']) rescue nil end
32
32
 
33
+ # Returns an instance of Flickrie::Location
34
+ #
33
35
  def location() Location.new(@info['location']) rescue nil end
36
+ # Returns an instance of Flickrie::Media::Visibility
37
+ #
34
38
  def geo_permissions() Visibility.new(@info['geoperms']) rescue nil end
35
39
 
40
+ # Returns an array of Flickrie::Media::Tag
41
+ #
36
42
  def tags() @info['tags'].map { |info| Tag.new(info) } rescue nil end
43
+ # Returns an array of Flickrie::Media::Tag
44
+ #
37
45
  def machine_tags() tags.select { |tag| tag.machine_tag? } rescue nil end
38
46
 
47
+ # Returns an instance of Flickrie::License
48
+ #
39
49
  def license() License.new(@info['license']) rescue nil end
40
50
 
41
51
  def posted_at() Time.at(Integer(@info['dates']['posted'])) rescue nil end
@@ -44,6 +54,8 @@ module Flickrie
44
54
  def taken_at() DateTime.parse(@info['dates']['taken']).to_time rescue nil end
45
55
  def taken_at_granularity() Integer(@info['dates']['takengranularity']) rescue nil end
46
56
 
57
+ # Returns an instance of Flickrie::User
58
+ #
47
59
  def owner() User.new(@info['owner']) rescue nil end
48
60
 
49
61
  def safety_level() Integer(@info['safety_level']) rescue nil end
@@ -52,6 +64,7 @@ module Flickrie
52
64
  def moderate?() safety_level == 2 if safety_level end
53
65
  def restricted?() safety_level == 3 if safety_level end
54
66
 
67
+ #--
55
68
  # TODO: Take care about the url from #get_info
56
69
  def url
57
70
  if owner and id
@@ -61,6 +74,8 @@ module Flickrie
61
74
  end
62
75
  end
63
76
 
77
+ # Returns an instance of Flickrie::Media::Visibility
78
+ #
64
79
  def visibility() Visibility.new(@info['visibility']) rescue nil end
65
80
 
66
81
  def primary?() Integer(@info['isprimary']) == 1 rescue nil end
@@ -82,8 +97,12 @@ module Flickrie
82
97
 
83
98
  def faved?() Integer(@info['is_faved']) == 1 rescue nil end
84
99
 
100
+ # Returns an array of Flickrie::Media::Note
101
+ #
85
102
  def notes() @info['notes']['note'].map { |hash| Note.new(hash) } rescue nil end
86
103
 
104
+ # Returns an array of Flickrie::User
105
+ #
87
106
  def favorites() @info['person'].map { |info| User.new(info) } rescue nil end
88
107
 
89
108
  def [](key) @info[key] end
@@ -8,18 +8,16 @@ module Flickrie
8
8
 
9
9
  # :nodoc:
10
10
  def self.new_connection(additional_oauth_params = {})
11
- oauth_params = {
12
- :consumer_key => Flickrie.api_key,
13
- :consumer_secret => Flickrie.shared_secret
14
- }.merge(additional_oauth_params)
15
-
16
11
  Faraday.new(URL) do |conn|
17
- conn.use FaradayMiddleware::OAuth, oauth_params
12
+ conn.use FaradayMiddleware::OAuth, {
13
+ :consumer_key => Flickrie.api_key,
14
+ :consumer_secret => Flickrie.shared_secret
15
+ }.merge(additional_oauth_params)
18
16
 
19
17
  conn.use StatusCheck
20
18
  conn.use ParseResponseParams
21
19
 
22
- conn.adapter Faraday.default_adapter
20
+ conn.adapter :net_http
23
21
  end
24
22
  end
25
23
 
@@ -1,9 +1,9 @@
1
1
  module Flickrie
2
+ # See Flickrie::Media for the other methods.
3
+ #
2
4
  class Photo
3
5
  include Media
4
6
 
5
- attr_reader :size
6
-
7
7
  SIZES = {
8
8
  'Square 75' => 'sq',
9
9
  'Thumbnail' => 't',
@@ -17,6 +17,8 @@ module Flickrie
17
17
  'Original' => 'o'
18
18
  }
19
19
 
20
+ def size() @size end
21
+
20
22
  def square!(number) @size = "Square #{number}"; self end
21
23
  def thumbnail!() @size = "Thumbnail"; self end
22
24
  def small!(number) @size = "Small #{number}"; self end
@@ -63,6 +65,8 @@ module Flickrie
63
65
 
64
66
  def rotation() Integer(@info['rotation']) rescue nil end
65
67
 
68
+ # Same as calling <tt>Flickrie.get_photo_sizes(photo.id)</tt>
69
+ #
66
70
  def get_sizes(params = {}, info = nil)
67
71
  info ||= Flickrie.client.get_media_sizes(id, params).body['sizes']
68
72
  @info['usage'] ||= {}
data/lib/flickrie/set.rb CHANGED
@@ -19,10 +19,18 @@ module Flickrie
19
19
  photos_count + videos_count rescue nil
20
20
  end
21
21
 
22
+ # Returns an instance of Flickrie::User
23
+ #
22
24
  def owner() User.new('nsid' => @info['owner']) if @info['owner'] end
23
25
 
26
+ # Same as calling <tt>Flickrie.photos_from_set(set.id)</tt>
27
+ #
24
28
  def photos(params = {}) Flickrie.photos_from_set(id, params) end
29
+ # Same as calling <tt>Flickrie.videos_from_set(set.id)</tt>
30
+ #
25
31
  def videos(params = {}) Flickrie.videos_from_set(id, params) end
32
+ # Same as calling <tt>Flickrie.media_from_set(set.id)</tt>
33
+ #
26
34
  def media(params = {}) Flickrie.media_from_set(id, params) end
27
35
 
28
36
  def can_comment?() Integer(@info['can_comment']) == 1 rescue nil end
@@ -42,6 +50,8 @@ module Flickrie
42
50
  def [](key) @info[key] end
43
51
  def hash() @info end
44
52
 
53
+ # Same as calling <tt>Flickrie.get_set_info(set.id)</tt>
54
+ #
45
55
  def get_info(info = nil)
46
56
  info ||= Flickrie.client.get_set_info(id).body['photoset']
47
57
  @info.update(info)
@@ -1,5 +1,6 @@
1
1
  module Flickrie
2
2
  class << self
3
+ # :nodoc:
3
4
  def upload_client
4
5
  @upload_client ||= new_upload_client
5
6
  end
@@ -17,7 +18,7 @@ module Flickrie
17
18
  conn.use FaradayMiddleware::ParseXml
18
19
  conn.use OAuthStatusCheck
19
20
 
20
- conn.adapter Faraday.default_adapter
21
+ conn.adapter :net_http
21
22
  end
22
23
  end
23
24
 
@@ -27,7 +28,7 @@ module Flickrie
27
28
  {
28
29
  :url => 'http://api.flickr.com/services',
29
30
  :request => {
30
- :open_timeout => open_timeout || OPEN_TIMEOUT
31
+ :open_timeout => open_timeout || DEFAULTS[:open_timeout]
31
32
  }
32
33
  }
33
34
  end
@@ -43,7 +44,7 @@ module Flickrie
43
44
  end
44
45
  end
45
46
 
46
- class UploadClient < Faraday::Connection
47
+ class UploadClient < Faraday::Connection # :nodoc:
47
48
  def upload(media, params = {})
48
49
  media_file = get_file(media, params[:mime_type])
49
50
  media_title = get_title(media)
@@ -80,16 +81,13 @@ module Flickrie
80
81
  }.freeze
81
82
 
82
83
  def get_file(object, mime_type = nil)
83
- if object.class.name == "String"
84
- # file path
84
+ if object.class.name == "String" # file path
85
85
  file_path = object
86
86
  mime_type ||= get_mime_type(file_path)
87
- elsif object.class.name == "ActionDispatch::Http::UploadedFile"
88
- # Rails
87
+ elsif object.class.name == "ActionDispatch::Http::UploadedFile" # Rails
89
88
  file_path = object.tempfile
90
89
  mime_type ||= object.content_type
91
- elsif object.class.name == "Hash"
92
- # Sinatra
90
+ elsif object.class.name == "Hash" # Sinatra
93
91
  file_path = object[:tempfile].path
94
92
  mime_type ||= object[:type]
95
93
  end
@@ -107,11 +105,11 @@ module Flickrie
107
105
 
108
106
  def get_title(object)
109
107
  filename =
110
- if object.class.name == "String"
108
+ if object.class.name == "String" # file path
111
109
  File.basename(object)
112
- elsif object.class.name == "ActionDispatch::Http::UploadedFile"
110
+ elsif object.class.name == "ActionDispatch::Http::UploadedFile" # Rails
113
111
  object.original_filename
114
- elsif object.class.name == "Hash"
112
+ elsif object.class.name == "Hash" # Sinatra
115
113
  object[:filename]
116
114
  end
117
115
 
data/lib/flickrie/user.rb CHANGED
@@ -39,6 +39,8 @@ module Flickrie
39
39
  alias photos_count media_count
40
40
  alias videos_count media_count
41
41
 
42
+ # The same as calling <tt>Flickrie.public_photos_from_user(user.nsid)</tt>
43
+ #
42
44
  def public_photos() Flickrie.public_photos_from_user(nsid) end
43
45
 
44
46
  def pro?() Integer(@info['ispro']) == 1 rescue nil end
@@ -46,6 +48,8 @@ module Flickrie
46
48
  def [](key) @info[key] end
47
49
  def hash() @info end
48
50
 
51
+ # The same as calling <tt>Flickrie.get_user_info(user.nsid)</tt>
52
+ #
49
53
  def get_info(params = {}, info = nil)
50
54
  info ||= Flickrie.client.get_user_info(nsid, params).body['person']
51
55
  @info.update(info)
@@ -1,3 +1,3 @@
1
1
  module Flickrie
2
- VERSION = '0.7.1'
2
+ VERSION = "0.7.2"
3
3
  end
@@ -1,4 +1,6 @@
1
1
  module Flickrie
2
+ # See Flickrie::Media for the other methods.
3
+ #
2
4
  class Video
3
5
  include Media
4
6
 
@@ -15,6 +17,8 @@ module Flickrie
15
17
  def download_url() @video['download_url'] end
16
18
  def mobile_download_url() @video['mobile_download_url'] end
17
19
 
20
+ # This fetches the #source_url, #download_url and the #mobile_download_url
21
+ #
18
22
  def get_sizes(params = {}, info = nil)
19
23
  info ||= Flickrie.client.get_media_sizes(id, params).body['sizes']
20
24
  @info['usage'] ||= {}
@@ -1,3 +1,5 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper"))
2
+
1
3
  describe Flickrie::ApiMethods do
2
4
  it "should have certain methods working" do
3
5
  VCR.use_cassette "api_methods/upload_and_delete" do