paid 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.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +8 -0
  3. data/Gemfile.lock +54 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.rdoc +35 -0
  6. data/Rakefile +34 -0
  7. data/lib/data/ca-certificates.crt +0 -0
  8. data/lib/paid/account.rb +4 -0
  9. data/lib/paid/api_operations/create.rb +17 -0
  10. data/lib/paid/api_operations/delete.rb +11 -0
  11. data/lib/paid/api_operations/list.rb +17 -0
  12. data/lib/paid/api_operations/update.rb +57 -0
  13. data/lib/paid/api_resource.rb +32 -0
  14. data/lib/paid/certificate_blacklist.rb +55 -0
  15. data/lib/paid/customer.rb +16 -0
  16. data/lib/paid/errors/api_connection_error.rb +4 -0
  17. data/lib/paid/errors/api_error.rb +4 -0
  18. data/lib/paid/errors/authentication_error.rb +4 -0
  19. data/lib/paid/errors/invalid_request_error.rb +10 -0
  20. data/lib/paid/errors/paid_error.rb +20 -0
  21. data/lib/paid/event.rb +5 -0
  22. data/lib/paid/invoice.rb +7 -0
  23. data/lib/paid/list_object.rb +37 -0
  24. data/lib/paid/paid_object.rb +187 -0
  25. data/lib/paid/singleton_api_resource.rb +20 -0
  26. data/lib/paid/transaction.rb +7 -0
  27. data/lib/paid/util.rb +127 -0
  28. data/lib/paid/version.rb +3 -0
  29. data/lib/paid.rb +280 -0
  30. data/lib/tasks/paid_tasks.rake +4 -0
  31. data/paid.gemspec +30 -0
  32. data/test/paid/account_test.rb +12 -0
  33. data/test/paid/api_resource_test.rb +361 -0
  34. data/test/paid/certificate_blacklist_test.rb +18 -0
  35. data/test/paid/customer_test.rb +35 -0
  36. data/test/paid/invoice_test.rb +26 -0
  37. data/test/paid/list_object_test.rb +16 -0
  38. data/test/paid/metadata_test.rb +104 -0
  39. data/test/paid/paid_object_test.rb +27 -0
  40. data/test/paid/transaction_test.rb +49 -0
  41. data/test/paid/util_test.rb +59 -0
  42. data/test/test_data.rb +106 -0
  43. data/test/test_helper.rb +41 -0
  44. metadata +203 -0
