straight-server-kit 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 371f0f2803fd90c9dcc9f1e81a3c0d6e3a760c01
4
+ data.tar.gz: 0c5fe9a5d52bca199d784acce675b55d222ff3ef
5
+ SHA512:
6
+ metadata.gz: c88f6c14842cb15fbd44d8efe1ff5a764fd3e39110979b24c23a7afb3b4704fba92b249777f6397fa407a1ad42faca002689fdce3f471b0e0b05d910abbfc08e
7
+ data.tar.gz: 34726dbfcb75815f75fea12ac78625ec95f671e3104da9edc99c2369d1e9582c01e9993a2b5bf7d9d21cb49ed7ca8ec2236a84bfcc8852fbe912b935c12ee828
data/.gitignore ADDED
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - '2.0.0'
5
+ - '2.1.5'
6
+ - '2.2.1'
7
+
8
+ script:
9
+ - bundle exec rspec ./spec
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ### June 10, 2015 (v0.1.0)
2
+
3
+ * hello world
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in straight-server-kit.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # StraightServerKit
2
+
3
+ StraightServerKit is the official [StraightServer API]() client. It supports everything the API can do with a simple interface written in Ruby.
4
+
5
+ [![Build Status](https://travis-ci.org/MyceliumGear/straight-server-kit.svg?branch=master)](https://travis-ci.org/MyceliumGear/straight-server-kit)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'straight-server-kit'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install straight-server-kit
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ client = StraightServerKit::Client.new(url: 'http://gear.loc')
25
+ client = StraightServerKit::Client.new
26
+ ```
27
+
28
+ ### Order resource
29
+
30
+ client.orders #=> StraightServerKit::OrderResource
31
+
32
+ Actions supported:
33
+
34
+ * `client.orders.create(order, gateway_id: 'gateway_id')`
35
+ * `client.orders.find(gateway_id: 'gateway_id', id: 'id')`
36
+
37
+ ### Order signing
38
+
39
+ order = StraightServerKit::Order.new(amount: 0.01, callback_data: '123', keychain_id: 1)
40
+ order.sign_with 'gateway_secret'
41
+
42
+ ### Callback validation
43
+
44
+ if StraightServerKit.valid_callback?(params, 'gateway_secret')
45
+ # params can be trusted
46
+ end
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it ( https://github.com/MyceliumGear/straight-server-kit )
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ load './lib/tasks/resource_doc.rake'
@@ -0,0 +1,29 @@
1
+ require 'straight-server-kit/version'
2
+ require 'resource_kit'
3
+ require 'kartograph'
4
+
5
+ module StraightServerKit
6
+ autoload :Client, File.expand_path('../straight-server-kit/client', __FILE__)
7
+
8
+ # Models
9
+ autoload :BaseModel, File.expand_path('../straight-server-kit/models/base_model', __FILE__)
10
+ autoload :ApiError, File.expand_path('../straight-server-kit/models/api_error', __FILE__)
11
+ autoload :Order, File.expand_path('../straight-server-kit/models/order', __FILE__)
12
+
13
+ # Resources
14
+ autoload :OrderResource, File.expand_path('../straight-server-kit/resources/order_resource', __FILE__)
15
+
16
+ def self.valid_callback?(params, secret)
17
+ return false unless params[:signature] && params[:order_id]
18
+ sign(content: params[:order_id], secret: secret) == params[:signature]
19
+ end
20
+
21
+ def self.sign(content:, secret:, level: 1)
22
+ return unless secret
23
+ result = content.to_s
24
+ level.times do
25
+ result = OpenSSL::HMAC.hexdigest('sha256', secret.to_s, result)
26
+ end
27
+ result
28
+ end
29
+ end
@@ -0,0 +1,48 @@
1
+ require 'faraday'
2
+
3
+ module StraightServerKit
4
+ class Client
5
+
6
+ DEFAULT_API_URL = 'http://localhost:9000'.freeze
7
+
8
+ attr_reader :url, :resources
9
+
10
+ def initialize(url: DEFAULT_API_URL)
11
+ @url = url
12
+ @resources = {}
13
+ end
14
+
15
+ def pay_url(order)
16
+ File.join(url, order.pay_path) if order.pay_path
17
+ end
18
+
19
+ def connection
20
+ Faraday.new(connection_options) { |req|
21
+ req.adapter :net_http
22
+ }
23
+ end
24
+
25
+ def method_missing(name, *args, &block)
26
+ if self.class.resources.keys.include?(name)
27
+ resources[name] ||= self.class.resources[name].new(connection: connection)
28
+ else
29
+ super
30
+ end
31
+ end
32
+
33
+ def self.resources
34
+ {
35
+ orders: OrderResource,
36
+ }
37
+ end
38
+
39
+ private def connection_options
40
+ {
41
+ url: url,
42
+ headers: {
43
+ content_type: 'application/json',
44
+ }
45
+ }
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,11 @@
1
+ module StraightServerKit
2
+ class ApiError < StandardError
3
+
4
+ attr_reader :status
5
+
6
+ def initialize(status:, message:)
7
+ super(message)
8
+ @status = status
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require 'virtus'
2
+
3
+ module StraightServerKit
4
+ class BaseModel
5
+ include Virtus.model
6
+ include Virtus::Equalizer.new(name || inspect)
7
+
8
+ def inspect
9
+ values = Hash[instance_variables.map { |name| [name, instance_variable_get(name)] }]
10
+ "<#{self.class.name} #{values}>"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,49 @@
1
+ module StraightServerKit
2
+ class Order < BaseModel
3
+
4
+ attribute :address, String
5
+ attribute :amount, BigDecimal
6
+ attribute :amount_in_btc, BigDecimal
7
+ attribute :callback_data, String
8
+ attribute :id, Integer
9
+ attribute :keychain_id, Integer
10
+ attribute :last_keychain_id, Integer
11
+ attribute :payment_id, String
12
+ attribute :signature, String
13
+ attribute :status, Integer
14
+ attribute :tid, String
15
+
16
+ def sign_with(secret)
17
+ self.signature = StraightServerKit.sign(content: keychain_id.to_s, secret: secret)
18
+ end
19
+
20
+ def pay_path
21
+ "/pay/#{payment_id}" if payment_id
22
+ end
23
+
24
+ class Mapping
25
+ include Kartograph::DSL
26
+
27
+ kartograph do
28
+ mapping Order
29
+ scoped :create do
30
+ property :amount
31
+ property :callback_data
32
+ property :keychain_id
33
+ property :signature
34
+ end
35
+ scoped :created, :found do
36
+ property :address
37
+ property :amount
38
+ property :amount_in_btc
39
+ property :id
40
+ property :keychain_id
41
+ property :last_keychain_id
42
+ property :payment_id
43
+ property :status
44
+ property :tid
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,31 @@
1
+ module StraightServerKit
2
+ class OrderResource < ResourceKit::Resource
3
+
4
+ API_ERROR_HANDLER = lambda do |response|
5
+ raise ApiError.new(status: response.status, message: response.body)
6
+ end
7
+
8
+ resources do
9
+ action :create do
10
+ verb :post
11
+ path '/gateways/:gateway_id/orders'
12
+ body do |order|
13
+ Order::Mapping.representation_for(:create, order)
14
+ end
15
+ handler 200 do |response|
16
+ Order::Mapping.extract_single(response.body, :created)
17
+ end
18
+ handler &API_ERROR_HANDLER
19
+ end
20
+
21
+ action :find do
22
+ verb :get
23
+ path '/gateways/:gateway_id/orders/:id'
24
+ handler 200 do |response|
25
+ Order::Mapping.extract_single(response.body, :found)
26
+ end
27
+ handler &API_ERROR_HANDLER
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module StraightServerKit
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,47 @@
1
+ require 'straight-server-kit'
2
+ require 'active_support/all'
3
+
4
+ namespace :doc do
5
+ task :_resources do
6
+ resources = StraightServerKit::Client.resources
7
+
8
+ resources.each do |key, klass|
9
+ if klass.name.in?((ENV['SKIP_CLASSES'] || '').split(','))
10
+ next
11
+ end
12
+
13
+ puts "## #{klass.name.demodulize.underscore.humanize}"
14
+ puts
15
+ puts " client = StraightServerKit::Client.new"
16
+ puts " client.#{key} #=> #{klass.name}"
17
+ puts
18
+ puts "Actions supported: "
19
+ puts
20
+ klass._resources.each do |action|
21
+ action_options = action.path.scan(/\:[\w_\-]+/i)
22
+ params = []
23
+
24
+ if action.body && action.body.arity > 0
25
+ params << klass.name.demodulize.underscore.downcase.gsub('_resource', '')
26
+ end
27
+
28
+ if action_options.any?
29
+ action_string = action_options.map do |option|
30
+ option.gsub!(/^\:/, '')
31
+ "#{option}: '#{option}'"
32
+ end.join(', ')
33
+
34
+ params << action_string
35
+ end
36
+
37
+ action.query_keys.each do |key|
38
+ params << "#{key}: '#{key}'"
39
+ end
40
+
41
+ puts "* `client.#{key}.#{action.name}(#{params.join(', ')})`"
42
+ end
43
+ puts
44
+ puts
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://gear.loc/gateways/c2809c9fd3465529d2946fb8299450b4f46b24fc40f0e3a641e7e19cd75a3adb/orders/15
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ User-Agent:
13
+ - Faraday v0.9.1
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx/1.9.1
25
+ Date:
26
+ - Wed, 10 Jun 2015 13:13:44 GMT
27
+ Content-Length:
28
+ - '238'
29
+ Connection:
30
+ - keep-alive
31
+ body:
32
+ encoding: UTF-8
33
+ string: '{"status":5,"amount":4382,"address":"1EvNEJtVFuoGdGRMSKsDALxaZy5q66B2qq","tid":null,"id":15,"payment_id":"5d010bd6d45ec67ccd8d3c63dfdf038bd6310f89ed2b657d42b1831e551bc2fe","amount_in_btc":"0.00004382","keychain_id":1,"last_keychain_id":1}'
34
+ http_version:
35
+ recorded_at: Wed, 10 Jun 2015 13:13:44 GMT
36
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://gear.loc/gateways/c2809c9fd3465529d2946fb8299450b4f46b24fc40f0e3a641e7e19cd75a3adb/orders/5d010bd6d45ec67ccd8d3c63dfdf038bd6310f89ed2b657d42b1831e551bc2fe
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ User-Agent:
13
+ - Faraday v0.9.1
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx/1.9.1
25
+ Date:
26
+ - Wed, 10 Jun 2015 13:13:44 GMT
27
+ Content-Length:
28
+ - '238'
29
+ Connection:
30
+ - keep-alive
31
+ body:
32
+ encoding: UTF-8
33
+ string: '{"status":5,"amount":4382,"address":"1EvNEJtVFuoGdGRMSKsDALxaZy5q66B2qq","tid":null,"id":15,"payment_id":"5d010bd6d45ec67ccd8d3c63dfdf038bd6310f89ed2b657d42b1831e551bc2fe","amount_in_btc":"0.00004382","keychain_id":1,"last_keychain_id":1}'
34
+ http_version:
35
+ recorded_at: Wed, 10 Jun 2015 13:13:44 GMT
36
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,37 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://gear.loc/gateways/c2809c9fd3465529d2946fb8299450b4f46b24fc40f0e3a641e7e19cd75a3adb/orders/meah
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ User-Agent:
13
+ - Faraday v0.9.1
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 404
21
+ message: Not Found
22
+ headers:
23
+ Server:
24
+ - nginx/1.9.1
25
+ Date:
26
+ - Wed, 10 Jun 2015 13:37:14 GMT
27
+ Content-Length:
28
+ - '100'
29
+ Connection:
30
+ - keep-alive
31
+ body:
32
+ encoding: UTF-8
33
+ string: GET /gateways/c2809c9fd3465529d2946fb8299450b4f46b24fc40f0e3a641e7e19cd75a3adb/orders/meah
34
+ Not found
35
+ http_version:
36
+ recorded_at: Wed, 10 Jun 2015 13:37:14 GMT
37
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://gear.loc/gateways/c2809c9fd3465529d2946fb8299450b4f46b24fc40f0e3a641e7e19cd75a3adb/orders
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"amount":"0.1E-1","callback_data":"123","keychain_id":1,"signature":"1d295e79be14197cea096afbcd898267aebaa93d6e6973227132ff35d5f64147"}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ User-Agent:
13
+ - Faraday v0.9.1
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx/1.9.1
25
+ Date:
26
+ - Wed, 10 Jun 2015 11:54:27 GMT
27
+ Content-Length:
28
+ - '238'
29
+ Connection:
30
+ - keep-alive
31
+ body:
32
+ encoding: UTF-8
33
+ string: '{"status":0,"amount":4382,"address":"1EvNEJtVFuoGdGRMSKsDALxaZy5q66B2qq","tid":null,"id":15,"payment_id":"5d010bd6d45ec67ccd8d3c63dfdf038bd6310f89ed2b657d42b1831e551bc2fe","amount_in_btc":"0.00004382","keychain_id":1,"last_keychain_id":1}'
34
+ http_version:
35
+ recorded_at: Wed, 10 Jun 2015 11:54:27 GMT
36
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://gear.loc/gateways/c2809c9fd3465529d2946fb8299450b4f46b24fc40f0e3a641e7e19cd75a3adb/orders
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"amount":"0.1E-1","callback_data":"123","keychain_id":1,"signature":null}'
9
+ headers:
10
+ Content-Type:
11
+ - application/json
12
+ User-Agent:
13
+ - Faraday v0.9.1
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ Accept:
17
+ - "*/*"
18
+ response:
19
+ status:
20
+ code: 409
21
+ message: Conflict
22
+ headers:
23
+ Server:
24
+ - nginx/1.9.1
25
+ Date:
26
+ - Wed, 10 Jun 2015 13:01:45 GMT
27
+ Content-Length:
28
+ - '26'
29
+ Connection:
30
+ - keep-alive
31
+ body:
32
+ encoding: UTF-8
33
+ string: 'Invalid signature for id: '
34
+ http_version:
35
+ recorded_at: Wed, 10 Jun 2015 13:01:45 GMT
36
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe StraightServerKit::Client do
4
+ subject(:client) { StraightServerKit::Client.new }
5
+
6
+ it "can be initializes with an url" do
7
+ @client = StraightServerKit::Client.new(url: 'http://gear.loc')
8
+ expect(@client.url).to eq 'http://gear.loc'
9
+ end
10
+
11
+ it "constructs pay url" do
12
+ @order = StraightServerKit::Order.new(payment_id: 'abc')
13
+ expect(described_class.new.pay_url(@order)).to eq 'http://localhost:9000/pay/abc'
14
+ expect(described_class.new(url: 'https://gear.loc').pay_url(@order)).to eq 'https://gear.loc/pay/abc'
15
+ end
16
+
17
+ it "does respond to valid resources" do
18
+ expect { client.orders }.to_not raise_error
19
+ end
20
+
21
+ it "does not respond to invalid resources" do
22
+ expect { client.apples }.to raise_error NoMethodError
23
+ end
24
+
25
+ it "sets the content type" do
26
+ expect(client.connection.headers['Content-Type']).to eq 'application/json'
27
+ end
28
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe StraightServerKit::BaseModel do
4
+ subject(:model) do
5
+ Class.new(StraightServerKit::BaseModel) do |base|
6
+ attribute :attribute
7
+
8
+ def self.name
9
+ 'SomeModel'
10
+ end
11
+ end
12
+ end
13
+
14
+ describe '#inspect' do
15
+ it 'is inspectable' do
16
+ @instance = model.new(attribute: 5)
17
+ expect(@instance.inspect).to eq '<SomeModel {:@attribute=>5}>'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe StraightServerKit::Order do
4
+
5
+ it "constructs pay path" do
6
+ @order = described_class.new
7
+ expect(@order.pay_path).to eq nil
8
+ @order.payment_id = 'abc'
9
+ expect(@order.pay_path).to eq '/pay/abc'
10
+ @order.payment_id = 123
11
+ expect(@order.pay_path).to eq '/pay/123'
12
+ end
13
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe StraightServerKit::OrderResource do
4
+ include_context 'resources'
5
+ subject(:resource) { described_class.new(connection: connection) }
6
+
7
+ describe '#create' do
8
+ it 'creates order' do
9
+ @order = StraightServerKit::Order.new(amount: 0.01, callback_data: '123', keychain_id: 1)
10
+ @order.sign_with gateway_secret
11
+
12
+ expect(@order.amount).to eq 0.01
13
+ expect(@order.amount).to be_kind_of BigDecimal
14
+ expect(@order.callback_data).to eq '123'
15
+ expect(@order.keychain_id).to eq 1
16
+ expect(@order.signature).to eq '1d295e79be14197cea096afbcd898267aebaa93d6e6973227132ff35d5f64147'
17
+
18
+ VCR.use_cassette 'orders_create' do
19
+ @created_order = client.orders.create(@order, gateway_id: gateway_id)
20
+ end
21
+
22
+ expect(@created_order.address).to eq '1EvNEJtVFuoGdGRMSKsDALxaZy5q66B2qq'
23
+ expect(@created_order.amount).to eq 4382
24
+ expect(@created_order.amount).to be_kind_of BigDecimal
25
+ expect(@created_order.amount_in_btc).to eq 0.00004382
26
+ expect(@created_order.amount_in_btc).to be_kind_of BigDecimal
27
+ expect(@created_order.id).to eq 15
28
+ expect(@created_order.keychain_id).to eq 1
29
+ expect(@created_order.last_keychain_id).to eq 1
30
+ expect(@created_order.payment_id).to eq '5d010bd6d45ec67ccd8d3c63dfdf038bd6310f89ed2b657d42b1831e551bc2fe'
31
+ expect(@created_order.status).to eq 0
32
+ expect(@created_order.tid).to eq nil
33
+
34
+ # orders.create never sets these fields
35
+ expect(@created_order.callback_data).to eq nil
36
+ expect(@created_order.signature).to eq nil
37
+ end
38
+
39
+ it 'raises ApiError' do
40
+ @order = StraightServerKit::Order.new(amount: 0.01, callback_data: '123', keychain_id: 1)
41
+ VCR.use_cassette 'orders_create_unsigned' do
42
+ begin
43
+ client.orders.create(@order, gateway_id: gateway_id)
44
+ rescue => @error
45
+ end
46
+ end
47
+ expect(@error).to be_instance_of StraightServerKit::ApiError
48
+ expect(@error.status).to eq 409
49
+ expect(@error.message).to start_with "Invalid signature"
50
+ end
51
+ end
52
+
53
+ describe '#find' do
54
+ it 'finds existing order by id' do
55
+ VCR.use_cassette 'find_order_by_id' do
56
+ @order = client.orders.find(id: 15, gateway_id: gateway_id)
57
+ end
58
+ expect(@order.id).to eq 15
59
+ end
60
+
61
+ it 'finds existing order by payment_id' do
62
+ VCR.use_cassette 'find_order_by_payment_id' do
63
+ @order = client.orders.find(id: '5d010bd6d45ec67ccd8d3c63dfdf038bd6310f89ed2b657d42b1831e551bc2fe', gateway_id: gateway_id)
64
+ end
65
+ expect(@order.id).to eq 15
66
+ end
67
+
68
+ it 'raises ApiError when not found' do
69
+ VCR.use_cassette 'find_order_fails' do
70
+ begin
71
+ @order = client.orders.find(id: 'meah', gateway_id: gateway_id)
72
+ rescue => @error
73
+ end
74
+ end
75
+ expect(@error).to be_instance_of StraightServerKit::ApiError
76
+ expect(@error.status).to eq 404
77
+ expect(@error.message).to end_with "Not found"
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe StraightServerKit do
4
+ it "validates callback signature" do
5
+ secret = 'secret'
6
+ signature = described_class.sign(content: 1, secret: secret)
7
+ expect(described_class.valid_callback?({}, secret)).to eq false
8
+ expect(described_class.valid_callback?({signature: 'asdf'}, secret)).to eq false
9
+ expect(described_class.valid_callback?({order_id: 1}, secret)).to eq false
10
+ expect(described_class.valid_callback?({order_id: 1, signature: signature}, secret)).to eq true
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.start
4
+
5
+ require 'straight-server-kit'
6
+ require 'webmock/rspec'
7
+ require 'vcr'
8
+
9
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
10
+ SimpleCov::Formatter::HTMLFormatter
11
+ ]
12
+
13
+ Dir['./spec/support/**/*.rb'].each do |file|
14
+ require file
15
+ end
16
+
17
+ VCR.configure do |config|
18
+ config.cassette_library_dir = 'spec/fixtures/vcr'
19
+ config.hook_into :webmock
20
+ end
21
+
22
+ # RSpec.configure do |config|
23
+ # end
@@ -0,0 +1,6 @@
1
+ shared_context 'resources' do
2
+ let(:client) { StraightServerKit::Client.new(url: 'http://gear.loc') }
3
+ let(:connection) { client.connection }
4
+ let(:gateway_id) { 'c2809c9fd3465529d2946fb8299450b4f46b24fc40f0e3a641e7e19cd75a3adb' }
5
+ let(:gateway_secret) { 'w4b1lc5qs3n0vx9q8q76yxparfcmto1dqlr6vo5hh7mfvaoz64epa4e7qhvmv4vg' }
6
+ end
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'straight-server-kit/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'straight-server-kit'
7
+ spec.version = StraightServerKit::VERSION
8
+ spec.authors = ['Alexander Pavlenko']
9
+ spec.email = ['alerticus@gmail.com']
10
+ spec.summary = %q{Straight Server Kit is the official Ruby library for Straight Server's API}
11
+ spec.description = %q{Straight Server Kit is the official Ruby library for Straight Server's API}
12
+ spec.homepage = 'https://github.com/MyceliumGear/straight-server-kit'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.required_ruby_version = '>= 2.0.0'
21
+
22
+ spec.add_dependency 'virtus', '~> 1.0.5'
23
+ spec.add_dependency 'resource_kit', '~> 0.1.3'
24
+ spec.add_dependency 'kartograph', '~> 0.2.2'
25
+ spec.add_dependency 'faraday', '~> 0.9.1'
26
+
27
+ spec.add_development_dependency 'rspec'
28
+ spec.add_development_dependency 'simplecov'
29
+ spec.add_development_dependency 'webmock'
30
+ spec.add_development_dependency 'vcr'
31
+ spec.add_development_dependency 'activesupport'
32
+ end
metadata ADDED
@@ -0,0 +1,212 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: straight-server-kit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Pavlenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: virtus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: resource_kit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: kartograph
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
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: simplecov
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: webmock
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: vcr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: activesupport
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: Straight Server Kit is the official Ruby library for Straight Server's
140
+ API
141
+ email:
142
+ - alerticus@gmail.com
143
+ executables: []
144
+ extensions: []
145
+ extra_rdoc_files: []
146
+ files:
147
+ - ".gitignore"
148
+ - ".rspec"
149
+ - ".travis.yml"
150
+ - CHANGELOG.md
151
+ - Gemfile
152
+ - README.md
153
+ - Rakefile
154
+ - lib/straight-server-kit.rb
155
+ - lib/straight-server-kit/client.rb
156
+ - lib/straight-server-kit/models/api_error.rb
157
+ - lib/straight-server-kit/models/base_model.rb
158
+ - lib/straight-server-kit/models/order.rb
159
+ - lib/straight-server-kit/resources/order_resource.rb
160
+ - lib/straight-server-kit/version.rb
161
+ - lib/tasks/resource_doc.rake
162
+ - spec/fixtures/vcr/find_order_by_id.yml
163
+ - spec/fixtures/vcr/find_order_by_payment_id.yml
164
+ - spec/fixtures/vcr/find_order_fails.yml
165
+ - spec/fixtures/vcr/orders_create.yml
166
+ - spec/fixtures/vcr/orders_create_unsigned.yml
167
+ - spec/lib/straight-server-kit/client_spec.rb
168
+ - spec/lib/straight-server-kit/models/base_model_spec.rb
169
+ - spec/lib/straight-server-kit/models/order_spec.rb
170
+ - spec/lib/straight-server-kit/resources/order_resource_spec.rb
171
+ - spec/lib/straight-server-kit_spec.rb
172
+ - spec/spec_helper.rb
173
+ - spec/support/resource_context.rb
174
+ - straight-server-kit.gemspec
175
+ homepage: https://github.com/MyceliumGear/straight-server-kit
176
+ licenses:
177
+ - MIT
178
+ metadata: {}
179
+ post_install_message:
180
+ rdoc_options: []
181
+ require_paths:
182
+ - lib
183
+ required_ruby_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: 2.0.0
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ requirements: []
194
+ rubyforge_project:
195
+ rubygems_version: 2.4.6
196
+ signing_key:
197
+ specification_version: 4
198
+ summary: Straight Server Kit is the official Ruby library for Straight Server's API
199
+ test_files:
200
+ - spec/fixtures/vcr/find_order_by_id.yml
201
+ - spec/fixtures/vcr/find_order_by_payment_id.yml
202
+ - spec/fixtures/vcr/find_order_fails.yml
203
+ - spec/fixtures/vcr/orders_create.yml
204
+ - spec/fixtures/vcr/orders_create_unsigned.yml
205
+ - spec/lib/straight-server-kit/client_spec.rb
206
+ - spec/lib/straight-server-kit/models/base_model_spec.rb
207
+ - spec/lib/straight-server-kit/models/order_spec.rb
208
+ - spec/lib/straight-server-kit/resources/order_resource_spec.rb
209
+ - spec/lib/straight-server-kit_spec.rb
210
+ - spec/spec_helper.rb
211
+ - spec/support/resource_context.rb
212
+ has_rdoc: