Class: Wdt::Client

Inherits:
Object
  • Object
show all
Includes:
Authentication, Shipments, Stocks, Trades
Defined in:
lib/wdt/client.rb,
lib/wdt/client/stocks.rb,
lib/wdt/client/trades.rb,
lib/wdt/client/shipments.rb

Defined Under Namespace

Modules: Shipments, Stocks, Trades

Constant Summary

Constants included from Authentication

Authentication::SEPARATOR1, Authentication::SEPARATOR2, Authentication::SEPARATOR3

Instance Method Summary collapse

Methods included from Shipments

#ack_shipments, #query_shipments

Methods included from Trades

#push_trade

Methods included from Authentication

#get_signature, #sign, #stringify_keys

Constructor Details

#initialize(options = {}) ⇒ Client

Creates a new API



17
18
19
20
21
22
# File 'lib/wdt/client.rb', line 17

def initialize(options={})
  options = Wdt.options.merge(options)
  Configuration::VALID_OPTIONS_KEYS.each do |key|
    send("#{key}=", options[key])
  end
end

Instance Method Details

#configObject



24
25
26
27
28
29
30
# File 'lib/wdt/client.rb', line 24

def config
  conf = {}
  Configuration::VALID_OPTIONS_KEYS.each do |key|
    conf[key] = send key
  end
  conf
end

#delete(url, options = {}) ⇒ Object

Make a HTTP delete request



43
44
45
# File 'lib/wdt/client.rb', line 43

def delete(url, options = {})
  request :delete, url, options
end

#get(url, options = {}) ⇒ Object

Make a HTTP GET request



33
34
35
# File 'lib/wdt/client.rb', line 33

def get(url, options = {})
  request :get, url, options
end

#head(url, options = {}) ⇒ Object

Make a HTTP HEAD request



53
54
55
# File 'lib/wdt/client.rb', line 53

def head(url, options = {})
  request :head, url, options
end

#patch(url, options = {}) ⇒ Object

Make a HTTP PATCH request



58
59
60
# File 'lib/wdt/client.rb', line 58

def patch(url, options = {})
  request :patch, url, options
end

#post(url, options = {}) ⇒ Object

Make a HTTP POST request



38
39
40
# File 'lib/wdt/client.rb', line 38

def post(url, options = {})
  request :post, url, options
end

#put(url, options = {}) ⇒ Object

Make a HTTP PUT request



48
49
50
# File 'lib/wdt/client.rb', line 48

def put(url, options = {})
  request :put, url, options
end

#request(method, path, payload) ⇒ Object

Executes the request, checking if it was successfull.



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/wdt/client.rb', line 63

def request(method, path, payload)
  payload = sign(payload)
  response = RestClient::Request.execute(
      :method => method,
      :url => endpoint + path,
      :payload => payload,
      :timeout => 10,
      :open_timeout => 10
    )

  response_hash = JSON.parse response
  Response.new(response_hash)
end