Class: OcxClient::RestApi

Inherits:
Object show all
Defined in:
lib/ocx_client/rest_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ RestApi

Returns a new instance of RestApi.



9
10
11
12
13
14
# File 'lib/ocx_client/rest_api.rb', line 9

def initialize(options={})
  options = options.symbolize_keys
  setup_auth_keys options
  @endpoint = options[:endpoint] || 'https://openapi.ocx.com'
  @timeout  = options[:timeout]  || 60
end

Instance Attribute Details

#authObject (readonly)

Returns the value of attribute auth.



7
8
9
# File 'lib/ocx_client/rest_api.rb', line 7

def auth
  @auth
end

Instance Method Details

#get(path, params = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/ocx_client/rest_api.rb', line 25

def get(path, params={})
  check_auth!

  uri = URI("#{@endpoint}#{path}")

  request(:get, path, @auth, params) do |http, signed_params|
    uri.query = URI.encode_www_form signed_params
    http.request_get(uri.request_uri)
  end
end

#get_public(path, params = {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/ocx_client/rest_api.rb', line 16

def get_public(path, params={})
  uri = URI("#{@endpoint}#{path}")
  uri.query = URI.encode_www_form params

  request(:get, path, nil, params) do |http, _|
    http.request_get(uri.request_uri)
  end
end

#post(path, params = {}) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/ocx_client/rest_api.rb', line 36

def post(path, params={})
  check_auth!

  request(:post, path, @auth, params) do |http, signed_params|
    http.request_post(path, signed_params.to_query)
  end
end