spike-ruby 0.0.1

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: e90c5d3cd17f9db0d1e8181b42045c8891aa1f20
4
+ data.tar.gz: b0463b42b1186dd4d8d69a8c20c433f788a56cdf
5
+ SHA512:
6
+ metadata.gz: f7e6a8d2e4fae0518fde1d213ab6989e19811821a2e74ea319c0ba58bd4a2b7e6dbdbf5c070a2c3f3170c0f4112b3e407496a0c54f7f1b62df8f0261e737adc4
7
+ data.tar.gz: 009b6eafee3914c26fe3519fdffeca25e73620aa0a9645ce3be1aaff9610349a3d11be4d86208e8509f2021d3bd6b671fbbf69ba64978921a3435d39a4858152
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in spike-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 AKAMATSU Yuki
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,55 @@
1
+ # spike-ruby
2
+
3
+ [SPIKE](https://spike.cc/) API Client for Ruby.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'spike-ruby'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install spike-ruby
21
+
22
+ ## Usage
23
+
24
+ ### Create charge
25
+
26
+ ```ruby
27
+ require 'spike'
28
+
29
+ spike = Spike.new(spike_secret_apie_key)
30
+
31
+ request_params = {
32
+ amount: 1000,
33
+ currency: "JPY",
34
+ card: token_from_checkout
35
+ }
36
+ products = [{
37
+ title: "item title",
38
+ description: "item description",
39
+ price: 1000,
40
+ stock: 10,
41
+ count: 1,
42
+ currency: "JPY",
43
+ id: "00001"
44
+ }]
45
+
46
+ spike.charge.create(request_parmas, products)
47
+ ```
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it ( https://github.com/[my-github-username]/spike-ruby/fork )
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,64 @@
1
+ require 'json'
2
+
3
+ class Spike
4
+ class Charge
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ def create(params, products)
10
+ res = @client.post(request_path: "/charges", request_params: params.merge(products: JSON.generate(products)))
11
+ Spike::Charge::Response.new(res)
12
+ end
13
+
14
+ class Spike::Charge::Response
15
+ def initialize(hash)
16
+ @attributes = Hash[hash.map{|k,v| [k.to_s, v] }]
17
+ end
18
+
19
+ def id
20
+ @attributes['id']
21
+ end
22
+
23
+ def object
24
+ @attributes['object']
25
+ end
26
+
27
+ def created_at
28
+ Time.at(@attributes['created'])
29
+ end
30
+
31
+ def live_mode?
32
+ @attributes['livemode']
33
+ end
34
+
35
+ def paid?
36
+ @attributes['paid']
37
+ end
38
+
39
+ def captured?
40
+ @attributes['captured']
41
+ end
42
+
43
+ def amount
44
+ @attributes['amount'].to_f
45
+ end
46
+
47
+ def currency
48
+ @attributes['currency']
49
+ end
50
+
51
+ def refunded?
52
+ @attributes['refunded']
53
+ end
54
+
55
+ def amount_refunded
56
+ @attributes['amount_refunded']
57
+ end
58
+
59
+ def refunds
60
+ @attributes['refunds']
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,6 @@
1
+ class Spike
2
+ class BadRequestError < StandardError; end
3
+ class UnauthorizedError < StandardError; end
4
+ class RequestFailedError < StandardError; end
5
+ class ApiServerError < StandardError; end
6
+ end
@@ -0,0 +1,5 @@
1
+ class Spike
2
+ module Ruby
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/spike/ruby.rb ADDED
@@ -0,0 +1,7 @@
1
+ require "spike/ruby/version"
2
+
3
+ module Spike
4
+ module Ruby
5
+ # Your code goes here...
6
+ end
7
+ end
data/lib/spike.rb ADDED
@@ -0,0 +1,46 @@
1
+ require 'spike/charge'
2
+ require 'spike/error'
3
+
4
+ class Spike
5
+ API_BASE = 'https://api.spike.cc'
6
+ API_VERSION = '/v1'
7
+ API_URL = API_BASE+API_VERSION
8
+
9
+ def initialize(secret_token)
10
+ @secret_token = secret_token
11
+ end
12
+
13
+ def charge
14
+ Spike::Charge.new(self)
15
+ end
16
+
17
+ def post(request_path:, request_params:)
18
+ c = Curl::Easy.new
19
+ c.url = API_URL + request_path
20
+ c.http_auth_types = :basic
21
+ c.username = @secret_token
22
+ c.password = ''
23
+ c.verbose = true
24
+
25
+ curb_post_fields = request_params.map {|k,v| Curl::PostField.content(k,v)}
26
+ c.http_post(c.url, *curb_post_fields)
27
+
28
+ handle_response(c)
29
+ JSON.parse(c.body_str)
30
+ end
31
+
32
+ private
33
+
34
+ def handle_response(curl)
35
+ case curl.status.to_i
36
+ when 400
37
+ raise Spike::BadRequestError
38
+ when 401
39
+ raise Spike::UnauthorizedError
40
+ when 402
41
+ raise Spike::RequestFailedError
42
+ when 500
43
+ raise Spike::ApiServerError
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ require 'spike'
2
+
3
+ RSpec.configure do |config|
4
+ config.order = "random"
5
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spike/ruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spike-ruby"
8
+ spec.version = Spike::Ruby::VERSION
9
+ spec.authors = ["AKAMATSU Yuki"]
10
+ spec.email = ["y.akamatsu@ukstudio.jp"]
11
+ spec.summary = %q{Ruby library for SPIKE API}
12
+ spec.description = %q{Ruby library for SPIKE API}
13
+ spec.homepage = "http://github.com/spice-life/spike-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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.required_ruby_version = ">=2.0.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+
27
+ spec.add_dependency "curb"
28
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spike-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - AKAMATSU Yuki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-22 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: curb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Ruby library for SPIKE API
70
+ email:
71
+ - y.akamatsu@ukstudio.jp
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/spike.rb
83
+ - lib/spike/charge.rb
84
+ - lib/spike/error.rb
85
+ - lib/spike/ruby.rb
86
+ - lib/spike/ruby/version.rb
87
+ - spec/spec_helper.rb
88
+ - spike-ruby.gemspec
89
+ homepage: http://github.com/spice-life/spike-ruby
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: 2.0.0
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.2.2
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Ruby library for SPIKE API
113
+ test_files:
114
+ - spec/spec_helper.rb