Class: OcxClient::RestApi
Instance Attribute Summary collapse
-
#auth ⇒ Object
readonly
Returns the value of attribute auth.
Instance Method Summary collapse
- #get(path, params = {}) ⇒ Object
- #get_public(path, params = {}) ⇒ Object
-
#initialize(options = {}) ⇒ RestApi
constructor
A new instance of RestApi.
- #post(path, params = {}) ⇒ Object
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(={}) = .symbolize_keys setup_auth_keys @endpoint = [:endpoint] || 'https://openapi.ocx.com' @timeout = [:timeout] || 60 end |
Instance Attribute Details
#auth ⇒ Object (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 |