Class: Cloudflared::Client
- Inherits:
-
Object
- Object
- Cloudflared::Client
- Defined in:
- lib/cloudflared/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_default_key ⇒ String
The default key for signing private images.
-
#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:, images_default_key:, adapter: Faraday.default_adapter, stubs: nil) ⇒ Cloudflared
constructor
Initializes a new Cloudflare client.
Constructor Details
#initialize(api_key:, account_id:, images_hash:, images_default_key:, adapter: Faraday.default_adapter, stubs: nil) ⇒ Cloudflared
Initializes a new Cloudflare client.
30 31 32 33 34 35 36 37 |
# File 'lib/cloudflared/client.rb', line 30 def initialize(api_key:, account_id:, images_hash:, images_default_key:, adapter: Faraday.default_adapter, stubs: nil) @api_key = api_key @adapter = adapter @account_id = account_id @images_hash = images_hash @images_default_key = images_default_key @stubs = stubs end |
Instance Attribute Details
#account_id ⇒ String
Returns The Cloudflare account id to use.
30 31 32 |
# File 'lib/cloudflared/client.rb', line 30 def account_id @account_id end |
#adapter ⇒ Symbol
Returns The Faraday adapter to use.
30 31 32 |
# File 'lib/cloudflared/client.rb', line 30 def adapter @adapter end |
#api_key ⇒ String
Returns The Cloudflare api key to use.
30 31 32 |
# File 'lib/cloudflared/client.rb', line 30 def api_key @api_key end |
#images_default_key ⇒ String
Returns The default key for signing private images.
30 31 32 |
# File 'lib/cloudflared/client.rb', line 30 def images_default_key @images_default_key end |
#images_hash ⇒ String
Returns The Cloudflare images hash found on the images dashboard. This is used for image delivery urls.
30 31 32 |
# File 'lib/cloudflared/client.rb', line 30 def images_hash @images_hash end |
#request_type ⇒ JSON
Returns The request type to use (e.g. application/json).
48 49 50 51 52 53 54 55 |
# File 'lib/cloudflared/client.rb', line 48 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.
30 31 32 |
# File 'lib/cloudflared/client.rb', line 30 def stubs @stubs end |
Instance Method Details
#connection(request_type: :json) ⇒ Object
Creates a new connection with the given request type.
48 49 50 51 52 53 54 55 |
# File 'lib/cloudflared/client.rb', line 48 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
40 41 42 |
# File 'lib/cloudflared/client.rb', line 40 def images ImagesResource.new(self) end |