chargify2 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6920a74f0ebd8aa7b4fd70ed631e84bffcb8a90f
4
+ data.tar.gz: c038127114e6c5175c39e09713a49af4371dcf21
5
+ SHA512:
6
+ metadata.gz: 07f2e1f040ff64ae1c4537e5a7cf00cd32d5561b513f1493cd9b40805787e8c84a9563424f59f513050ac0ab5be6da991ab8ab0a833a9052e59903e349571cbe
7
+ data.tar.gz: 0da07436757d5d32df2d153b5c16e677d5a6360acf43ac1d0235d4b63fc16a53749179940ddf4a4475ab2fcbb565a208f9da8db4ce06e56aa7fb6ee38cc4ec73
data/.travis.yml CHANGED
@@ -1,7 +1,9 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem update --system
4
+ - gem install bundler
5
+ - bundle --version
1
6
  rvm:
2
7
  - 1.8.7
3
- - 1.9.2
8
+ - 1.9.3
4
9
  - ree
5
- branches:
6
- only:
7
- - master
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chargify2 (0.2.4)
4
+ chargify2 (0.2.5)
5
5
  hashery (~> 2.1.0)
6
6
  hashie
7
7
  httparty
@@ -22,17 +22,17 @@ GEM
22
22
  ffi (~> 1.0, >= 1.0.6)
23
23
  columnize (0.3.6)
24
24
  crack (0.3.1)
25
- debugger (1.2.0)
25
+ debugger (1.3.1)
26
26
  columnize (>= 0.3.1)
27
27
  debugger-linecache (~> 1.1.1)
28
- debugger-ruby_core_source (~> 1.1.3)
28
+ debugger-ruby_core_source (~> 1.1.8)
29
29
  debugger-linecache (1.1.2)
30
30
  debugger-ruby_core_source (>= 1.1.1)
31
- debugger-ruby_core_source (1.1.3)
31
+ debugger-ruby_core_source (1.1.8)
32
32
  diff-lcs (1.1.3)
33
33
  ffi (1.1.5)
34
34
  hashery (2.1.0)
35
- hashie (1.2.0)
35
+ hashie (2.0.3)
36
36
  httparty (0.10.2)
37
37
  multi_json (~> 1.0)
38
38
  multi_xml (>= 0.5.2)
@@ -40,7 +40,7 @@ GEM
40
40
  addressable
41
41
  mime-types (1.19)
42
42
  multi_json (1.3.6)
43
- multi_xml (0.5.2)
43
+ multi_xml (0.5.3)
44
44
  nokogiri (1.5.5)
45
45
  rack (1.4.1)
