digitalpardoe-rflickr 1.1.4 → 2.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +5 -0
  3. data/.document +5 -0
  4. data/.rspec +0 -0
  5. data/Gemfile +5 -5
  6. data/README.md +40 -0
  7. data/Rakefile +17 -21
  8. data/VERSION +1 -0
  9. data/digitalpardoe-rflickr.gemspec +39 -42
  10. data/lib/flickr.rb +44 -37
  11. data/lib/flickr/api.rb +26 -0
  12. data/lib/flickr/interaction/flickr_api_request.rb +75 -0
  13. data/lib/flickr/interaction/request.rb +37 -0
  14. data/spec/api/activity_spec.rb +16 -0
  15. data/spec/api/api_spec.rb +16 -0
  16. data/spec/api/auth_spec.rb +16 -0
  17. data/spec/api/blogs_spec.rb +12 -0
  18. data/spec/api/collections_spec.rb +17 -0
  19. data/spec/api/commons_spec.rb +12 -0
  20. data/spec/api/contacts_spec.rb +16 -0
  21. data/spec/api/favorites_spec.rb +11 -0
  22. data/spec/api/groups/members_spec.rb +20 -0
  23. data/spec/config/api.example.yml +3 -0
  24. data/spec/flickr_spec.rb +33 -0
  25. data/spec/spec_helper.rb +19 -0
  26. metadata +95 -116
  27. data/LICENSE +0 -278
  28. data/README.markdown +0 -22
  29. data/VERSION.yml +0 -5
  30. data/lib/flickr/auth.rb +0 -94
  31. data/lib/flickr/base.rb +0 -810
  32. data/lib/flickr/blogs.rb +0 -50
  33. data/lib/flickr/contacts.rb +0 -68
  34. data/lib/flickr/favorites.rb +0 -79
  35. data/lib/flickr/groups.rb +0 -102
  36. data/lib/flickr/interestingness.rb +0 -39
  37. data/lib/flickr/licenses.rb +0 -43
  38. data/lib/flickr/notes.rb +0 -44
  39. data/lib/flickr/people.rb +0 -99
  40. data/lib/flickr/photos.rb +0 -305
  41. data/lib/flickr/photosets.rb +0 -124
  42. data/lib/flickr/pools.rb +0 -90
  43. data/lib/flickr/reflection.rb +0 -109
  44. data/lib/flickr/tags.rb +0 -79
  45. data/lib/flickr/transform.rb +0 -29
  46. data/lib/flickr/upload.rb +0 -225
  47. data/lib/flickr/urls.rb +0 -69
  48. data/test/test_suite.rb +0 -3
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7596bae6878e18dab1003f43bf3967c325e16a73
4
+ data.tar.gz: e29c316402a4b7f1ba1501521dbda6df2afbe98e
5
+ SHA512:
6
+ metadata.gz: 2b0dd68fa6db8dba33ae5cfdf717b243ad90d1317d77117de647952b8e39f29f5134a2278feb19ab81f7a43e178b7891176dad15ac2acc9fb78507419323acd7
7
+ data.tar.gz: 83e1fe9d4fe531d710458d73e5b1230fa7df309c54e377a53571992070a592ae4a6feeedbc9a4bb8a9d4a0d31f4b3c89b06351287fd215b9afe6ffa341e7bdda
data/.autotest ADDED
@@ -0,0 +1,5 @@
1
+ require 'autotest/bundler'
2
+
3
+ Autotest.add_hook :initialize do |at|
4
+ %w{.git coverage}.each { |exception| at.add_exception(exception) }
5
+ end
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
File without changes
data/Gemfile CHANGED
@@ -1,9 +1,9 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "mime-types", ">= 0"
3
+ gem "json", "~> 1.8.0"
4
4
 
5
5
  group :development do
