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.
Instance Method Summary collapse
-
#create_verification_code(to:, service_id:, locale: nil, external_id: nil, code: nil, template_data: nil) ⇒ HTTParty::Response
Create Verification Code.
-
#get_message(id:) ⇒ HTTParty::Response
Get Message Details.
-
#get_message_status(id:) ⇒ HTTParty::Response
Get Message Status.
-
#get_verification_code_by_id(id:) ⇒ HTTParty::Response
Get Verification Code.
-
#send_message(type:, to:, service_id:, external_id: nil, text: nil, template: nil) ⇒ HTTParty::Response
Send New Message.
-
#verify_verification_code(id:, code:) ⇒ HTTParty::Response
Verify OTP Code.
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.
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 = 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.
149 150 151 152 153 154 155 |
# File 'lib/namabar/endpoints.rb', line 149 def (id:) url = '/messages/{id}' url = url.gsub('{id}', id.to_s) opts = 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.
167 168 169 170 171 172 173 |
# File 'lib/namabar/endpoints.rb', line 167 def (id:) url = '/messages/{id}/status' url = url.gsub('{id}', id.to_s) opts = self.class.get(url, opts) end |
#get_verification_code_by_id(id:) ⇒ HTTParty::Response
Get Verification Code
Retrieves details about a specific verification code.
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 = 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.
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 (type:, to:, service_id:, external_id: nil, text: nil, template: nil) url = '/messages' opts = 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.
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 = 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 |