Class: Pike13::HTTPClient
- Inherits:
-
Object
- Object
- Pike13::HTTPClient
- Includes:
- HTTParty
- Defined in:
- lib/pike13/http_client.rb
Overview
HTTParty-based HTTP client for Pike13 API Provides HTTP methods with error handling
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
Instance Method Summary collapse
-
#delete(path, params = {}) ⇒ Hash
DELETE request.
-
#get(path, params = {}) ⇒ Hash, Array
GET request.
-
#initialize(base_url:, access_token:) ⇒ HTTPClient
constructor
A new instance of HTTPClient.
-
#patch(path, body = {}, params = {}) ⇒ Hash
PATCH request.
-
#post(path, body = {}, params = {}) ⇒ Hash
POST request.
-
#put(path, body = {}, params = {}) ⇒ Hash
PUT request.
Constructor Details
#initialize(base_url:, access_token:) ⇒ HTTPClient
Returns a new instance of HTTPClient.
14 15 16 17 |
# File 'lib/pike13/http_client.rb', line 14 def initialize(base_url:, access_token:) @base_url = base_url @access_token = access_token end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
12 13 14 |
# File 'lib/pike13/http_client.rb', line 12 def access_token @access_token end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
12 13 14 |
# File 'lib/pike13/http_client.rb', line 12 def base_url @base_url end |
Instance Method Details
#delete(path, params = {}) ⇒ Hash
DELETE request
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/pike13/http_client.rb', line 94 def delete(path, params = {}) handle_response do self.class.delete( full_path(path), query: params, headers: headers, timeout: 30 ) end end |
#get(path, params = {}) ⇒ Hash, Array
GET request
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/pike13/http_client.rb', line 24 def get(path, params = {}) handle_response do self.class.get( full_path(path), query: params, headers: headers, timeout: 30 ) end end |
#patch(path, body = {}, params = {}) ⇒ Hash
PATCH request
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/pike13/http_client.rb', line 77 def patch(path, body = {}, params = {}) handle_response do self.class.patch( full_path(path), body: body.to_json, query: params, headers: headers, timeout: 30 ) end end |
#post(path, body = {}, params = {}) ⇒ Hash
POST request
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pike13/http_client.rb', line 41 def post(path, body = {}, params = {}) handle_response do self.class.post( full_path(path), body: body.to_json, query: params, headers: headers, timeout: 30 ) end end |
#put(path, body = {}, params = {}) ⇒ Hash
PUT request
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/pike13/http_client.rb', line 59 def put(path, body = {}, params = {}) handle_response do self.class.put( full_path(path), body: body.to_json, query: params, headers: headers, timeout: 30 ) end end |