bitex 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/bitex.rb CHANGED
@@ -8,4 +8,5 @@ Dir[File.expand_path("../bitex/*.rb", __FILE__)].each {|f| require f}
8
8
 
9
9
  module Bitex
10
10
  mattr_accessor :api_key
11
+ mattr_accessor :sandbox
11
12
  end
data/lib/bitex/api.rb CHANGED
@@ -1,17 +1,32 @@
1
1
  module Bitex
2
2
  class ApiError < StandardError; end
3
3
  class Api
4
- def self.curl(verb, path, options={})
4
+ def self.curl(verb, path, options={}, files={})
5
5
  verb = verb.upcase.to_sym
6
6
  query = verb == :GET ? "?#{options.to_query}" : ''
7
+ prefix = Bitex.sandbox ? 'sandbox.' : ''
7
8
 
8
- curl = Curl::Easy.new("https://bitex.la/api-v1/rest#{path}#{query}")
9
- curl.post_body = options.to_query if verb == :POST
10
- curl.http(verb)
9
+ curl = Curl::Easy.new("https://#{prefix}bitex.la/api-v1/rest#{path}#{query}")
10
+ if verb == :POST
11
+ fields = []
12
+ unless files.empty?
13
+ fields += files.collect{|k, v| Curl::PostField.file(k.to_s, v) }
14
+ curl.multipart_form_post = true
15
+ end
16
+ fields += options.collect do |k,v|
17
+ next unless v
18
+ Curl::PostField.content(k.to_s, v)
19
+ end.compact
20
+ curl.send("http_#{verb.downcase}", *fields)
21
+ else
22
+ curl.put_data = options.to_query if verb == :PUT
23
+ curl.http(verb)
24
+ end
11
25
  code = curl.response_code
12
26
 
13
27
  unless [200, 201, 202].include?(code)
