saas_runner 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +87 -0
- data/Rakefile +10 -0
- data/lib/faraday/response/raise_response_error.rb +14 -0
- data/lib/saas_runner.rb +14 -0
- data/lib/saas_runner/client.rb +66 -0
- data/lib/saas_runner/resource/activation.rb +16 -0
- data/lib/saas_runner/resource/event.rb +26 -0
- data/lib/saas_runner/resource/subscriber.rb +16 -0
- data/lib/saas_runner/resource/transaction.rb +21 -0
- data/lib/saas_runner/response_error.rb +34 -0
- data/lib/saas_runner/version.rb +3 -0
- data/saas_runner.gemspec +29 -0
- data/spec/cassettes/SaasRunner_Client/activations/should_add_an_activation.yml +54 -0
- data/spec/cassettes/SaasRunner_Client/events/should_delete_a_requested_event.yml +99 -0
- data/spec/cassettes/SaasRunner_Client/events/should_get_a_single_event.yml +193 -0
- data/spec/cassettes/SaasRunner_Client/events/should_show_all_events.yml +142 -0
- data/spec/cassettes/SaasRunner_Client/subscribers/should_add_a_subscriber.yml +54 -0
- data/spec/cassettes/SaasRunner_Client/transactions/should_charge_a_transaction.yml +54 -0
- data/spec/cassettes/SaasRunner_Client/transactions/should_refund_a_transaction.yml +54 -0
- data/spec/response_errors_spec.rb +18 -0
- data/spec/saas_runner/client_spec.rb +14 -0
- data/spec/saas_runner/resource/activation_spec.rb +15 -0
- data/spec/saas_runner/resource/event_spec.rb +23 -0
- data/spec/saas_runner/resource/subscriber_spec.rb +15 -0
- data/spec/saas_runner/resource/transaction_spec.rb +22 -0
- data/spec/spec_helper.rb +25 -0
- metadata +189 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 67a6f0c7c6583703dda6d1ae28dafa1be6ff9ced
|
4
|
+
data.tar.gz: 0d53a46109465f0e668d2a4424d6fbacf2902192
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 14dfa1de39f3c122a20ec61385bc1190ac94c32f355cc7adb01a062fe653273fe47f551c772347b264d5fdbd18c12e01024ba1e70e2aa1656dbd8caa4b26f57e
|
7
|
+
data.tar.gz: e4ad8430d1d14f0098d59d17c9749299460ea253212d498eb3a87c5fce4a8075cbb88ddeda962a4703c7041ad0f8842fd54b1815728aa3a5cdd68a9097a4decc
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Simpleweb Ltd
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# SaasRunner
|
2
|
+
|
3
|
+
[](https://travis-ci.org/simpleweb/saasrunner-client-ruby)
|
4
|
+
|
5
|
+
Ruby client library for the SaaS Runner REST API
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'saas_runner'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install saas_runner
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Refer to the [SaaS Runner API docs](http://docs.saasrunner.apiary.io/) for more information on the API.
|
24
|
+
|
25
|
+
First create a new client object with your SaaS Runner API key
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
client = SaasRunner::Client.new(api_key: 'YOUR API KEY')
|
29
|
+
```
|
30
|
+
|
31
|
+
And then call the relevant resource
|
32
|
+
|
33
|
+
### Subscribers
|
34
|
+
|
35
|
+
Create a new subscriber
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
client.subscribers.create!(subscriber_uid: 'ABC123')
|
39
|
+
```
|
40
|
+
|
41
|
+
### Transactions
|
42
|
+
|
43
|
+
Create a new transaction charge using the three digit letter code for the currency (eg USD or GBP)
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
client.transactions.charge!(subscriber_uid: 'ABC123', transaction_uid: '123', amount_in_cents: 1000, currency: 'USD')
|
47
|
+
```
|
48
|
+
|
49
|
+
Create a new transaction refund
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
client.transactions.refund!(subscriber_uid: 'ABC123', transaction_uid: '124', amount_in_cents: 150, currecny: 'USD')
|
53
|
+
```
|
54
|
+
|
55
|
+
### Activations
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
client.activations.create!(subscriber_uid: 'ABC123')
|
59
|
+
```
|
60
|
+
|
61
|
+
### Events
|
62
|
+
|
63
|
+
List all events
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
client.events.index
|
67
|
+
```
|
68
|
+
|
69
|
+
List a single event
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
client.events.show(568)
|
73
|
+
```
|
74
|
+
|
75
|
+
Delete an event
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
client.events.destroy!(568)
|
79
|
+
```
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
|
83
|
+
1. Fork it
|
84
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
85
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
86
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
87
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'saas_runner/response_error'
|
3
|
+
|
4
|
+
module Faraday
|
5
|
+
class Response::RaiseResponseError < Response::Middleware
|
6
|
+
def on_complete(env)
|
7
|
+
status = env[:status].to_i
|
8
|
+
|
9
|
+
if (400..599).include?(status)
|
10
|
+
raise SaasRunner::ResponseError.new(env)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/saas_runner.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'saas_runner/version'
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
require 'faraday'
|
5
|
+
require 'faraday_middleware'
|
6
|
+
require 'hashie/mash'
|
7
|
+
|
8
|
+
require 'faraday/response/raise_response_error'
|
9
|
+
|
10
|
+
require 'saas_runner/client'
|
11
|
+
require 'saas_runner/resource/subscriber'
|
12
|
+
require 'saas_runner/resource/transaction'
|
13
|
+
require 'saas_runner/resource/activation'
|
14
|
+
require 'saas_runner/resource/event'
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module SaasRunner
|
2
|
+
class Client
|
3
|
+
attr_reader :api_key, :api_host
|
4
|
+
|
5
|
+
def initialize(options = {})
|
6
|
+
@api_key = options.fetch(:api_key)
|
7
|
+
@api_host = options.fetch(:api_host, 'api.saasrunner.com')
|
8
|
+
end
|
9
|
+
|
10
|
+
# Public: Access the subscribers resource
|
11
|
+
#
|
12
|
+
# Returns a Resource::Subscriber
|
13
|
+
def subscribers
|
14
|
+
@subscribers ||= Resource::Subscriber.new(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
def transactions
|
18
|
+
@transactions ||= Resource::Transaction.new(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
def activations
|
22
|
+
@activations ||= Resource::Activation.new(self)
|
23
|
+
end
|
24
|
+
|
25
|
+
def events
|
26
|
+
@events ||= Resource::Event.new(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
def get(path, params)
|
30
|
+
request(:get, path, params)
|
31
|
+
end
|
32
|
+
|
33
|
+
def post(path, body)
|
34
|
+
request(:post, path, {}, body)
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete(path, params)
|
38
|
+
request(:delete, path, params)
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def request(method, path, params = {}, body = {})
|
44
|
+
connection.send(method) do |request|
|
45
|
+
request.headers['X-API-Key'] = api_key
|
46
|
+
request.params = params
|
47
|
+
request.body = body
|
48
|
+
|
49
|
+
request.url(path)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def connection
|
54
|
+
@connection ||= Faraday.new(url: "http://#{api_host}") do |builder|
|
55
|
+
builder.request :url_encoded
|
56
|
+
|
57
|
+
builder.use Faraday::Response::RaiseResponseError
|
58
|
+
|
59
|
+
builder.use FaradayMiddleware::Mashify
|
60
|
+
builder.use FaradayMiddleware::ParseJson, content_type: /\bjson$/
|
61
|
+
|
62
|
+
builder.adapter :net_http
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SaasRunner
|
2
|
+
module Resource
|
3
|
+
class Activation
|
4
|
+
attr_reader :client, :response
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def create!(params = {})
|
11
|
+
@response = client.post('/activations', { activation: params })
|
12
|
+
@response.body
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SaasRunner
|
2
|
+
module Resource
|
3
|
+
class Event
|
4
|
+
attr_reader :client, :response
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def index(params = {})
|
11
|
+
@response = client.get('/events', params)
|
12
|
+
@response.body
|
13
|
+
end
|
14
|
+
|
15
|
+
def show(id, params = {})
|
16
|
+
@response = client.get("/events/#{id}", params)
|
17
|
+
@response.body
|
18
|
+
end
|
19
|
+
|
20
|
+
def destroy!(id, params = {})
|
21
|
+
@response = client.delete("/events/#{id}", params)
|
22
|
+
@response.body
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SaasRunner
|
2
|
+
module Resource
|
3
|
+
class Subscriber
|
4
|
+
attr_reader :client, :response
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def create!(params = {})
|
11
|
+
@response = client.post('/subscribers', { subscriber: params })
|
12
|
+
@response.body
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SaasRunner
|
2
|
+
module Resource
|
3
|
+
class Transaction
|
4
|
+
attr_reader :client, :response
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
def charge!(params = {})
|
11
|
+
@response = client.post('/transactions/charge', { transaction: params })
|
12
|
+
@response.body
|
13
|
+
end
|
14
|
+
|
15
|
+
def refund!(params = {})
|
16
|
+
@response = client.post('/transactions/refund', { transaction: params })
|
17
|
+
@response.body
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module SaasRunner
|
2
|
+
class ResponseError < StandardError
|
3
|
+
attr_reader :response, :body, :status, :method, :url
|
4
|
+
|
5
|
+
def initialize(response = nil)
|
6
|
+
@response = response
|
7
|
+
|
8
|
+
@body = response[:body]
|
9
|
+
@status = response[:status].to_i
|
10
|
+
@method = response[:method].to_s.upcase
|
11
|
+
@url = response[:url]
|
12
|
+
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
"#{status} #{method} #{url} | Errors: #{errors}"
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def errors
|
23
|
+
return body if body.kind_of?(String)
|
24
|
+
|
25
|
+
messages = []
|
26
|
+
|
27
|
+
body.each do |error|
|
28
|
+
messages.push "#{error.field} #{error.message}"
|
29
|
+
end
|
30
|
+
|
31
|
+
messages.join(', ')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/saas_runner.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'saas_runner/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "saas_runner"
|
8
|
+
spec.version = SaasRunner::VERSION
|
9
|
+
spec.authors = ["Paul Springett", "Peter Rhoades"]
|
10
|
+
spec.email = ["paul@simpleweb.co.uk", "pete@simpleweb.co.uk"]
|
11
|
+
spec.description = %q{Ruby client library for the Saas Runner REST API}
|
12
|
+
spec.summary = %q{Ruby client library for the Saas Runner REST API}
|
13
|
+
spec.homepage = "https://github.com/simpleweb/saasrunner-client-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "faraday", "~> 0.8"
|
22
|
+
spec.add_dependency "faraday_middleware", "~> 0.9"
|
23
|
+
spec.add_dependency "hashie", "~> 2.0.5"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
spec.add_development_dependency "rspec"
|
28
|
+
spec.add_development_dependency "vcr"
|
29
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: http://api.saasrunner.com/activations
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: activation%5Bsubscriber_uid%5D=sub1398853222
|
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:18 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
|
+
- '"4ae4e39e2a9ce0e906cd85f2b6d0a61f"'
|
43
|
+
cache-control:
|
44
|
+
- max-age=0, private, must-revalidate
|
45
|
+
x-request-id:
|
46
|
+
- a11e57fe-c778-447e-8bba-6898719ee698
|
47
|
+
x-runtime:
|
48
|
+
- '0.009839'
|
49
|
+
body:
|
50
|
+
encoding: UTF-8
|
51
|
+
string: '{"activation":{"id":8356,"subscriber_uid":"sub1398853222","dated_at":"2014-04-30","meta":null,"errors":[]}}'
|
52
|
+
http_version:
|
53
|
+
recorded_at: Wed, 30 Apr 2014 10:20:22 GMT
|
54
|
+
recorded_with: VCR 2.9.0
|