coinsetter 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aedfcd337a3f59c601cbd025d7468061811e0572
4
- data.tar.gz: 4512405dec9f1052afe28b08202535cd54ce6ade
3
+ metadata.gz: 0549dc7dac8f00511771de0fd1755776352de7ed
4
+ data.tar.gz: 6f1a4e13ed46e238685487451dca478332fa1ac5
5
5
  SHA512:
6
- metadata.gz: 0ab4587aac672330aed95d0f763d5a59788d3408c7ec1722af41f8a0e23454bcc88df4b1e5f0c93869c913d95f0cadbfb279c4d0c832d65ca9b7fb36eb417926
7
- data.tar.gz: f6d4aee9db741e02b4944c0131a18baaa68fd936bf6dac97c4099c0fb27ae86db53fe71e5326b0f577e15962709a17b7dbe21971ae7d00b609705a4882d56967
6
+ metadata.gz: 574c4c149d396ba13aaf70f9c4a0dc1be0b961e986c6c06639c7b3d40a847b67deb6924d3fd7fe4a34dab2aa2a4fee3093cd487e7e4bf22c1c7d7635c10d8e0c
7
+ data.tar.gz: 0c05f54be060c345b691d59be7eabfdb16eca26d0936e74fe703b0b9e60b513420cce9e4b9d832a326bb0ab8c75447711a9059cdd5ce8ad100e19844658ab3f6
@@ -43,7 +43,7 @@ module Coinsetter
43
43
  yield client_session if block_given?
44
44
  destroy_client_session!
45
45
  else
46
- client_session
46
+ {error: 'No Client Session available.'}
47
47
  end
48
48
  end
49
49
 
@@ -51,13 +51,29 @@ module Coinsetter
51
51
  @client_session ||= ClientSessions.new.create(credentials)
52
52
  end
53
53
 
54
+ def self.get_account(account_uuid)
55
+ Customer::Accounts.new(client_session.uuid).get(account_uuid)
56
+ end
57
+
54
58
  def self.destroy_client_session!
55
59
  client_session.destroy!
56
60
  @client_session = nil
57
61
  end
58
62
 
59
- def self.orders
60
- @@orders ||= Orders.new
63
+ def self.orders(uuid=nil)
64
+ Orders.new(uuid)
65
+ end
66
+
67
+ def self.accounts(uuid=nil)
68
+ Customer::Accounts.new(uuid)
69
+ end
70
+
71
+ def self.list_orders(account_id, view="OPEN")
72
+ orders.list("customer/account/#{account_id}/order", view: view)
73
+ end
74
+
75
+ def self.list_accounts
76
+ accounts.list
61
77
  end
62
78
 
63
79
  def self.add_order(side='BUY', options={})
@@ -1,15 +1,5 @@
1
1
  module Coinsetter
2
2
  class ClientSessions < Coinsetter::Collection
3
3
 
4
- def example
5
- JSON.generate({
6
- uuid: "38363173-e6fd-4f3a-8146-9ba50da2b1e3",
7
- message: "OK",
8
- requestStatus: "SUCCESS",
9
- userName: "johnqsmith#{rand(100)}",
10
- customerUuid: "b20ba985-827d-42f7-a355-37e699ac964b",
11
- customerStatus: "ACTIVE"
12
- })
13
- end
14
4
  end
15
5
  end
@@ -1,39 +1,36 @@
1
1
  module Coinsetter
2
2
  class Collection
3
- attr_accessor :module, :name, :model, :path, :response
3
+ attr_accessor :module, :name, :model, :path, :response, :headers, :session_uuid
4
4
 
5
- def initialize
5
+ def initialize(uuid=nil)
6
+ self.session_uuid = uuid ? {'coinsetter-client-session-id' => uuid} : {}
6
7
  self.module = self.class.name.singularize.underscore
7
8
  split_module = self.module.split('/')
8
9
  split_module.shift
9
10
  self.name = split_module.join('/')
10
11
  self.model = self.module.camelize.constantize
11
12
  last = split_module.pop
12
- self.path = split_module.join('/') + last.camelize(:lower)
13
+ self.path = [split_module.join('/'), last.camelize(:lower)].join('/')
13
14
  end
14
15
 
15
- def create(options={}, route=path)
16
- if Coinsetter.configured?
17
- self.response = Coinsetter::Net.post(route, options)
18
- else
19
- self.response = example
20
- end
16
+ def create(route=path, options={}, headers={})
17
+ headers.merge!(session_uuid)
18
+ self.response = Coinsetter::Net.post(route, options, headers)
21
19
 
22
20
  parse
23
21
  end
24
22
 
25
- def list(route=path, options={})
26
- if Coinsetter.configured?
27
- self.response = Coinsetter::Net.get(route, options)
28
- else
29
- self.response = example
30
- end
23
+ def list(route=path, options={}, headers={})
24
+ headers.merge!(session_uuid)
25
+ self.response = Coinsetter::Net.get(route, options, headers)
31
26
 
32
27
  parse_collection