14
- raise ApiError.new("Got #{code} fetching #{path} with #{options}")
28
+ raise ApiError.new("Got #{code} fetching #{path} with
29
+ #{options}\n\n#{curl.head}\n\n#{curl.body}")
15
30
  end
16
31
 
17
32
  return curl
@@ -21,11 +36,11 @@ module Bitex
21
36
  JSON.parse(curl(:GET, path).body)
22
37
  end
23
38
 
24
- def self.private(verb, path, options={})
39
+ def self.private(verb, path, options={}, files={})
25
40
  if Bitex.api_key.nil?
26
41
  raise StandardError.new("No api_key available to make private key calls")
27
42
  end
28
- JSON.parse(curl(verb, path, options.merge(api_key: Bitex.api_key)).body)
43
+ JSON.parse(curl(verb, path, options.merge(api_key: Bitex.api_key), files).body)
29
44
  end
30
45
 
31
46
  # Deserialize a single object from a json representation as specified on the
@@ -0,0 +1,18 @@
1
+ module Bitex
2
+ class KycFile
3
+ attr_accessor :id, :kyc_profile_id, :url, :file_name,
4
+ :content_type, :file_size
5
+
6
+ def self.from_json(json)
7
+ t = new
8
+ t.id, t.kyc_profile_id, t.url, t.file_name, t.content_type, t.file_size =
9
+ json
10
+ t
11
+ end
12
+
13
+ def self.all
14
+ Api.private(:get, "/private/kyc_files").collect{|x| from_json(x) }
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,66 @@
1
+ module Bitex
2
+ class KycProfile
3
+
4
+ attr_accessor :id, :first_name, :last_name, :personal_id_number,
5
+ :personal_id_issuer, :personal_id_type, :tax_id, :birth_date,
6
+ :nationality, :gender, :occupation, :home_address, :work_address,
7
+ :phone_numbers, :legal_entity, :politically_exposed_person,
8
+ :usage_tier, :accepted_usage_tier
9
+
10
+ # @visibility private
11
+ def self.from_json(json)
12
+ new.tap do |thing|
13
+ thing.id = json[0]
14
+ thing.first_name = json[1]
15
+ thing.last_name = json[2]
16
+ thing.personal_id_number = json[3]
17
+ thing.personal_id_issuer = json[4]
18
+ thing.personal_id_type = json[5]
19
+ thing.tax_id = json[6]
20
+ thing.birth_date = Time.at(json[7])
21
+ thing.nationality = json[8]
22
+ thing.gender = json[9]
23
+ thing.occupation = json[10]
24
+ thing.home_address = json[11]
25
+ thing.work_address = json[12]
26
+ thing.phone_numbers = json[13]
27
+ thing.legal_entity = json[14]
28
+ thing.politically_exposed_person = json[15]
29
+ thing.usage_tier = json[16]
30
+ thing.accepted_usage_tier = json[17]
31
+ end
32
+ end
33
+
34
+ def self.create!(params)
35
+ params = params.dup
36
+ .merge(birth_date: params[:birth_date].strftime('%Y/%m/%d'))
37
+ from_json(Api.private(:post, "/private/kyc_profiles", params))
38
+ end
39
+
40
+ def self.find(id)
41
+ from_json(Api.private(:get, "/private/kyc_profiles/#{id}"))
42
+ end
43
+
44
+ def self.all
45
+ Api.private(:get, "/private/kyc_profiles").collect{|x| from_json(x) }
46
+ end
47
+
48
+ def update!(params)
49
+ params = params.dup
50
+ .merge(birth_date: params[:birth_date].strftime('%Y/%m/%d'))
51
+ self.class.from_json(Api.private(:put, "/private/kyc_profiles/#{id}", params))
52
+ end
53
+
54
+ def add_kyc_file!(path)
55
+ response = Api.private(:post, "/private/kyc_profiles/#{id}/kyc_files",
56
+ {}, {document: path})
57
+ KycFile.from_json(response)
58
+ end
59
+
60
+ def kyc_files
61
+ Api.private(:get, "/private/kyc_profiles/#{id}/kyc_files")
62
+ .collect{|x| KycFile.from_json(x)}
63
+ end
64
+ end
65
+ end
66
+
@@ -0,0 +1,11 @@
1
+ module Bitex
2
+ # Exchange rates for cash in and cash out
3
+ class Rates
4
+ # The rates tree conveniently formatted as a ruby Hash with
5
+ # symbolized keys.
6
+ # @see https://bitex.la/developers#rates
7
+ def self.all
8
+ Api.private(:get, "/private/rates").deep_symbolize_keys
9
+ end
10
+ end
11
+ end
@@ -23,5 +23,13 @@ module Bitex
23
23
  thing.quantity = BigDecimal.new(json[4].to_s)
24
24
  end
25
25
  end
26
+
27
+ def self.find(specie, id)
28
+ from_json(Api.private(:get, "/private/#{specie}/deposits/#{id}"))
29
+ end
30
+
31
+ def self.all(specie)
32
+ Api.private(:get, "/private/#{specie}/deposits").collect{|x| from_json(x) }
33
+ end
26
34
  end
27
35
  end
@@ -28,8 +28,8 @@ module Bitex
28
28
  # @!attribute reason
29
29
  # Returns the reason for cancellation of this withdrawal, if any.
30
30
  # * :not_cancelled
31
- # * :insufficient_funds The instruction was received, but you didn't have enough
32
- # funds available
31
+ # * :insufficient_funds The instruction was received, but you didn't have
32
+ # enough funds available
33
33
  # * :destination_invalid The destination address was invalid.
34
34
  attr_accessor :reason
35
35
 
@@ -40,6 +40,10 @@ module Bitex
40
40
  # @!attribute label
41
41
  # @return [String] A custom label you gave to this address.
42
42
  attr_accessor :label
43
+
44
+ # @!attribute kyc_profile_id
45
+ # @return [Integer] Kyc profile id for which this request was made.
46
+ attr_accessor :kyc_profile_id
43
47
 
44
48
  # @visibility private
45
49
  def self.from_json(json)
@@ -60,7 +64,26 @@ module Bitex
60
64
  thing.reason = reason_lookup[json[6]]
61
65
  thing.to_address = json[7]
62
66
  thing.label = json[8]
67
+ thing.kyc_profile_id = json[9]
63
68
  end
64
69
  end
70
+
71
+ def self.create!(specie, address, amount, label, kyc_profile_id=nil)
72
+ from_json(Api.private(:post, "/private/#{specie}/withdrawals", {
73
+ address: address,
74
+ amount: amount,
75
+ label: label,
76
+ kyc_profile_id: kyc_profile_id
77
+ }))
78
+ end
79
+
80
+ def self.find(specie, id)
81
+ from_json(Api.private(:get, "/private/#{specie}/withdrawals/#{id}"))
82
+ end
83
+
84
+ def self.all(specie)
85
+ Api.private(:get, "/private/#{specie}/withdrawals")
86
+ .collect{|x| from_json(x) }
87
+ end
65
88
  end
66
89
  end
@@ -41,6 +41,31 @@ module Bitex
41
41
  # sender.
42
42
  # * :other we'll contact you regarding this deposit.
43
43
  attr_accessor :reason
44
+
45
+ # @!attribute country
46
+ # Country of origin for this deposit.
47
+ attr_accessor :country
48
+
49
+ # @!attribute currency
50
+ # Local currency for the country.
51
+ attr_accessor :currency
52
+
53
+ # @!attribute kyc_profile_id
54
+ # KYC profile on whose behalf this deposit is being created.
55
+ attr_accessor :kyc_profile_id
56
+
57
+ # @!attribute request_details
58
+ # Details for our account officers about this deposit.
59
+ attr_accessor :request_details
60
+
61
+ # @!attribute astropay_response_body
62
+ # Response from astropay if selected as the deposit method.
63
+ # The 'url' field should be the astropay payment url for this deposit.
64
+ attr_accessor :astropay_response_body
65
+
66
+ # @!attribute third_party_reference
67
+ # This deposit's id as issued by the third party payment processor, if any.
68
+ attr_accessor :third_party_reference
44
69
 
45
70
  # @visibility private
46
71
  def self.from_json(json)
@@ -65,7 +90,32 @@ module Bitex
65
90
  thing.deposit_method = deposit_method_lookup[json[5]]
66
91
  thing.status = status_lookup[json[6]]
67
92
  thing.reason = reason_lookup[json[7]]
93
+ thing.country = json[8]
94
+ thing.currency = json[9]
95
+ thing.kyc_profile_id = json[10]
96
+ thing.request_details = json[11]
97
+ thing.astropay_response_body = json[12]
98
+ thing.third_party_reference = json[13]
68
99
  end
69
100
  end
101
+
102
+ def self.create!(country, amount, currency, method, details, profile=nil)
103
+ from_json(Api.private(:post, "/private/usd/deposits", {
104
+ country: country,
105
+ amount: amount,
106
+ currency: currency,
107
+ deposit_method: method,
108
+ request_details: details,
109
+ kyc_profile_id: profile,
110
+ }))
111
+ end
112
+
113
+ def self.find(id)
114
+ from_json(Api.private(:get, "/private/usd/deposits/#{id}"))
115
+ end
116
+
117
+ def self.all
118
+ Api.private(:get, "/private/usd/deposits").collect{|x| from_json(x) }
119
+ end
70
120
  end
71
121
  end
@@ -32,6 +32,29 @@ module Bitex
32
32
  # not the receiving party.
33
33
  attr_accessor :reason
34
34
 
35
+ # @!attribute countr
36
+ # Returns ISO country code.
37
+ attr_accessor :country
38
+
39
+ # @!attribute currency
40
+ # Currency for this withdrawal.
41
+ attr_accessor :currency
42
+
43
+ # @!attribute payment_method
44
+ # Returns the payment method for this withdrawal.
45
+ # * :international_bank International bank transfer
46
+ # * :bb we'll contact you regarding this withdrawal.
47
+ attr_accessor :payment_method
48
+
49
+ # @!attribute label
50
+ attr_accessor :label
51
+
52
+ # @!attribute kyc_profile_id
53
+ attr_accessor :kyc_profile_id
54
+
55
+ # @!attribute instructions
56
+ attr_accessor :instructions
57
+
35
58
  # @visibility private
36
59
  def self.from_json(json)
37
60
  status_lookup = {
@@ -50,7 +73,33 @@ module Bitex
50
73
  thing.amount = BigDecimal.new(json[3].to_s)
51
74
  thing.status = status_lookup[json[4]]
52
75
  thing.reason = reason_lookup[json[5]]
76
+ thing.country = json[6]
77
+ thing.currency = json[7]
78
+ thing.payment_method = json[8]
79
+ thing.label = json[9]
80
+ thing.kyc_profile_id = json[10]
81
+ thing.instructions = json[11]
53
82
  end
54
83
  end
84
+
85
+ def self.create!(country, amount, currency, method, instructions, label, profile=nil)
86
+ from_json(Api.private(:post, "/private/usd/withdrawals", {
87
+ country: country,
88
+ amount: amount,
89
+ currency: currency,
90
+ payment_method: method,
91
+ instructions: instructions,
92
+ label: label,
93
+ kyc_profile_id: profile,
94
+ }))
95
+ end
96
+
97
+ def self.find(id)
98
+ from_json(Api.private(:get, "/private/usd/withdrawals/#{id}"))
99
+ end
100
+
101
+ def self.all
102
+ Api.private(:get, "/private/usd/withdrawals").collect{|x| from_json(x) }
103
+ end
55
104
  end
56
105
  end
data/lib/bitex/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bitex
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
Binary file
@@ -0,0 +1 @@
1
+ [1,1,"http://..","test.jpg","application/jpeg",10000]
@@ -0,0 +1 @@
1
+ [[1,1,"http://..","test.jpg","application/jpeg",10000]]
@@ -0,0 +1 @@
1
+ [ 1, "Billy", "Bob", "33222111N", "AR", "passport", "4332221115", 946685400, "brazilian", "male", "Singer", "Argentina, Buenos Aires, etc", "Argentina, La Plata", "+51 555 120921", true, true, "micro", "micro" ]
@@ -0,0 +1 @@
1
+ [[ 1, "Billy", "Bob", "33222111N", "AR", "passport", "4332221115", 946685400, "brazilian", "male", "Singer", "Argentina, Buenos Aires, etc", "Argentina, La Plata", "+51 555 120921", true, true, "micro", "micro" ]]
@@ -0,0 +1 @@
1
+ {"AR":{"astropay":{"USDARS":[8.7592,null,1412969688]},"reference":{"USDARS":[null,null,0]}},"BR":{"astropay":{"USDBRL":[2.3779,null,1412969689]}},"CL":{"astropay":{"USDCLP":[611.673,null,1412969691]}},"CO":{"astropay":{"USDCOP":[2006.368,null,1412969693]}},"PE":{"astropay":{"USDPEN":[2.9807,null,1412969696]}},"UY":{"astropay":{"USDUYU":[24.751,null,1412969698]}},"MX":{"astropay":{"USDMXN":[13.7471,null,1412969700]}}}
@@ -0,0 +1 @@
1
+ [5,12345678,946685400,1,100.00000000]
@@ -0,0 +1 @@
1
+ [[5,12345678,946685400,1,100.00000000]]
@@ -0,0 +1 @@
1
+ [6,12345678,946685400,1,100.00000000,1,0,"helloworld","label",1]
@@ -0,0 +1 @@
1
+ [[6,12345678,946685400,1,100.00000000,1,0,"helloworld","label",1]]
@@ -0,0 +1 @@
1
+ [7,12345678,946685400,110.00000000,100.00000000,1,1,0,"UY","UYU",1,"bank of new york mellon",{"status":"OK","link":"https://astr.com"},"ABABABABA"]
@@ -0,0 +1 @@
1
+ [[7,12345678,946685400,110.00000000,100.00000000,1,1,0,"UY","UYU",1,"bank of new york mellon",{"status":"OK","link":"https://astr.com"},"ABABABABA"]]
@@ -0,0 +1 @@
1
+ [8,12345678,946685400,100.00000000,1,0,"UY","UYU", "bb", "billy bob", 1, "las instrucciones"]
@@ -0,0 +1 @@
1
+ [[8,12345678,946685400,100.00000000,1,0,"UY","UYU", "bb", "billy bob", 1, "las instrucciones"]]
@@ -1 +1 @@
1
- [[3,12345678,946685400,1,2.00000000,600.00000000,0.05000000,300.00000000,123],[4,12345678,946685400,1,2.00000000,600.00000000,0.05000000,300.00000000,456],[5,12345678,946685400,1,100.00000000],[6,12345678,946685400,1,100.00000000,1,0,"helloworld","label"],[7,12345678,946685400,110.00000000,100.00000000,1,1,0],[8,12345678,946685400,100.00000000,1,0]]
1
+ [[3,12345678,946685400,1,2.00000000,600.00000000,0.05000000,300.00000000,123],[4,12345678,946685400,1,2.00000000,600.00000000,0.05000000,300.00000000,456],[5,12345678,946685400,1,100.00000000],[6,12345678,946685400,1,100.00000000,1,0,"helloworld","label",1],[7,12345678,946685400,110.00000000,100.00000000,1,1,0,"UY","UYU",1,"bank of new york mellon","{\"status\":\"OK\",\"link\":\"https://astr.com\"}","ABABABABA"],[8,12345678,946685400,100.00000000,1,0,"UY","UYU", "bb", "billy bob", 1, "las instrucciones"]]
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bitex::KycFile do
4
+ before :each do
5
+ Bitex.api_key = 'valid_api_key'
6
+ end
7
+
8
+ let(:as_json) do
9
+ [1,2,'http://foo.bar.example/photo.jpg', 'photo.jpg', 'application/jpeg', 10000]
10
+ end
11
+
12
+ { id: 1,
13
+ kyc_profile_id: 2,
14
+ url:'http://foo.bar.example/photo.jpg',
15
+ file_name: 'photo.jpg',
16
+ content_type: 'application/jpeg',
17
+ file_size: 10000
18
+ }.each do |field, value|
19
+ it "sets #{field}" do
20
+ subject.class.from_json(as_json).send(field).should == value
21
+ end
22
+ end
23
+
24
+ it 'lists all kyc profiles' do
25
+ stub_private(:get, '/private/kyc_files', 'kyc_files')
26
+ kyc_files = Bitex::KycFile.all
27
+ kyc_files.should be_an Array
28
+ kyc_files.first.should be_an Bitex::KycFile
29
+ end
30
+ end
@@ -0,0 +1,138 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bitex::KycProfile do
4
+ before :each do
5
+ Bitex.api_key = 'valid_api_key'
6
+ end
7
+
8
+ let(:params_for_create_or_update) do
9
+ { first_name: 'Billy',
10
+ last_name: 'Bob',
11
+ personal_id_number: '33222111N',
12
+ personal_id_issuer: 'AR',
13
+ personal_id_type: 'passport',
14
+ tax_id: '4332221115',
15
+ birth_date: Time.at(946685400),
16
+ nationality: 'brazilian',
17
+ gender: 'male',
18
+ occupation: 'Singer',
19
+ home_address: 'Argentina, Buenos Aires, etc',
20
+ work_address: 'Argentina, La Plata',
21
+ phone_numbers: '+51 555 120921',
22
+ legal_entity: true,
23
+ politically_exposed_person: true,
24
+ usage_tier: 'micro'
25
+ }
26
+ end
27
+
28
+ let(:rest_params_for_create_or_update) do
29
+ { first_name: 'Billy',
30
+ last_name: 'Bob',
31
+ personal_id_number: '33222111N',
32
+ personal_id_issuer: 'AR',
33
+ personal_id_type: 'passport',
34
+ tax_id: '4332221115',
35
+ birth_date: '1999/12/31',
36
+ nationality: 'brazilian',
37
+ gender: 'male',
38
+ occupation: 'Singer',
39
+ home_address: 'Argentina, Buenos Aires, etc',
40
+ work_address: 'Argentina, La Plata',
41
+ phone_numbers: '+51 555 120921',
42
+ legal_entity: true,
43
+ politically_exposed_person: true,
44
+ usage_tier: 'micro',
45
+ }
46
+ end
47
+
48
+ let(:as_json) do
49
+ [ 1, # Kyc Profile id.
50
+ 'Billy', # Name
51
+ 'Bob', # Last Name.
52
+ '33222111N', # Personal ID Number
53
+ 'AR', # ISO country code for the issuer of this ID.
54
+ 'passport', # Type of ID
55
+ '4332221115', # Tax Id
56
+ 946685400, # Birth date as unix timestamp.
57
+ 'brazilian', # Nationality
58
+ 'male', # Gender
59
+ 'Singer', # Occupation
60
+ 'Argentina, Buenos Aires, etc', # Home address.
61
+ 'Argentina, La Plata', # Work address.
62
+ '+51 555 120921', # Phone numbers.
63
+ true, # Is legal entity.
64
+ true, # Is politically exposed.
65
+ 'micro', # Requested usage tier.
66
+ 'micro', # Current usage tier as accepted by
67
+ # our compliance officers.
68
+ ]
69
+ end
70
+
71
+ { id: 1,
72
+ first_name: 'Billy',
73
+ last_name: 'Bob',
74
+ personal_id_number: '33222111N',
75
+ personal_id_issuer: 'AR',
76
+ personal_id_type: 'passport',
77
+ tax_id: '4332221115',
78
+ birth_date: Time.at(946685400),
79
+ nationality: 'brazilian',
80
+ gender: 'male',
81
+ occupation: 'Singer',
82
+ home_address: 'Argentina, Buenos Aires, etc',
83
+ work_address: 'Argentina, La Plata',
84
+ phone_numbers: '+51 555 120921',
85
+ legal_entity: true,
86
+ politically_exposed_person: true,
87
+ usage_tier: 'micro',
88
+ accepted_usage_tier: 'micro',
89
+ }.each do |field, value|
90
+ it "sets #{field}" do
91
+ subject.class.from_json(as_json).send(field).should == value
92
+ end
93
+ end
94
+
95
+ it 'creates a new kyc profile' do
96
+ stub_private(:post, "/private/kyc_profiles", 'kyc_profile',
97
+ rest_params_for_create_or_update)
98
+ Bitex::KycProfile.create!(params_for_create_or_update)
99
+ .should be_a Bitex::KycProfile
100
+ end
101
+
102
+ it 'finds a single kyc profile' do
103
+ stub_private(:get, '/private/kyc_profiles/1', 'kyc_profile')
104
+ kyc_profile = Bitex::KycProfile.find(1)
105
+ kyc_profile.should be_a Bitex::KycProfile
106
+ end
107
+
108
+ it 'lists all kyc profiles' do
109
+ stub_private(:get, '/private/kyc_profiles', 'kyc_profiles')
110
+ kyc_profiles = Bitex::KycProfile.all
111
+ kyc_profiles.should be_an Array
112
+ kyc_profiles.first.should be_an Bitex::KycProfile
113
+ end
114
+
115
+ it 'updates a kyc profile' do
116
+ stub_private(:put, "/private/kyc_profiles/1", 'kyc_profile',
117
+ rest_params_for_create_or_update)
118
+ kyc_profile = Bitex::KycProfile.from_json(as_json)
119
+ kyc_profile.update!(params_for_create_or_update)
120
+ end
121
+
122
+ it 'creates a kyc file' do
123
+ path = File.expand_path('../fixtures/file.jpg', __FILE__)
124
+ stub_private(:post, '/private/kyc_profiles/1/kyc_files', 'kyc_file',
125
+ {document: path})
126
+ kyc_profile = Bitex::KycProfile.from_json(as_json)
127
+ kyc_file = kyc_profile.add_kyc_file!(path)
128
+ kyc_file.should be_a Bitex::KycFile
129
+ end
130
+
131
+ it 'lists a profiles kyc files' do
132
+ stub_private(:get, '/private/kyc_profiles/1/kyc_files', 'kyc_files')
133
+ kyc_profile = Bitex::KycProfile.from_json(as_json)
134
+ kyc_files = kyc_profile.kyc_files
135
+ kyc_files.should be_an Array
136
+ kyc_files.first.should be_a Bitex::KycFile
137
+ end
138
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bitex::Rates do
4
+ it "gets all rates" do
5
+ Bitex.api_key = 'valid_api_key'
6
+ stub_private(:get, "/private/rates", 'rates')
7
+ Bitex::Rates.all.should == {
8
+ AR: {
9
+ astropay: {USDARS: [8.7592,nil,1412969688]},
10
+ reference:{USDARS: [nil,nil,0]}},
11
+ BR: {astropay:{USDBRL: [2.3779,nil,1412969689]}},
12
+ CL: {astropay:{USDCLP: [611.673,nil,1412969691]}},
13
+ CO: {astropay:{USDCOP: [2006.368,nil,1412969693]}},
14
+ PE: {astropay:{USDPEN: [2.9807,nil,1412969696]}},
15
+ UY: {astropay:{USDUYU: [24.751,nil,1412969698]}},
16
+ MX: {astropay:{USDMXN: [13.7471,nil,1412969700]}}
17
+ }
18
+ end
19
+ end
@@ -1,6 +1,10 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bitex::SpecieDeposit do
4
+ before :each do
5
+ Bitex.api_key = 'valid_api_key'
6
+ end
7
+
4
8
  let(:as_json) do
5
9
  [5,12345678,946685400,1,100.50000000]
6
10
  end
@@ -13,4 +17,18 @@ describe Bitex::SpecieDeposit do
13
17
  thing.should be_a BigDecimal
14
18
  thing.should == 100.5
15
19
  end
20
+
21
+ it 'finds a single btc deposit' do
22
+ stub_private(:get, '/private/btc/deposits/1', 'specie_deposit')
23
+ deposit = Bitex::SpecieDeposit.find(:btc, 1)
24
+ deposit.should be_a Bitex::SpecieDeposit
25
+ deposit.specie.should == :btc
26
+ end
27
+
28
+ it 'lists all btc deposits' do
29
+ stub_private(:get, '/private/btc/deposits', 'specie_deposits')
30
+ deposits = Bitex::SpecieDeposit.all(:btc)
31
+ deposits.should be_an Array
32
+ deposits.first.should be_an Bitex::SpecieDeposit
33
+ end
16
34
  end
@@ -1,8 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bitex::SpecieWithdrawal do
4
+ before :each do
5
+ Bitex.api_key = 'valid_api_key'
6
+ end
7
+
4
8
  let(:as_json) do
5
- [6,12345678,946685400,1,100.00000000,1,0, '1helloworld', 'label']
9
+ [6,12345678,946685400,1,100.00000000,1,0, '1helloworld', 'label', 1]
6
10
  end
7
11
 
8
12
  it_behaves_like 'API class'
@@ -40,8 +44,38 @@ describe Bitex::SpecieWithdrawal do
40
44
  thing.should == 'label'
41
45
  end
42
46
 
43
- it "sets to_addresses" do
47
+ it "sets to_address" do
44
48
  thing = Bitex::SpecieWithdrawal.from_json(as_json).to_address
45
49
  thing.should == "1helloworld"
46
50
  end
51
+
52
+ it "sets the kyc profile id" do
53
+ Bitex::SpecieWithdrawal.from_json(as_json).kyc_profile_id.should == 1
54
+ end
55
+
56
+ it 'creates a new withdrawal' do
57
+ stub_private(:post, "/private/ltc/withdrawals", 'specie_withdrawal', {
58
+ address: '1ADDR',
59
+ amount: 110,
60
+ label: 'thelabel',
61
+ })
62
+ deposit = Bitex::SpecieWithdrawal.create!(:ltc, '1ADDR', 110, 'thelabel')
63
+ deposit.should be_a Bitex::SpecieWithdrawal
64
+ deposit.status.should == :received
65
+ end
66
+
67
+ it 'finds a single usd deposit' do
68
+ stub_private(:get, '/private/btc/withdrawals/1', 'specie_withdrawal')
69
+ deposit = Bitex::SpecieWithdrawal.find(:btc, 1)
70
+ deposit.should be_a Bitex::SpecieWithdrawal
71
+ deposit.status.should == :received
72
+ end
73
+
74
+ it 'lists all usd deposits' do
75
+ stub_private(:get, '/private/btc/withdrawals', 'specie_withdrawals')
76
+ deposits = Bitex::SpecieWithdrawal.all(:btc)
77
+ deposits.should be_an Array
78
+ deposits.first.should be_an Bitex::SpecieWithdrawal
79
+ deposits.first.status.should == :received
80
+ end
47
81
  end
@@ -1,15 +1,23 @@
1
+ require 'open-uri'
1
2
  module RequestStubs
2
3
  def stub_get(path, fixture)
3
4
  stub_api(:get, path, fixture, {})
4
5
  end
5
6
 
6
7
  def stub_private(method, path, fixture, options = {})
7
- stub_api(method, path, fixture, options.merge({api_key: 'valid_api_key'}))
8
+ options[:api_key] = 'valid_api_key'
9
+ stub_api(method, path, fixture, options)
8
10
  end
9
11
 
10
12
  def stub_api(method, path, fixture, options)
11
13
  fixture_path = File.expand_path("../../fixtures/#{fixture}.json", __FILE__)
12
- with = method == :get ? {query: options} : {body: options.to_query}
14
+ with = if method == :get
15
+ {query: options}
16
+ elsif method == :put
17
+ {body: options.to_query }
18
+ else
19
+ {body: options.collect{|k,v| "#{k}=#{CGI.escape(v.to_s).gsub('+','%20')}"}* '&' }
20
+ end
13
21
  stub_request(method, "https://bitex.la/api-v1/rest#{path}")
14
22
  .with(with)
15
23
  .to_return(status: 200, body: File.read(fixture_path))
@@ -1,8 +1,14 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bitex::UsdDeposit do
4
+ before :each do
5
+ Bitex.api_key = 'valid_api_key'
6
+ end
7
+
4
8
  let(:as_json) do
5
- [7,12345678,946685400,110.0000000, 100.00000000,1,1,0]
9
+ [ 7,12345678,946685400,110.0000000, 100.00000000,1,1,0,
10
+ 'UY', 'UYU', 1, 'bank of new york mellon',
11
+ {"status" => "OK","link" => "https://astr.com"}, 'ABABABABA']
6
12
  end
7
13
 
8
14
  it_behaves_like 'API class'
@@ -18,6 +24,32 @@ describe Bitex::UsdDeposit do
18
24
  thing.should be_a BigDecimal
19
25
  thing.should == 110.0
20
26
  end
27
+
28
+ it "sets country" do
29
+ Bitex::UsdDeposit.from_json(as_json).country.should == 'UY'
30
+ end
31
+
32
+ it "sets currency" do
33
+ Bitex::UsdDeposit.from_json(as_json).currency.should == 'UYU'
34
+ end
35
+
36
+ it "sets kyc profile" do
37
+ Bitex::UsdDeposit.from_json(as_json).kyc_profile_id.should == 1
38
+ end
39
+
40
+ it "sets details" do
41
+ Bitex::UsdDeposit.from_json(as_json).request_details.should ==
42
+ 'bank of new york mellon'
43
+ end
44
+
45
+ it "sets the astropay_response_body" do
46
+ Bitex::UsdDeposit.from_json(as_json).astropay_response_body.should ==
47
+ {"status" => "OK","link" => "https://astr.com"}
48
+ end
49
+
50
+ it "sets the third party reference" do
51
+ Bitex::UsdDeposit.from_json(as_json).third_party_reference.should == 'ABABABABA'
52
+ end
21
53
 
22
54
  { 1 => :astropay,
23
55
  2 => :other,
@@ -48,4 +80,34 @@ describe Bitex::UsdDeposit do
48
80
  Bitex::UsdDeposit.from_json(as_json).reason.should == symbol
49
81
  end
50
82
  end
83
+
84
+ it 'creates a new deposit' do
85
+ stub_private(:post, "/private/usd/deposits", 'usd_deposit', {
86
+ country: 'UY',
87
+ amount: 110,
88
+ currency: 'UYU',
89
+ deposit_method: 'astropay',
90
+ request_details: 'bank of new york mellon',
91
+ })
92
+ deposit = Bitex::UsdDeposit.create!('UY', 110, 'UYU', 'astropay',
93
+ 'bank of new york mellon')
94
+ deposit.should be_a Bitex::UsdDeposit
95
+ deposit.astropay_response_body.should be_a Hash
96
+ deposit.status.should == :pending
97
+ end
98
+
99
+ it 'finds a single usd deposit' do
100
+ stub_private(:get, '/private/usd/deposits/1', 'usd_deposit')
101
+ deposit = Bitex::UsdDeposit.find(1)
102
+ deposit.should be_a Bitex::UsdDeposit
103
+ deposit.status.should == :pending
104
+ end
105
+
106
+ it 'lists all usd deposits' do
107
+ stub_private(:get, '/private/usd/deposits', 'usd_deposits')
108
+ deposits = Bitex::UsdDeposit.all
109
+ deposits.should be_an Array
110
+ deposits.first.should be_an Bitex::UsdDeposit
111
+ deposits.first.status.should == :pending
112
+ end
51
113
  end
@@ -1,8 +1,12 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bitex::UsdWithdrawal do
4
+ before :each do
5
+ Bitex.api_key = 'valid_api_key'
6
+ end
7
+
4
8
  let(:as_json) do
5
- [8,12345678,946685400,100.00000000,1,0,]
9
+ [8,12345678,946685400,100.00000000,1,0,'UY','UYU', 'bb', 'billy bob', 1, 'las instrucciones']
6
10
  end
7
11
 
8
12
  it_behaves_like 'API class'
@@ -13,6 +17,36 @@ describe Bitex::UsdWithdrawal do
13
17
  thing.should == 100.0
14
18
  end
15
19
 
20
+ it 'sets country' do
21
+ thing = Bitex::UsdWithdrawal.from_json(as_json).country
22
+ thing.should == 'UY'
23
+ end
24
+
25
+ it 'sets currency' do
26
+ thing = Bitex::UsdWithdrawal.from_json(as_json).currency
27
+ thing.should == 'UYU'
28
+ end
29
+
30
+ it 'sets payment method' do
31
+ thing = Bitex::UsdWithdrawal.from_json(as_json).payment_method
32
+ thing.should == 'bb'
33
+ end
34
+
35
+ it 'sets label' do
36
+ thing = Bitex::UsdWithdrawal.from_json(as_json).label
37
+ thing.should == 'billy bob'
38
+ end
39
+
40
+ it 'sets kyc profile id' do
41
+ thing = Bitex::UsdWithdrawal.from_json(as_json).kyc_profile_id
42
+ thing.should == 1
43
+ end
44
+
45
+ it 'sets instructions' do
46
+ thing = Bitex::UsdWithdrawal.from_json(as_json).instructions
47
+ thing.should == 'las instrucciones'
48
+ end
49
+
16
50
  { 1 => :received,
17
51
  2 => :pending,
18
52
  3 => :done,
@@ -34,4 +68,34 @@ describe Bitex::UsdWithdrawal do
34
68
  Bitex::UsdWithdrawal.from_json(as_json).reason.should == symbol
35
69
  end
36
70
  end
71
+
72
+ it 'creates a new withdrawal' do
73
+ stub_private(:post, "/private/usd/withdrawals", 'usd_withdrawal', {
74
+ country: 'UY',
75
+ amount: 110,
76
+ currency: 'UYU',
77
+ payment_method: 'bb',
78
+ instructions: 'bank of new york mellon',
79
+ label: 'a label',
80
+ })
81
+ deposit = Bitex::UsdWithdrawal.create!('UY', 110, 'UYU', 'bb',
82
+ 'bank of new york mellon', 'a label')
83
+ deposit.should be_a Bitex::UsdWithdrawal
84
+ deposit.status.should == :received
85
+ end
86
+
87
+ it 'finds a single usd deposit' do
88
+ stub_private(:get, '/private/usd/withdrawals/1', 'usd_withdrawal')
89
+ deposit = Bitex::UsdWithdrawal.find(1)
90
+ deposit.should be_a Bitex::UsdWithdrawal
91
+ deposit.status.should == :received
92
+ end
93
+
94
+ it 'lists all usd deposits' do
95
+ stub_private(:get, '/private/usd/withdrawals', 'usd_withdrawals')
96
+ deposits = Bitex::UsdWithdrawal.all
97
+ deposits.should be_an Array
98
+ deposits.first.should be_an Bitex::UsdWithdrawal
99
+ deposits.first.status.should == :received
100
+ end
37
101
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-08-17 00:00:00.000000000 Z
13
+ date: 2014-10-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -175,10 +175,13 @@ files:
175
175
  - lib/bitex.rb
176
176
  - lib/bitex/api.rb
177
177
  - lib/bitex/buy.rb
178
+ - lib/bitex/kyc_file.rb
179
+ - lib/bitex/kyc_profile.rb
178
180
  - lib/bitex/market.rb
179
181
  - lib/bitex/match.rb
180
182
  - lib/bitex/order.rb
181
183
  - lib/bitex/profile.rb
184
+ - lib/bitex/rates.rb
182
185
  - lib/bitex/sell.rb
183
186
  - lib/bitex/specie_deposit.rb
184
187
  - lib/bitex/specie_withdrawal.rb
@@ -196,15 +199,32 @@ files:
196
199
  - spec/fixtures/bids_cancel.json
197
200
  - spec/fixtures/bids_create.json
198
201
  - spec/fixtures/bids_show.json
202
+ - spec/fixtures/file.jpg
203
+ - spec/fixtures/kyc_file.json
204
+ - spec/fixtures/kyc_files.json
205
+ - spec/fixtures/kyc_profile.json
206
+ - spec/fixtures/kyc_profiles.json
199
207
  - spec/fixtures/market_ticker.json
200
208
  - spec/fixtures/order_book.json
201
209
  - spec/fixtures/orders.json
202
210
  - spec/fixtures/profile.json
211
+ - spec/fixtures/rates.json
212
+ - spec/fixtures/specie_deposit.json
213
+ - spec/fixtures/specie_deposits.json
214
+ - spec/fixtures/specie_withdrawal.json
215
+ - spec/fixtures/specie_withdrawals.json
203
216
  - spec/fixtures/transactions.json
217
+ - spec/fixtures/usd_deposit.json
218
+ - spec/fixtures/usd_deposits.json
219
+ - spec/fixtures/usd_withdrawal.json
220
+ - spec/fixtures/usd_withdrawals.json
204
221
  - spec/fixtures/user_transactions.json
222
+ - spec/kyc_file_spec.rb
223
+ - spec/kyc_profile_spec.rb
205
224
  - spec/market_spec.rb
206
225
  - spec/order_spec.rb
207
226
  - spec/profile_spec.rb
227
+ - spec/rates_spec.rb
208
228
  - spec/sell_spec.rb
209
229
  - spec/spec_helper.rb
210
230
  - spec/specie_deposit_spec.rb
@@ -251,15 +271,32 @@ test_files:
251
271
  - spec/fixtures/bids_cancel.json
252
272
  - spec/fixtures/bids_create.json
253
273
  - spec/fixtures/bids_show.json
274
+ - spec/fixtures/file.jpg
275
+ - spec/fixtures/kyc_file.json
276
+ - spec/fixtures/kyc_files.json
277
+ - spec/fixtures/kyc_profile.json
278
+ - spec/fixtures/kyc_profiles.json
254
279
  - spec/fixtures/market_ticker.json
255
280
  - spec/fixtures/order_book.json
256
281
  - spec/fixtures/orders.json
257
282
  - spec/fixtures/profile.json
283
+ - spec/fixtures/rates.json
284
+ - spec/fixtures/specie_deposit.json
285
+ - spec/fixtures/specie_deposits.json
286
+ - spec/fixtures/specie_withdrawal.json
287
+ - spec/fixtures/specie_withdrawals.json
258
288
  - spec/fixtures/transactions.json
289
+ - spec/fixtures/usd_deposit.json
290
+ - spec/fixtures/usd_deposits.json
291
+ - spec/fixtures/usd_withdrawal.json
292
+ - spec/fixtures/usd_withdrawals.json
259
293
  - spec/fixtures/user_transactions.json
294
+ - spec/kyc_file_spec.rb
295
+ - spec/kyc_profile_spec.rb
260
296
  - spec/market_spec.rb
261
297
  - spec/order_spec.rb
262
298
  - spec/profile_spec.rb
299
+ - spec/rates_spec.rb
263
300
  - spec/sell_spec.rb
264
301
  - spec/spec_helper.rb
265
302
  - spec/specie_deposit_spec.rb