Class: BunnyCdn::Client
- Inherits:
-
Object
- Object
- BunnyCdn::Client
- Defined in:
- lib/bunny_cdn/client.rb
Constant Summary collapse
- DEFAULT_BASE_URL =
"https://api.bunny.net"
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(api_key:, base_url: DEFAULT_BASE_URL, adapter: Faraday.default_adapter) ⇒ Client
constructor
A new instance of Client.
- #pull_zones ⇒ Object
- #storage(zone_name:, region: nil) ⇒ Object
Constructor Details
#initialize(api_key:, base_url: DEFAULT_BASE_URL, adapter: Faraday.default_adapter) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 |
# File 'lib/bunny_cdn/client.rb', line 9 def initialize(api_key:, base_url: DEFAULT_BASE_URL, adapter: Faraday.default_adapter) @api_key = api_key @base_url = base_url @adapter = adapter end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
7 8 9 |
# File 'lib/bunny_cdn/client.rb', line 7 def adapter @adapter end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
7 8 9 |
# File 'lib/bunny_cdn/client.rb', line 7 def api_key @api_key end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
7 8 9 |
# File 'lib/bunny_cdn/client.rb', line 7 def base_url @base_url end |
Instance Method Details
#connection ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/bunny_cdn/client.rb', line 23 def connection @connection ||= Faraday.new(url: base_url) do |conn| conn.headers["AccessKey"] = api_key conn.headers["Accept"] = "application/json" conn.request :json conn.request :retry, max: 3, interval: 1, interval_randomness: 0.5, backoff_factor: 2, exceptions: [Faraday::ServerError, Faraday::TimeoutError, Faraday::ConnectionFailed] conn.adapter adapter end end |