33
28
  end
34
29
 
35
- def get(id, route=path, options={})
36
- self.response = Coinsetter::Net.get("#{route}/#{id}", options)
30
+ def get(id, route=path, options={}, headers={})
31
+ headers.merge!(session_uuid)
32
+ self.response = Coinsetter::Net.get("#{route}/#{id}", options, headers)
33
+
37
34
  parse
38
35
  end
39
36
 
@@ -43,12 +40,11 @@ module Coinsetter
43
40
 
44
41
  private
45
42
  def parse
46
- @parsed ||=
47
- if response.include? "\"requestStatus\":\"SUCCESS\""
48
- Coinsetter::Helper.parse_object! response, model
49
- else
50
- Coinsetter::Helper.parse_message! response
51
- end
43
+ if response.include? "\"requestStatus\":\"SUCCESS\""
44
+ Coinsetter::Helper.parse_object! response, model
45
+ else
46
+ Coinsetter::Helper.parse_message! response
47
+ end
52
48
  end
53
49
 
54
50
  def parse_collection
@@ -1,9 +1,13 @@
1
1
  module Coinsetter
2
2
  class Configuration
3
- attr_accessor :username, :password, :ip_address, :uri
3
+ attr_accessor :username, :password, :ip_address, :staging
4
4
 
5
5
  def initialize
6
- @uri = 'https://api.coinsetter.com/v1/'
6
+ @staging = false
7
+ end
8
+
9
+ def uri
10
+ "https://#{'staging-' if staging}api.coinsetter.com/v1/"
7
11
  end
8
12
  end
9
13
  end
@@ -1,6 +1,6 @@
1
1
  module Coinsetter
2
2
  module Customer
3
- class Account < ::Coinsetter::Model
3
+ class Account < Coinsetter::Model
4
4
  attr_accessor :account_uuid, :customer_uuid, :account_number, :name, :description, :btc_balance
5
5
  attr_accessor :usd_balance, :account_class, :active_status, :approved_margin_ratio, :create_date
6
6
 
@@ -2,40 +2,6 @@ module Coinsetter
2
2
  module Customer
3
3
  class Accounts < Coinsetter::Collection
4
4
 
5
- def example
6
- JSON.generate({
7
- accountList:
8
- [
9
- {
10
- accountUuid: "50af62c2-7221-49a1-85a8-dd34c6e0dd70",
11
- customerUuid: "b20ba985-827d-42f7-a355-37e699ac964b",
12
- accountNumber: "CST0000001",
13
- name: "My Bitcoin account",
14
- description: "For primary trading",
15
- btcBalance: 0E-8,
16
- usdBalance: 11.2,
17
- accountClass: "TEST",
18
- activeStatus: "ACTIVE",
19
- approvedMarginRatio: 1.0000,
20
- createDate: "18/05/2013 10:10:25.000",
21
- },
22
- {
23
- accountUuid: "b03a8e48-6ce4-4b5a-a8f5-ea6af8f288da",
24
- customerUuid: "b20ba985-827d-42f7-a355-37e699ac964b",
25
- accountNumber: "CSV0000002",
26
- name: "My Bitcoin account.2",
27
- description: "For primary trading",
28
- btcBalance: 0E-8,
29
- usdBalance: 11.2,
30
- accountClass: "VIRTUAL",
31
- activeStatus: "ACTIVE",
32
- approvedMarginRatio: 1.0000,
33
- createDate: "18/05/2013 10:10:25.000",
34
- }
35
- ]
36
- }
37
- )
38
- end
39
5
  end
40
6
  end
41
7
  end
@@ -27,10 +27,9 @@ module Coinsetter
27
27
 
28
28
  def self.put(path, args={}, headers={})
29
29
  res = connection.put do |req|
30
- req.url path
31
- req.headers["Accept"] = "application/json"
30
+ req.url path, args
31
+ req.headers['Content-Type'] = 'application/json'
32
32
  req.headers.merge!(headers)
33
- req.body = JSON.generate(args)
34
33
  end
35
34
 
36
35
  body(res)
@@ -47,10 +46,10 @@ module Coinsetter
47
46
  end
48
47
 
49
48
  def self.body(res)
50
- if res.status == 403
51
- "403 - Forbidden: You don't have permission to access"
52
- else
49
+ if res.status == 200
53
50
  res.body
51
+ else
52
+ JSON.generate({status: res.status, message: res.body})
54
53
  end
55
54
  end
56
55
 
@@ -1,13 +1,5 @@
1
1
  module Coinsetter
2
2
  class Orders < Coinsetter::Collection
3
3
 
4
- def example
5
- JSON.generate({
6
- uuid:"a8836f1d-53ee-4fbf-882b-577c90a711ff",
7
- message: "OK",
8
- orderNumber: "CS00000016",
9
- requestStatus: "SUCCESS"
10
- })
11
- end
12
4
  end
13
5
  end
@@ -1,3 +1,3 @@
1
1
  module Coinsetter
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coinsetter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis Galaviz