@@ -0,0 +1,59 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Paid
4
+ class UtilTest < Test::Unit::TestCase
5
+ should "symbolize_names should convert names to symbols" do
6
+ start = {
7
+ 'foo' => 'bar',
8
+ 'array' => [{ 'foo' => 'bar' }],
9
+ 'nested' => {
10
+ 1 => 2,
11
+ :symbol => 9,
12
+ 'string' => nil
13
+ }
14
+ }
15
+ finish = {
16
+ :foo => 'bar',
17
+ :array => [{ :foo => 'bar' }],
18
+ :nested => {
19
+ 1 => 2,
20
+ :symbol => 9,
21
+ :string => nil
22
+ }
23
+ }
24
+
25
+ symbolized = Paid::Util.symbolize_names(start)
26
+ assert_equal(finish, symbolized)
27
+ end
28
+
29
+ should "parse a nil opts argument" do
30
+ api_key, headers = Paid::Util.parse_opts(nil)
31
+ assert_equal({}, headers)
32
+ assert_equal(nil, api_key)
33
+ end
34
+
35
+ should "parse a string opts argument" do
36
+ api_key, headers = Paid::Util.parse_opts('foo')
37
+ assert_equal({}, headers)
38
+ assert_equal('foo', api_key)
39
+ end
40
+
41
+ should "parse a hash opts argument with just api_key" do
42
+ api_key, headers = Paid::Util.parse_opts({:api_key => 'foo'})
43
+ assert_equal({}, headers)
44
+ assert_equal('foo', api_key)
45
+ end
46
+
47
+ should "parse a hash opts argument with just idempotency_key" do
48
+ api_key, headers = Paid::Util.parse_opts({:idempotency_key => 'foo'})
49
+ assert_equal({:idempotency_key => 'foo'}, headers)
50
+ assert_equal(nil, api_key)
51
+ end
52
+
53
+ should "parse a hash opts argument both idempotency_key and api_key" do
54
+ api_key, headers = Paid::Util.parse_opts({:api_key => 'bar', :idempotency_key => 'foo'})
55
+ assert_equal({:idempotency_key => 'foo'}, headers)
56
+ assert_equal('bar', api_key)
57
+ end
58
+ end
59
+ end
data/test/test_data.rb ADDED
@@ -0,0 +1,106 @@
1
+ module Paid
2
+ module TestData
3
+ def test_response(body, code=200)
4
+ # When an exception is raised, restclient clobbers method_missing. Hence we
5
+ # can't just use the stubs interface.
6
+ body = JSON.generate(body) if !(body.kind_of? String)
7
+ m = mock
8
+ m.instance_variable_set('@paid_values', { :body => body, :code => code })
9
+ def m.body; @paid_values[:body]; end
10
+ def m.code; @paid_values[:code]; end
11
+ m
12
+ end
13
+
14
+ def test_customer(params={})
15
+ id = params[:id] || 'c_test_customer'
16
+ {
17
+ :transactions => [],
18
+ :object => "customer",
19
+ :id => id,
20
+ :created => 1304114758
21
+ }.merge(params)
22
+ end
23
+
24
+ def test_customer_array
25
+ {
26
+ :data => [test_customer, test_customer, test_customer],
27
+ :object => 'list',
28
+ :url => '/v0/customers'
29
+ }
30
+ end
31
+
32
+ def test_transaction(params={})
33
+ id = params[:id] || 'tr_test_transaction'
34
+ {
35
+ :paid => false,
36
+ :amount => 100,
37
+ :id => id,
38
+ :object => "transaction",
39
+ :description => 'a description',
40
+ :created => 1304114826,
41
+ :customer => 'c_test_customer'
42
+ }.merge(params)
43
+ end
44
+
45
+ def test_transaction_array
46
+ {
47
+ :data => [test_transaction, test_transaction, test_transaction],
48
+ :object => 'list',
49
+ :url => '/v0/transactions'
50
+ }
51
+ end
52
+
53
+ def test_invoice
54
+ {
55
+ object: "invoice",
56
+ id: "inv_test_invoice",
57
+ summary: nil,
58
+ chase_schedule: [
59
+ "-7",
60
+ "-1",
61
+ "0",
62
+ "1",
63
+ "5",
64
+ "10",
65
+ "15",
66
+ "20",
67
+ "25",
68
+ "30",
69
+ "~1"
70
+ ],
71
+ next_chase_on: nil,
72
+ terms: 30,
73
+ due_date: nil,
74
+ customer: "c_test_customer",
75
+ issued_at: nil
76
+ }
77
+ end
78
+
79
+ def test_invalid_api_key_error
80
+ {
81
+ :error => {
82
+ :type => "invalid_request_error",
83
+ :message => "Invalid API Key provided: invalid"
84
+ }
85
+ }
86
+ end
87
+
88
+ def test_missing_id_error
89
+ {
90
+ :error => {
91
+ :param => "id",
92
+ :type => "invalid_request_error",
93
+ :message => "Missing id"
94
+ }
95
+ }
96
+ end
97
+
98
+ def test_api_error
99
+ {
100
+ :error => {
101
+ :type => "api_error"
102
+ }
103
+ }
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,41 @@
1
+ require 'paid'
2
+ require 'test/unit'
3
+ require 'mocha/setup'
4
+ require 'stringio'
5
+ require 'shoulda'
6
+ require File.expand_path('../test_data', __FILE__)
7
+
8
+ # monkeypatch request methods
9
+ module Paid
10
+ @mock_rest_client = nil
11
+
12
+ def self.mock_rest_client=(mock_client)
13
+ @mock_rest_client = mock_client
14
+ end
15
+
16
+ def self.execute_request(opts)
17
+ get_params = (opts[:headers] || {})[:params]
18
+ post_params = opts[:payload]
19
+ case opts[:method]
20
+ when :get then @mock_rest_client.get opts[:url], get_params, post_params
21
+ when :post then @mock_rest_client.post opts[:url], get_params, post_params
22
+ when :delete then @mock_rest_client.delete opts[:url], get_params, post_params
23
+ end
24
+ end
25
+ end
26
+
27
+ class Test::Unit::TestCase
28
+ include Paid::TestData
29
+ include Mocha
30
+
31
+ setup do
32
+ @mock = mock
33
+ Paid.mock_rest_client = @mock
34
+ Paid.api_key="foo"
35
+ end
36
+
37
+ teardown do
38
+ Paid.mock_rest_client = nil
39
+ Paid.api_key=nil
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Jackson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mime-types
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.25'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '3.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '1.25'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: json
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 1.8.1
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 1.8.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: mocha
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.13.2
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.13.2
75
+ - !ruby/object:Gem::Dependency
76
+ name: shoulda
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 3.4.0
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 3.4.0
89
+ - !ruby/object:Gem::Dependency
90
+ name: test-unit
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rake
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ description: Paid is the programmatic way to manage payments. See https://paidapi.com
118
+ for details.
119
+ email:
120
+ - ryan@paidapi.com
121
+ executables: []
122
+ extensions: []
123
+ extra_rdoc_files: []
124
+ files:
125
+ - Gemfile
126
+ - Gemfile.lock
127
+ - MIT-LICENSE
128
+ - README.rdoc
129
+ - Rakefile
130
+ - lib/data/ca-certificates.crt
131
+ - lib/paid.rb
132
+ - lib/paid/account.rb
133
+ - lib/paid/api_operations/create.rb
134
+ - lib/paid/api_operations/delete.rb
135
+ - lib/paid/api_operations/list.rb
136
+ - lib/paid/api_operations/update.rb
137
+ - lib/paid/api_resource.rb
138
+ - lib/paid/certificate_blacklist.rb
139
+ - lib/paid/customer.rb
140
+ - lib/paid/errors/api_connection_error.rb
141
+ - lib/paid/errors/api_error.rb
142
+ - lib/paid/errors/authentication_error.rb
143
+ - lib/paid/errors/invalid_request_error.rb
144
+ - lib/paid/errors/paid_error.rb
145
+ - lib/paid/event.rb
146
+ - lib/paid/invoice.rb
147
+ - lib/paid/list_object.rb
148
+ - lib/paid/paid_object.rb
149
+ - lib/paid/singleton_api_resource.rb
150
+ - lib/paid/transaction.rb
151
+ - lib/paid/util.rb
152
+ - lib/paid/version.rb
153
+ - lib/tasks/paid_tasks.rake
154
+ - paid.gemspec
155
+ - test/paid/account_test.rb
156
+ - test/paid/api_resource_test.rb
157
+ - test/paid/certificate_blacklist_test.rb
158
+ - test/paid/customer_test.rb
159
+ - test/paid/invoice_test.rb
160
+ - test/paid/list_object_test.rb
161
+ - test/paid/metadata_test.rb
162
+ - test/paid/paid_object_test.rb
163
+ - test/paid/transaction_test.rb
164
+ - test/paid/util_test.rb
165
+ - test/test_data.rb
166
+ - test/test_helper.rb
167
+ homepage: https://docs.paidapi.com
168
+ licenses:
169
+ - MIT
170
+ metadata: {}
171
+ post_install_message:
172
+ rdoc_options: []
173
+ require_paths:
174
+ - lib
175
+ required_ruby_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '0'
180
+ required_rubygems_version: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ requirements: []
186
+ rubyforge_project:
187
+ rubygems_version: 2.4.5
188
+ signing_key:
189
+ specification_version: 4
190
+ summary: Ruby bindings for Paid API
191
+ test_files:
192
+ - test/paid/account_test.rb
193
+ - test/paid/api_resource_test.rb
194
+ - test/paid/certificate_blacklist_test.rb
195
+ - test/paid/customer_test.rb
196
+ - test/paid/invoice_test.rb
197
+ - test/paid/list_object_test.rb
198
+ - test/paid/metadata_test.rb
199
+ - test/paid/paid_object_test.rb
200
+ - test/paid/transaction_test.rb
201
+ - test/paid/util_test.rb
202
+ - test/test_data.rb
203
+ - test/test_helper.rb