Class: Cloudflared::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudflared/client.rb

Constant Summary collapse

BASE_URL =
"https://api.cloudflare.com/client/v4/accounts"

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = 
  @images_hash = images_hash
  @images_default_key = images_default_key
  @stubs = stubs
end

Instance Attribute Details

#account_idString

Returns The Cloudflare account id to use.

Returns:

  • (String)

    The Cloudflare account id to use



30
31
32
# File 'lib/cloudflared/client.rb', line 30

def 
  @account_id
end

#adapterSymbol

Returns The Faraday adapter to use.

Returns:

  • (Symbol)

    The Faraday adapter to use



30
31
32
# File 'lib/cloudflared/client.rb', line 30

def adapter
  @adapter
end

#api_keyString

Returns The Cloudflare api key to use.

Returns:

  • (String)

    The Cloudflare api key to use



30
31
32
# File 'lib/cloudflared/client.rb', line 30

def api_key
  @api_key
end

#images_default_keyString

Returns The default key for signing private images.

Returns:

  • (String)

    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_hashString

Returns The Cloudflare images hash found on the images dashboard. This is used for image delivery urls.

Returns:

  • (String)

    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_typeJSON

Returns The request type to use (e.g. application/json).

Returns:

  • (JSON)

    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

#stubsSymbol

Returns Stubs for use in testing.

Returns:

  • (Symbol)

    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

#imagesObject

Accesses the Cloudflare Images developer platform



40
41
42
# File 'lib/cloudflared/client.rb', line 40

def images
  ImagesResource.new(self)
end