snapcard 1.0.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/LICENSE +21 -0
- data/README.md +56 -0
- data/lib/snapcard/client.rb +85 -0
- data/lib/snapcard.rb +1 -0
- data/spec/snapcard_spec.rb +20 -0
- metadata +91 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: e8c07a8afd5c61be268ee1a89d5364658cf2fc40
|
|
4
|
+
data.tar.gz: a9f37332cd435b83d088a9e4755232371377936c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6bcb482bbac29690aadb308fdb4859d771e8e1ed23da9fa0aefc02bc11730e7ae960aa7ef9c978affcffd10dde91ad02442e6d300ac0ae9c6145f3372812e710
|
|
7
|
+
data.tar.gz: 6e1cd09049aaa7bed1fe234be748677e334efe7e990cb59549f4e79cc6523a118cfbb9fa4ddde07386c167a253c5c52a99843002709459a59c51a578cd1200af
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 SNAPCARD
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
SNAPCARD
|
|
2
|
+
========
|
|
3
|
+
|
|
4
|
+
Ruby client library for the [Snapcard API](http://wallets.docs.snapcard.io/).
|
|
5
|
+
|
|
6
|
+
Install
|
|
7
|
+
-------
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
gem install snapcard
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Usage
|
|
14
|
+
-----
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
require 'snapcard'
|
|
18
|
+
|
|
19
|
+
snapcard = Snapcard::Client.new api_key: "A0gQfloO731hkLG", secret_key: "A7zjaklHkODeFiO"
|
|
20
|
+
|
|
21
|
+
response = snapcard.get path: "rates"
|
|
22
|
+
puts response.body
|
|
23
|
+
|
|
24
|
+
response = snapcard.get path: "transactions", limit: 1, offset: 1
|
|
25
|
+
puts response.body
|
|
26
|
+
|
|
27
|
+
response = snapcard.post path: "transfers", sourceAmount: "0.01", sourceCurrency: "BTC", dest: "email:test@snapcard.io"
|
|
28
|
+
puts response.body
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
At the moment this client is synchronous only.
|
|
32
|
+
|
|
33
|
+
Optional arguments on client initialization:
|
|
34
|
+
```ruby
|
|
35
|
+
:read_timeout # default = 20
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Errors
|
|
39
|
+
------
|
|
40
|
+
|
|
41
|
+
Any status codes other than 2xx will result in an error.
|
|
42
|
+
|
|
43
|
+
Example error response:
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"language":"en",
|
|
47
|
+
"subType":"INVALID_VALUE",
|
|
48
|
+
"problematicField":"dest",
|
|
49
|
+
"problematicValue":"asdf",
|
|
50
|
+
"exceptionId":"CvjMPW",
|
|
51
|
+
"compositeType":"ValidationException.INVALID_VALUE",
|
|
52
|
+
"message":"asdf is not a valid value for dest",
|
|
53
|
+
"type":"ValidationException",
|
|
54
|
+
"transient":false
|
|
55
|
+
}
|
|
56
|
+
```
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
module Snapcard
|
|
2
|
+
class Client
|
|
3
|
+
require 'net/http'
|
|
4
|
+
require 'uri'
|
|
5
|
+
require 'json'
|
|
6
|
+
require 'openssl'
|
|
7
|
+
|
|
8
|
+
API_BASE_URL = 'https://api.snapcard.io/'
|
|
9
|
+
API_VERSION = '2'
|
|
10
|
+
|
|
11
|
+
def initialize options
|
|
12
|
+
raise "api_key and secret_key required" unless options[:api_key] && options[:secret_key]
|
|
13
|
+
@options = options
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def post options
|
|
17
|
+
make_request Net::HTTP::Post, options
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def get options
|
|
21
|
+
make_request Net::HTTP::Get, options
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def put options
|
|
25
|
+
make_request Net::HTTP::Put, options
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def delete options
|
|
29
|
+
make_request Net::HTTP::Delete, options
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def make_request http_generic_request_class, options
|
|
35
|
+
raise "Please specify path" unless options[:path]
|
|
36
|
+
path = options[:path]
|
|
37
|
+
options.delete :path
|
|
38
|
+
params = options
|
|
39
|
+
request = assemble_request http_generic_request_class, path, params
|
|
40
|
+
send_request request
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def assemble_request http_generic_request_class, path, params={}
|
|
44
|
+
uri = URI.parse API_BASE_URL + path
|
|
45
|
+
timestamp = (Time.now.to_f * 1000).to_i
|
|
46
|
+
if http_generic_request_class == Net::HTTP::Get
|
|
47
|
+
uri.query = URI.encode_www_form params.merge timestamp: timestamp
|
|
48
|
+
else
|
|
49
|
+
uri.query = URI.encode_www_form timestamp: timestamp
|
|
50
|
+
end
|
|
51
|
+
request = http_generic_request_class.new uri
|
|
52
|
+
body = http_generic_request_class == Net::HTTP::Get ? {} : params
|
|
53
|
+
request.body = body.to_json if !body.empty?
|
|
54
|
+
headers = generate_headers uri, body
|
|
55
|
+
headers.each do |key, value|
|
|
56
|
+
request.add_field key, value
|
|
57
|
+
end
|
|
58
|
+
request
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def send_request request
|
|
62
|
+
http = Net::HTTP.new request.uri.host, request.uri.port
|
|
63
|
+
http.use_ssl = true
|
|
64
|
+
http.read_timeout = @options[:read_timeout] || 20
|
|
65
|
+
http.request request
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def generate_headers uri, body={}
|
|
69
|
+
signature = generate_signature uri, body
|
|
70
|
+
headers = {
|
|
71
|
+
'X-Api-Key' => @options[:api_key],
|
|
72
|
+
'X-Api-Signature' => signature,
|
|
73
|
+
'X-Api-Version' => API_VERSION,
|
|
74
|
+
'Content-Type' => "application/json"
|
|
75
|
+
}
|
|
76
|
+
headers
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def generate_signature uri, body={}
|
|
80
|
+
body_s = body.empty? ? "" : body.to_json.to_s
|
|
81
|
+
to_sign = uri.to_s + body_s
|
|
82
|
+
OpenSSL::HMAC.hexdigest OpenSSL::Digest::SHA256.new, @options[:secret_key], to_sign
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
data/lib/snapcard.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "snapcard/client"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'snapcard'
|
|
2
|
+
|
|
3
|
+
describe Snapcard do
|
|
4
|
+
let(:snapcard) do
|
|
5
|
+
Snapcard::Client.new api_key: "A0gQfloO731hkLG", secret_key: "A7zjaklHkODeFiO"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
context '#generate_signature' do
|
|
9
|
+
it 'generates correct signatures' do
|
|
10
|
+
uri = URI.parse "https://api.snapcard.io/rates"
|
|
11
|
+
uri.query = URI.encode_www_form timestamp: 1458687110894
|
|
12
|
+
signature1 = snapcard.send :generate_signature, uri, {}
|
|
13
|
+
expect(signature1).to eq "a5067c02d0859c754e411c81fc30e55c8271e83c773da6f64f5cf2be2ace7067"
|
|
14
|
+
signature2 = snapcard.send :generate_signature, uri, {"testProperty" => "testValue"}
|
|
15
|
+
expect(signature2).to eq "37aec98359bfe8e3bc93c8baae4d8d36b6e5b028c3ee7a8fa40d6c1c6feae97d"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# should probably have more tests
|
|
20
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: snapcard
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jordan Luyke
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-03-23 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: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
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
|
+
description: Client library for Snapcard API
|
|
56
|
+
email:
|
|
57
|
+
- support@snapcard.io
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- LICENSE
|
|
63
|
+
- README.md
|
|
64
|
+
- lib/snapcard.rb
|
|
65
|
+
- lib/snapcard/client.rb
|
|
66
|
+
- spec/snapcard_spec.rb
|
|
67
|
+
homepage: https://www.snapcard.io/
|
|
68
|
+
licenses:
|
|
69
|
+
- MIT
|
|
70
|
+
metadata: {}
|
|
71
|
+
post_install_message:
|
|
72
|
+
rdoc_options: []
|
|
73
|
+
require_paths:
|
|
74
|
+
- lib
|
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '0'
|
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '0'
|
|
85
|
+
requirements: []
|
|
86
|
+
rubyforge_project:
|
|
87
|
+
rubygems_version: 2.5.1
|
|
88
|
+
signing_key:
|
|
89
|
+
specification_version: 4
|
|
90
|
+
summary: Client library for Snapcard API
|
|
91
|
+
test_files: []
|