Module: Namabar::Endpoints

Included in:
Client
Defined in:
lib/namabar/endpoints.rb

Overview

One to one mapping of API endpoint methods from OpenAPI specification

This module contains methods that correspond to API endpoints defined in the OpenAPI spec. Each method provides a convenient Ruby interface to the HTTP endpoints.

All methods return HTTParty::Response objects which can be used to access response data, status codes, headers, etc.

Examples:

Basic usage

client = Namabar::Client.new
response = client.some_endpoint(param: 'value')
puts response.code
puts response.body

Instance Method Summary collapse

Instance Method Details

#create_verification_code(to:, service_id:, locale: nil, external_id: nil, code: nil, template_data: nil) ⇒ HTTParty::Response

Create Verification Code

Generates and sends a new verification code to the specified recipient using the configured verify service.

Examples:

response = create_verification_code(to: 'value', service_id: 'value')
puts response.code

Parameters:

  • to (string)

    (required)

  • locale (String) (defaults to: nil)

    (optional)

  • external_id (string) (defaults to: nil)

    (optional)

  • code (string) (defaults to: nil)

    (optional)

  • service_id (String)

    (required)

  • template_data (object) (defaults to: nil)

    (optional)

Returns:

  • (HTTParty::Response)

    the HTTP response object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/namabar/endpoints.rb', line 33

def create_verification_code(to:, service_id:, locale: nil, external_id: nil, code: nil, template_data: nil)
  url = '/verification-codes'
  opts = default_options

  body_data = {
    'to' => to,
    'locale' => locale,
    'externalId' => external_id,
    'code' => code,
    'serviceId' => service_id,
    'templateData' => template_data
  }.compact

  unless body_data.empty?
    opts = opts.merge(body: body_data.to_json)
    opts[:headers] ||= {}
    opts[:headers]['Content-Type'] = 'application/json'
  end

  self.class.post(url, opts)
end

#get_message(id:) ⇒ HTTParty::Response

Get Message Details

Retrieves detailed information about a specific message including its status, cost, and delivery information.

Examples:

response = get_message(id: 'value')
puts response.code

Parameters:

  • id (string)

    The ID of the message to get. (required)

Returns:

  • (HTTParty::Response)

    the HTTP response object



149
150
151
152
153
154
155
# File 'lib/namabar/endpoints.rb', line 149

def get_message(id:)
  url = '/messages/{id}'
  url = url.gsub('{id}', id.to_s)
  opts = default_options

  self.class.get(url, opts)
end

#get_message_status(id:) ⇒ HTTParty::Response

Get Message Status

Retrieves the status of a specific message, can be used for polling message delivery status.

Examples:

response = get_message_status(id: 'value')
puts response.code

Parameters:

  • id (string)

    The ID of the message to get. (required)

Returns:

  • (HTTParty::Response)

    the HTTP response object



167
168
169
170
171
172
173
# File 'lib/namabar/endpoints.rb', line 167

def get_message_status(id:)
  url = '/messages/{id}/status'
  url = url.gsub('{id}', id.to_s)
  opts = default_options

  self.class.get(url, opts)
end

#get_verification_code_by_id(id:) ⇒ HTTParty::Response

Get Verification Code

Retrieves details about a specific verification code.

Examples:

response = get_verification_code_by_id(id: 'value')
puts response.code

Parameters:

  • id (string)

    The ID of the verification code to retrieve (required)

Returns:

  • (HTTParty::Response)

    the HTTP response object



94
95
96
97
98
99
100
# File 'lib/namabar/endpoints.rb', line 94

def get_verification_code_by_id(id:)
  url = '/verification-codes/{id}'
  url = url.gsub('{id}', id.to_s)
  opts = default_options

  self.class.get(url, opts)
end

#send_message(type:, to:, service_id:, external_id: nil, text: nil, template: nil) ⇒ HTTParty::Response

Send New Message

Creates and sends a new message through the specified messaging service. Requires the CreateMessage permission.

Examples:

response = send_message(type: 'value', to: 'value', service_id: 'value')
puts response.code

Parameters:

  • type (String)

    (required)

  • to (string)

    (required)

  • external_id (string) (defaults to: nil)

    (optional)

  • service_id (String)

    (required)

  • text (string) (defaults to: nil)

    (optional)

  • template (String) (defaults to: nil)

    (optional)

Returns:

  • (HTTParty::Response)

    the HTTP response object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/namabar/endpoints.rb', line 117

def send_message(type:, to:, service_id:, external_id: nil, text: nil, template: nil)
  url = '/messages'
  opts = default_options

  body_data = {
    'type' => type,
    'to' => to,
    'externalId' => external_id,
    'serviceId' => service_id,
    'text' => text,
    'template' => template
  }.compact

  unless body_data.empty?
    opts = opts.merge(body: body_data.to_json)
    opts[:headers] ||= {}
    opts[:headers]['Content-Type'] = 'application/json'
  end

  self.class.post(url, opts)
end

#verify_verification_code(id:, code:) ⇒ HTTParty::Response

Verify OTP Code

Verifies a previously sent verification code. Returns the verification status and any associated data.

Examples:

response = verify_verification_code(id: 'value', code: 'value')
puts response.code

Parameters:

  • id (string)

    The id of the verification code to verify. (required)

  • code (string)

    (required)

Returns:

  • (HTTParty::Response)

    the HTTP response object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/namabar/endpoints.rb', line 66

def verify_verification_code(id:, code:)
  url = '/verification-codes/{id}/verify'
  url = url.gsub('{id}', id.to_s)
  opts = default_options

  body_data = {
    'code' => code
  }.compact

  unless body_data.empty?
    opts = opts.merge(body: body_data.to_json)
    opts[:headers] ||= {}
    opts[:headers]['Content-Type'] = 'application/json'
  end

  self.class.post(url, opts)
end