coinsetter 0.0.4 → 0.0.5
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 +4 -4
 - data/lib/coinsetter.rb +19 -3
 - data/lib/coinsetter/client_sessions.rb +0 -10
 - data/lib/coinsetter/collection.rb +19 -23
 - data/lib/coinsetter/configuration.rb +6 -2
 - data/lib/coinsetter/customer/account.rb +1 -1
 - data/lib/coinsetter/customer/accounts.rb +0 -34
 - data/lib/coinsetter/net.rb +5 -6
 - data/lib/coinsetter/orders.rb +0 -8
 - data/lib/coinsetter/version.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 0549dc7dac8f00511771de0fd1755776352de7ed
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 6f1a4e13ed46e238685487451dca478332fa1ac5
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 574c4c149d396ba13aaf70f9c4a0dc1be0b961e986c6c06639c7b3d40a847b67deb6924d3fd7fe4a34dab2aa2a4fee3093cd487e7e4bf22c1c7d7635c10d8e0c
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 0c05f54be060c345b691d59be7eabfdb16eca26d0936e74fe703b0b9e60b513420cce9e4b9d832a326bb0ab8c75447711a9059cdd5ce8ad100e19844658ab3f6
         
     | 
    
        data/lib/coinsetter.rb
    CHANGED
    
    | 
         @@ -43,7 +43,7 @@ module Coinsetter 
     | 
|
| 
       43 
43 
     | 
    
         
             
                  yield client_session if block_given?
         
     | 
| 
       44 
44 
     | 
    
         
             
                  destroy_client_session!
         
     | 
| 
       45 
45 
     | 
    
         
             
                else
         
     | 
| 
       46 
     | 
    
         
            -
                   
     | 
| 
      
 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 
     | 
    
         
            -
                 
     | 
| 
      
 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('/')  
     | 
| 
      
 13 
     | 
    
         
            +
                  self.path   = [split_module.join('/'), last.camelize(:lower)].join('/')
         
     | 
| 
       13 
14 
     | 
    
         
             
                end
         
     | 
| 
       14 
15 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
                def create(options={},  
     | 
| 
       16 
     | 
    
         
            -
                   
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
                   
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
    
         
            -
                   
     | 
| 
      
 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 
     | 
    
         
            -
                   
     | 
| 
       47 
     | 
    
         
            -
                     
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
                     
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       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, : 
     | 
| 
      
 3 
     | 
    
         
            +
                attr_accessor :username, :password, :ip_address, :staging
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
                def initialize
         
     | 
| 
       6 
     | 
    
         
            -
                  @ 
     | 
| 
      
 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 <  
     | 
| 
      
 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
         
     | 
    
        data/lib/coinsetter/net.rb
    CHANGED
    
    | 
         @@ -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[ 
     | 
| 
      
 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 ==  
     | 
| 
       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 
     | 
    
         | 
    
        data/lib/coinsetter/orders.rb
    CHANGED
    
    
    
        data/lib/coinsetter/version.rb
    CHANGED