Class: Cloudflare::Artifacts::Client
- Inherits:
-
Object
- Object
- Cloudflare::Artifacts::Client
- Defined in:
- lib/cloudflare/artifacts/client.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #account_id ⇒ Object
- #api_token ⇒ Object
- #delete(path, params: nil, namespace: nil) ⇒ Object
- #get(path, params: nil, namespace: nil) ⇒ Object
-
#initialize(config = nil, **opts) ⇒ Client
constructor
A new instance of Client.
- #namespace ⇒ Object
- #post(path, body: nil, params: nil, namespace: nil) ⇒ Object
- #repos ⇒ Object
- #request(method, path, params: nil, body: nil, namespace: nil) ⇒ Object
- #tokens ⇒ Object
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
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/cloudflare/artifacts/client.rb', line 8 def config @config end |
#connection ⇒ Object (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_id ⇒ Object
16 17 18 |
# File 'lib/cloudflare/artifacts/client.rb', line 16 def account_id @config.account_id end |
#api_token ⇒ Object
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 |
#namespace ⇒ Object
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 |
#repos ⇒ Object
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
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.account_id}/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 |