Class: PostalCodesRubyClient::Client
- Inherits:
-
Object
- Object
- PostalCodesRubyClient::Client
- Defined in:
- lib/postal_codes_ruby_client/client.rb
Instance Attribute Summary collapse
-
#api_token ⇒ Object
writeonly
Update the API token (e.g. after login or token regeneration).
-
#postal_codes ⇒ Object
readonly
Returns the value of attribute postal_codes.
Instance Method Summary collapse
-
#get(path, params = {}) ⇒ Object
Perform a GET request.
-
#initialize(api_token: nil, base_url: nil) ⇒ Client
constructor
A new instance of Client.
-
#post(path, body = nil) ⇒ Object
Perform a POST request with a JSON body.
Constructor Details
#initialize(api_token: nil, base_url: nil) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 |
# File 'lib/postal_codes_ruby_client/client.rb', line 11 def initialize(api_token: nil, base_url: nil) @api_token = api_token || PostalCodesRubyClient.configuration.api_token @base_url = base_url || PostalCodesRubyClient.configuration.base_url @timeout = PostalCodesRubyClient.configuration.timeout @postal_codes = Resources::PostalCodes.new(self) end |
Instance Attribute Details
#api_token=(value) ⇒ Object (writeonly)
Update the API token (e.g. after login or token regeneration).
20 21 22 |
# File 'lib/postal_codes_ruby_client/client.rb', line 20 def api_token=(value) @api_token = value end |
#postal_codes ⇒ Object (readonly)
Returns the value of attribute postal_codes.
9 10 11 |
# File 'lib/postal_codes_ruby_client/client.rb', line 9 def postal_codes @postal_codes end |
Instance Method Details
#get(path, params = {}) ⇒ Object
Perform a GET request.
23 24 25 26 27 |
# File 'lib/postal_codes_ruby_client/client.rb', line 23 def get(path, params = {}) uri = build_uri(path, params) request = Net::HTTP::Get.new(uri) execute(uri, request) end |
#post(path, body = nil) ⇒ Object
Perform a POST request with a JSON body.
30 31 32 33 34 35 36 37 38 |
# File 'lib/postal_codes_ruby_client/client.rb', line 30 def post(path, body = nil) uri = build_uri(path) request = Net::HTTP::Post.new(uri) if body request.body = JSON.generate(body) request['Content-Type'] = 'application/json' end execute(uri, request) end |