6
- gem "rdoc", ">= 0"
7
- gem "bundler", ">= 0"
8
- gem "jeweler", ">= 0"
9
- end
6
+ gem "rspec", ">= 0"
7
+ gem "jeweler", "~> 1.8.4"
8
+ gem "ZenTest", ">= 0"
9
+ end
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # rFlickr
2
+
3
+ **Note**: This gem has only been tested on Ruby 2.0 (but should work with 1.9).
4
+
5
+ Before you start using this gem you'll need a Flickr API key from [http://www.flickr.com/services/api/misc.api_keys.html](http://www.flickr.com/services/api/misc.api_keys.html).
6
+
7
+ ## Using the Gem
8
+
9
+ Add:
10
+
11
+ gem 'digitalpardoe-rflickr', '~> 2.0.pre.1'
12
+
13
+ In your Gemfile then using the gem should be as simple as:
14
+
15
+ require 'flickr'
16
+
17
+ After requiring the gem create an instance of it using your API details (instructions on how to get an auth token (optional) for authenticated requests below):
18
+
19
+ flickr = Flickr.new( API_KEY, SHARED_SECRET, AUTH_TOKEN )
20
+
21
+ The gem will automatically construct queries to the Flickr API (returning JSON results) from method names, similar to the way ActiveRecord finders work, for example, to make an authenticated query to get all the members of a group you could call:
22
+
23
+ flickr.flickr_groups_members_getList( args: { group_id: @group_id, membertypes: [2] }, auth: true )
24
+
25
+ No checking happens before the request is sent so ensure you've checked the [Flickr API](http://www.flickr.com/services/api/) for the required parameters if you run in to problems.
26
+
27
+ If the Flickr method requires a `POST` you can pass `get: false` in the method hash.
28
+
29
+ ## Getting an Auth Token
30
+
31
+ First you'll need an IRB console with rFlickr available so you can `require 'flickr'` then perform the following steps:
32
+
33
+ >> flickr = Flickr.new(API_KEY, SHARED_SECRET)
34
+ >> flickr.api.login_link
35
+
36
+ Navigate to the URL provided and authorise the application.
37
+
38
+ >> flickr.auth.get_token
39
+
40
+ Store the token received in the response, this is your auth token, you can either use it when you initialise a `Flickr` object or add it at a later point using `flickr.auth_token(AUTH_TOKEN)`.
data/Rakefile CHANGED
@@ -13,30 +13,26 @@ require 'rake'
13
13
 
14
14
  require 'jeweler'
15
15
  Jeweler::Tasks.new do |gem|
16
- gem.name = "digitalpardoe-rflickr"
17
- gem.summary = "rFlickr is a Ruby interface to the Flickr API"
18
- gem.email = "contact@digitalpardoe.co.uk"
19
- gem.homepage = "http://github.com/digitalpardoe/rflickr"
20
- gem.authors = ["digital:pardoe"]
21
- gem.description = "rFlickr is a clone of the original RubyForge based rflickr, a Ruby implementation of the Flickr API. It includes a faithful albeit old reproduction of the published API."
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "digitalpardoe-rflickr"
18
+ gem.homepage = "http://github.com/digitalpardoe/rflickr"
19
+ gem.summary = "rFlickr is a Ruby interface to the Flickr API"
20
+ gem.description = "rFlickr is a clone of the original RubyForge based rflickr, a Ruby implementation of the Flickr API. It includes a faithful albeit old reproduction of the published API."
21
+ gem.email = "contact@digitalpardoe.co.uk"
22
+ gem.authors = ["Alex Pardoe"]
23
+ # dependencies defined in Gemfile
22
24
  end
23
25
  Jeweler::RubygemsDotOrgTasks.new
24
26
 
25
- require 'rake/testtask'
26
- Rake::TestTask.new(:test) do |test|
27
- test.libs << 'lib' << 'test'
28
- test.pattern = 'test/**/test_*.rb'
29
- test.verbose = true
27
+ require 'rspec/core/rake_task'
28
+ RSpec::Core::RakeTask.new(:spec) do |spec|
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
30
  end
31
31
 
32
- task :default => :test
33
-
34
- require 'rdoc/task'
35
- Rake::RDocTask.new do |rdoc|
36
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
37
-
38
- rdoc.rdoc_dir = 'rdoc'
39
- rdoc.title = "digitalpardoe-rflickr #{version}"
40
- rdoc.rdoc_files.include('README*')
41
- rdoc.rdoc_files.include('lib/**/*.rb')
32
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
33
+ spec.pattern = 'spec/**/*_spec.rb'
34
+ spec.rcov = true
35
+ spec.rcov_opts = ['--exclude', 'spec,.*/.gem']
42
36
  end
37
+
38
+ task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 2.0.0.pre.1
@@ -5,69 +5,66 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "digitalpardoe-rflickr"
8
- s.version = "1.1.4"
8
+ s.version = "2.0.0.pre.1"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["digital:pardoe"]
12
- s.date = "2013-08-09"
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Alex Pardoe"]
12
+ s.date = "2013-08-12"
13
13
  s.description = "rFlickr is a clone of the original RubyForge based rflickr, a Ruby implementation of the Flickr API. It includes a faithful albeit old reproduction of the published API."
14
14
  s.email = "contact@digitalpardoe.co.uk"
15
15
  s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.markdown"
16
+ "README.md"
18
17
  ]
19
18
  s.files = [
19
+ ".autotest",
20
+ ".document",
21
+ ".rspec",
20
22
  "Gemfile",
21
- "LICENSE",
22
- "README.markdown",
23
+ "README.md",
23
24
  "Rakefile",
24
- "VERSION.yml",
25
+ "VERSION",
25
26
  "digitalpardoe-rflickr.gemspec",
26
27
  "lib/flickr.rb",
27
- "lib/flickr/auth.rb",
28
- "lib/flickr/base.rb",
29
- "lib/flickr/blogs.rb",
30
- "lib/flickr/contacts.rb",
31
- "lib/flickr/favorites.rb",
32
- "lib/flickr/groups.rb",
33
- "lib/flickr/interestingness.rb",
34
- "lib/flickr/licenses.rb",
35
- "lib/flickr/notes.rb",
36
- "lib/flickr/people.rb",
37
- "lib/flickr/photos.rb",
38
- "lib/flickr/photosets.rb",
39
- "lib/flickr/pools.rb",
40
- "lib/flickr/reflection.rb",
41
- "lib/flickr/tags.rb",
42
- "lib/flickr/transform.rb",
43
- "lib/flickr/upload.rb",
44
- "lib/flickr/urls.rb",
45
- "test/test_suite.rb"
28
+ "lib/flickr/api.rb",
29
+ "lib/flickr/interaction/flickr_api_request.rb",
30
+ "lib/flickr/interaction/request.rb",
31
+ "spec/api/activity_spec.rb",
32
+ "spec/api/api_spec.rb",
33
+ "spec/api/auth_spec.rb",
34
+ "spec/api/blogs_spec.rb",
35
+ "spec/api/collections_spec.rb",
36
+ "spec/api/commons_spec.rb",
37
+ "spec/api/contacts_spec.rb",
38
+ "spec/api/favorites_spec.rb",
39
+ "spec/api/groups/members_spec.rb",
40
+ "spec/config/api.example.yml",
41
+ "spec/flickr_spec.rb",
42
+ "spec/spec_helper.rb"
46
43
  ]
47
44
  s.homepage = "http://github.com/digitalpardoe/rflickr"
48
45
  s.require_paths = ["lib"]
49
- s.rubygems_version = "1.8.25"
46
+ s.rubygems_version = "2.0.3"
50
47
  s.summary = "rFlickr is a Ruby interface to the Flickr API"
51
48
 
52
49
  if s.respond_to? :specification_version then
53
- s.specification_version = 3
50
+ s.specification_version = 4
54
51
 
55
52
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
- s.add_runtime_dependency(%q<mime-types>, [">= 0"])
57
- s.add_development_dependency(%q<rdoc>, [">= 0"])
58
- s.add_development_dependency(%q<bundler>, [">= 0"])
59
- s.add_development_dependency(%q<jeweler>, [">= 0"])
53
+ s.add_runtime_dependency(%q<json>, ["~> 1.8.0"])
54
+ s.add_development_dependency(%q<rspec>, [">= 0"])
55
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
56
+ s.add_development_dependency(%q<ZenTest>, [">= 0"])
60
57
  else
