Class: CloudWaba::HttpClient
- Inherits:
-
Object
- Object
- CloudWaba::HttpClient
- Defined in:
- lib/cloud_waba/http_client.rb
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
Instance Method Summary collapse
- #delete(headers: {}, params: {}) ⇒ Object
- #get(headers: {}, params: {}) ⇒ Object
-
#initialize(base_url:, auth_token:) ⇒ HttpClient
constructor
A new instance of HttpClient.
- #post(headers: {}, body:) ⇒ Object
- #put(headers: {}, body:) ⇒ Object
Constructor Details
#initialize(base_url:, auth_token:) ⇒ HttpClient
Returns a new instance of HttpClient.
11 12 13 14 |
# File 'lib/cloud_waba/http_client.rb', line 11 def initialize(base_url:, auth_token:) @base_url = base_url @auth_token = auth_token end |
Instance Attribute Details
#auth_token ⇒ Object
Returns the value of attribute auth_token.
9 10 11 |
# File 'lib/cloud_waba/http_client.rb', line 9 def auth_token @auth_token end |
#base_url ⇒ Object
Returns the value of attribute base_url.
8 9 10 |
# File 'lib/cloud_waba/http_client.rb', line 8 def base_url @base_url end |
Instance Method Details
#delete(headers: {}, params: {}) ⇒ Object
34 35 36 37 38 |
# File 'lib/cloud_waba/http_client.rb', line 34 def delete(headers:{}, params:{}) client = http_client.headers(headers) client = client.auth("Bearer #{@auth_token}") unless @auth_token.nil? response = client.delete(@base_url, ssl_context: ssl_ctx, params: params) end |
#get(headers: {}, params: {}) ⇒ Object
16 17 18 19 20 |
# File 'lib/cloud_waba/http_client.rb', line 16 def get(headers: {}, params: {}) client = http_client.headers(headers) client = client.auth("Bearer #{@auth_token}") unless @auth_token.nil? response = client.get(@base_url, ssl_context: ssl_ctx, params: params) end |
#post(headers: {}, body:) ⇒ Object
22 23 24 25 26 |
# File 'lib/cloud_waba/http_client.rb', line 22 def post(headers: {}, body:) client = http_client.headers(headers) client = client.auth("Bearer #{@auth_token}") unless @auth_token.nil? response = client.post(@base_url, ssl_context: ssl_ctx, json: body) end |
#put(headers: {}, body:) ⇒ Object
28 29 30 31 32 |
# File 'lib/cloud_waba/http_client.rb', line 28 def put(headers: {}, body:) client = http_client.headers(headers) client = client.auth("Bearer #{@auth_token}") unless @auth_token.nil? response = client.put(@base_url, ssl_context: ssl_ctx, json: body.to_json) end |