Class: HlrLookupsSDK::Client
- Inherits:
-
Object
- Object
- HlrLookupsSDK::Client
- Defined in:
- lib/ruby_hlr_client/client.rb
Instance Method Summary collapse
-
#delete(endpoint, params = {}) ⇒ Object
Use this method to communicate with DELETE endpoints.
-
#get(endpoint, params = {}) ⇒ Object
Use this method to communicate with GET endpoints.
-
#initialize(key, secret, log_file = nil) ⇒ Client
constructor
HLR Lookups API client constructor, initialize this with the API key and secret as given by www.hlr-lookups.com/en/api-settings.
-
#post(endpoint, params = {}) ⇒ Object
Use this method to communicate with POST endpoints.
-
#put(endpoint, params = {}) ⇒ Object
Use this method to communicate with PUT endpoints.
Constructor Details
#initialize(key, secret, log_file = nil) ⇒ Client
HLR Lookups API client constructor, initialize this with the API key and secret as given by www.hlr-lookups.com/en/api-settings
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ruby_hlr_client/client.rb', line 19 def initialize(key, secret, log_file = nil) # @string The API Key as given by https://www.hlr-lookups.com/en/api-settings @key = key # @string The API Secret as given by https://www.hlr-lookups.com/en/api-settings @secret = secret # @string The API version to which we connect (leave it as is) @api_version = HlrLookupsSDK::API_VERSION # @string Used in the HTTP user agent (leave it as is) @client_name = HlrLookupsSDK::CLIENT_NAME # @string The current version of this SDK, used in the HTTP user agent (leave it as is) @client_version = HlrLookupsSDK::CLIENT_VERSION # @string HLR Lookup connect url @connect_url = HlrLookupsSDK::CONNECT_URL # @string|nil Specifies the log file to which to write, if any. @log_file = log_file ? log_file : nil end |
Instance Method Details
#delete(endpoint, params = {}) ⇒ Object
Use this method to communicate with DELETE endpoints
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/ruby_hlr_client/client.rb', line 123 def delete(endpoint, params = {}) path = build_connect_url(endpoint) headers = build_headers(endpoint, 'DELETE', params) log "DELETE " + path + " " + params.to_s log headers.to_s begin response = RestClient::Request.execute(method: :delete, url: path, payload: params.to_json, headers: headers, timeout: 15) rescue RestClient::ExceptionWithResponse => e log e.http_code.to_s + " " + e.response.to_s return e.response end log response.code.to_s + " " + response.to_s response end |
#get(endpoint, params = {}) ⇒ Object
Use this method to communicate with GET endpoints
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ruby_hlr_client/client.rb', line 48 def get(endpoint, params = {}) path = build_connect_url(endpoint) + '?' + URI.encode_www_form(params) headers = build_headers(endpoint, 'GET', params) log "GET " + path log headers.to_s begin response = RestClient::Request.execute(method: :get, url: path, headers: headers, timeout: 15) rescue RestClient::ExceptionWithResponse => e log e.http_code.to_s + " " + e.response.to_s return e.response end log response.code.to_s + " " + response.to_s response end |
#post(endpoint, params = {}) ⇒ Object
Use this method to communicate with POST endpoints
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ruby_hlr_client/client.rb', line 73 def post(endpoint, params = {}) path = build_connect_url(endpoint) headers = build_headers(endpoint, 'POST', params) log "POST " + path + " " + params.to_s log headers.to_s begin response = RestClient::Request.execute(method: :post, url: path, payload: params.to_json, headers: headers, timeout: 15) rescue RestClient::ExceptionWithResponse => e log e.http_code.to_s + " " + e.response.to_s return e.response end log response.code.to_s + " " + response.to_s response end |
#put(endpoint, params = {}) ⇒ Object
Use this method to communicate with PUT endpoints
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/ruby_hlr_client/client.rb', line 98 def put(endpoint, params = {}) path = build_connect_url(endpoint) headers = build_headers(endpoint, 'PUT', params) log "PUT " + path + " " + params.to_s log headers.to_s begin response = RestClient::Request.execute(method: :put, url: path, payload: params.to_json, headers: headers, timeout: 15) rescue RestClient::ExceptionWithResponse => e log e.http_code.to_s + " " + e.response.to_s return e.response end log response.code.to_s + " " + response.to_s response end |