Class: Baid::ApiClient
- Inherits:
-
Object
- Object
- Baid::ApiClient
- Defined in:
- lib/baid/api_client.rb
Constant Summary collapse
- BASE_URL =
ENV.fetch("BAID_API_URL", "https://baid.dev")
Instance Method Summary collapse
- #get(path, params = {}) ⇒ Object
-
#initialize(token: nil) ⇒ ApiClient
constructor
A new instance of ApiClient.
- #post(path, body = {}) ⇒ Object
Constructor Details
#initialize(token: nil) ⇒ ApiClient
Returns a new instance of ApiClient.
7 8 9 |
# File 'lib/baid/api_client.rb', line 7 def initialize(token: nil) @token = token || Config.load_token end |
Instance Method Details
#get(path, params = {}) ⇒ Object
11 12 13 14 15 |
# File 'lib/baid/api_client.rb', line 11 def get(path, params = {}) HTTParty.get("#{BASE_URL}/api#{path}", query: params, headers: auth_headers) end |
#post(path, body = {}) ⇒ Object
17 18 19 20 21 |
# File 'lib/baid/api_client.rb', line 17 def post(path, body = {}) HTTParty.post("#{BASE_URL}/api#{path}", body: body.to_json, headers: auth_headers.merge("Content-Type" => "application/json")) end |