Class: Mailhub::CustomField::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



9
10
11
# File 'lib/Mailhub/custom_field/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#create_custom_field(request_options: {}, **params) ⇒ Mailhub::Types::CustomFieldModel

Examples:

client.custom_field.create_custom_field

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:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/Mailhub/custom_field/client.rb', line 56

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

#delete_custom_field(request_options: {}, **params) ⇒ untyped

Examples:

client.custom_field.delete_custom_field(key: "key")

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):

  • :key (String)

Returns:

  • (untyped)

Raises:

  • (error_class)


167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/Mailhub/custom_field/client.rb', line 167

def delete_custom_field(request_options: {}, **params)
  params = Mailhub::Internal::Types::Utils.normalize_keys(params)
  request = Mailhub::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "DELETE",
    path: "v1/custom-fields/#{URI.encode_uri_component(params[:key].to_s)}",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Mailhub::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

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

#get_custom_field(request_options: {}, **params) ⇒ Mailhub::Types::CustomFieldModel

Examples:

client.custom_field.get_custom_field(key: "key")

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):

  • :key (String)

Returns:



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/Mailhub/custom_field/client.rb', line 92

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

#get_custom_fields(request_options: {}, **_params) ⇒ Array[Mailhub::Types::CustomFieldModel]

Examples:

client.custom_field.get_custom_fields

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)

Returns:

Raises:

  • (error_class)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/Mailhub/custom_field/client.rb', line 25

def get_custom_fields(request_options: {}, **_params)
  request = Mailhub::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "v1/custom-fields",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Mailhub::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

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

#update_custom_field(request_options: {}, **params) ⇒ Mailhub::Types::CustomFieldModel

Examples:

client.custom_field.update_custom_field(key: "key")

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):

  • :key (String)

Returns:



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/Mailhub/custom_field/client.rb', line 127

def update_custom_field(request_options: {}, **params)
  params = Mailhub::Internal::Types::Utils.normalize_keys(params)
  request_data = Mailhub::CustomField::Types::UpdateCustomFieldRequest.new(params).to_h
  non_body_param_names = %w[key]
  body = request_data.except(*non_body_param_names)

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