Skip to content

Commit

Permalink
Use Faraday middleware to set basic auth
Browse files Browse the repository at this point in the history
  • Loading branch information
amro committed Sep 11, 2021
1 parent 863a835 commit 902d61c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## [Unreleased][unreleased]


## [3.4.1] - 2021-03-12
- Fix deprecation warning for upcoming versions of Faraday (2.x.x)

## [3.4.0] - 2021-03-12
- Support for Faraday 1.x.x and higer

Expand Down
8 changes: 5 additions & 3 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ gibbon.open_timeout = 30
You can read about `timeout` and `open_timeout` in the [Net::HTTP](https://ruby-doc.org/stdlib-2.3.3/libdoc/net/http/rdoc/Net/HTTP.html) doc.

Now you can make requests using the resources defined in [MailChimp's docs](http://kb.mailchimp.com/api/resources). Resource IDs
are specified inline and a `CRUD` (`create`, `retrieve`, `update`, `upsert`, or `delete`) verb initiates the request. `upsert` lets you update a record, if it exists, or insert it otherwise where supported by MailChimp's API.
are specified inline and a `CRUD` (`create`, `retrieve` (or `get`), `update`, `upsert`, or `delete`) verb initiates the request. `upsert` lets you update a record, if it exists, or insert it otherwise where supported by MailChimp's API.

***Note*** `upsert` requires Gibbon version 2.1.0 or newer!

Expand All @@ -48,6 +48,8 @@ You can specify `headers`, `params`, and `body` when calling a `CRUD` method. Fo
gibbon.lists.retrieve(headers: {"SomeHeader": "SomeHeaderValue"}, params: {"query_param": "query_param_value"})
```

***Note*** `get` can be substituted for `retrieve` as of Gibbon version 3.4.1 or newer!

Of course, `body` is only supported on `create`, `update`, and `upsert` calls. Those map to HTTP `POST`, `PATCH`, and `PUT` verbs respectively.

You can set `api_key`, `timeout`, `open_timeout`, `faraday_adapter`, `proxy`, `symbolize_keys`, `logger`, and `debug` globally:
Expand Down Expand Up @@ -506,5 +508,5 @@ Thanks to everyone who has [contributed](https://github.com/amro/gibbon/contribu

## Copyright

* Copyright (c) 2010-2020 Amro Mousa. See LICENSE.txt for details.
* MailChimp (c) 2001-2020 The Rocket Science Group.
* Copyright (c) 2010-2021 Amro Mousa. See LICENSE.txt for details.
* MailChimp (c) 2001-2021 The Rocket Science Group.
3 changes: 2 additions & 1 deletion lib/gibbon/api_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ def rest_client
if @request_builder.debug
faraday.response :logger, @request_builder.logger, bodies: true
end
faraday.request :basic_auth, 'apikey', self.api_key
end
client.basic_auth('apikey', self.api_key)

client
end

Expand Down
4 changes: 4 additions & 0 deletions lib/gibbon/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def upsert(params: nil, headers: nil, body: nil)
reset
end

def get(params: nil, headers: nil)
retrieve(params: params, headers: headers)
end

def retrieve(params: nil, headers: nil)
APIRequest.new(builder: self).get(params: params, headers: headers)
ensure
Expand Down
2 changes: 1 addition & 1 deletion lib/gibbon/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Gibbon
VERSION = "3.4.0"
VERSION = "3.4.1"
end

0 comments on commit 902d61c

Please sign in to comment.