reagent-fleakr 0.3.0 → 0.4.0
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/README.rdoc +115 -20
- data/Rakefile +1 -1
- data/lib/fleakr.rb +66 -7
- data/lib/fleakr/api.rb +7 -0
- data/lib/fleakr/api/file_parameter.rb +47 -0
- data/lib/fleakr/api/method_request.rb +57 -0
- data/lib/fleakr/api/parameter.rb +35 -0
- data/lib/fleakr/api/parameter_list.rb +96 -0
- data/lib/fleakr/api/response.rb +2 -2
- data/lib/fleakr/api/upload_request.rb +64 -0
- data/lib/fleakr/api/value_parameter.rb +36 -0
- data/lib/fleakr/core_ext.rb +1 -0
- data/lib/fleakr/core_ext/hash.rb +22 -0
- data/lib/fleakr/objects.rb +9 -0
- data/lib/fleakr/objects/authentication_token.rb +43 -0
- data/lib/fleakr/objects/contact.rb +5 -5
- data/lib/fleakr/objects/error.rb +2 -2
- data/lib/fleakr/objects/group.rb +2 -2
- data/lib/fleakr/objects/image.rb +7 -7
- data/lib/fleakr/objects/photo.rb +69 -5
- data/lib/fleakr/objects/search.rb +3 -6
- data/lib/fleakr/objects/set.rb +11 -5
- data/lib/fleakr/objects/user.rb +14 -26
- data/lib/fleakr/support.rb +2 -0
- data/lib/fleakr/support/attribute.rb +30 -12
- data/lib/fleakr/support/object.rb +20 -4
- data/lib/fleakr/version.rb +1 -1
- data/test/fixtures/auth.checkToken.xml +8 -0
- data/test/fixtures/auth.getFullToken.xml +8 -0
- data/test/fixtures/people.getInfo.xml +1 -1
- data/test/fixtures/photos.getInfo.xml +20 -0
- data/test/test_helper.rb +18 -3
- data/test/unit/fleakr/api/file_parameter_test.rb +63 -0
- data/test/unit/fleakr/api/method_request_test.rb +103 -0
- data/test/unit/fleakr/api/parameter_list_test.rb +161 -0
- data/test/unit/fleakr/api/parameter_test.rb +34 -0
- data/test/unit/fleakr/api/upload_request_test.rb +133 -0
- data/test/unit/fleakr/api/value_parameter_test.rb +41 -0
- data/test/unit/fleakr/core_ext/hash_test.rb +32 -0
- data/test/unit/fleakr/objects/authentication_token_test.rb +47 -0
- data/test/unit/fleakr/objects/image_test.rb +10 -5
- data/test/unit/fleakr/objects/photo_test.rb +96 -36
- data/test/unit/fleakr/objects/search_test.rb +1 -1
- data/test/unit/fleakr/objects/set_test.rb +12 -1
- data/test/unit/fleakr/objects/user_test.rb +2 -16
- data/test/unit/fleakr/support/attribute_test.rb +82 -24
- data/test/unit/fleakr/support/object_test.rb +26 -3
- data/test/unit/fleakr_test.rb +65 -6
- metadata +27 -4
- data/lib/fleakr/api/request.rb +0 -58
- data/test/unit/fleakr/api/request_test.rb +0 -93
data/test/unit/fleakr_test.rb
CHANGED
@@ -4,11 +4,13 @@ class FleakrTest < Test::Unit::TestCase
|
|
4
4
|
|
5
5
|
describe "The Fleakr module" do
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
[:api_key, :shared_secret, :mini_token, :auth_token].each do |attribute|
|
8
|
+
it "should be able to set a value for :#{attribute}" do
|
9
|
+
value = 'value'
|
10
|
+
|
11
|
+
Fleakr.send("#{attribute}=".to_sym, value)
|
12
|
+
Fleakr.send(attribute).should == value
|
13
|
+
end
|
12
14
|
end
|
13
15
|
|
14
16
|
it "should provide a means to find a user by his username" do
|
@@ -21,7 +23,7 @@ class FleakrTest < Test::Unit::TestCase
|
|
21
23
|
user = stub()
|
22
24
|
email = 'user@host.com'
|
23
25
|
|
24
|
-
Fleakr::Objects::User.stubs(:find_by_username).with(email).raises(Fleakr::
|
26
|
+
Fleakr::Objects::User.stubs(:find_by_username).with(email).raises(Fleakr::ApiError)
|
25
27
|
Fleakr::Objects::User.expects(:find_by_email).with(email).returns(user)
|
26
28
|
|
27
29
|
Fleakr.user(email).should == user
|
@@ -38,6 +40,63 @@ class FleakrTest < Test::Unit::TestCase
|
|
38
40
|
Fleakr::Objects::Search.expects(:new).with(:tags => %w(one two)).returns(stub(:results => []))
|
39
41
|
Fleakr.search(:tags => %w(one two))
|
40
42
|
end
|
43
|
+
|
44
|
+
it "should be able to upload a collection of images" do
|
45
|
+
glob = '*.jpg'
|
46
|
+
filenames = %w(one.jpg two.jpg)
|
47
|
+
|
48
|
+
Dir.expects(:[]).with(glob).returns(filenames)
|
49
|
+
|
50
|
+
Fleakr::Objects::Photo.expects(:upload).with('one.jpg')
|
51
|
+
Fleakr::Objects::Photo.expects(:upload).with('two.jpg')
|
52
|
+
|
53
|
+
Fleakr.upload(glob)
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when generating an AuthenticationToken from an auth_token string" do
|
57
|
+
|
58
|
+
before do
|
59
|
+
@token = stub()
|
60
|
+
|
61
|
+
Fleakr.expects(:auth_token).with().at_least_once.returns('abc123')
|
62
|
+
Fleakr::Objects::AuthenticationToken.expects(:from_auth_token).with('abc123').returns(@token)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Make sure to clear the cache
|
66
|
+
after { Fleakr.instance_variable_set(:@token, nil) }
|
67
|
+
|
68
|
+
it "should return the token" do
|
69
|
+
Fleakr.token.should == @token
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should cache the result" do
|
73
|
+
2.times { Fleakr.token }
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
context "when generating an AuthenticationToken from a mini_token string" do
|
79
|
+
|
80
|
+
before do
|
81
|
+
@token = stub()
|
82
|
+
|
83
|
+
Fleakr.expects(:auth_token).with().at_least_once.returns(nil)
|
84
|
+
Fleakr.expects(:mini_token).with().at_least_once.returns('123-123-123')
|
85
|
+
Fleakr::Objects::AuthenticationToken.expects(:from_mini_token).with('123-123-123').returns(@token)
|
86
|
+
end
|
87
|
+
|
88
|
+
# Make sure to clear the cache
|
89
|
+
after { Fleakr.instance_variable_set(:@token, nil) }
|
90
|
+
|
91
|
+
it "should return the token" do
|
92
|
+
Fleakr.token.should == @token
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should cache the result" do
|
96
|
+
2.times { Fleakr.token }
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
41
100
|
|
42
101
|
end
|
43
102
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reagent-fleakr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Reagan
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-01-02 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -43,9 +43,19 @@ files:
|
|
43
43
|
- Rakefile
|
44
44
|
- lib/fleakr
|
45
45
|
- lib/fleakr/api
|
46
|
-
- lib/fleakr/api/
|
46
|
+
- lib/fleakr/api/file_parameter.rb
|
47
|
+
- lib/fleakr/api/method_request.rb
|
48
|
+
- lib/fleakr/api/parameter.rb
|
49
|
+
- lib/fleakr/api/parameter_list.rb
|
47
50
|
- lib/fleakr/api/response.rb
|
51
|
+
- lib/fleakr/api/upload_request.rb
|
52
|
+
- lib/fleakr/api/value_parameter.rb
|
53
|
+
- lib/fleakr/api.rb
|
54
|
+
- lib/fleakr/core_ext
|
55
|
+
- lib/fleakr/core_ext/hash.rb
|
56
|
+
- lib/fleakr/core_ext.rb
|
48
57
|
- lib/fleakr/objects
|
58
|
+
- lib/fleakr/objects/authentication_token.rb
|
49
59
|
- lib/fleakr/objects/contact.rb
|
50
60
|
- lib/fleakr/objects/error.rb
|
51
61
|
- lib/fleakr/objects/group.rb
|
@@ -54,12 +64,16 @@ files:
|
|
54
64
|
- lib/fleakr/objects/search.rb
|
55
65
|
- lib/fleakr/objects/set.rb
|
56
66
|
- lib/fleakr/objects/user.rb
|
67
|
+
- lib/fleakr/objects.rb
|
57
68
|
- lib/fleakr/support
|
58
69
|
- lib/fleakr/support/attribute.rb
|
59
70
|
- lib/fleakr/support/object.rb
|
71
|
+
- lib/fleakr/support.rb
|
60
72
|
- lib/fleakr/version.rb
|
61
73
|
- lib/fleakr.rb
|
62
74
|
- test/fixtures
|
75
|
+
- test/fixtures/auth.checkToken.xml
|
76
|
+
- test/fixtures/auth.getFullToken.xml
|
63
77
|
- test/fixtures/contacts.getPublicList.xml
|
64
78
|
- test/fixtures/groups.pools.getPhotos.xml
|
65
79
|
- test/fixtures/people.findByEmail.xml
|
@@ -67,6 +81,7 @@ files:
|
|
67
81
|
- test/fixtures/people.getInfo.xml
|
68
82
|
- test/fixtures/people.getPublicGroups.xml
|
69
83
|
- test/fixtures/people.getPublicPhotos.xml
|
84
|
+
- test/fixtures/photos.getInfo.xml
|
70
85
|
- test/fixtures/photos.getSizes.xml
|
71
86
|
- test/fixtures/photos.search.xml
|
72
87
|
- test/fixtures/photosets.getList.xml
|
@@ -75,9 +90,17 @@ files:
|
|
75
90
|
- test/unit
|
76
91
|
- test/unit/fleakr
|
77
92
|
- test/unit/fleakr/api
|
78
|
-
- test/unit/fleakr/api/
|
93
|
+
- test/unit/fleakr/api/file_parameter_test.rb
|
94
|
+
- test/unit/fleakr/api/method_request_test.rb
|
95
|
+
- test/unit/fleakr/api/parameter_list_test.rb
|
96
|
+
- test/unit/fleakr/api/parameter_test.rb
|
79
97
|
- test/unit/fleakr/api/response_test.rb
|
98
|
+
- test/unit/fleakr/api/upload_request_test.rb
|
99
|
+
- test/unit/fleakr/api/value_parameter_test.rb
|
100
|
+
- test/unit/fleakr/core_ext
|
101
|
+
- test/unit/fleakr/core_ext/hash_test.rb
|
80
102
|
- test/unit/fleakr/objects
|
103
|
+
- test/unit/fleakr/objects/authentication_token_test.rb
|
81
104
|
- test/unit/fleakr/objects/contact_test.rb
|
82
105
|
- test/unit/fleakr/objects/error_test.rb
|
83
106
|
- test/unit/fleakr/objects/group_test.rb
|
data/lib/fleakr/api/request.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
module Fleakr
|
2
|
-
module Api # :nodoc:
|
3
|
-
|
4
|
-
# = Request
|
5
|
-
#
|
6
|
-
# Performs requests against the Flickr API and returns response objects (Flickr::Api::Response)
|
7
|
-
# that contain Hpricot documents for further parsing and inspection. This class is used internally
|
8
|
-
# in all the defined model objects.
|
9
|
-
#
|
10
|
-
class Request
|
11
|
-
|
12
|
-
# Generic catch-all exception for any API errors
|
13
|
-
class ApiError < StandardError; end
|
14
|
-
|
15
|
-
# Makes a request to the Flickr API and returns a valid Response object. If
|
16
|
-
# there are errors on the response it will rais an ApiError exception
|
17
|
-
def self.with_response!(method, additional_parameters = {})
|
18
|
-
request = Request.new(method, additional_parameters)
|
19
|
-
response = request.send
|
20
|
-
|
21
|
-
raise(ApiError, "Code: #{response.error.code} - #{response.error.message}") if response.error?
|
22
|
-
|
23
|
-
response
|
24
|
-
end
|
25
|
-
|
26
|
-
# Create a new request for the specified API method and pass along any additional
|
27
|
-
# parameters. The Flickr API uses namespacing for its methods - this is optional
|
28
|
-
# when calling this method.
|
29
|
-
#
|
30
|
-
# This must be called after initializing the library with the required API key
|
31
|
-
# see (#Fleakr.api_key=)
|
32
|
-
def initialize(method, additional_parameters = {})
|
33
|
-
method = method.sub(/^(flickr\.)?/, 'flickr.')
|
34
|
-
|
35
|
-
default_parameters = {:api_key => Fleakr.api_key, :method => method}
|
36
|
-
@parameters = default_parameters.merge(additional_parameters)
|
37
|
-
end
|
38
|
-
|
39
|
-
def send # :nodoc:
|
40
|
-
Response.new(Net::HTTP.get(endpoint_uri))
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
def endpoint_uri
|
45
|
-
uri = URI.parse('http://api.flickr.com/services/rest/')
|
46
|
-
uri.query = query_parameters
|
47
|
-
uri
|
48
|
-
end
|
49
|
-
|
50
|
-
def query_parameters
|
51
|
-
@parameters.map {|key,value| "#{key}=#{CGI.escape(value)}" }.join('&')
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../../test_helper'
|
2
|
-
|
3
|
-
module Fleakr::Api
|
4
|
-
class RequestTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
describe "A Request instance" do
|
7
|
-
|
8
|
-
context "with an API key" do
|
9
|
-
|
10
|
-
before do
|
11
|
-
@api_key = 'f00b4r'
|
12
|
-
Fleakr.stubs(:api_key).with().returns(@api_key)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should know the full query parameters" do
|
16
|
-
request = Request.new('flickr.people.findByUsername', :username => 'foobar')
|
17
|
-
|
18
|
-
expected = [
|
19
|
-
"api_key=#{@api_key}",
|
20
|
-
"method=flickr.people.findByUsername",
|
21
|
-
"username=foobar"
|
22
|
-
]
|
23
|
-
|
24
|
-
request.query_parameters.split('&').sort.should == expected
|
25
|
-
end
|
26
|
-
|
27
|
-
it "should escape the keys and values in the parameter list" do
|
28
|
-
request = Request.new('flickr.people.findByUsername', :username => 'the decapitator')
|
29
|
-
request.query_parameters.split('&').include?("username=#{CGI.escape('the decapitator')}").should be(true)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should translate a shorthand API call" do
|
33
|
-
request = Request.new('people.findByUsername')
|
34
|
-
request.query_parameters.split('&').include?('method=flickr.people.findByUsername').should be(true)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should know the endpoint with full parameters" do
|
38
|
-
query_parameters = 'foo=bar'
|
39
|
-
|
40
|
-
request = Request.new('people.getInfo')
|
41
|
-
request.stubs(:query_parameters).with().returns(query_parameters)
|
42
|
-
|
43
|
-
uri_mock = mock() {|m| m.expects(:query=).with(query_parameters)}
|
44
|
-
|
45
|
-
URI.expects(:parse).with("http://api.flickr.com/services/rest/").returns(uri_mock)
|
46
|
-
|
47
|
-
request.endpoint_uri.should == uri_mock
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should be able to make a request" do
|
51
|
-
endpoint_uri = stub()
|
52
|
-
|
53
|
-
request = Request.new('flickr.people.findByUsername')
|
54
|
-
|
55
|
-
request.stubs(:endpoint_uri).with().returns(endpoint_uri)
|
56
|
-
Net::HTTP.expects(:get).with(endpoint_uri).returns('<xml>')
|
57
|
-
|
58
|
-
request.send
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should create a response from the request" do
|
62
|
-
response_xml = '<xml>'
|
63
|
-
response_stub = stub()
|
64
|
-
|
65
|
-
request = Request.new('flickr.people.findByUsername')
|
66
|
-
|
67
|
-
Net::HTTP.stubs(:get).returns(response_xml)
|
68
|
-
Response.expects(:new).with(response_xml).returns(response_stub)
|
69
|
-
|
70
|
-
request.send.should == response_stub
|
71
|
-
end
|
72
|
-
|
73
|
-
it "should be able to make a full request and response cycle" do
|
74
|
-
response = stub(:error? => false)
|
75
|
-
Response.expects(:new).with(kind_of(String)).returns(response)
|
76
|
-
|
77
|
-
Request.with_response!('flickr.people.findByUsername', :username => 'foobar').should == response
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should raise an exception when the full request / response cycle has errors" do
|
81
|
-
response = stub(:error? => true, :error => stub(:code => '1', :message => 'User not found'))
|
82
|
-
Response.stubs(:new).with(kind_of(String)).returns(response)
|
83
|
-
|
84
|
-
lambda do
|
85
|
-
Request.with_response!('flickr.people.findByUsername', :username => 'foobar')
|
86
|
-
end.should raise_error(Fleakr::Api::Request::ApiError)
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|