mexbt-transfer-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0a28e39628022d32ddc4e0faa6ec20145813afc6
4
+ data.tar.gz: d2ec9b0aa7e33fc6b6382f64f6c2df9eaa9f23ad
5
+ SHA512:
6
+ metadata.gz: 7cb4bd82e69e2fe21d937cafdfcf762a22a329ddc489f8a14ca3ff063d2d94840e5519a4368b88212771bfa68417f8a7bd5d9056827b60e3d48ca57fa1b533e3
7
+ data.tar.gz: 787ea49e4d206e602d6004eca6f7bfe7a4eca0dff68c3807358d749f4e123d20161ae8528b3e2a14bec17330808b779ad5af3145c0c88dbbb4e558dd6a7d5235
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Exchange of the Americas SAPI de CV
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,37 @@
1
+ # Mexbt Transfer API Ruby client
2
+
3
+ This is a lightweight ruby client for the [meXBT](https://mexbt.com) Transfer API. It doesn't try and do anything clever with the JSON response from the API, it simply
4
+ returns it as-is.
5
+
6
+ ## Install
7
+
8
+ If using bundler simply this to your Gemfile:
9
+
10
+ gem 'mexbt-transfer-api'
11
+
12
+ And run `bundle install` of course.
13
+
14
+ ## Ruby version
15
+
16
+ You need to be using Ruby 2.1 or higher.
17
+
18
+
19
+ ## Setting up a client
20
+
21
+ api = Mexbt::TransferApi.new("your-api-key", "your-api-key", your_client_id)
22
+
23
+ If you want to work against another endpoint, you can configure that like:
24
+
25
+ api = Mexbt::TransferApi.new("your-api-key", "your-api-key", your_client_id, endpoint: "https://transfer-staging.mexbt.com/v1")
26
+
27
+ ## Checking api is up and you can authenticate ok
28
+
29
+ api.ping()
30
+
31
+ ## Creating orders
32
+
33
+ api.create_order(in_currency: 'btc', out_currency: 'mxn', out_via: 'atm', out_amount: 100, webhook: 'http://your.domain/hook')
34
+
35
+ ## Fetching an order
36
+
37
+ api.get_order(1)
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ begin
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ rescue LoadError
5
+ end
6
+
7
+ task default: [:spec]
@@ -0,0 +1,5 @@
1
+ module Mexbt
2
+ class TransferApi
3
+ CLIENT_VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,74 @@
1
+ require 'rest_client'
2
+ require 'active_support/core_ext/hash/indifferent_access'
3
+ require 'json'
4
+
5
+ module Mexbt
6
+ class TransferApi
7
+ DEFAULT_ENDPOINT = "https://transfer.mexbt.com/v1"
8
+ SSL_VERSION = :TLSv1_2
9
+
10
+ def initialize(api_key, api_secret, client_id, endpoint: DEFAULT_ENDPOINT)
11
+ @api_key = api_key
12
+ @api_secret = api_secret
13
+ @client_id = client_id
14
+ @endpoint = endpoint
15
+ end
16
+
17
+ def create_order(in_currency:, out_currency:, out_via:, webhook:, in_amount: 0, out_amount: 0, sender_info: {}, recipient_info: {})
18
+ params = {
19
+ in_currency: in_currency,
20
+ out_currency: out_currency,
21
+ out_via: out_via,
22
+ webhook: webhook,
23
+ sender_info: sender_info,
24
+ recipient_info: recipient_info
25
+ }
26
+ if in_amount > 0
27
+ params[:in] = in_amount
28
+ elsif out_amount > 0
29
+ params[:out] = out_amount
30
+ else
31
+ raise "You must specify a value for either in or out"
32
+ end
33
+ call("/orders", params)
34
+ end
35
+
36
+ def get_order(id)
37
+ call("/orders/#{id}")
38
+ end
39
+
40
+ def ping
41
+ call("/ping")
42
+ end
43
+
44
+ private
45
+
46
+ def url(path)
47
+ "#{@endpoint}#{path}"
48
+ end
49
+
50
+ def call(path, params={})
51
+ url = url(path)
52
+ params.merge!(auth_params)
53
+ res = RestClient::Request.execute(method: :post, url: url, payload: params.to_json, ssl_version: SSL_VERSION, headers: { content_type: :json, accept: :json }) do |response, request, result|
54
+ case response.code
55
+ when 200, 400
56
+ response
57
+ else
58
+ response.return!(request, result)
59
+ end
60
+ end
61
+ ActiveSupport::HashWithIndifferentAccess.new(JSON.parse(res))
62
+ end
63
+
64
+ def auth_params
65
+ nonce = (Time.now.to_f*10000).to_i
66
+ {
67
+ api_key: @api_key,
68
+ nonce: nonce,
69
+ signature: OpenSSL::HMAC.hexdigest('sha512', @api_secret, "#{nonce}#{@client_id}#{@api_key}").upcase
70
+ }
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mexbt_transfer_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mexbt-transfer-api"
8
+ spec.description = "A lightweight ruby client for the meXBT Transfer API"
9
+ spec.version = Mexbt::TransferApi::CLIENT_VERSION
10
+ spec.authors = ["williamcoates"]
11
+ spec.email = ["william@mexbt.com"]
12
+ spec.summary = %q{meXBT Transfer API client}
13
+ spec.homepage = "https://github.com/meXBT/transfer-api-ruby"
14
+ spec.license = "MIT"
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
+ spec.add_runtime_dependency "activesupport", ["~> 4.1.8"]
20
+ spec.add_runtime_dependency "rest_client", ["= 1.8.2"]
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "webmock"
25
+ spec.add_development_dependency "vcr"
26
+ end
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:3000/v1/orders
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"in_currency":"btc","out_currency":"mxn","out_via":"atm","webhook":"http://requestb.in/11rzly71","sender_info":{},"recipient_info":{},"out":5000,"api_key":"e22a52802d6db99d524f51a93a413536","nonce":14189157550507,"signature":"94C7D4D1E024E178D955D63ED4536D19177A69AFE1106D0FEC956590DFB02891C7347D85F60960EDF9D9CA295CFA90A88EA455F3B28FD571914FED3CDCB35FE4"}'
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json
16
+ Content-Length:
17
+ - '357'
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: 'OK '
24
+ headers:
25
+ X-Frame-Options:
26
+ - SAMEORIGIN
27
+ X-Xss-Protection:
28
+ - 1; mode=block
29
+ X-Content-Type-Options:
30
+ - nosniff
31
+ Content-Type:
32
+ - application/json; charset=utf-8
33
+ Etag:
34
+ - W/"e00e97c34919a5c1de7a0f64c8137a55"
35
+ Cache-Control:
36
+ - max-age=0, private, must-revalidate
37
+ X-Request-Id:
38
+ - 36dd8164-5eac-4e83-93f6-5484b149e9c1
39
+ X-Runtime:
40
+ - '1.763409'
41
+ Server:
42
+ - WEBrick/1.3.1 (Ruby/2.1.2/2014-05-08)
43
+ Date:
44
+ - Thu, 18 Dec 2014 15:15:56 GMT
45
+ Content-Length:
46
+ - '341'
47
+ Connection:
48
+ - Keep-Alive
49
+ body:
50
+ encoding: UTF-8
51
+ string: '{"id":6,"in":{"currency":"btc","amount":1.15173726},"out":{"currency":"mxn","amount":5000.0},"out_via":"atm","sender_info":null,"recipient_info":null,"withdraw_info":null,"quote_valid_until":1418916655,"deposit_info":{"address":"ByNafb7C39BB7JqdkSVFUPzJoGsumUA4ks"},"webhook":"http://requestb.in/11rzly71","confirmations":0,"status":"quote"}'
52
+ http_version:
53
+ recorded_at: Thu, 18 Dec 2014 15:15:56 GMT
54
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://localhost:3000/v1/ping
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"api_key":"e22a52802d6db99d524f51a93a413536","nonce":14189139204916,"signature":"B50005D7C66BD97C4E0CC53B11D234D42DA9CF98E30D52553602B3DC8B0F5B0A1BBA73E35D65B63CB273D584F4DBC552ADAAE981D75DC4C1A3E6AAD4EA42A88B"}'
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json
16
+ Content-Length:
17
+ - '212'
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: 'OK '
24
+ headers:
25
+ X-Frame-Options:
26
+ - SAMEORIGIN
27
+ X-Xss-Protection:
28
+ - 1; mode=block
29
+ X-Content-Type-Options:
30
+ - nosniff
31
+ Content-Type:
32
+ - application/json; charset=utf-8
33
+ Etag:
34
+ - W/"82380d1e263b6093f3c7535690fcdd75"
35
+ Cache-Control:
36
+ - max-age=0, private, must-revalidate
37
+ X-Request-Id:
38
+ - 68e4ae20-94ef-4e83-9d7e-4167e795859e
39
+ X-Runtime:
40
+ - '0.033339'
41
+ Server:
42
+ - WEBrick/1.3.1 (Ruby/2.1.2/2014-05-08)
43
+ Date:
44
+ - Thu, 18 Dec 2014 14:45:20 GMT
45
+ Content-Length:
46
+ - '11'
47
+ Connection:
48
+ - Keep-Alive
49
+ body:
50
+ encoding: UTF-8
51
+ string: '{"ok":true}'
52
+ http_version:
53
+ recorded_at: Thu, 18 Dec 2014 14:45:20 GMT
54
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,12 @@
1
+ require 'mexbt_transfer_api'
2
+ require 'vcr'
3
+
4
+ VCR.configure do |c|
5
+ c.cassette_library_dir = 'spec/cassettes'
6
+ c.hook_into :webmock
7
+ c.configure_rspec_metadata!
8
+ end
9
+
10
+ RSpec.configure do |config|
11
+ config.order = :random
12
+ end
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+
3
+ describe Mexbt::TransferApi do
4
+
5
+ subject(:transfer_api) do
6
+ Mexbt::TransferApi.new("e22a52802d6db99d524f51a93a413536", "3bf5501c8149958a3e2494e1f0f24f5a71a52a80248198bf0f1c6570fc89e095", 1, endpoint: "http://localhost:3000/v1")
7
+ end
8
+
9
+ context "ping", :vcr do
10
+ it "returns a 200 response if authentication successful" do
11
+ expect(transfer_api.ping).to eql({ "ok" => true })
12
+ end
13
+ end
14
+
15
+ context "creating orders", :vcr do
16
+ it "allows creating a btc -> mxn transfer order for 5000 pesos, cashed out via ATM" do
17
+ res = transfer_api.create_order(in_currency: 'btc', out_currency: 'mxn', out_amount: 5000, out_via: 'atm', webhook: 'http://requestb.in/11rzly71')
18
+ expect(res).to eql({
19
+ "id"=>6,
20
+ "in"=>{"currency"=>"btc", "amount"=>1.15173726},
21
+ "out"=>{"currency"=>"mxn", "amount"=>5000.0},
22
+ "out_via"=>"atm",
23
+ "sender_info"=>nil,
24
+ "recipient_info"=>nil,
25
+ "withdraw_info"=>nil,
26
+ "quote_valid_until"=>1418916655,
27
+ "deposit_info"=>{"address"=>"ByNafb7C39BB7JqdkSVFUPzJoGsumUA4ks"},
28
+ "webhook"=>"http://requestb.in/11rzly71",
29
+ "confirmations"=>0,
30
+ "status"=>"quote"
31
+ })
32
+ end
33
+ end
34
+
35
+ context "getting orders" do
36
+ # TODO
37
+ it "allows you to fetch orders you own"
38
+
39
+ end
40
+
41
+ end
metadata ADDED
@@ -0,0 +1,158 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mexbt-transfer-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - williamcoates
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.1.8
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.1.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: rest_client
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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: 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: webmock
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: vcr
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
+ description: A lightweight ruby client for the meXBT Transfer API
112
+ email:
113
+ - william@mexbt.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - lib/mexbt_transfer_api.rb
124
+ - lib/mexbt_transfer_api/version.rb
125
+ - mexbt_transfer_api.gemspec
126
+ - spec/cassettes/Mexbt_TransferApi/creating_orders/allows_creating_a_btc_-_mxn_transfer_order_for_5000_pesos_cashed_out_via_ATM.yml
127
+ - spec/cassettes/Mexbt_TransferApi/ping/returns_a_200_response_if_authentication_successful.yml
128
+ - spec/spec_helper.rb
129
+ - spec/transfer_api_spec.rb
130
+ homepage: https://github.com/meXBT/transfer-api-ruby
131
+ licenses:
132
+ - MIT
133
+ metadata: {}
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubyforge_project:
150
+ rubygems_version: 2.2.2
151
+ signing_key:
152
+ specification_version: 4
153
+ summary: meXBT Transfer API client
154
+ test_files:
155
+ - spec/cassettes/Mexbt_TransferApi/creating_orders/allows_creating_a_btc_-_mxn_transfer_order_for_5000_pesos_cashed_out_via_ATM.yml
156
+ - spec/cassettes/Mexbt_TransferApi/ping/returns_a_200_response_if_authentication_successful.yml
157
+ - spec/spec_helper.rb
158
+ - spec/transfer_api_spec.rb