Class: Wavix::APIKeys::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



9
10
11
# File 'lib/wavix/api_keys/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#create(request_options: {}, **params) ⇒ Wavix::Types::APIKey

Creates an API key for the authenticated account. Restrict access by listing permitted IP addresses in permitted_ips.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/wavix/api_keys/client.rb', line 61

def create(request_options: {}, **params)
  params = Wavix::Internal::Types::Utils.normalize_keys(params)
  request = Wavix::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v1/api-keys",
    body: Wavix::APIKeys::Types::APIKeyCreateRequest.new(params).to_h,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Wavix::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Wavix::Types::APIKey.load(response.body)
  else
    error_class = Wavix::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#delete(request_options: {}, **params) ⇒ Wavix::Types::SuccessResponse

Deletes the API key identified by id. Deletion is permanent and revokes the key immediately.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id (Integer)

Returns:



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/wavix/api_keys/client.rb', line 96

def delete(request_options: {}, **params)
  params = Wavix::Internal::Types::Utils.normalize_keys(params)
  request = Wavix::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "DELETE",
    path: "v1/api-keys/#{URI.encode_uri_component(params[:id].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Wavix::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Wavix::Types::SuccessResponse.load(response.body)
  else
    error_class = Wavix::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end

#list(request_options: {}, **params) ⇒ Array[Wavix::Types::APIKey]

Returns the API keys belonging to the authenticated account.

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :label (String, nil)

Returns:

Raises:

  • (error_class)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/wavix/api_keys/client.rb', line 25

def list(request_options: {}, **params)
  params = Wavix::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["label"] = params[:label] if params.key?(:label)

  request = Wavix::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v1/api-keys",
    query: query_params,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Wavix::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Wavix::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end

#update(request_options: {}, **params) ⇒ Wavix::Types::APIKey

Updates an API key identified by id. Only the provided fields are changed.

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id (Integer)

Returns:



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/wavix/api_keys/client.rb', line 130

def update(request_options: {}, **params)
  params = Wavix::Internal::Types::Utils.normalize_keys(params)
  request_data = Wavix::APIKeys::Types::APIKeyUpdateRequest.new(params).to_h
  non_body_param_names = %w[id]
  body = request_data.except(*non_body_param_names)

  request = Wavix::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "PATCH",
    path: "v1/api-keys/#{URI.encode_uri_component(params[:id].to_s)}",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Wavix::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Wavix::Types::APIKey.load(response.body)
  else
    error_class = Wavix::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end