saas_runner 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +7 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +22 -0
  7. data/README.md +87 -0
  8. data/Rakefile +10 -0
  9. data/lib/faraday/response/raise_response_error.rb +14 -0
  10. data/lib/saas_runner.rb +14 -0
  11. data/lib/saas_runner/client.rb +66 -0
  12. data/lib/saas_runner/resource/activation.rb +16 -0
  13. data/lib/saas_runner/resource/event.rb +26 -0
  14. data/lib/saas_runner/resource/subscriber.rb +16 -0
  15. data/lib/saas_runner/resource/transaction.rb +21 -0
  16. data/lib/saas_runner/response_error.rb +34 -0
  17. data/lib/saas_runner/version.rb +3 -0
  18. data/saas_runner.gemspec +29 -0
  19. data/spec/cassettes/SaasRunner_Client/activations/should_add_an_activation.yml +54 -0
  20. data/spec/cassettes/SaasRunner_Client/events/should_delete_a_requested_event.yml +99 -0
  21. data/spec/cassettes/SaasRunner_Client/events/should_get_a_single_event.yml +193 -0
  22. data/spec/cassettes/SaasRunner_Client/events/should_show_all_events.yml +142 -0
  23. data/spec/cassettes/SaasRunner_Client/subscribers/should_add_a_subscriber.yml +54 -0
  24. data/spec/cassettes/SaasRunner_Client/transactions/should_charge_a_transaction.yml +54 -0
  25. data/spec/cassettes/SaasRunner_Client/transactions/should_refund_a_transaction.yml +54 -0
  26. data/spec/response_errors_spec.rb +18 -0
  27. data/spec/saas_runner/client_spec.rb +14 -0
  28. data/spec/saas_runner/resource/activation_spec.rb +15 -0
  29. data/spec/saas_runner/resource/event_spec.rb +23 -0
  30. data/spec/saas_runner/resource/subscriber_spec.rb +15 -0
  31. data/spec/saas_runner/resource/transaction_spec.rb +22 -0
  32. data/spec/spec_helper.rb +25 -0
  33. metadata +189 -0
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://api.saasrunner.com/transactions/charge
6
+ body:
7
+ encoding: US-ASCII
8
+ string: transaction%5Bsubscriber_uid%5D=sub1398853218&transaction%5Bamount_in_cents%5D=1000&transaction%5Bcurrency%5D=USD&transaction%5Btransaction_uid%5D=1398853219
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.8
12
+ X-API-Key:
13
+ - 00b4040a-ed54-4524-a33e-f992298383cc
14
+ Content-Type:
15
+ - application/x-www-form-urlencoded
16
+ response:
17
+ status:
18
+ code: 201
19
+ message:
20
+ headers:
21
+ server:
22
+ - nginx/1.4.4
23
+ date:
24
+ - Wed, 30 Apr 2014 10:20:15 GMT
25
+ content-type:
26
+ - application/json; charset=utf-8
27
+ transfer-encoding:
28
+ - chunked
29
+ connection:
30
+ - close
31
+ status:
32
+ - 201 Created
33
+ x-frame-options:
34
+ - SAMEORIGIN
35
+ x-xss-protection:
36
+ - 1; mode=block
37
+ x-content-type-options:
38
+ - nosniff
39
+ x-ua-compatible:
40
+ - chrome=1
41
+ etag:
42
+ - '"820441ed9b259088d304102b49efaa93"'
43
+ cache-control:
44
+ - max-age=0, private, must-revalidate
45
+ x-request-id:
46
+ - 5ebff437-c930-4b01-a5e2-e8a4e695e248
47
+ x-runtime:
48
+ - '0.010185'
49
+ body:
50
+ encoding: UTF-8
51
+ string: '{"transaction":{"id":8355,"subscriber_uid":"sub1398853218","dated_at":"2014-04-30","meta":null,"errors":[],"transaction_uid":"1398853219","amount_in_cents":1000,"currency":"USD"}}'
52
+ http_version:
53
+ recorded_at: Wed, 30 Apr 2014 10:20:18 GMT
54
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://api.saasrunner.com/transactions/refund
6
+ body:
7
+ encoding: US-ASCII
8
+ string: transaction%5Bsubscriber_uid%5D=sub1398853212&transaction%5Bamount_in_cents%5D=1000&transaction%5Bcurrency%5D=USD&transaction%5Btransaction_uid%5D=1398853213
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.8
12
+ X-API-Key:
13
+ - 00b4040a-ed54-4524-a33e-f992298383cc
14
+ Content-Type:
15
+ - application/x-www-form-urlencoded
16
+ response:
17
+ status:
18
+ code: 201
19
+ message:
20
+ headers:
21
+ server:
22
+ - nginx/1.4.4
23
+ date:
24
+ - Wed, 30 Apr 2014 10:20:09 GMT
25
+ content-type:
26
+ - application/json; charset=utf-8
27
+ transfer-encoding:
28
+ - chunked
29
+ connection:
30
+ - close
31
+ status:
32
+ - 201 Created
33
+ x-frame-options:
34
+ - SAMEORIGIN
35
+ x-xss-protection:
36
+ - 1; mode=block
37
+ x-content-type-options:
38
+ - nosniff
39
+ x-ua-compatible:
40
+ - chrome=1
41
+ etag:
42
+ - '"ba5d5d887a7634a5621ab4c5f4ba3782"'
43
+ cache-control:
44
+ - max-age=0, private, must-revalidate
45
+ x-request-id:
46
+ - c2a85a84-080b-4754-a18a-467bab2610bd
47
+ x-runtime:
48
+ - '0.011283'
49
+ body:
50
+ encoding: UTF-8
51
+ string: '{"transaction":{"id":8354,"subscriber_uid":"sub1398853212","dated_at":"2014-04-30","meta":null,"errors":[],"transaction_uid":"1398853213","amount_in_cents":1000,"currency":"USD"}}'
52
+ http_version:
53
+ recorded_at: Wed, 30 Apr 2014 10:20:12 GMT
54
+ recorded_with: VCR 2.9.0
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe SaasRunner::ResponseError do
4
+ let(:params) { ({body: 'Something went wrong', status: '500', method: 'post', url: 'http://example.org/test'}) }
5
+ it 'should have correct response' do
6
+ ex = SaasRunner::ResponseError.new(params).to_s
7
+ expect(ex).to eq("500 POST http://example.org/test | Errors: Something went wrong")
8
+ end
9
+ let(:body) { [Hashie::Mash.new({"field" => "subscriber_uid", "message" => "can't be blank"}), Hashie::Mash.new({"field" => "transaction_uid", "message" => "can't be blank"})] }
10
+ let(:params2) { ({body: body, status: '422', method: 'post', url: 'http://example.com/test'}) }
11
+ it 'should report multiple errors if present' do
12
+ ex = SaasRunner::ResponseError.new(params2).to_s
13
+ expect(ex).to eq("422 POST http://example.com/test | Errors: subscriber_uid can't be blank, transaction_uid can't be blank")
14
+ end
15
+ end
16
+
17
+
18
+
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe SaasRunner::Client, :vcr do
4
+ let(:client) { SaasRunner::Client.new(api_key: "00b4040a-ed54-4524-a33e-f992298383cc") }
5
+
6
+ describe "#initiialize" do
7
+ it "should assign the API key" do
8
+ expect(client.api_key).to eq "00b4040a-ed54-4524-a33e-f992298383cc"
9
+ end
10
+ it "should get the correct API host" do
11
+ expect(client.api_host).to eq "api.saasrunner.com"
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe SaasRunner::Client, :vcr do
4
+ let(:client) { SaasRunner::Client.new(api_key: "00b4040a-ed54-4524-a33e-f992298383cc") }
5
+ let(:subscriber_uid) { "sub#{Time.now.to_i}" }
6
+
7
+
8
+ describe "activations" do
9
+ it "should add an activation" do
10
+ resource = client.activations
11
+ resource.create!(subscriber_uid: subscriber_uid)
12
+ expect(resource.response.status).to eq(201)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe SaasRunner::Client, :vcr do
4
+ let(:client) { SaasRunner::Client.new(api_key: "00b4040a-ed54-4524-a33e-f992298383cc") }
5
+
6
+ describe "events" do
7
+ let(:resource) { client.events }
8
+ it "should show all events" do
9
+ resource.index
10
+ expect(resource.response.status).to eq(200)
11
+ end
12
+ it "should get a single event" do
13
+ event = client.subscribers.create!(subscriber_uid: "event#{Time.now.to_i}")
14
+ resource.show(event.id)
15
+ expect(resource.response.status).to eq(200)
16
+ end
17
+ it "should delete a requested event" do
18
+ event = client.subscribers.create!(subscriber_uid: "event#{Time.now.to_i + 1}")
19
+ resource.destroy!(event.subscriber.id)
20
+ expect(resource.response.status).to eq(204)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe SaasRunner::Client, :vcr do
4
+ let(:client) { SaasRunner::Client.new(api_key: "00b4040a-ed54-4524-a33e-f992298383cc") }
5
+ let(:subscriber_uid) { "sub#{Time.now.to_i}" }
6
+
7
+
8
+ describe "subscribers" do
9
+ it "should add a subscriber" do
10
+ resource = client.subscribers
11
+ resource.create!(subscriber_uid: subscriber_uid)
12
+ expect(resource.response.status).to eq(201)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe SaasRunner::Client, :vcr do
4
+ let(:client) { SaasRunner::Client.new(api_key: "00b4040a-ed54-4524-a33e-f992298383cc") }
5
+ let(:subscriber_uid) { "sub#{Time.now.to_i}" }
6
+ let(:transaction_uid) { "#{Time.now.to_i}" }
7
+ let(:transaction_uid2) { "#{Time.now.to_i + 1}" }
8
+
9
+ describe "transactions" do
10
+ let(:params) { ({ subscriber_uid: subscriber_uid, amount_in_cents: 1000, currency: "USD", transaction_uid: transactionuid} ) }
11
+ let(:resource) { client.transactions }
12
+ it "should charge a transaction" do
13
+ resource.charge!(params)
14
+ expect(resource.response.status).to eq(201)
15
+ end
16
+ let(:params) { ({subscriber_uid: subscriber_uid, amount_in_cents: 1000, currency: "USD", transaction_uid: transaction_uid2} )}
17
+ it "should refund a transaction" do
18
+ resource.refund!(params)
19
+ expect(resource.response.status).to eq(201)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ require 'vcr'
2
+ require 'saas_runner'
3
+
4
+ VCR.configure do |c|
5
+ c.cassette_library_dir = 'spec/cassettes'
6
+ c.hook_into :faraday
7
+ c.default_cassette_options = { record: :new_episodes }
8
+ c.configure_rspec_metadata!
9
+ end
10
+
11
+ RSpec.configure do |config|
12
+ config.filter_run :focus
13
+ config.run_all_when_everything_filtered = true
14
+ config.order = :random
15
+ Kernel.srand config.seed
16
+
17
+ config.expect_with :rspec do |expectations|
18
+ expectations.syntax = :expect
19
+ end
20
+
21
+ config.mock_with :rspec do |mocks|
22
+ mocks.syntax = :expect
23
+ mocks.verify_partial_doubles = true
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: saas_runner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Springett
8
+ - Peter Rhoades
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-09-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.8'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.8'
28
+ - !ruby/object:Gem::Dependency
29
+ name: faraday_middleware
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '0.9'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '0.9'
42
+ - !ruby/object:Gem::Dependency
43
+ name: hashie
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 2.0.5
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 2.0.5
56
+ - !ruby/object:Gem::Dependency
57
+ name: bundler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.3'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.3'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rake
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rspec
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: vcr
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ description: Ruby client library for the Saas Runner REST API
113
+ email:
114
+ - paul@simpleweb.co.uk
115
+ - pete@simpleweb.co.uk
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - ".rspec"
122
+ - ".travis.yml"
123
+ - Gemfile
124
+ - LICENSE
125
+ - README.md
126
+ - Rakefile
127
+ - lib/faraday/response/raise_response_error.rb
128
+ - lib/saas_runner.rb
129
+ - lib/saas_runner/client.rb
130
+ - lib/saas_runner/resource/activation.rb
131
+ - lib/saas_runner/resource/event.rb
132
+ - lib/saas_runner/resource/subscriber.rb
133
+ - lib/saas_runner/resource/transaction.rb
134
+ - lib/saas_runner/response_error.rb
135
+ - lib/saas_runner/version.rb
136
+ - saas_runner.gemspec
137
+ - spec/cassettes/SaasRunner_Client/activations/should_add_an_activation.yml
138
+ - spec/cassettes/SaasRunner_Client/events/should_delete_a_requested_event.yml
139
+ - spec/cassettes/SaasRunner_Client/events/should_get_a_single_event.yml
140
+ - spec/cassettes/SaasRunner_Client/events/should_show_all_events.yml
141
+ - spec/cassettes/SaasRunner_Client/subscribers/should_add_a_subscriber.yml
142
+ - spec/cassettes/SaasRunner_Client/transactions/should_charge_a_transaction.yml
143
+ - spec/cassettes/SaasRunner_Client/transactions/should_refund_a_transaction.yml
144
+ - spec/response_errors_spec.rb
145
+ - spec/saas_runner/client_spec.rb
146
+ - spec/saas_runner/resource/activation_spec.rb
147
+ - spec/saas_runner/resource/event_spec.rb
148
+ - spec/saas_runner/resource/subscriber_spec.rb
149
+ - spec/saas_runner/resource/transaction_spec.rb
150
+ - spec/spec_helper.rb
151
+ homepage: https://github.com/simpleweb/saasrunner-client-ruby
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.2.2
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Ruby client library for the Saas Runner REST API
175
+ test_files:
176
+ - spec/cassettes/SaasRunner_Client/activations/should_add_an_activation.yml
177
+ - spec/cassettes/SaasRunner_Client/events/should_delete_a_requested_event.yml
178
+ - spec/cassettes/SaasRunner_Client/events/should_get_a_single_event.yml
179
+ - spec/cassettes/SaasRunner_Client/events/should_show_all_events.yml
180
+ - spec/cassettes/SaasRunner_Client/subscribers/should_add_a_subscriber.yml
181
+ - spec/cassettes/SaasRunner_Client/transactions/should_charge_a_transaction.yml
182
+ - spec/cassettes/SaasRunner_Client/transactions/should_refund_a_transaction.yml
183
+ - spec/response_errors_spec.rb
184
+ - spec/saas_runner/client_spec.rb
185
+ - spec/saas_runner/resource/activation_spec.rb
186
+ - spec/saas_runner/resource/event_spec.rb
187
+ - spec/saas_runner/resource/subscriber_spec.rb
188
+ - spec/saas_runner/resource/transaction_spec.rb
189
+ - spec/spec_helper.rb