spike-ruby 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/Rakefile +8 -0
- data/checkoutapp.rb +10 -0
- data/checkoutapp/index.haml +27 -0
- data/circle.yml +3 -0
- data/lib/spike.rb +25 -7
- data/lib/spike/charge.rb +5 -0
- data/lib/spike/version.rb +1 -1
- data/spec/spec_helper.rb +9 -0
- data/spec/spike_spec.rb +48 -0
- data/spec/vcr/lib/spike_create_charge.yml +40 -0
- data/spec/vcr/lib/spike_get_charge.yml +40 -0
- data/spike-ruby.gemspec +5 -3
- metadata +45 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3a4e9fb8aad6e8d754bcaf6a888af457423d80d
|
4
|
+
data.tar.gz: a87e25103fba6aad2a56ff8dd4e811b552bbaee0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b33514b2895e64754e1be43906074e006a9073bebc56b19e4b87838563ae9ab0a503abc07c29017d0f37ac3862458ccb45c1d22030d7cd31492529688b0d2b5a
|
7
|
+
data.tar.gz: 8192285c61da000a7635eb6e525a9651d81163d292ccbf41e73b596dadcbc0ece4ded294f6d117253dbad7515bf4d6dbc1bfbce90c9efe3e932900d377d47f95
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# spike-ruby
|
1
|
+
# spike-ruby ![build status](https://circleci.com/gh/spice-life/spike-ruby.png?style=shield&circle-token=793417d2dc17daaef4dfba6afb6552e4ca4c1023)
|
2
2
|
|
3
3
|
[SPIKE](https://spike.cc/) API Client for Ruby.
|
4
4
|
|
@@ -46,6 +46,15 @@ Or install it yourself as:
|
|
46
46
|
spike.charge.create(request_parmas, products)
|
47
47
|
```
|
48
48
|
|
49
|
+
## Get credit card token
|
50
|
+
|
51
|
+
```shell
|
52
|
+
$ gem install sinatra
|
53
|
+
$ SPIKE_PUBLIC_KEY=pk_xxxxxxx ruby checkoutapp.rb
|
54
|
+
```
|
55
|
+
|
56
|
+
Access to http://localhost:4567
|
57
|
+
|
49
58
|
## Contributing
|
50
59
|
|
51
60
|
1. Fork it ( https://github.com/spice-life/spike-ruby/fork )
|
data/Rakefile
CHANGED
data/checkoutapp.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'sinatra'
|
2
|
+
require 'haml'
|
3
|
+
|
4
|
+
set :views, settings.root + '/checkoutapp'
|
5
|
+
|
6
|
+
get '/' do
|
7
|
+
fail('missing SPIKE_PUBLIC_KEY env') if ENV['SPIKE_PUBLIC_KEY'].nil? || ENV['SPIKE_PUBLIC_KEY'].empty?
|
8
|
+
@public_key = ENV['SPIKE_PUBLIC_KEY']
|
9
|
+
haml :index
|
10
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
!!!
|
2
|
+
|
3
|
+
%html
|
4
|
+
%body
|
5
|
+
%button#customButton submit
|
6
|
+
|
7
|
+
%script{type: 'text/javascript', src: 'https://checkout.spike.cc/v1/checkout.js'}
|
8
|
+
|
9
|
+
:javascript
|
10
|
+
var handler = SpikeCheckout.configure({
|
11
|
+
key: "#{@public_key}",
|
12
|
+
token: function(token, args) {
|
13
|
+
console.log(token.id);
|
14
|
+
}
|
15
|
+
});
|
16
|
+
|
17
|
+
|
18
|
+
document.getElementById("customButton").addEventListener("click", function(e) {
|
19
|
+
handler.open({
|
20
|
+
name: "Sample app for get token",
|
21
|
+
amount: 900,
|
22
|
+
currency: "JPY",
|
23
|
+
guest: true,
|
24
|
+
email: "foo@example.com"
|
25
|
+
});
|
26
|
+
e.preventDefault();
|
27
|
+
});
|
data/circle.yml
ADDED
data/lib/spike.rb
CHANGED
@@ -15,13 +15,19 @@ class Spike
|
|
15
15
|
Spike::Charge.new(self)
|
16
16
|
end
|
17
17
|
|
18
|
+
def get(request_path:)
|
19
|
+
c = build_curl(request_path)
|
20
|
+
basic_auth(c)
|
21
|
+
|
22
|
+
c.http_get
|
23
|
+
|
24
|
+
handle_response(c)
|
25
|
+
JSON.parse(c.body_str)
|
26
|
+
end
|
27
|
+
|
18
28
|
def post(request_path:, request_params:)
|
19
|
-
c =
|
20
|
-
c
|
21
|
-
c.http_auth_types = :basic
|
22
|
-
c.username = @secret_token
|
23
|
-
c.password = ''
|
24
|
-
c.verbose = true
|
29
|
+
c = build_curl(request_path)
|
30
|
+
basic_auth(c)
|
25
31
|
|
26
32
|
curb_post_fields = request_params.map {|k,v| Curl::PostField.content(k,v)}
|
27
33
|
c.http_post(c.url, *curb_post_fields)
|
@@ -31,11 +37,23 @@ class Spike
|
|
31
37
|
end
|
32
38
|
|
33
39
|
private
|
40
|
+
def build_curl(request_path)
|
41
|
+
c = Curl::Easy.new
|
42
|
+
c.url = API_URL + request_path
|
43
|
+
c.verbose = true
|
44
|
+
c
|
45
|
+
end
|
46
|
+
|
47
|
+
def basic_auth(curl)
|
48
|
+
curl.http_auth_types = :basic
|
49
|
+
curl.username = @secret_token
|
50
|
+
curl.password = ''
|
51
|
+
end
|
34
52
|
|
35
53
|
def handle_response(curl)
|
36
54
|
case curl.status.to_i
|
37
55
|
when 400
|
38
|
-
raise Spike::BadRequestError
|
56
|
+
raise Spike::BadRequestError, JSON.parse(curl.body_str)['error']['message']
|
39
57
|
when 401
|
40
58
|
raise Spike::UnauthorizedError
|
41
59
|
when 402
|
data/lib/spike/charge.rb
CHANGED
@@ -11,6 +11,11 @@ class Spike
|
|
11
11
|
Spike::Charge::Response.new(res)
|
12
12
|
end
|
13
13
|
|
14
|
+
def retrieve(charge_id)
|
15
|
+
res = @client.get(request_path: "/charges/#{charge_id}")
|
16
|
+
Spike::Charge::Response.new(res)
|
17
|
+
end
|
18
|
+
|
14
19
|
class Spike::Charge::Response
|
15
20
|
def initialize(hash)
|
16
21
|
@attributes = Hash[hash.map{|k,v| [k.to_s, v] }]
|
data/lib/spike/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler.require(:default, :development)
|
3
|
+
|
1
4
|
require 'spike'
|
2
5
|
|
6
|
+
VCR.configure do |c|
|
7
|
+
c.cassette_library_dir = 'spec/vcr'
|
8
|
+
c.hook_into :webmock
|
9
|
+
c.allow_http_connections_when_no_cassette = true
|
10
|
+
end
|
11
|
+
|
3
12
|
RSpec.configure do |config|
|
4
13
|
config.order = "random"
|
5
14
|
end
|
data/spec/spike_spec.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spike::Charge do
|
4
|
+
let(:secret_api_key) { 'sk_test_Lkg0iMrN5x02S7e4WVE5FgTj' }
|
5
|
+
|
6
|
+
describe 'create new charge' do
|
7
|
+
let(:token) { 'tok_rNUiMLP32pYQkpe2PqYAUuHK' }
|
8
|
+
let(:products) { [{title: '商品', description: '商品説明', language: 'JA', price: 900, currency: 'JPY', count: 1, id: '00001', stock: 10}]}
|
9
|
+
let(:request_params) { { amount: 900, currency: 'JPY', card: token } }
|
10
|
+
|
11
|
+
subject do
|
12
|
+
res = nil
|
13
|
+
VCR.use_cassette 'lib/spike_create_charge' do
|
14
|
+
res = Spike.new(secret_api_key).charge.create(request_params, products)
|
15
|
+
end
|
16
|
+
res
|
17
|
+
end
|
18
|
+
|
19
|
+
it { expect(subject.object).to eq 'charge' }
|
20
|
+
it { expect(subject).to_not be_live_mode }
|
21
|
+
it { expect(subject).to be_paid }
|
22
|
+
it { expect(subject).to be_captured }
|
23
|
+
it { expect(subject.amount).to eq 900.0 }
|
24
|
+
it { expect(subject.currency).to eq 'JPY' }
|
25
|
+
it { expect(subject).to_not be_refunded }
|
26
|
+
it { expect(subject.amount_refunded).to be_nil }
|
27
|
+
it { expect(subject.refunds).to be_empty }
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'get charge' do
|
31
|
+
subject do
|
32
|
+
res = nil
|
33
|
+
VCR.use_cassette 'lib/spike_get_charge' do
|
34
|
+
res = Spike.new(secret_api_key).charge.retrieve("20141007-113905-mj7atv4rkg")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it { expect(subject.object).to eq 'charge' }
|
39
|
+
it { expect(subject).to_not be_live_mode }
|
40
|
+
it { expect(subject).to be_paid }
|
41
|
+
it { expect(subject).to be_captured }
|
42
|
+
it { expect(subject.amount).to eq 900.0 }
|
43
|
+
it { expect(subject.currency).to eq 'JPY' }
|
44
|
+
it { expect(subject).to_not be_refunded }
|
45
|
+
it { expect(subject.amount_refunded).to be_nil }
|
46
|
+
it { expect(subject.refunds).to be_empty }
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://sk_test_Lkg0iMrN5x02S7e4WVE5FgTj:@api.spike.cc/v1/charges
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: https://api.spike.cc/v1/charges&amount=900¤cy=JPY&card=tok_rNUiMLP32pYQkpe2PqYAUuHK&products=%5B%7B%22title%22%3A%22%E5%95%86%E5%93%81%22%2C%22description%22%3A%22%E5%95%86%E5%93%81%E8%AA%AC%E6%98%8E%22%2C%22language%22%3A%22JA%22%2C%22price%22%3A900%2C%22currency%22%3A%22JPY%22%2C%22count%22%3A1%2C%22id%22%3A%2200001%22%2C%22stock%22%3A10%7D%5D
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 201
|
13
|
+
message: Created
|
14
|
+
headers:
|
15
|
+
Cache-Control:
|
16
|
+
- max-age=0, private, must-revalidate
|
17
|
+
Content-Type:
|
18
|
+
- application/json
|
19
|
+
Date:
|
20
|
+
- Tue, 07 Oct 2014 11:39:05 GMT
|
21
|
+
Etag:
|
22
|
+
- '"20f59ea808e5712eb3dcf1378658c6c6"'
|
23
|
+
Server:
|
24
|
+
- nginx
|
25
|
+
Status:
|
26
|
+
- 201 Created
|
27
|
+
X-Request-Id:
|
28
|
+
- ebc65445-26b6-439d-a0db-f84b2013dec0
|
29
|
+
X-Runtime:
|
30
|
+
- '0.249048'
|
31
|
+
Content-Length:
|
32
|
+
- '392'
|
33
|
+
Connection:
|
34
|
+
- keep-alive
|
35
|
+
body:
|
36
|
+
encoding: ASCII-8BIT
|
37
|
+
string: '{"id":"20141007-113905-mj7atv4rkg","object":"charge","created":1412681945,"livemode":false,"paid":true,"amount":"900.0","currency":"JPY","refunded":false,"card":{},"captured":true,"refunds":[],"balance_transaction":"","failure_message":null,"failure_code":null,"amount_refunded":null,"customer":null,"invoice":null,"description":null,"dispute":null,"metadata":{},"statement_description":null}'
|
38
|
+
http_version:
|
39
|
+
recorded_at: Tue, 07 Oct 2014 11:39:05 GMT
|
40
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,40 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://sk_test_Lkg0iMrN5x02S7e4WVE5FgTj:@api.spike.cc/v1/charges/20141007-113905-mj7atv4rkg
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Cache-Control:
|
16
|
+
- max-age=0, private, must-revalidate
|
17
|
+
Content-Type:
|
18
|
+
- application/json
|
19
|
+
Date:
|
20
|
+
- Tue, 07 Oct 2014 12:10:04 GMT
|
21
|
+
Etag:
|
22
|
+
- '"20f59ea808e5712eb3dcf1378658c6c6"'
|
23
|
+
Server:
|
24
|
+
- nginx
|
25
|
+
Status:
|
26
|
+
- 200 OK
|
27
|
+
X-Request-Id:
|
28
|
+
- b1783930-6a6a-4b04-8f1a-6132e74bb014
|
29
|
+
X-Runtime:
|
30
|
+
- '0.024541'
|
31
|
+
Content-Length:
|
32
|
+
- '392'
|
33
|
+
Connection:
|
34
|
+
- keep-alive
|
35
|
+
body:
|
36
|
+
encoding: ASCII-8BIT
|
37
|
+
string: '{"id":"20141007-113905-mj7atv4rkg","object":"charge","created":1412681945,"livemode":false,"paid":true,"amount":"900.0","currency":"JPY","refunded":false,"card":{},"captured":true,"refunds":[],"balance_transaction":"","failure_message":null,"failure_code":null,"amount_refunded":null,"customer":null,"invoice":null,"description":null,"dispute":null,"metadata":{},"statement_description":null}'
|
38
|
+
http_version:
|
39
|
+
recorded_at: Tue, 07 Oct 2014 12:10:04 GMT
|
40
|
+
recorded_with: VCR 2.9.3
|
data/spike-ruby.gemspec
CHANGED
@@ -20,9 +20,11 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.required_ruby_version = ">=2.0.0"
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler", "
|
23
|
+
spec.add_development_dependency "bundler", ">= 1.0.0"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
-
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "rspec", ">= 3.0.0"
|
26
|
+
spec.add_development_dependency "webmock"
|
27
|
+
spec.add_development_dependency "vcr"
|
26
28
|
|
27
|
-
spec.add_dependency "curb"
|
29
|
+
spec.add_dependency "curb", "~> 0.8.6"
|
28
30
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spike-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- AKAMATSU Yuki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.0.0
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -40,6 +40,20 @@ dependencies:
|
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.0.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - ">="
|
@@ -53,19 +67,33 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: vcr
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|
60
74
|
- !ruby/object:Gem::Version
|
61
75
|
version: '0'
|
62
|
-
type: :
|
76
|
+
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - ">="
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: curb
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.8.6
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.8.6
|
69
97
|
description: Ruby library for SPIKE API
|
70
98
|
email:
|
71
99
|
- y.akamatsu@ukstudio.jp
|
@@ -79,11 +107,17 @@ files:
|
|
79
107
|
- LICENSE.txt
|
80
108
|
- README.md
|
81
109
|
- Rakefile
|
110
|
+
- checkoutapp.rb
|
111
|
+
- checkoutapp/index.haml
|
112
|
+
- circle.yml
|
82
113
|
- lib/spike.rb
|
83
114
|
- lib/spike/charge.rb
|
84
115
|
- lib/spike/error.rb
|
85
116
|
- lib/spike/version.rb
|
86
117
|
- spec/spec_helper.rb
|
118
|
+
- spec/spike_spec.rb
|
119
|
+
- spec/vcr/lib/spike_create_charge.yml
|
120
|
+
- spec/vcr/lib/spike_get_charge.yml
|
87
121
|
- spike-ruby.gemspec
|
88
122
|
homepage: http://github.com/spice-life/spike-ruby
|
89
123
|
licenses:
|
@@ -111,3 +145,6 @@ specification_version: 4
|
|
111
145
|
summary: Ruby library for SPIKE API
|
112
146
|
test_files:
|
113
147
|
- spec/spec_helper.rb
|
148
|
+
- spec/spike_spec.rb
|
149
|
+
- spec/vcr/lib/spike_create_charge.yml
|
150
|
+
- spec/vcr/lib/spike_get_charge.yml
|