61
- s.add_dependency(%q<mime-types>, [">= 0"])
62
- s.add_dependency(%q<rdoc>, [">= 0"])
63
- s.add_dependency(%q<bundler>, [">= 0"])
64
- s.add_dependency(%q<jeweler>, [">= 0"])
58
+ s.add_dependency(%q<json>, ["~> 1.8.0"])
59
+ s.add_dependency(%q<rspec>, [">= 0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
61
+ s.add_dependency(%q<ZenTest>, [">= 0"])
65
62
  end
66
63
  else
67
- s.add_dependency(%q<mime-types>, [">= 0"])
68
- s.add_dependency(%q<rdoc>, [">= 0"])
69
- s.add_dependency(%q<bundler>, [">= 0"])
70
- s.add_dependency(%q<jeweler>, [">= 0"])
64
+ s.add_dependency(%q<json>, ["~> 1.8.0"])
65
+ s.add_dependency(%q<rspec>, [">= 0"])
66
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
67
+ s.add_dependency(%q<ZenTest>, [">= 0"])
71
68
  end
72
69
  end
73
70
 
data/lib/flickr.rb CHANGED
@@ -1,38 +1,45 @@
1
- # rFlickr: A Ruby based Flickr API implementation.
2
- # Copyright (C) 2009, Alex Pardoe (digital:pardoe)
3
- #
4
- # Derrived from work by Trevor Schroeder, see here:
5
- # http://rubyforge.org/projects/rflickr/.
6
- #
7
- # This program is free software; you can redistribute it and/or
8
- # modify it under the terms of the GNU General Public License
9
- # as published by the Free Software Foundation; either version 2
10
- # of the License, or (at your option) any later version.
11
- #
12
- # This program is distributed in the hope that it will be useful,
13
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- # GNU General Public License for more details.
16
- #
17
- # You should have received a copy of the GNU General Public License
18
- # along with this program; if not, write to the Free Software
19
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1
+ Dir[File.dirname(__FILE__) + "/flickr/**/*.rb"].each { |file| require file }
20
2
 
21
- require 'flickr/auth'
22
- require 'flickr/base'
23
- require 'flickr/blogs'
24
- require 'flickr/contacts'
25
- require 'flickr/favorites'
26
- require 'flickr/groups'
27
- require 'flickr/licenses'
28
- require 'flickr/notes'
29
- require 'flickr/people'
30
- require 'flickr/photos'
31
- require 'flickr/photosets'
32
- require 'flickr/pools'
33
- require 'flickr/reflection'
34
- require 'flickr/transform'
35
- require 'flickr/upload'
36
- require 'flickr/urls'
37
- require 'flickr/tags'
38
- require 'flickr/interestingness'
3
+ class Flickr
4
+ def initialize(api_key, shared_secret, auth_token=nil)
5
+ @tokens = Flickr::Tokens.new(api_key, shared_secret, auth_token)
6
+ @api_request = FlickrApiRequest.new(@tokens)
7
+ end
8
+
9
+ def auth_token(auth_token)
10
+ @tokens.auth_token = auth_token
11
+ self
12
+ end
13
+
14
+ class Tokens
15
+ attr_reader :api_key, :shared_secret
16
+ attr_accessor :auth_token
17
+
18
+ def initialize(api_key, shared_secret, auth_token)
19
+ @api_key = api_key
20
+ @shared_secret = shared_secret
21
+ @auth_token = auth_token
22
+ end
23
+ end
24
+
25
+ def api
26
+ @api ||= Api.new(@api_request, self)
27
+ end
28
+
29
+ def method_missing(method, *arguments, &block)
30
+ if method.to_s =~ /^flickr_[\w]+/
31
+ self.class.send :define_method, method do |*arguments|
32
+ if (arguments = arguments.flatten) != []
33
+ args = arguments[0][:args]
34
+ auth = arguments[0][:auth]
35
+ get = arguments[0][:get]
36
+ end
37
+
38
+ @api_request.call("#{method.to_s.gsub('_', '.')}", args || {}, (auth == nil ? false : auth), (get == nil ? true : get))
39
+ end
40
+ self.send(method, arguments)
41
+ else
42
+ super
43
+ end
44
+ end
45
+ end
data/lib/flickr/api.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'flickr/interaction/request'
2
+
3
+ class Api
4
+ attr_accessor :frob
5
+
6
+ def initialize(api, parent)
7
+ @api = api
8
+ @parent = parent
9
+ end
10
+
11
+ def login_link(perms='read')
12
+ @frob = @parent.flickr_auth_getFrob['frob']['_content']
13
+ args = {'api_key' => @api.tokens.api_key, 'perms' => perms, 'frob' => @frob}
14
+ args = @api.sign_request(args)
15
+
16
+ Request.build_url('http://flickr.com/services/auth/', args)
17
+ end
18
+
19
+ def get_token(frob=@frob)
20
+ if frob
21
+ @parent.flickr_auth_getToken(args: { frob: frob })
22
+ else
23
+ raise ArgumentError, "missing 'frob' argument, perhaps you need to call 'login_link' first"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,75 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+ require 'digest'
4
+
5
+ require 'flickr/interaction/request'
6
+
7
+ class FlickrApiRequest
8
+ API_RSP = 'json'
9
+ API_REQ = 'rest'
10
+ API_URL = "http://api.flickr.com/services/#{API_REQ}/"
11
+
12
+ attr_reader :tokens
13
+
14
+ def initialize(tokens)
15
+ @tokens = tokens
16
+ @arguments = { 'format' => API_RSP, 'api_key' => @tokens.api_key }
17
+ end
18
+
19
+ def call(method, arguments, authenticated, get)
20
+ arguments ? arguments = arguments.merge(@arguments) : arguments = @arguments
21
+
22
+ arguments = arguments.merge({'method' => method})
23
+ arguments = objects_to_strings(arguments)
24
+ arguments = remove_blank_args(arguments)
25
+
26
+ if authenticated
27
+ if !@tokens.auth_token
28
+ return {'stat' => 'fail'}
29
+ end
30
+
31
+ arguments = arguments.merge({'auth_token' => @tokens.auth_token})
32
+ end
33
+
34
+ arguments = sign_request(arguments)
35
+
36
+ begin
37
+ JSON.parse strip_function(Request.make(API_URL, arguments.class == Array ? arguments : arguments.to_a, get))
38
+ rescue JSON::ParserError
39
+ nil
40
+ end
41
+ end
42
+
43
+ def sign_request(arguments)
44
+ arguments = sort_arguments(arguments)
45
+
46
+ api_sig = @tokens.shared_secret.clone
47
+ arguments.each { |item| api_sig << item[0].to_s + item[1].to_s }
48
+ sig_digest = Digest::MD5.hexdigest(api_sig)
49
+
50
+ arguments.insert(0, ['api_sig', sig_digest])
51
+
52
+ arguments
53
+ end
54
+
55
+ private
56
+ def objects_to_strings(arguments)
57
+ {}.tap do |hash|
58
+ arguments.each do |key,value|
59
+ hash[key.to_s] = value.class == Array ? value.join(",") : value
60
+ end
61
+ end
62
+ end
63
+
64
+ def remove_blank_args(arguments)
65
+ arguments.delete_if { |key,value| value == nil }
66
+ end
67
+
68
+ def sort_arguments(arguments)
69
+ arguments.sort { |a,b| a[0]<=>b[0] }
70
+ end
71
+
72
+ def strip_function(json_string)
73
+ json_string.gsub('jsonFlickrApi(', '').gsub(')', '')
74
+ end
75
+ end
@@ -0,0 +1,37 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+
4
+ class Request
5
+ def self.make(url, arguments, get)
6
+ get ? get(url, arguments) : post(url, arguments)
7
+ end
8
+
9
+ def self.build_url(url, arguments)
10
+ query_string = '?'
11
+ arguments.length.times do |i|
12
+ query_string << arguments[i][0].to_s + '=' + arguments[i][1].to_s + '&'
13
+ end
14
+
15
+ url + query_string.chomp('&')
16
+ end
17
+
18
+ private
19
+ def self.get(url, arguments)
20
+ connection.get URI.parse(build_url(url, arguments))
21
+ end
22
+
23
+ def self.post(url, arguments)
24
+ connection.post_form URI.parse(url), arguments
25
+ end
26
+
27
+ def self.connection
28
+ if proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
29
+ proxy = URI.parse(proxy)
30
+ agent = Net::HTTP.Proxy(proxy.host, proxy.port)
31
+ else
32
+ agent = Net::HTTP
33
+ end
34
+
35
+ agent
36
+ end
37
+ end