flickr_oauth 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -0
- data/.rspec +0 -0
- data/Gemfile +4 -0
- data/README.md +45 -0
- data/Rakefile +13 -0
- data/flickr_oauth.gemspec +32 -0
- data/lib/faraday/response/raise_flickr_error.rb +14 -0
- data/lib/flickr/client.rb +75 -0
- data/lib/flickr/error.rb +14 -0
- data/lib/flickr/node.rb +56 -0
- data/lib/flickr.rb +13 -0
- data/lib/flickr_oauth/version.rb +3 -0
- data/lib/flickr_oauth.rb +4 -0
- data/spec/fixtures/cassettes/JSON_format/it_should_behave_like_Flickr_with_specified_format/Flickr/flickr_test_echo/no_oauth_token.yml +40 -0
- data/spec/fixtures/cassettes/JSON_format/it_should_behave_like_Flickr_with_specified_format/Flickr/flickr_test_echo/with_oauth_token.yml +45 -0
- data/spec/fixtures/cassettes/REST_format/it_should_behave_like_Flickr_with_specified_format/Flickr/flickr_test_echo/no_oauth_token.yml +39 -0
- data/spec/fixtures/cassettes/REST_format/it_should_behave_like_Flickr_with_specified_format/Flickr/flickr_test_echo/with_oauth_token.yml +44 -0
- data/spec/json/flickr_spec.rb +6 -0
- data/spec/rest/flickr_spec.rb +6 -0
- data/spec/shared_examples.rb +65 -0
- data/spec/spec_helper.rb +34 -0
- metadata +169 -0
data/.gitignore
ADDED
data/.rspec
ADDED
File without changes
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
flickr_oauth
|
2
|
+
=
|
3
|
+
Flickr API adapter for Ruby using OAuth authentication method.
|
4
|
+
|
5
|
+
USAGE
|
6
|
+
-
|
7
|
+
You can instantiate an instance of `Flickr`
|
8
|
+
|
9
|
+
require 'flickr_oauth'
|
10
|
+
|
11
|
+
flickr = Flickr.new(
|
12
|
+
:consumer_key => CONSUMER_KEY,
|
13
|
+
:consumer_secret => CONSUMER_SECRET,
|
14
|
+
:token => OAUTH_ACCESS_TOKEN,
|
15
|
+
:token_secret => OAUTH_ACCESS_TOKEN_SECRET,
|
16
|
+
:format => :json
|
17
|
+
)
|
18
|
+
flickr.test.echo(:foo => 'bar')
|
19
|
+
|
20
|
+
Or, you can use the `flickr` method:
|
21
|
+
|
22
|
+
require 'flickr_oauth'
|
23
|
+
|
24
|
+
flickr.test.echo(:foo => 'bar',
|
25
|
+
:consumer_key => CONSUMER_KEY,
|
26
|
+
:consumer_secret => CONSUMER_SECRET,
|
27
|
+
:token => OAUTH_ACCESS_TOKEN,
|
28
|
+
:token_secret => OAUTH_ACCESS_TOKEN_SECRET,
|
29
|
+
:format => :json
|
30
|
+
)
|
31
|
+
|
32
|
+
TODO
|
33
|
+
-
|
34
|
+
* flickr_oauth may support all of the existing Flickr API methods, with the exception of those that require no additional arguments, to name a few:
|
35
|
+
|
36
|
+
- `flickr.test.null`
|
37
|
+
- `flickr.test.login`
|
38
|
+
- `flickr.photos.licenses.getInfo`
|
39
|
+
|
40
|
+
* Upload/replace
|
41
|
+
* More tests
|
42
|
+
|
43
|
+
ACKNOWLEDGEMENT
|
44
|
+
-
|
45
|
+
Much of the code has been patterned around the [twitter](https://github.com/jnunemaker/twitter) gem.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
7
|
+
spec.pattern = "./spec/**/*_spec.rb"
|
8
|
+
end
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
11
|
+
spec.pattern = "./spec/**/*_spec.rb"
|
12
|
+
spec.rcov = true
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "flickr_oauth/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "flickr_oauth"
|
7
|
+
s.version = FlickrOAuth::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Evan Sagge"]
|
10
|
+
s.email = ["evansagge@gmail.com"]
|
11
|
+
s.homepage = "http://github.com/evansagge/flickr_oauth"
|
12
|
+
s.summary = %q{Flickr API adapter using OAuth}
|
13
|
+
s.description = %q{}
|
14
|
+
|
15
|
+
s.rubyforge_project = "flickr_oauth"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.autorequire = 'flickr'
|
23
|
+
|
24
|
+
s.add_dependency 'faraday', '>= 0.7'
|
25
|
+
s.add_dependency 'faraday_middleware', '>= 0.7.0.rc1'
|
26
|
+
s.add_dependency 'multi_xml'
|
27
|
+
s.add_dependency 'multi_json'
|
28
|
+
s.add_dependency 'simple_oauth'
|
29
|
+
s.add_development_dependency 'rspec', '>= 2.6'
|
30
|
+
s.add_development_dependency 'webmock', '>= 1.6'
|
31
|
+
s.add_development_dependency 'vcr', '>= 1.7'
|
32
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'flickr/error'
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Response::RaiseFlickrError < Response::Middleware
|
5
|
+
|
6
|
+
def on_complete(env)
|
7
|
+
if env[:body]['rsp'] and env[:body]['rsp']['stat'] == 'fail'
|
8
|
+
raise Flickr::Error.new(env[:body]['rsp']['err']['code'] , env[:body]['rsp']['err']['msg'])
|
9
|
+
elsif env[:body]['stat'] == 'fail'
|
10
|
+
raise Flickr::Error.new(env[:body]['code'] , env[:body]['message'])
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'faraday/response/raise_flickr_error'
|
4
|
+
require 'flickr/node'
|
5
|
+
|
6
|
+
module Flickr
|
7
|
+
class Client
|
8
|
+
DEFAULT_ENDPOINT = 'http://api.flickr.com'.freeze
|
9
|
+
SECURE_ENDPOINT = 'https://secure.flickr.com'.freeze
|
10
|
+
REST_PATH = '/services/rest'.freeze
|
11
|
+
UPLOAD_PATH = '/services/upload'.freeze
|
12
|
+
REPLACE_PATH = '/services/resplace'.freeze
|
13
|
+
|
14
|
+
CONFIGURATION_KEYS = [
|
15
|
+
:consumer_key,
|
16
|
+
:consumer_secret,
|
17
|
+
:token,
|
18
|
+
:token_secret,
|
19
|
+
:secure,
|
20
|
+
:format,
|
21
|
+
:enable_logging
|
22
|
+
]
|
23
|
+
|
24
|
+
attr_accessor *CONFIGURATION_KEYS
|
25
|
+
|
26
|
+
def initialize(options = {})
|
27
|
+
CONFIGURATION_KEYS.each do |key|
|
28
|
+
send("#{key}=", options[key])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def endpoint(secure = false)
|
33
|
+
secure or self.secure ? SECURE_ENDPOINT : DEFAULT_ENDPOINT
|
34
|
+
end
|
35
|
+
|
36
|
+
def authentication(options = {})
|
37
|
+
{
|
38
|
+
:consumer_key => consumer_key,
|
39
|
+
:consumer_secret => consumer_secret,
|
40
|
+
:token => token,
|
41
|
+
:token_secret => token_secret
|
42
|
+
}.merge(options.select{|k,v| [:consumer_key, :consumer_secret, :token, :token_secret].include?(k.to_sym)})
|
43
|
+
end
|
44
|
+
|
45
|
+
def adapter
|
46
|
+
@adapter || Faraday.default_adapter
|
47
|
+
end
|
48
|
+
|
49
|
+
def connection(options = {})
|
50
|
+
@connection = Faraday.new(:url => endpoint(options[:secure])) do |builder|
|
51
|
+
builder.use Faraday::Request::OAuth, authentication(options)
|
52
|
+
builder.use Faraday::Request::Multipart
|
53
|
+
builder.use Faraday::Request::UrlEncoded
|
54
|
+
|
55
|
+
builder.use Faraday::Response::RaiseFlickrError
|
56
|
+
if (options[:format] or format).to_s == 'json'
|
57
|
+
builder.use Faraday::Response::ParseJson
|
58
|
+
else
|
59
|
+
builder.use Faraday::Response::ParseXml
|
60
|
+
end
|
61
|
+
builder.use Faraday::Response::RaiseError
|
62
|
+
builder.use Faraday::Response::Logger if options[:enable_logging] or enable_logging
|
63
|
+
|
64
|
+
builder.adapter adapter
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
protected
|
69
|
+
|
70
|
+
def method_missing(method_name, *args)
|
71
|
+
args.empty? ? Flickr::Node.new(self, ['flickr', method_name].join('.')) : super
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
data/lib/flickr/error.rb
ADDED
data/lib/flickr/node.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
3
|
+
module Flickr
|
4
|
+
class Node
|
5
|
+
attr_reader :name, :client
|
6
|
+
|
7
|
+
def initialize(client, name)
|
8
|
+
@client, @name = client, name
|
9
|
+
end
|
10
|
+
|
11
|
+
def require_parameters?
|
12
|
+
true
|
13
|
+
end
|
14
|
+
|
15
|
+
def invoke(params = {})
|
16
|
+
params = params.dup
|
17
|
+
connection_options = extract_connection_options(params)
|
18
|
+
response = client.connection(connection_options).get(build_rest_query(params))
|
19
|
+
response.body
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
name
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def build_rest_query(params = {})
|
29
|
+
format = params[:format] || client.format
|
30
|
+
params = {
|
31
|
+
:method => name,
|
32
|
+
:format => format,
|
33
|
+
:nojsoncallback => (format.to_s == 'json' ? 1 : nil)
|
34
|
+
}.merge(params)
|
35
|
+
query = params.map{|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" unless v.nil?}.compact.join("&")
|
36
|
+
[Flickr::Client::REST_PATH, query].join("?")
|
37
|
+
end
|
38
|
+
|
39
|
+
def extract_connection_options(params = {})
|
40
|
+
Flickr::Client::CONFIGURATION_KEYS.inject({}) do |options, k|
|
41
|
+
if k == :format
|
42
|
+
options[k.to_sym] = params.fetch(k)
|
43
|
+
else
|
44
|
+
options[k.to_sym] = params.delete(k)
|
45
|
+
end if params.has_key?(k)
|
46
|
+
options
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def method_missing(method_name, *args)
|
52
|
+
node = Flickr::Node.new(client, [name, method_name].join('.'))
|
53
|
+
node.require_parameters? and args.first.is_a?(Hash) ? node.invoke(args.first) : node
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/flickr.rb
ADDED
data/lib/flickr_oauth.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: http://api.flickr.com:80/services/rest?foo=bar&format=json&method=flickr.test.echo&nojsoncallback=1
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
authorization:
|
9
|
+
- OAuth oauth_consumer_key="", oauth_nonce="beff09eaac9ae76f7e8494a19602b8cc", oauth_signature="9CcsMhPiC0Qz7TqOb3m11yYUJ%2Fs%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1309463375", oauth_token="", oauth_version="1.0"
|
10
|
+
accept-encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
response: !ruby/struct:VCR::Response
|
13
|
+
status: !ruby/struct:VCR::ResponseStatus
|
14
|
+
code: 200
|
15
|
+
message: OK
|
16
|
+
headers:
|
17
|
+
date:
|
18
|
+
- Thu, 30 Jun 2011 19:49:36 GMT
|
19
|
+
p3p:
|
20
|
+
- policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"
|
21
|
+
access-control-allow-origin:
|
22
|
+
- "*"
|
23
|
+
x-served-by:
|
24
|
+
- www136.flickr.mud.yahoo.com
|
25
|
+
cache-control:
|
26
|
+
- private
|
27
|
+
vary:
|
28
|
+
- Accept-Encoding
|
29
|
+
content-encoding:
|
30
|
+
- gzip
|
31
|
+
content-length:
|
32
|
+
- "91"
|
33
|
+
content-type:
|
34
|
+
- text/plain; charset=utf-8
|
35
|
+
body: !binary |
|
36
|
+
H4sIAAAAAAAAA6tWKi5JLFGyUkpLzMxR0lFQSs5PSVWyMjQwALJzU4uLE9OB
|
37
|
+
XCXPvLLEnMwUBccATwXv1EoFDRCRkViskAmVSMsvyk0s0VSqBQC/jELiUQAA
|
38
|
+
AA==
|
39
|
+
|
40
|
+
http_version: "1.1"
|
@@ -0,0 +1,45 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: http://api.flickr.com:80/services/rest?foo=bar&format=json&method=flickr.test.echo&nojsoncallback=1
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
authorization:
|
9
|
+
- OAuth oauth_consumer_key="832f9421926d1232acaf6dc9a7e8881e", oauth_nonce="c1b9fbd8d0d1794111c8f4f2071dcd65", oauth_signature="hwp1vDTQgtCFkQk2E%2F3mI%2B%2BemYU%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1309463376", oauth_token="72157626958368895-7040ded2da3c9b6b", oauth_version="1.0"
|
10
|
+
accept-encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
response: !ruby/struct:VCR::Response
|
13
|
+
status: !ruby/struct:VCR::ResponseStatus
|
14
|
+
code: 200
|
15
|
+
message: OK
|
16
|
+
headers:
|
17
|
+
date:
|
18
|
+
- Thu, 30 Jun 2011 19:49:37 GMT
|
19
|
+
p3p:
|
20
|
+
- policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"
|
21
|
+
access-control-allow-origin:
|
22
|
+
- "*"
|
23
|
+
x-served-by:
|
24
|
+
- www139.flickr.mud.yahoo.com
|
25
|
+
cache-control:
|
26
|
+
- private
|
27
|
+
vary:
|
28
|
+
- Accept-Encoding
|
29
|
+
content-encoding:
|
30
|
+
- gzip
|
31
|
+
content-length:
|
32
|
+
- "326"
|
33
|
+
content-type:
|
34
|
+
- text/plain; charset=utf-8
|
35
|
+
body: !binary |
|
36
|
+
H4sIAAAAAAAAA6WRzUvDMByG/xXJdW42SZuPgYcxlXnwMNSDIJQ0H2vN0ow2
|
37
|
+
m8jY/25bPJTQi3oLvzzvS/L8zsDpUHoFlmeQS18HXQewBGZfSdssgm7DQsvS
|
38
|
+
g8v1FTC+cSJE5Efr6+G29v1Riv2+ENJGFPwp8NG8EM1w48UxlP28PTrd5FZ/
|
39
|
+
RSDDyPAUQY6IgggjIYUhSnJBNWMM6lFL3b1CR3EJC24KxVSiIOUphFAykxqU
|
40
|
+
UKikItko3la7WoRjE1eUnwd4unvZ7sL6wW4tun+/we5xNtPu7fV2Kp9Pmt08
|
41
|
+
rdbz580KjiKhcp1o4Q6xNZzwlGBMyRj2VtcRSBHMKEGEZwwTxng2p0maKK2Q
|
42
|
+
EljyghSjgpNu2srHFXCRDIw4VPmAVW0+8JOb7Kk/LqmPdo5+bfe/n+8E97S3
|
43
|
+
4PINIxTqz/UCAAA=
|
44
|
+
|
45
|
+
http_version: "1.1"
|
@@ -0,0 +1,39 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: http://api.flickr.com:80/services/rest?foo=bar&format=rest&method=flickr.test.echo
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
authorization:
|
9
|
+
- OAuth oauth_consumer_key="", oauth_nonce="557fb7ff9b5b8d7b2c5dddfdba2c1dc3", oauth_signature="QlNe2R7Z0m6WvnB%2BnS38dsgMUVk%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1309463377", oauth_token="", oauth_version="1.0"
|
10
|
+
accept-encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
response: !ruby/struct:VCR::Response
|
13
|
+
status: !ruby/struct:VCR::ResponseStatus
|
14
|
+
code: 200
|
15
|
+
message: OK
|
16
|
+
headers:
|
17
|
+
date:
|
18
|
+
- Thu, 30 Jun 2011 19:49:38 GMT
|
19
|
+
p3p:
|
20
|
+
- policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"
|
21
|
+
x-served-by:
|
22
|
+
- www133.flickr.mud.yahoo.com
|
23
|
+
cache-control:
|
24
|
+
- private
|
25
|
+
vary:
|
26
|
+
- Accept-Encoding
|
27
|
+
content-encoding:
|
28
|
+
- gzip
|
29
|
+
content-length:
|
30
|
+
- "136"
|
31
|
+
content-type:
|
32
|
+
- text/xml; charset=utf-8
|
33
|
+
body: !binary |
|
34
|
+
H4sIAAAAAAAAAy2MOw4CMQwFa3IKyxUUsEtHkWRFuaLhChbrgKV8UBJWcHuM
|
35
|
+
RPOaeTN2eqcIK9cmJTs8HkYEzreySL47fPWwPyFM3tjantA6dYeBJKI3G8u1
|
36
|
+
gj5ZtVG11NSY80pRFjhfZ7jwB7a/eVAD+YNQaqK+Qxg0OmjVmy/WdvqWhAAA
|
37
|
+
AA==
|
38
|
+
|
39
|
+
http_version: "1.1"
|
@@ -0,0 +1,44 @@
|
|
1
|
+
---
|
2
|
+
- !ruby/struct:VCR::HTTPInteraction
|
3
|
+
request: !ruby/struct:VCR::Request
|
4
|
+
method: :get
|
5
|
+
uri: http://api.flickr.com:80/services/rest?foo=bar&format=rest&method=flickr.test.echo
|
6
|
+
body:
|
7
|
+
headers:
|
8
|
+
authorization:
|
9
|
+
- OAuth oauth_consumer_key="832f9421926d1232acaf6dc9a7e8881e", oauth_nonce="cd2eb58df9aa16e717acd1b71f728c8b", oauth_signature="5t48BHozfDFhqNcXvXs%2F9qMJs8g%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1309463378", oauth_token="72157626958368895-7040ded2da3c9b6b", oauth_version="1.0"
|
10
|
+
accept-encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
response: !ruby/struct:VCR::Response
|
13
|
+
status: !ruby/struct:VCR::ResponseStatus
|
14
|
+
code: 200
|
15
|
+
message: OK
|
16
|
+
headers:
|
17
|
+
date:
|
18
|
+
- Thu, 30 Jun 2011 19:49:38 GMT
|
19
|
+
p3p:
|
20
|
+
- policyref="http://p3p.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"
|
21
|
+
x-served-by:
|
22
|
+
- www103.flickr.mud.yahoo.com
|
23
|
+
cache-control:
|
24
|
+
- private
|
25
|
+
vary:
|
26
|
+
- Accept-Encoding
|
27
|
+
content-encoding:
|
28
|
+
- gzip
|
29
|
+
content-length:
|
30
|
+
- "369"
|
31
|
+
content-type:
|
32
|
+
- text/xml; charset=utf-8
|
33
|
+
body: !binary |
|
34
|
+
H4sIAAAAAAAAA5WSy27CMBRE93wFyh6CnYdtKTGirSpUiW66YRc5fpAoJIbY
|
35
|
+
oLZfX0MwqKJS2+WdOWPlzk02f2+346PsTa27PADTWTCWHdei7jZ5cLBqgoPx
|
36
|
+
nI6y3uzGxjKbB7oJ3NxKW2lB1bbmTT+10tip5JXOwosxypTuW2Zp76wsvAwn
|
37
|
+
VdOS9SdFu1Gzg60KrjtzaGVfNPKD4ggqEkNAYCoAjCDjTKWCE4YkxhjILPwh
|
38
|
+
5F/qdMcl5QLKMsFCEcZAKhFAjAtQIqAQxByX/omB9llTbzpmD72kiY3xw1J/
|
39
|
+
qqfnav/K18e1Ccl+9WLwJvfZG32XLy4dLFeLx8nbcgHuMsW1pcGwdetqYu2O
|
40
|
+
gmhG4jSKEPahm3eldSM7iiBIUApTkuAoxZgkEzSLZ0IKKFjESZle1xx4n74c
|
41
|
+
m7pbe8BLo4zt6uIs1aY4e9R9/L04gH+7lieHjKvgl3o95fj/Lftt19D9sHT0
|
42
|
+
BaF23rffAgAA
|
43
|
+
|
44
|
+
http_version: "1.1"
|
@@ -0,0 +1,65 @@
|
|
1
|
+
shared_examples_for 'Flickr with specified format' do
|
2
|
+
describe Flickr do
|
3
|
+
context 'flickr.test.echo' do
|
4
|
+
describe 'no oauth token' do
|
5
|
+
use_vcr_cassette
|
6
|
+
|
7
|
+
let(:flickr) { Flickr.new(:format => format) }
|
8
|
+
it 'raises a Flickr::Error exception' do
|
9
|
+
expect { flickr.test.echo :foo => 'bar' }.to raise_exception(Flickr::Error, /Invalid API key/i)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe 'with oauth token' do
|
14
|
+
use_vcr_cassette
|
15
|
+
|
16
|
+
let(:flickr) { Flickr.new({:format => format}.merge(oauth_options)) }
|
17
|
+
it 'does not raise a Flickr::Error exception' do
|
18
|
+
expect { flickr.test.echo :foo => 'bar' }.to_not raise_error(Flickr::Error)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'responds with the original request parameters' do
|
22
|
+
response = flickr.test.echo({:foo => 'bar', :format => format}.merge(oauth_options))
|
23
|
+
if format == :json
|
24
|
+
response['method']['_content'].should == 'flickr.test.echo'
|
25
|
+
response['foo']['_content'].should == 'bar'
|
26
|
+
else
|
27
|
+
response['rsp']['method'].should == 'flickr.test.echo'
|
28
|
+
response['rsp']['foo'].should == 'bar'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe :flickr do
|
36
|
+
context 'flickr.test.echo' do
|
37
|
+
describe 'no oauth token' do
|
38
|
+
use_vcr_cassette
|
39
|
+
|
40
|
+
it 'raises a Flickr::Error exception' do
|
41
|
+
expect { flickr.test.echo :foo => 'bar', :format => format }.to raise_exception(Flickr::Error, /Invalid API key/i)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'with oauth token' do
|
46
|
+
use_vcr_cassette
|
47
|
+
|
48
|
+
it 'does not raise a Flickr::Error exception' do
|
49
|
+
expect { flickr.test.echo oauth_options.reverse_merge(:foo => 'bar', :format => format, :enable_logging => true) }.to_not raise_error(Flickr::Error)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'responds with the original request parameters' do
|
53
|
+
response = flickr.test.echo({:foo => 'bar', :format => format}.merge(oauth_options))
|
54
|
+
if format == :json
|
55
|
+
response['method']['_content'].should == 'flickr.test.echo'
|
56
|
+
response['foo']['_content'].should == 'bar'
|
57
|
+
else
|
58
|
+
response['rsp']['method'].should == 'flickr.test.echo'
|
59
|
+
response['rsp']['foo'].should == 'bar'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
3
|
+
Bundler.setup
|
4
|
+
|
5
|
+
require 'rspec'
|
6
|
+
require 'vcr'
|
7
|
+
require 'flickr_oauth'
|
8
|
+
|
9
|
+
$:.unshift File.expand_path('..', __FILE__)
|
10
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
11
|
+
|
12
|
+
VCR.config do |config|
|
13
|
+
config.cassette_library_dir = 'spec/fixtures/cassettes'
|
14
|
+
config.stub_with :webmock
|
15
|
+
end
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.extend VCR::RSpec::Macros
|
19
|
+
config.include RSpec::Matchers
|
20
|
+
config.mock_with :rspec
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'shared_examples'
|
24
|
+
|
25
|
+
def oauth_options
|
26
|
+
{
|
27
|
+
:consumer_key => '',
|
28
|
+
:consumer_secret => '',
|
29
|
+
:token => '',
|
30
|
+
:token_secret => '',
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
# flickr.enable_logging = true # watch the magic come alive!
|
metadata
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flickr_oauth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Evan Sagge
|
9
|
+
autorequire: flickr
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-30 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: faraday
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0.7"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: faraday_middleware
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.7.0.rc1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: multi_xml
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: multi_json
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
type: :runtime
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: simple_oauth
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
type: :runtime
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
prerelease: false
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: "2.6"
|
79
|
+
type: :development
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: webmock
|
83
|
+
prerelease: false
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "1.6"
|
90
|
+
type: :development
|
91
|
+
version_requirements: *id007
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: vcr
|
94
|
+
prerelease: false
|
95
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: "1.7"
|
101
|
+
type: :development
|
102
|
+
version_requirements: *id008
|
103
|
+
description: ""
|
104
|
+
email:
|
105
|
+
- evansagge@gmail.com
|
106
|
+
executables: []
|
107
|
+
|
108
|
+
extensions: []
|
109
|
+
|
110
|
+
extra_rdoc_files: []
|
111
|
+
|
112
|
+
files:
|
113
|
+
- .gitignore
|
114
|
+
- .rspec
|
115
|
+
- Gemfile
|
116
|
+
- README.md
|
117
|
+
- Rakefile
|
118
|
+
- flickr_oauth.gemspec
|
119
|
+
- lib/faraday/response/raise_flickr_error.rb
|
120
|
+
- lib/flickr.rb
|
121
|
+
- lib/flickr/client.rb
|
122
|
+
- lib/flickr/error.rb
|
123
|
+
- lib/flickr/node.rb
|
124
|
+
- lib/flickr_oauth.rb
|
125
|
+
- lib/flickr_oauth/version.rb
|
126
|
+
- spec/fixtures/cassettes/JSON_format/it_should_behave_like_Flickr_with_specified_format/Flickr/flickr_test_echo/no_oauth_token.yml
|
127
|
+
- spec/fixtures/cassettes/JSON_format/it_should_behave_like_Flickr_with_specified_format/Flickr/flickr_test_echo/with_oauth_token.yml
|
128
|
+
- spec/fixtures/cassettes/REST_format/it_should_behave_like_Flickr_with_specified_format/Flickr/flickr_test_echo/no_oauth_token.yml
|
129
|
+
- spec/fixtures/cassettes/REST_format/it_should_behave_like_Flickr_with_specified_format/Flickr/flickr_test_echo/with_oauth_token.yml
|
130
|
+
- spec/json/flickr_spec.rb
|
131
|
+
- spec/rest/flickr_spec.rb
|
132
|
+
- spec/shared_examples.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
homepage: http://github.com/evansagge/flickr_oauth
|
135
|
+
licenses: []
|
136
|
+
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
none: false
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: "0"
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: "0"
|
154
|
+
requirements: []
|
155
|
+
|
156
|
+
rubyforge_project: flickr_oauth
|
157
|
+
rubygems_version: 1.8.5
|
158
|
+
signing_key:
|
159
|
+
specification_version: 3
|
160
|
+
summary: Flickr API adapter using OAuth
|
161
|
+
test_files:
|
162
|
+
- spec/fixtures/cassettes/JSON_format/it_should_behave_like_Flickr_with_specified_format/Flickr/flickr_test_echo/no_oauth_token.yml
|
163
|
+
- spec/fixtures/cassettes/JSON_format/it_should_behave_like_Flickr_with_specified_format/Flickr/flickr_test_echo/with_oauth_token.yml
|
164
|
+
- spec/fixtures/cassettes/REST_format/it_should_behave_like_Flickr_with_specified_format/Flickr/flickr_test_echo/no_oauth_token.yml
|
165
|
+
- spec/fixtures/cassettes/REST_format/it_should_behave_like_Flickr_with_specified_format/Flickr/flickr_test_echo/with_oauth_token.yml
|
166
|
+
- spec/json/flickr_spec.rb
|
167
|
+
- spec/rest/flickr_spec.rb
|
168
|
+
- spec/shared_examples.rb
|
169
|
+
- spec/spec_helper.rb
|