Class: CloudflareDev::Client
- Inherits:
-
Object
- Object
- CloudflareDev::Client
- Defined in:
- lib/cloudflare_dev/client.rb
Constant Summary collapse
- BASE_URL =
"https://api.cloudflare.com/client/v4/accounts"
Instance Attribute Summary collapse
-
#account_id ⇒ String
The Cloudflare account id to use.
-
#adapter ⇒ Symbol
The Faraday adapter to use.
-
#api_key ⇒ String
The Cloudflare api key to use.
-
#images_hash ⇒ String
The Cloudflare images hash found on the images dashboard.
-
#request_type ⇒ JSON
The request type to use (e.g. application/json).
-
#stubs ⇒ Symbol
Stubs for use in testing.
Instance Method Summary collapse
-
#connection(request_type: :json) ⇒ Object
Creates a new connection with the given request type.
-
#images ⇒ Object
Accesses the Cloudflare Images developer platform.
-
#initialize(api_key:, account_id:, images_hash: nil, adapter: Faraday.default_adapter, stubs: nil) ⇒ CloudflareDev
constructor
Initializes a new Cloudflare client.
Constructor Details
#initialize(api_key:, account_id:, images_hash: nil, adapter: Faraday.default_adapter, stubs: nil) ⇒ CloudflareDev
Initializes a new Cloudflare client.
27 28 29 30 31 32 33 |
# File 'lib/cloudflare_dev/client.rb', line 27 def initialize(api_key:, account_id:, images_hash: nil, adapter: Faraday.default_adapter, stubs: nil) @api_key = api_key @adapter = adapter @account_id = account_id @images_hash = images_hash @stubs = stubs end |
Instance Attribute Details
#account_id ⇒ String
Returns The Cloudflare account id to use.
27 28 29 |
# File 'lib/cloudflare_dev/client.rb', line 27 def account_id @account_id end |
#adapter ⇒ Symbol
Returns The Faraday adapter to use.
27 28 29 |
# File 'lib/cloudflare_dev/client.rb', line 27 def adapter @adapter end |
#api_key ⇒ String
Returns The Cloudflare api key to use.
27 28 29 |
# File 'lib/cloudflare_dev/client.rb', line 27 def api_key @api_key end |
#images_hash ⇒ String
Returns The Cloudflare images hash found on the images dashboard. This is used for image delivery urls.
27 28 29 |
# File 'lib/cloudflare_dev/client.rb', line 27 def images_hash @images_hash end |
#request_type ⇒ JSON
Returns The request type to use (e.g. application/json).
44 45 46 47 48 49 50 51 |
# File 'lib/cloudflare_dev/client.rb', line 44 def connection(request_type: :json) @connection ||= Faraday.new do |conn| conn.url_prefix = "#{BASE_URL}/#{@account_id}" conn.request request_type conn.response :json, content_type: "application/json" conn.adapter @stubs.nil? ? adapter : :test, @stubs end end |
#stubs ⇒ Symbol
Returns Stubs for use in testing.
27 28 29 30 31 32 33 |
# File 'lib/cloudflare_dev/client.rb', line 27 def initialize(api_key:, account_id:, images_hash: nil, adapter: Faraday.default_adapter, stubs: nil) @api_key = api_key @adapter = adapter @account_id = account_id @images_hash = images_hash @stubs = stubs end |
Instance Method Details
#connection(request_type: :json) ⇒ Object
Creates a new connection with the given request type.
44 45 46 47 48 49 50 51 |
# File 'lib/cloudflare_dev/client.rb', line 44 def connection(request_type: :json) @connection ||= Faraday.new do |conn| conn.url_prefix = "#{BASE_URL}/#{@account_id}" conn.request request_type conn.response :json, content_type: "application/json" conn.adapter @stubs.nil? ? adapter : :test, @stubs end end |
#images ⇒ Object
Accesses the Cloudflare Images developer platform
36 37 38 |
# File 'lib/cloudflare_dev/client.rb', line 36 def images ImagesResource.new(self) end |