Module: Cloudflare::Artifacts

Defined in:
lib/cloudflare/artifacts.rb,
lib/cloudflare/artifacts/error.rb,
lib/cloudflare/artifacts/repos.rb,
lib/cloudflare/artifacts/client.rb,
lib/cloudflare/artifacts/tokens.rb,
lib/cloudflare/artifacts/version.rb,
lib/cloudflare/artifacts/response.rb,
lib/cloudflare/artifacts/configuration.rb

Defined Under Namespace

Classes: APIError, AuthenticationError, BadRequestError, Client, Configuration, ConflictError, Error, ForbiddenError, NotFoundError, RateLimitError, Repos, Response, ServerError, Tokens, UnprocessableEntityError

Constant Summary collapse

STATUS_ERRORS =
{
  400 => BadRequestError,
  401 => AuthenticationError,
  403 => ForbiddenError,
  404 => NotFoundError,
  409 => ConflictError,
  422 => UnprocessableEntityError,
  429 => RateLimitError
}.freeze
VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject



18
19
20
# File 'lib/cloudflare/artifacts.rb', line 18

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Yields:



22
23
24
25
# File 'lib/cloudflare/artifacts.rb', line 22

def configure
  yield configuration
  configuration
end

.error_for(status, body) ⇒ Object



37
38
39
40
41
# File 'lib/cloudflare/artifacts/error.rb', line 37

def self.error_for(status, body)
  klass = STATUS_ERRORS[status] || (status >= 500 ? ServerError : APIError)
  message = extract_message(body) || "HTTP #{status}"
  klass.new(message, status: status, body: body)
end

.extract_message(body) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/cloudflare/artifacts/error.rb', line 43

def self.extract_message(body)
  return unless body.is_a?(Hash)

  errors = body["errors"]
  return unless errors.is_a?(Array) && !errors.empty?

  errors.filter_map { |e| e.is_a?(Hash) ? e["message"] : nil }.join("; ").then do |msg|
    msg.empty? ? nil : msg
  end
end

.reset_configuration!Object



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

def reset_configuration!
  @configuration = Configuration.new
end