46
46
  rack-test (0.6.1)
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Chargify API V2 Ruby Wrapper [![build status](https://secure.travis-ci.org/chargify/chargify2.png)](http://travis-ci.org/chargify/chargify2)
1
+ Chargify API V2 Ruby Wrapper [![build status](https://travis-ci.org/chargify/chargify2.png?branch=master)](http://travis-ci.org/chargify/chargify2)
2
2
  ============================
3
3
 
4
4
  This gem is meant to be used with the [Chargify Direct API](http://docs.chargify.com/chargify-direct-introduction).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.2.5
data/chargify2.gemspec CHANGED
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
4
4
  s.rubygems_version = '1.6.2'
5
5
 
6
6
  s.name = 'chargify2'
7
- s.version = '0.2.4'
7
+ s.version = '0.2.5'
8
8
  s.date = '2011-10-28'
9
9
  s.summary = %q{Chargify API V2 Ruby Wrapper}
10
10
  s.description = ''
@@ -16,22 +16,22 @@ module Chargify2
16
16
  attr_reader :api_password
17
17
  attr_reader :api_secret
18
18
  attr_reader :base_uri
19
-
19
+
20
20
  def initialize(args = {})
21
21
  options = args.symbolize_keys
22
-
22
+
23
23
  @api_id = options[:api_id]
24
24
  @api_password = options[:api_password]
25
25
  @api_secret = options[:api_secret]
26
26
  @base_uri = options[:base_uri] || BASE_URI
27
27
  end
28
-
28
+
29
29
  def direct
30
30
  Chargify2::Direct.new(self)
31
31
  end
32
-
32
+
33
33
  def calls
34
34
  Chargify2::CallResource.new(self)
35
35
  end
36
36
  end
37
- end
37
+ end
@@ -12,22 +12,12 @@ module Chargify2
12
12
  base_uri Chargify2::Client::BASE_URI
13
13
  headers 'Content-Type' => 'application/json', 'Accept' => 'application/json'
14
14
  format :json
15
-
16
- def self.path(resource_path)
15
+
16
+ def self.path(resource_path = nil)
17
+ return @path unless resource_path
17
18
  @path = resource_path
18
19
  end
19
20
 
20
- def self.uri
21
- if @path.nil? || @path.to_s.size == 0
22
- raise ResourceError, "No path configured. Please use a defined Resource."
23
- end
24
- "#{base_uri}/#{@path}"
25
- end
26
-
27
- def uri
28
- self.class.uri
29
- end
30
-
31
21
  # Define the representation class for this resource
32
22
  def self.representation(klass = nil)
33
23
  unless klass.nil?
@@ -35,26 +25,38 @@ module Chargify2
35
25
  end
36
26
  @@representation ||= nil
37
27
  end
38
-
28
+
39
29
  def initialize(client)
40
30
  @client = client
41
- @username = client.api_id
42
- @password = client.api_password
43
-
44
- self.class.base_uri(client.base_uri)
45
- self.class.basic_auth(@username, @password)
31
+ @base_uri = client.base_uri
32
+ @auth = {:username => client.api_id, :password => client.api_password}
46
33
  end
47
-
48
- def self.read(id, query = {})
49
- response = get("#{uri}/#{id}", :query => query.empty? ? nil : query)
34
+
35
+ def self.read(id, query = {}, options = {})
36
+ options.merge!(:query => query.empty? ? nil : query)
37
+ response = get("/#{path}/#{id}", options)
38
+
50
39
  response_hash = response[representation.to_s.downcase.split('::').last] || {}
51
40
  representation.new(response_hash.symbolize_keys)
52
41
  end
53
-
54
- def read(id, query = {})
55
- self.class.read(id, query)
42
+
43
+ def read(id, query = {}, options = {})
44
+ self.class.read(id, query, merge_options(options))
45
+ end
46
+
47
+ private
48
+ def merge_options(options)
49
+ if @base_uri
50
+ options.merge!(:base_uri => @base_uri)
51
+ end
52
+
53
+ if @auth
54
+ options.merge!(:basic_auth => @auth)
55
+ end
56
+
57
+ options
56
58
  end
57
59
  end
58
-
60
+
59
61
  class ResourceError < StandardError; end
60
- end
62
+ end
@@ -2,55 +2,74 @@ require 'spec_helper'
2
2
 
3
3
  module Chargify2
4
4
  describe CallResource do
5
- it "should have a URI of 'https://api.chargify.com/api/v2/calls'" do
6
- CallResource.uri.should == 'https://api.chargify.com/api/v2/calls'
5
+ it "should have a path of 'calls'" do
6
+ CallResource.path.should == 'calls'
7
7
  end
8
8
 
9
9
  it "represents with the Call class" do
10
10
  CallResource.representation.should == Call
11
11
  end
12
-
13
- describe "#read" do
14
- it "performs a GET request to 'https://api.chargify.com/api/v2/calls/123' (without authentication) when called with '123'" do
15
- # What is this 'a_request' method?
16
- pending 'Rewrite this test.'
17
- WebMock.stub_request(:get, 'https://api.chargify.com/api/v2/calls/123')
18
- CallResource.read('123')
19
- a_request(:get, 'https://api.chargify.com/api/v2/calls/123').should have_been_made.once
20
- end
21
-
22
- it "returns a Call representation" do
23
- WebMock.stub_request(:get, 'https://api.chargify.com/api/v2/calls/123')
24
- CallResource.read('123').should be_a(Call)
25
- end
26
- end
27
-
28
- context "instance configured with a client and a non-standard base URI" do
29
- it "has a URI of 'http://www.example.com/calls'" do
30
- base_uri = 'http://www.example.com'
31
- client = Client.new(valid_client_credentials.merge(:base_uri => base_uri))
32
- CallResource.new(client).uri.should == 'http://www.example.com/calls'
12
+
13
+ context 'without an instance configured with a client' do
14
+ describe '.read' do
15
+ it "performs a GET request to 'https://api.chargify.com/api/v2/calls/123' (without authentication) when called with '123'" do
16
+ WebMock.stub_request(:get, 'https://api.chargify.com/api/v2/calls/123')
17
+ CallResource.read('123')
18
+ a_request(:get, 'https://api.chargify.com/api/v2/calls/123').should have_been_made.once
19
+ end
20
+
21
+ it "returns a Call representation" do
22
+ WebMock.stub_request(:get, 'https://api.chargify.com/api/v2/calls/123')
23
+ CallResource.read('123').should be_a(Call)
24
+ end
33
25
  end
34
26
  end
35
-
36
- context "instance configured with a valid client" do
37
- before(:each) do
38
- @client = Client.new(valid_client_credentials)
39
- @call_resource = CallResource.new(@client)
27
+
28
+ context 'with an instance configured with a client' do
29
+ let(:client) { Client.new(valid_client_credentials) }
30
+ let!(:call_resource) { CallResource.new(client) }
31
+
32
+ describe '.read' do
33
+ it 'ignores the instance configuration and uses class defaults' do
34
+ WebMock.stub_request(:get, 'https://api.chargify.com/api/v2/calls/123')
35
+ CallResource.read('123')
36
+ a_request(:get, 'https://api.chargify.com/api/v2/calls/123').should have_been_made.once
37
+ end
40
38
  end
41
-
42
- it "performs a GET request to 'https://<api_login>:<api_password>@api.chargify.com/api/v2/calls/123' (with authentication) when called with '123'" do
43
- # What is this 'a_request' method?
44
- pending 'Rewrite this test.'
45
- WebMock.stub_request(:get, "https://#{@client.api_id}:#{@client.api_password}@api.chargify.com/api/v2/calls/123")
46
- CallResource.read('123')
47
- a_request(:get, "https://#{@client.api_id}:#{@client.api_password}@api.chargify.com/api/v2/calls/123").should have_been_made.once
39
+
40
+ describe '#read' do
41
+ it "performs a GET request to 'https://<api_login>:<api_password>@api.chargify.com/api/v2/calls/123' (with authentication) when called with '123'" do
42
+ WebMock.stub_request(:get, client_authenticated_uri(client, '/calls/123'))
43
+ call_resource.read('123')
44
+ a_request(:get, client_authenticated_uri(client, '/calls/123')).should have_been_made.once
45
+ end
46
+
47
+ it "returns a Call representation" do
48
+ WebMock.stub_request(:get, client_authenticated_uri(client, '/calls/123'))
49
+ call_resource.read('123').should be_a(Call)
50
+ end
48
51
  end
49
-
50
- it "returns a Call representation" do
51
- WebMock.stub_request(:get, "https://#{@client.api_id}:#{@client.api_password}@api.chargify.com/api/v2/calls/123")
52
- CallResource.read('123').should be_a(Call)
52
+
53
+ context 'with a non-standard base URI' do
54
+ let(:base_uri) { 'http://www.example.com' }
55
+ let(:client) { Client.new(valid_client_credentials.merge(:base_uri => base_uri)) }
56
+
57
+ describe '#read' do
58
+ it "has a URI of 'http://www.example.com/calls'" do
59
+ WebMock.stub_request(:get, client_authenticated_uri(client, '/calls/123'))
60
+ call_resource.read('123')
61
+ a_request(:get, client_authenticated_uri(client, '/calls/123')).should have_been_made.once
62
+ end
63
+ end
53
64
  end
54
65
  end
66
+
67
+ def client_authenticated_uri(client, path)
68
+ uri = URI(client.base_uri)
69
+ uri.user = client.api_id
70
+ uri.password = client.api_password
71
+
72
+ uri.to_s + path
73
+ end
55
74
  end
56
75
  end
@@ -100,17 +100,20 @@ module Chargify2
100
100
  describe "#encoded_data" do
101
101
  it "turns the data hash in to query string format" do
102
102
  sp = Direct::SecureParameters.new({'data' => {'one' => 'two', 'three' => 'four'}}, client)
103
- sp.encoded_data.should == "one=two&three=four"
103
+ sp.encoded_data.should include 'one=two'
104
+ sp.encoded_data.should include 'three=four'
104
105
  end
105
106
 
106
107
  it "turns a nested data hash in to nested query string format" do
107
108
  sp = Direct::SecureParameters.new({'data' => {'one' => {'two' => {'three' => 'four'}}, 'foo' => 'bar'}}, client)
108
- sp.encoded_data.should == "one[two][three]=four&foo=bar"
109
+ sp.encoded_data.should include 'one[two][three]=four'
110
+ sp.encoded_data.should include 'foo=bar'
109
111
  end
110
112
 
111
113
  it "performs percent encoding on unsafe characters" do
112
114
  sp = Direct::SecureParameters.new({'data' => {'redirect_uri' => 'http://www.example.com', 'sentence' => 'Michael was here!'}}, client)
113
- sp.encoded_data.should == "redirect_uri=http%3A%2F%2Fwww.example.com&sentence=Michael+was+here%21"
115
+ sp.encoded_data.should include 'redirect_uri=http%3A%2F%2Fwww.example.com'
116
+ sp.encoded_data.should include 'sentence=Michael+was+here%21'
114
117
  end
115
118
  end
116
119
 
@@ -184,6 +187,10 @@ module Chargify2
184
187
  data = {'one' => 'two', 'three' => {'four' => "http://www.example.com"}}
185
188
  sp = Direct::SecureParameters.new({'timestamp' => timestamp, 'nonce' => nonce, 'data' => data}, client)
186
189
 
190
+ # Rack::Utils.build_nested_query puts the string elements in a different order in different rubies
191
+ # Stub here to test the signature method. We test the encoded_data method above.
192
+ sp.stub(:encoded_data).and_return("one=two&three[four]=http%3A%2F%2Fwww.example.com")
193
+
187
194
  # Used the generator here: http://hash.online-convert.com/sha1-generator
188
195
  # ... with message: "1c016050-498a-012e-91b1-005056a216ab12345678one=two&three[four]=http%3A%2F%2Fwww.example.com"
189
196
  # ... and secret: "p5lxQ804MYtwZecFWNOT"
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
 
3
3
  require 'bundler'
4
4
  Bundler.require(:default, :development)
5
+ require 'webmock/rspec'
5
6
 
6
7
  # Requires supporting files with custom matchers and macros, etc,
7
8
  # in ./support/ and its subdirectories.
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chargify2
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.2.4
4
+ version: 0.2.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Michael Klett
@@ -13,161 +12,141 @@ cert_chain: []
13
12
  date: 2011-10-28 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
- type: :runtime
17
- version_requirements: !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
23
15
  name: rack
24
- prerelease: false
25
16
  requirement: !ruby/object:Gem::Requirement
26
- none: false
27
17
  requirements:
28
- - - ! '>='
18
+ - - '>='
29
19
  - !ruby/object:Gem::Version
30
20
  version: '0'
31
- - !ruby/object:Gem::Dependency
32
21
  type: :runtime
22
+ prerelease: false
33
23
  version_requirements: !ruby/object:Gem::Requirement
34
- none: false
35
24
  requirements:
36
- - - ~>
25
+ - - '>='
37
26
  - !ruby/object:Gem::Version
38
- version: 2.1.0
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
39
29
  name: hashery
40
- prerelease: false
41
30
  requirement: !ruby/object:Gem::Requirement
42
- none: false
43
31
  requirements:
44
32
  - - ~>
45
33
  - !ruby/object:Gem::Version
46
34
  version: 2.1.0
47
- - !ruby/object:Gem::Dependency
48
35
  type: :runtime
36
+ prerelease: false
49
37
  version_requirements: !ruby/object:Gem::Requirement
50
- none: false
51
38
  requirements:
52
- - - ! '>='
39
+ - - ~>
53
40
  - !ruby/object:Gem::Version
54
- version: '0'
41
+ version: 2.1.0
42
+ - !ruby/object:Gem::Dependency
55
43
  name: hashie
56
- prerelease: false
57
44
  requirement: !ruby/object:Gem::Requirement
58
- none: false
59
45
  requirements:
60
- - - ! '>='
46
+ - - '>='
61
47
  - !ruby/object:Gem::Version
62
48
  version: '0'
63
- - !ruby/object:Gem::Dependency
64
49
  type: :runtime
50
+ prerelease: false
65
51
  version_requirements: !ruby/object:Gem::Requirement
66
- none: false
67
52
  requirements:
68
- - - ! '>='
53
+ - - '>='
69
54
  - !ruby/object:Gem::Version
70
55
  version: '0'
56
+ - !ruby/object:Gem::Dependency
71
57
  name: httparty
72
- prerelease: false
73
58
  requirement: !ruby/object:Gem::Requirement
74
- none: false
75
59
  requirements:
76
- - - ! '>='
60
+ - - '>='
77
61
  - !ruby/object:Gem::Version
78
62
  version: '0'
79
- - !ruby/object:Gem::Dependency
80
- type: :development
63
+ type: :runtime
64
+ prerelease: false
81
65
  version_requirements: !ruby/object:Gem::Requirement
82
- none: false
83
66
  requirements:
84
- - - ~>
67
+ - - '>='
85
68
  - !ruby/object:Gem::Version
86
- version: 0.9.2.2
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
87
71
  name: rake
88
- prerelease: false
89
72
  requirement: !ruby/object:Gem::Requirement
90
- none: false
91
73
  requirements:
92
74
  - - ~>
93
75
  - !ruby/object:Gem::Version
94
76
  version: 0.9.2.2
95
- - !ruby/object:Gem::Dependency
96
77
  type: :development
78
+ prerelease: false
97
79
  version_requirements: !ruby/object:Gem::Requirement
98
- none: false
99
80
  requirements:
100
81
  - - ~>
101
82
  - !ruby/object:Gem::Version
102
- version: 2.11.0
83
+ version: 0.9.2.2
84
+ - !ruby/object:Gem::Dependency
103
85
  name: rspec
104
- prerelease: false
105
86
  requirement: !ruby/object:Gem::Requirement
106
- none: false
107
87
  requirements:
108
88
  - - ~>
109
89
  - !ruby/object:Gem::Version
110
90
  version: 2.11.0
111
- - !ruby/object:Gem::Dependency
112
91
  type: :development
92
+ prerelease: false
113
93
  version_requirements: !ruby/object:Gem::Requirement
114
- none: false
115
94
  requirements:
116
- - - ! '>='
95
+ - - ~>
117
96
  - !ruby/object:Gem::Version
118
- version: '0'
97
+ version: 2.11.0
98
+ - !ruby/object:Gem::Dependency
119
99
  name: capybara
120
- prerelease: false
121
100
  requirement: !ruby/object:Gem::Requirement
122
- none: false
123
101
  requirements:
124
- - - ! '>='
102
+ - - '>='
125
103
  - !ruby/object:Gem::Version
126
104
  version: '0'
127
- - !ruby/object:Gem::Dependency
128
105
  type: :development
106
+ prerelease: false
129
107
  version_requirements: !ruby/object:Gem::Requirement
130
- none: false
131
108
  requirements:
132
- - - ! '>='
109
+ - - '>='
133
110
  - !ruby/object:Gem::Version
134
111
  version: '0'
112
+ - !ruby/object:Gem::Dependency
135
113
  name: vcr
136
- prerelease: false
137
114
  requirement: !ruby/object:Gem::Requirement
138
- none: false
139
115
  requirements:
140
- - - ! '>='
116
+ - - '>='
141
117
  - !ruby/object:Gem::Version
142
118
  version: '0'
143
- - !ruby/object:Gem::Dependency
144
119
  type: :development
120
+ prerelease: false
145
121
  version_requirements: !ruby/object:Gem::Requirement
146
- none: false
147
122
  requirements:
148
- - - ! '>='
123
+ - - '>='
149
124
  - !ruby/object:Gem::Version
150
125
  version: '0'
126
+ - !ruby/object:Gem::Dependency
151
127
  name: webmock
152
- prerelease: false
153
128
  requirement: !ruby/object:Gem::Requirement
154
- none: false
155
129
  requirements:
156
- - - ! '>='
130
+ - - '>='
157
131
  - !ruby/object:Gem::Version
158
132
  version: '0'
159
- - !ruby/object:Gem::Dependency
160
133
  type: :development
134
+ prerelease: false
161
135
  version_requirements: !ruby/object:Gem::Requirement
162
- none: false
136
+ requirements:
137
+ - - '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: yard
142
+ requirement: !ruby/object:Gem::Requirement
163
143
  requirements:
164
144
  - - ~>
165
145
  - !ruby/object:Gem::Version
166
146
  version: 0.8.0
167
- name: yard
147
+ type: :development
168
148
  prerelease: false
169
- requirement: !ruby/object:Gem::Requirement
170
- none: false
149
+ version_requirements: !ruby/object:Gem::Requirement
171
150
  requirements:
172
151
  - - ~>
173
152
  - !ruby/object:Gem::Version
@@ -206,28 +185,24 @@ files:
206
185
  homepage: http://github.com/chargify/chargify2
207
186
  licenses:
208
187
  - MIT
188
+ metadata: {}
209
189
  post_install_message:
210
190
  rdoc_options: []
211
191
  require_paths:
212
192
  - lib
213
193
  required_ruby_version: !ruby/object:Gem::Requirement
214
- none: false
215
194
  requirements:
216
- - - ! '>='
195
+ - - '>='
217
196
  - !ruby/object:Gem::Version
218
- segments:
219
- - 0
220
- hash: 4516507312252909387
221
197
  version: '0'
222
198
  required_rubygems_version: !ruby/object:Gem::Requirement
223
- none: false
224
199
  requirements:
225
- - - ! '>='
200
+ - - '>='
226
201
  - !ruby/object:Gem::Version
227
202
  version: '0'
228
203
  requirements: []
229
204
  rubyforge_project:
230
- rubygems_version: 1.8.23
205
+ rubygems_version: 2.0.0
231
206
  signing_key:
232
207
  specification_version: 3
233
208
  summary: Chargify API V2 Ruby Wrapper