Skip to content

Commit

Permalink
Allow user to override default headers
Browse files Browse the repository at this point in the history
  • Loading branch information
distler authored Jul 11, 2022
1 parent 76fc78a commit 38ccc8a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/tesla_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(
retry_options: nil,
base_uri: nil,
sso_uri: nil,
client_options: {headers: {"Accept" => "application/json"}}
client_options: {}
)
@email = email
@base_uri = base_uri || BASE_URI
Expand All @@ -30,7 +30,7 @@ def initialize(

@api = Faraday.new(
@base_uri + "/api/1",
client_options
{headers: {"Accept" => "application/json"}}.merge(client_options)
) { |conn|
# conn.response :logger, nil, {headers: true, bodies: true}
conn.request :json
Expand Down

1 comment on commit 38ccc8a

@distler
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A different fix for timdorr/issues/594. The user can pass a client_options hash to TeslaApi::Client.new().

  • If the hash includes an Accept header (e.g. client_options: {headers: {"Accept" => "application/json; charset=utf-8"}}), that will be used.
  • If not (or if no client_options hash is supplied), the default will be used.

Please sign in to comment.