Class: Cloudflare::Artifacts::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil, **opts) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
# File 'lib/cloudflare/artifacts/client.rb', line 10

def initialize(config = nil, **opts)
  @config = resolve_config(config, opts)
  @config.validate!
  @connection = build_connection
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/cloudflare/artifacts/client.rb', line 8

def config
  @config
end

#connectionObject (readonly)

Returns the value of attribute connection.



8
9
10
# File 'lib/cloudflare/artifacts/client.rb', line 8

def connection
  @connection
end

Instance Method Details

#account_idObject



16
17
18
# File 'lib/cloudflare/artifacts/client.rb', line 16

def 
  @config.
end

#api_tokenObject



20
21
22
# File 'lib/cloudflare/artifacts/client.rb', line 20

def api_token
  @config.api_token
end

#delete(path, params: nil, namespace: nil) ⇒ Object



44
45
46
# File 'lib/cloudflare/artifacts/client.rb', line 44

def delete(path, params: nil, namespace: nil)
  request(:delete, path, params: params, namespace: namespace)
end

#get(path, params: nil, namespace: nil) ⇒ Object



36
37
38
# File 'lib/cloudflare/artifacts/client.rb', line 36

def get(path, params: nil, namespace: nil)
  request(:get, path, params: params, namespace: namespace)
end

#namespaceObject



24
25
26
# File 'lib/cloudflare/artifacts/client.rb', line 24

def namespace
  @config.namespace
end

#post(path, body: nil, params: nil, namespace: nil) ⇒ Object



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

def post(path, body: nil, params: nil, namespace: nil)
  request(:post, path, body: body, params: params, namespace: namespace)
end

#reposObject



28
29
30
# File 'lib/cloudflare/artifacts/client.rb', line 28

def repos
  @repos ||= Repos.new(self)
end

#request(method, path, params: nil, body: nil, namespace: nil) ⇒ Object

Raises:

  • (ArgumentError)


48
49
50
51
52
53
54
55
56
57
58
# File 'lib/cloudflare/artifacts/client.rb', line 48

def request(method, path, params: nil, body: nil, namespace: nil)
  ns = namespace || @config.namespace
  raise ArgumentError, "namespace is required" if ns.nil? || ns.empty?

  full_path = "/client/v4/accounts/#{@config.}/artifacts/namespaces/#{ns}#{path}"
  response = @connection.public_send(method, full_path) do |req|
    req.params.update(params) if params && !params.empty?
    req.body = body if body
  end
  handle_response(response)
end

#tokensObject



32
33
34
# File 'lib/cloudflare/artifacts/client.rb', line 32

def tokens
  @tokens ||= Tokens.new(self)
end