armor_payments 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.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +4 -0
  7. data/Guardfile +15 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +115 -0
  10. data/Rakefile +1 -0
  11. data/armor_payments.gemspec +30 -0
  12. data/lib/armor_payments.rb +5 -0
  13. data/lib/armor_payments/api.rb +44 -0
  14. data/lib/armor_payments/api/accounts.rb +19 -0
  15. data/lib/armor_payments/api/bankaccounts.rb +10 -0
  16. data/lib/armor_payments/api/disputes.rb +17 -0
  17. data/lib/armor_payments/api/documents.rb +10 -0
  18. data/lib/armor_payments/api/notes.rb +10 -0
  19. data/lib/armor_payments/api/offers.rb +18 -0
  20. data/lib/armor_payments/api/orderevents.rb +5 -0
  21. data/lib/armor_payments/api/orders.rb +39 -0
  22. data/lib/armor_payments/api/paymentinstructions.rb +5 -0
  23. data/lib/armor_payments/api/resource.rb +44 -0
  24. data/lib/armor_payments/api/shipments.rb +10 -0
  25. data/lib/armor_payments/api/users.rb +10 -0
  26. data/lib/armor_payments/authenticator.rb +30 -0
  27. data/lib/armor_payments/version.rb +3 -0
  28. data/spec/armor_payments/api/accounts_spec.rb +29 -0
  29. data/spec/armor_payments/api/disputes_spec.rb +20 -0
  30. data/spec/armor_payments/api/documents_spec.rb +19 -0
  31. data/spec/armor_payments/api/notes_spec.rb +19 -0
  32. data/spec/armor_payments/api/offers_spec.rb +20 -0
  33. data/spec/armor_payments/api/orders_spec.rb +30 -0
  34. data/spec/armor_payments/api/resource_spec.rb +78 -0
  35. data/spec/armor_payments/api/users_spec.rb +20 -0
  36. data/spec/armor_payments/api_spec.rb +24 -0
  37. data/spec/armor_payments/authenticator_spec.rb +51 -0
  38. data/spec/spec_helper.rb +25 -0
  39. metadata +204 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e9ae49ac2caa04bfb73d0346bd9c92b84fe4f0e1
