fleakr 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/README.rdoc +114 -19
  2. data/Rakefile +1 -1
  3. data/lib/fleakr/api/file_parameter.rb +47 -0
  4. data/lib/fleakr/api/method_request.rb +57 -0
  5. data/lib/fleakr/api/parameter.rb +35 -0
  6. data/lib/fleakr/api/parameter_list.rb +96 -0
  7. data/lib/fleakr/api/response.rb +2 -2
  8. data/lib/fleakr/api/upload_request.rb +64 -0
  9. data/lib/fleakr/api/value_parameter.rb +36 -0
  10. data/lib/fleakr/api.rb +7 -0
  11. data/lib/fleakr/core_ext/hash.rb +22 -0
  12. data/lib/fleakr/core_ext.rb +1 -0
  13. data/lib/fleakr/objects/authentication_token.rb +43 -0
  14. data/lib/fleakr/objects/contact.rb +5 -5
  15. data/lib/fleakr/objects/error.rb +2 -2
  16. data/lib/fleakr/objects/group.rb +2 -2
  17. data/lib/fleakr/objects/image.rb +7 -7
  18. data/lib/fleakr/objects/photo.rb +69 -5
  19. data/lib/fleakr/objects/search.rb +3 -6
  20. data/lib/fleakr/objects/set.rb +11 -5
  21. data/lib/fleakr/objects/user.rb +14 -26
  22. data/lib/fleakr/objects.rb +9 -0
  23. data/lib/fleakr/support/attribute.rb +30 -12
  24. data/lib/fleakr/support/object.rb +20 -4
  25. data/lib/fleakr/support.rb +2 -0
  26. data/lib/fleakr/version.rb +1 -1
  27. data/lib/fleakr.rb +66 -7
  28. data/test/fixtures/auth.checkToken.xml +8 -0
  29. data/test/fixtures/auth.getFullToken.xml +8 -0
  30. data/test/fixtures/people.getInfo.xml +1 -1
  31. data/test/fixtures/photos.getInfo.xml +20 -0
  32. data/test/test_helper.rb +18 -3
  33. data/test/unit/fleakr/api/file_parameter_test.rb +63 -0
  34. data/test/unit/fleakr/api/method_request_test.rb +103 -0
  35. data/test/unit/fleakr/api/parameter_list_test.rb +161 -0
  36. data/test/unit/fleakr/api/parameter_test.rb +34 -0
  37. data/test/unit/fleakr/api/upload_request_test.rb +133 -0
  38. data/test/unit/fleakr/api/value_parameter_test.rb +41 -0
  39. data/test/unit/fleakr/core_ext/hash_test.rb +32 -0
  40. data/test/unit/fleakr/objects/authentication_token_test.rb +47 -0
  41. data/test/unit/fleakr/objects/image_test.rb +10 -5
  42. data/test/unit/fleakr/objects/photo_test.rb +96 -36
  43. data/test/unit/fleakr/objects/search_test.rb +1 -1
  44. data/test/unit/fleakr/objects/set_test.rb +12 -1
  45. data/test/unit/fleakr/objects/user_test.rb +2 -16
  46. data/test/unit/fleakr/support/attribute_test.rb +82 -24
  47. data/test/unit/fleakr/support/object_test.rb +26 -3
  48. data/test/unit/fleakr_test.rb +65 -6
  49. metadata +28 -5
  50. data/lib/fleakr/api/request.rb +0 -58
  51. data/test/unit/fleakr/api/request_test.rb +0 -93
@@ -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