4
+ data.tar.gz: 29ea37edd11f94a17a774d916313d595aee355ee
5
+ SHA512:
6
+ metadata.gz: 00d147bcaf1634320188c2baa9a01c1667646a7a44a6dfc863ed1b874069069e649f9b36b426f047fb7d65c932861395e3c1a8f2c9ce601225ee407559ef1624
7
+ data.tar.gz: 303ddf688969c99d82361b6f53166f3fb969a4640583061a425b6410e4473578e4e69c152027d797bd2d03a9b454f59465e24d5113a3c43b0dbdf417fc8e208d
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ armor_payments
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in armor_payments.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,15 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :bundler do
5
+ watch('Gemfile')
6
+ watch(/^.+\.gemspec/)
7
+ end
8
+
9
+ guard :rspec do
10
+ watch(%r{^spec/.+_spec\.rb$})
11
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
12
+ watch('spec/spec_helper.rb') { "spec" }
13
+
14
+ end
15
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Matt Wilson
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,115 @@
1
+ # ArmorPayments
2
+
3
+ This is intended to be a clean, idiomatic client for the [Armor Payments API](http://armorpayments.com/api/index.html). This will handle generating the authenticated headers and constructing the properly nested request URI, as well as parsing any response JSON for you.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'armor_payments'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install armor_payments
18
+
19
+ ## Usage
20
+
21
+ The Armor Payments API is REST-ish and nested, so the client relies on chaining. We return an `Excon::Response` object, with the added nice-ness that we've parsed the JSON response body for you if possible.
22
+
23
+ ```ruby
24
+ require 'armor_payments'
25
+
26
+ client = ArmorPayments::API.new 'your-key', 'your-secret', should_use_sandbox
27
+
28
+ # There are three top-level resources: accounts, users, and orders
29
+ # Querying users and orders requires an account_id
30
+
31
+ client.accounts.all
32
+ client.accounts.get(account_id)
33
+
34
+ client.users(account_id).all
35
+ client.users(account_id).get(user_id)
36
+
37
+ client.orders(account_id).all
38
+ client.orders(account_id).get(order_id)
39
+
40
+ # From accounts, we chain bank accounts
41
+
42
+ client.accounts.bankaccounts(account_id).all
43
+ client.accounts.bankaccounts(account_id).get(bank_account_id)
44
+
45
+ # From orders, many things chain: documents, notes, disputes, shipments, payment instructions, order events
46
+
47
+ client.orders(account_id).documents(order_id).all
48
+ client.orders(account_id).documents(order_id).get(document_id)
49
+
50
+ client.orders(account_id).notes(order_id).all
51
+ client.orders(account_id).notes(order_id).get(note_id)
52
+
53
+ client.orders(account_id).disputes(order_id).all
54
+ client.orders(account_id).disputes(order_id).get(dispute_id)
55
+
56
+ client.orders(account_id).shipments(order_id).all
57
+ client.orders(account_id).shipments(order_id).get(shipment_id)
58
+
59
+ client.orders(account_id).paymentinstructions(order_id).all
60
+
61
+ client.orders(account_id).orderevents(order_id).all
62
+ client.orders(account_id).orderevents(order_id).get(event_id)
63
+
64
+ # From disputes, further things chain: documents, notes, offers
65
+
66
+ client.orders(account_id).disputes(order_id).documents(dispute_id).all
67
+ client.orders(account_id).disputes(order_id).documents(dispute_id).get(document_id)
68
+
69
+ client.orders(account_id).disputes(order_id).notes(dispute_id).all
70
+ client.orders(account_id).disputes(order_id).notes(dispute_id).get(note_id)
71
+
72
+ client.orders(account_id).disputes(order_id).offers(dispute_id).all
73
+ client.orders(account_id).disputes(order_id).offers(dispute_id).get(offer_id)
74
+
75
+ # From offers, documents and notes chain
76
+
77
+ client.orders(account_id).disputes(order_id).offers(dispute_id).
78
+ documents(offer_id).all
79
+ client.orders(account_id).disputes(order_id).offers(dispute_id).
80
+ documents(offer_id).get(document_id)
81
+
82
+ client.orders(account_id).disputes(order_id).offers(dispute_id).
83
+ notes(offer_id).all
84
+ client.orders(account_id).disputes(order_id).offers(dispute_id).
85
+ notes(offer_id).get(note_id)
86
+ ```
87
+
88
+ Some of the resource endpoints support Create/Update `POST` operations, and this client aims to support those as well:
89
+
90
+ ```ruby
91
+ client.accounts.create(your_data)
92
+ client.accounts.update(account_id, your_data)
93
+
94
+ client.accounts.bankaccounts(account_id).create(your_data)
95
+
96
+ client.orders(account_id).create(your_data)
97
+
98
+ client.orders(account_id).shipments(order_id).create(your_data)
99
+
100
+ client.{object-path}.documents.create(your_data)
101
+
102
+ client.{object-path}.notes.create(your_data)
103
+
104
+ client.{object-path}.orders.update(order_id, your_data)
105
+
106
+ client.{object-path}.offers.update(offer_id, your_data)
107
+ ```
108
+
109
+ ## Contributing
110
+
111
+ 1. Fork it
112
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
113
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
114
+ 4. Push to the branch (`git push origin my-new-feature`)
115
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'armor_payments/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "armor_payments"
8
+ spec.version = ArmorPayments::VERSION
9
+ spec.authors = ["Matt Wilson"]
10
+ spec.email = ["mhw@hypomodern.com"]
11
+ spec.description = 'Ruby gem for interacting with Armor Payments.'
12
+ spec.summary = 'Ruby gem for interacting with Armor Payments.'
13
+ spec.homepage = "http://github.com/hypomodern/armor_payments"
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_development_dependency 'bundler', "~> 1.3"
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'guard-rspec'
25
+ spec.add_development_dependency 'guard-bundler'
26
+ spec.add_development_dependency 'vcr'
27
+ spec.add_development_dependency 'timecop'
28
+
29
+ spec.add_dependency 'excon'
30
+ end
@@ -0,0 +1,5 @@
1
+ require 'armor_payments/version'
2
+ require 'armor_payments/api'
3
+
4
+ module ArmorPayments
5
+ end
@@ -0,0 +1,44 @@
1
+ require 'excon'
2
+ require 'json'
3
+ require 'armor_payments/authenticator'
4
+ require 'armor_payments/api/resource'
5
+ require 'armor_payments/api/accounts'
6
+ require 'armor_payments/api/orders'
7
+ require 'armor_payments/api/documents'
8
+ require 'armor_payments/api/notes'
9
+ require 'armor_payments/api/disputes'
10
+ require 'armor_payments/api/offers'
11
+ require 'armor_payments/api/users'
12
+ require 'armor_payments/api/paymentinstructions'
13
+ require 'armor_payments/api/shipments'
14
+ require 'armor_payments/api/orderevents'
15
+ require 'armor_payments/api/bankaccounts'
16
+
17
+ module ArmorPayments
18
+ class API
19
+
20
+ attr_accessor :authenticator, :sandbox
21
+
22
+ def initialize api_key, api_secret, sandbox = false
23
+ self.authenticator = ArmorPayments::Authenticator.new(api_key, api_secret)
24
+ self.sandbox = sandbox
25
+ end
26
+
27
+ def armor_host
28
+ "https://#{sandbox ? 'sandbox' : 'api'}.armorpayments.com"
29
+ end
30
+
31
+ def accounts
32
+ @accounts ||= ArmorPayments::Accounts.new(armor_host, authenticator, '')
33
+ end
34
+
35
+ def orders account_id
36
+ ArmorPayments::Orders.new(armor_host, authenticator, accounts.uri(account_id))
37
+ end
38
+
39
+ def users account_id
40
+ ArmorPayments::Users.new(armor_host, authenticator, accounts.uri(account_id))
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,19 @@
1
+ module ArmorPayments
2
+ class Accounts < Resource
3
+
4
+ def create data
5
+ headers = authenticator.secure_headers 'post', uri
6
+ request :post, { path: uri, headers: headers, body: JSON.generate(data) }
7
+ end
8
+
9
+ def update account_id, data
10
+ headers = authenticator.secure_headers 'post', uri(account_id)
11
+ request :post, { path: uri(account_id), headers: headers, body: JSON.generate(data) }
12
+ end
13
+
14
+ def bankaccounts account_id
15
+ ArmorPayments::BankAccounts.new(host, authenticator, uri(account_id))
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,10 @@
1
+ module ArmorPayments
2
+ class BankAccounts < Resource
3
+
4
+ def create data
5
+ headers = authenticator.secure_headers 'post', uri
6
+ request :post, { path: uri, headers: headers, body: JSON.generate(data) }
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ module ArmorPayments
2
+ class Disputes < Resource
3
+
4
+ def documents dispute_id
5
+ ArmorPayments::Documents.new(host, authenticator, uri(dispute_id))
6
+ end
7
+
8
+ def notes dispute_id
9
+ ArmorPayments::Notes.new(host, authenticator, uri(dispute_id))
10
+ end
11
+
12
+ def offers dispute_id
13
+ ArmorPayments::Offers.new(host, authenticator, uri(dispute_id))
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ module ArmorPayments
2
+ class Documents < Resource
3
+
4
+ def create data
5
+ headers = authenticator.secure_headers 'post', uri
6
+ request :post, { path: uri, headers: headers, body: JSON.generate(data) }
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module ArmorPayments
2
+ class Notes < Resource
3
+
4
+ def create data
5
+ headers = authenticator.secure_headers 'post', uri
6
+ request :post, { path: uri, headers: headers, body: JSON.generate(data) }
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ module ArmorPayments
2
+ class Offers < Resource
3
+
4
+ def update offer_id, data
5
+ headers = authenticator.secure_headers 'post', uri(offer_id)
6
+ request :post, { path: uri(offer_id), headers: headers, body: JSON.generate(data) }
7
+ end
8
+
9
+ def documents offer_id
10
+ ArmorPayments::Documents.new(host, authenticator, uri(offer_id))
11
+ end
12
+
13
+ def notes offer_id
14
+ ArmorPayments::Notes.new(host, authenticator, uri(offer_id))
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module ArmorPayments
2
+ class OrderEvents < Resource
3
+
4
+ end
5
+ end
@@ -0,0 +1,39 @@
1
+ module ArmorPayments
2
+ class Orders < Resource
3
+
4
+ def create data
5
+ headers = authenticator.secure_headers 'post', uri
6
+ request :post, { path: uri, headers: headers, body: JSON.generate(data) }
7
+ end
8
+
9
+ def update order_id, data
10
+ headers = authenticator.secure_headers 'post', uri(order_id)
11
+ request :post, { path: uri(order_id), headers: headers, body: JSON.generate(data) }
12
+ end
13
+
14
+ def documents order_id
15
+ ArmorPayments::Documents.new(host, authenticator, uri(order_id))
16
+ end
17
+
18
+ def notes order_id
19
+ ArmorPayments::Notes.new(host, authenticator, uri(order_id))
20
+ end
21
+
22
+ def disputes order_id
23
+ ArmorPayments::Disputes.new(host, authenticator, uri(order_id))
24
+ end
25
+
26
+ def orderevents order_id
27
+ ArmorPayments::OrderEvents.new(host, authenticator, uri(order_id))
28
+ end
29
+
30
+ def paymentinstructions order_id
31
+ ArmorPayments::PaymentInstructions.new(host, authenticator, uri(order_id))
32
+ end
33
+
34
+ def shipments order_id
35
+ ArmorPayments::Shipments.new(host, authenticator, uri(order_id))
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ module ArmorPayments
2
+ class PaymentInstructions < Resource
3
+
4
+ end
5
+ end
@@ -0,0 +1,44 @@
1
+ module ArmorPayments
2
+ class Resource
3
+ attr_accessor :host, :authenticator, :uri_root
4
+
5
+ def initialize host, authenticator, uri_root
6
+ self.host = host
7
+ self.authenticator = authenticator
8
+ self.uri_root = uri_root
9
+ end
10
+
11
+ def connection
12
+ @connection ||= Excon.new(host, headers: { 'Accept' => 'application/json' })
13
+ end
14
+
15
+ def resource_name
16
+ self.class.to_s.downcase.split('::').last
17
+ end
18
+
19
+ def uri object_id = nil
20
+ base = "#{uri_root}/#{resource_name}"
21
+ base += "/#{object_id}" if object_id
22
+ base
23
+ end
24
+
25
+ # If possible, parse the JSON
26
+ def request method, params
27
+ response = connection.send(method, params)
28
+ if response.get_header('Content-Type') =~ /json/i
29
+ response.body = JSON.parse response.body
30
+ end
31
+ response
32
+ end
33
+
34
+ def all
35
+ headers = authenticator.secure_headers 'get', uri
36
+ request :get, { path: uri, headers: headers }
37
+ end
38
+
39
+ def get object_id
40
+ headers = authenticator.secure_headers 'get', uri(object_id)
41
+ request :get, { path: uri(object_id), headers: headers }
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,10 @@
1
+ module ArmorPayments
2
+ class Shipments < Resource
3
+
4
+ def create data
5
+ headers = authenticator.secure_headers 'post', uri
6
+ request :post, { path: uri, headers: headers, body: JSON.generate(data) }
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module ArmorPayments
2
+ class Users < Resource
3
+
4
+ def update user_id, data
5
+ headers = authenticator.secure_headers 'post', uri(user_id)
6
+ request :post, { path: uri(user_id), headers: headers, body: JSON.generate(data) }
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,30 @@
1
+ require 'digest/sha2'
2
+
3
+ module ArmorPayments
4
+ class Authenticator
5
+
6
+ attr_accessor :api_key, :api_secret
7
+
8
+ def initialize key, secret
9
+ self.api_key = key
10
+ self.api_secret = secret
11
+ end
12
+
13
+ def secure_headers method, uri
14
+ {
15
+ 'x-armorpayments-apikey' => api_key,
16
+ 'x-armorpayments-requesttimestamp' => current_timestamp,
17
+ 'x-armorpayments-signature' => request_signature(method, uri)
18
+ }
19
+ end
20
+
21
+ def current_timestamp
22
+ Time.now.utc.iso8601
23
+ end
24
+
25
+ def request_signature method, uri
26
+ Digest::SHA512.hexdigest "#{api_secret}:#{method.to_s.upcase}:#{uri}:#{current_timestamp}"
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module ArmorPayments
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ module ArmorPayments
4
+ describe Accounts do
5
+ let(:authenticator) { Authenticator.new('my-api-key', 'my-secret-code') }
6
+ let(:host) { 'https://sandbox.armorpayments.com' }
7
+ let(:accounts) { Accounts.new(host, authenticator, '') }
8
+
9
+ describe "#uri" do
10
+ it "returns '/accounts' if given no id" do
11
+ accounts.uri.should == '/accounts'
12
+ end
13
+
14
+ it "returns '/accounts/:id' if given an id" do
15
+ accounts.uri(456).should == '/accounts/456'
16
+ end
17
+ end
18
+
19
+ describe "#create" do
20
+
21
+ it "makes POST with /accounts and JSONified data" do
22
+ accounts.should_receive(:request).with( :post, hash_including(path: '/accounts', body: '{"name":"Bobby Lee"}'))
23
+ accounts.create({ 'name' => 'Bobby Lee'})
24
+ end
25
+
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ module ArmorPayments
4
+ describe Disputes do
5
+ let(:authenticator) { Authenticator.new('my-api-key', 'my-secret-code') }
6
+ let(:host) { 'https://sandbox.armorpayments.com' }
7
+ let(:disputes) { Disputes.new(host, authenticator, '/accounts/1234/orders/56') }
8
+
9
+ describe "#uri" do
10
+ it "returns '/accounts/:aid/orders/:oid/disputes' if given no id" do
11
+ disputes.uri.should == '/accounts/1234/orders/56/disputes'
12
+ end
13
+
14
+ it "returns '/accounts/:aid/disputes/:dispute_id' if given an id" do
15
+ disputes.uri(78).should == '/accounts/1234/orders/56/disputes/78'
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ module ArmorPayments
4
+ describe Documents do
5
+ let(:authenticator) { Authenticator.new('my-api-key', 'my-secret-code') }
6
+ let(:host) { 'https://sandbox.armorpayments.com' }
7
+ let(:documents) { Documents.new(host, authenticator, '/accounts/123/orders/456') }
8
+
9
+ describe "#create" do
10
+
11
+ it "makes POST with the right uri and JSONified data" do
12
+ documents.should_receive(:request).with( :post, hash_including(path: '/accounts/123/orders/456/documents', body: '{"name":"Bobby Lee"}'))
13
+ documents.create({ 'name' => 'Bobby Lee'})
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ module ArmorPayments
4
+ describe Notes do
5
+ let(:authenticator) { Authenticator.new('my-api-key', 'my-secret-code') }
6
+ let(:host) { 'https://sandbox.armorpayments.com' }
7
+ let(:notes) { Notes.new(host, authenticator, '/accounts/123/orders/456') }
8
+
9
+ describe "#create" do
10
+
11
+ it "makes POST with the right uri and JSONified data" do
12
+ notes.should_receive(:request).with( :post, hash_including(path: '/accounts/123/orders/456/notes', body: '{"name":"Bobby Lee"}'))
13
+ notes.create({ 'name' => 'Bobby Lee'})
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ module ArmorPayments
4
+ describe Offers do
5
+ let(:authenticator) { Authenticator.new('my-api-key', 'my-secret-code') }
6
+ let(:host) { 'https://sandbox.armorpayments.com' }
7
+ let(:offers) { Offers.new(host, authenticator, '/accounts/1234') }
8
+
9
+ describe "#update" do
10
+ it "makes POST with the right uri and JSONified data" do
11
+ offers.should_receive(:request).with(
12
+ :post,
13
+ hash_including(path: '/accounts/1234/offers/90', body: '{"name":"Bobby Lee"}')
14
+ )
15
+ offers.update(90, { 'name' => 'Bobby Lee'})
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ module ArmorPayments
4
+ describe Orders do
5
+ let(:authenticator) { Authenticator.new('my-api-key', 'my-secret-code') }
6
+ let(:host) { 'https://sandbox.armorpayments.com' }
7
+ let(:orders) { Orders.new(host, authenticator, '/accounts/1234') }
8
+
9
+ describe "#uri" do
10
+ it "returns '/accounts/:aid/orders' if given no id" do
11
+ orders.uri.should == '/accounts/1234/orders'
12
+ end
13
+
14
+ it "returns '/accounts/:aid/orders/:order_id' if given an id" do
15
+ orders.uri(456).should == '/accounts/1234/orders/456'
16
+ end
17
+ end
18
+
19
+ describe "#update" do
20
+ it "makes POST with the right uri and JSONified data" do
21
+ orders.should_receive(:request).with(
22
+ :post,
23
+ hash_including(path: '/accounts/1234/orders/90', body: '{"name":"Bobby Lee"}')
24
+ )
25
+ orders.update(90, { 'name' => 'Bobby Lee'})
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ module ArmorPayments
4
+ describe Resource do
5
+ let(:authenticator) { Authenticator.new('my-api-key', 'my-secret-code') }
6
+ let(:host) { 'https://sandbox.armorpayments.com' }
7
+ let(:uri_root) { '/wibble/123' }
8
+ let(:resource) { Resource.new(host, authenticator, uri_root) }
9
+ let(:successful_response) { Excon::Response.new(status: 200, body: '{"whee":42}', headers: { 'Content-Type' => 'application/json' }) }
10
+
11
+ describe "#uri" do
12
+ it "returns '/%{uri_root}/resource_name' if given no id" do
13
+ resource.uri.should == '/wibble/123/resource'
14
+ end
15
+
16
+ it "returns '/%{uri_root}/resource_name/:id' if given an id" do
17
+ resource.uri(456).should == '/wibble/123/resource/456'
18
+ end
19
+ end
20
+
21
+ describe "#request" do
22
+ context "on a response with a JSON body" do
23
+ it "returns the parsed JSON body" do
24
+ resource.connection.stub(:get).and_return(successful_response)
25
+ response = resource.request('get', {})
26
+ response.body.should == { 'whee' => 42 }
27
+ end
28
+ end
29
+
30
+ context "on a response without JSON" do
31
+ it "returns the full response object" do
32
+ failed_response = Excon::Response.new(status: 502, body: 'Gateway Timeout')
33
+ resource.connection.stub(:get).and_return(failed_response)
34
+ response = resource.request('get', {})
35
+ response.body.should == 'Gateway Timeout'
36
+ end
37
+ end
38
+ end
39
+
40
+ context "smoketest" do
41
+ describe "#all" do
42
+ it "queries the host for all of the resources, with approprate headers" do
43
+ Timecop.freeze(2014, 2, 22, 12, 0, 0) do
44
+ resource.connection.should_receive(:get).with({
45
+ path: '/wibble/123/resource',
46
+ headers: {
47
+ "X_ARMORPAYMENTS_APIKEY" => "my-api-key",
48
+ "X_ARMORPAYMENTS_REQUESTTIMESTAMP" => "2014-02-22T17:00:00Z",
49
+ "X_ARMORPAYMENTS_SIGNATURE" => "ec41629dc204b449c71bf89d1be4630f5353e37869197f5a926539f6fc676ebcccdb5426fb3f01a01fa7dc9551d38d152e41294a5147b15e460d09ff60cf1562"
50
+ }
51
+ }).and_return(successful_response)
52
+
53
+ resource.all
54
+ end
55
+ end
56
+ end
57
+
58
+ describe "#get" do
59
+ it "queries the host for a specific resource, with approprate headers" do
60
+ Timecop.freeze(2014, 2, 22, 12, 0, 0) do
61
+ resource.connection.should_receive(:get).with({
62
+ path: '/wibble/123/resource/456',
63
+ headers: {
64
+ "X_ARMORPAYMENTS_APIKEY" => "my-api-key",
65
+ "X_ARMORPAYMENTS_REQUESTTIMESTAMP" => "2014-02-22T17:00:00Z",
66
+ "X_ARMORPAYMENTS_SIGNATURE" => "48886620cfebb95ffd9ee351f4f68d4f103a8f4bdc0e3301f7ee709ec2cf3c19588ae1b67aa8ee38305de802651fb10093cf1af40f467ac936185d551a58a844"
67
+ }
68
+ }).and_return(successful_response)
69
+
70
+ resource.get(456)
71
+ end
72
+ end
73
+ end
74
+
75
+ end
76
+
77
+ end
78
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ module ArmorPayments
4
+ describe Users do
5
+ let(:authenticator) { Authenticator.new('my-api-key', 'my-secret-code') }
6
+ let(:host) { 'https://sandbox.armorpayments.com' }
7
+ let(:users) { Users.new(host, authenticator, '/accounts/1234') }
8
+
9
+ describe "#uri" do
10
+ it "returns '/users' if given no id" do
11
+ users.uri.should == '/accounts/1234/users'
12
+ end
13
+
14
+ it "returns '/users/:id' if given an id" do
15
+ users.uri(456).should == '/accounts/1234/users/456'
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ module ArmorPayments
4
+ describe API do
5
+ let(:client) { ArmorPayments::API.new('my-key', 'my-secret', true) }
6
+
7
+ describe "#armor_host" do
8
+ context "in sandbox mode" do
9
+ it "returns https://sandbox.armorpayments.com" do
10
+ client.sandbox.should be_true
11
+ client.armor_host.should == "https://sandbox.armorpayments.com"
12
+ end
13
+ end
14
+
15
+ context "*not* in sandbox mode" do
16
+ it "returns https://api.armorpayments.com" do
17
+ client.sandbox = false
18
+ client.armor_host.should == "https://api.armorpayments.com"
19
+ end
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'armor_payments/authenticator'
3
+
4
+ module ArmorPayments
5
+ describe Authenticator do
6
+ let(:authenticator) { Authenticator.new('my-api-key', 'my-secret-code') }
7
+
8
+ describe "#current_timestamp" do
9
+ it "returns the current time in iso8601 format" do
10
+ Timecop.freeze(2014, 2, 22, 12, 0, 0) do
11
+ authenticator.current_timestamp.should == '2014-02-22T17:00:00Z'
12
+ end
13
+ end
14
+ end
15
+
16
+ describe "#request_signature" do
17
+ it "hands a concatenated string encompassing the secret, request method, uri, and date to the digest service" do
18
+ Timecop.freeze(2014, 2, 22, 12, 0, 0) do
19
+ the_beast = "#{authenticator.api_secret}:GET:/accounts:#{authenticator.current_timestamp}"
20
+ Digest::SHA512.should_receive(:hexdigest).with(the_beast)
21
+ authenticator.request_signature('get', '/accounts')
22
+ end
23
+ end
24
+
25
+ it "returns a SHA512 hash value" do
26
+ Timecop.freeze(2014, 2, 22, 12, 0, 0) do
27
+ authenticator.request_signature("get", "/accounts").should ==
28
+ "777990373678937074c1b357d632e0ea3439d0e834e573c03076ee557f526565f9ac2b38483b3e41024b96ec2644d60b4f70f0d9c760b2ebeb9827f9b335d069"
29
+ end
30
+ end
31
+ end
32
+
33
+ describe "#secure_headers" do
34
+ it "returns a hash with the required headers in" do
35
+ required_headers = %w( X_ARMORPAYMENTS_APIKEY X_ARMORPAYMENTS_REQUESTTIMESTAMP X_ARMORPAYMENTS_SIGNATURE )
36
+ authenticator.secure_headers('get', '/accounts').keys.sort.should == required_headers.sort
37
+ end
38
+
39
+ it "assigns the correct value for each of the headers" do
40
+ Timecop.freeze(2014, 2, 22, 12, 0, 0) do
41
+ authenticator.secure_headers('get', '/accounts').should == {
42
+ "X_ARMORPAYMENTS_APIKEY" => "my-api-key",
43
+ "X_ARMORPAYMENTS_SIGNATURE" => "777990373678937074c1b357d632e0ea3439d0e834e573c03076ee557f526565f9ac2b38483b3e41024b96ec2644d60b4f70f0d9c760b2ebeb9827f9b335d069",
44
+ "X_ARMORPAYMENTS_REQUESTTIMESTAMP" => "2014-02-22T17:00:00Z"
45
+ }
46
+ end
47
+ end
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,25 @@
1
+ require 'armor_payments'
2
+ require 'timecop'
3
+ require 'vcr'
4
+
5
+ Timecop.safe_mode = true
6
+
7
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
8
+ RSpec.configure do |config|
9
+ config.treat_symbols_as_metadata_keys_with_true_values = true
10
+ config.run_all_when_everything_filtered = true
11
+ config.filter_run :focus
12
+
13
+ # Run specs in random order to surface order dependencies. If you find an
14
+ # order dependency and want to debug it, you can fix the order by providing
15
+ # the seed, which is printed after each run.
16
+ # --seed 1234
17
+ config.order = 'random'
18
+ end
19
+
20
+ VCR.configure do |c|
21
+ c.cassette_library_dir = 'spec/cassettes'
22
+ c.hook_into :excon
23
+ c.default_cassette_options = { record: :new_episodes }
24
+ c.configure_rspec_metadata!
25
+ end
metadata ADDED
@@ -0,0 +1,204 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: armor_payments
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Wilson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: timecop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: excon
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Ruby gem for interacting with Armor Payments.
126
+ email:
127
+ - mhw@hypomodern.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - .rspec
134
+ - .ruby-gemset
135
+ - .ruby-version
136
+ - Gemfile
137
+ - Guardfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - armor_payments.gemspec
142
+ - lib/armor_payments.rb
143
+ - lib/armor_payments/api.rb
144
+ - lib/armor_payments/api/accounts.rb
145
+ - lib/armor_payments/api/bankaccounts.rb
146
+ - lib/armor_payments/api/disputes.rb
147
+ - lib/armor_payments/api/documents.rb
148
+ - lib/armor_payments/api/notes.rb
149
+ - lib/armor_payments/api/offers.rb
150
+ - lib/armor_payments/api/orderevents.rb
151
+ - lib/armor_payments/api/orders.rb
152
+ - lib/armor_payments/api/paymentinstructions.rb
153
+ - lib/armor_payments/api/resource.rb
154
+ - lib/armor_payments/api/shipments.rb
155
+ - lib/armor_payments/api/users.rb
156
+ - lib/armor_payments/authenticator.rb
157
+ - lib/armor_payments/version.rb
158
+ - spec/armor_payments/api/accounts_spec.rb
159
+ - spec/armor_payments/api/disputes_spec.rb
160
+ - spec/armor_payments/api/documents_spec.rb
161
+ - spec/armor_payments/api/notes_spec.rb
162
+ - spec/armor_payments/api/offers_spec.rb
163
+ - spec/armor_payments/api/orders_spec.rb
164
+ - spec/armor_payments/api/resource_spec.rb
165
+ - spec/armor_payments/api/users_spec.rb
166
+ - spec/armor_payments/api_spec.rb
167
+ - spec/armor_payments/authenticator_spec.rb
168
+ - spec/spec_helper.rb
169
+ homepage: http://github.com/hypomodern/armor_payments
170
+ licenses:
171
+ - MIT
172
+ metadata: {}
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - '>='
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ requirements: []
188
+ rubyforge_project:
189
+ rubygems_version: 2.4.2
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: Ruby gem for interacting with Armor Payments.
193
+ test_files:
194
+ - spec/armor_payments/api/accounts_spec.rb
195
+ - spec/armor_payments/api/disputes_spec.rb
196
+ - spec/armor_payments/api/documents_spec.rb
197
+ - spec/armor_payments/api/notes_spec.rb
198
+ - spec/armor_payments/api/offers_spec.rb
199
+ - spec/armor_payments/api/orders_spec.rb
200
+ - spec/armor_payments/api/resource_spec.rb
201
+ - spec/armor_payments/api/users_spec.rb
202
+ - spec/armor_payments/api_spec.rb
203
+ - spec/armor_payments/authenticator_spec.rb
204
+ - spec/spec_helper.rb