Class: Nexmo::Client
- Inherits:
-
Object
- Object
- Nexmo::Client
- Defined in:
- lib/nexmo.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#secret ⇒ Object
Returns the value of attribute secret.
Instance Method Summary collapse
- #buy_number(params) ⇒ Object
- #cancel_number(params) ⇒ Object
- #cancel_verification(request_id) ⇒ Object
- #check_signature(params) ⇒ Object
- #check_verification(request_id, params) ⇒ Object
- #check_verification_request(params) ⇒ Object
- #control_verification_request(params) ⇒ Object
- #create_application(params) ⇒ Object
- #create_call(params) ⇒ Object
- #delete_application(id) ⇒ Object
- #get_account_numbers(params) ⇒ Object
- #get_application(id) ⇒ Object
- #get_applications(params = {}) ⇒ Object
- #get_available_numbers(country_code, params = {}) ⇒ Object
- #get_balance ⇒ Object
- #get_basic_number_insight(params) ⇒ Object
- #get_call(uuid) ⇒ Object
- #get_calls(params = nil) ⇒ Object
- #get_country_pricing(country_code) ⇒ Object
- #get_event_alert_numbers ⇒ Object
- #get_message(id) ⇒ Object
- #get_message_rejections(params) ⇒ Object
- #get_number_insight(params) ⇒ Object
- #get_prefix_pricing(prefix) ⇒ Object
- #get_sms_pricing(number) ⇒ Object
- #get_verification(request_id) ⇒ Object
- #get_verification_request(id) ⇒ Object
- #get_voice_pricing(number) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #initiate_call(params) ⇒ Object
- #initiate_tts_call(params) ⇒ Object
- #initiate_tts_prompt_call(params) ⇒ Object
- #request_number_insight(params) ⇒ Object
- #resubscribe_event_alert_number(params) ⇒ Object
- #search_messages(params) ⇒ Object
- #send_2fa_message(params) ⇒ Object
- #send_audio(uuid, params) ⇒ Object
- #send_dtmf(uuid, params) ⇒ Object
- #send_event_alert_message(params) ⇒ Object
- #send_marketing_message(params) ⇒ Object
- #send_message(params) ⇒ Object
- #send_speech(uuid, params) ⇒ Object
- #send_ussd_prompt_message(params) ⇒ Object
- #send_ussd_push_message(params) ⇒ Object
- #send_verification_request(params) ⇒ Object
- #sns_publish(message, params) ⇒ Object
- #sns_subscribe(recipient, params) ⇒ Object
- #start_verification(params) ⇒ Object
- #stop_audio(uuid) ⇒ Object
- #stop_speech(uuid) ⇒ Object
- #topup(params) ⇒ Object
- #trigger_next_verification_event(request_id) ⇒ Object
- #update_application(id, params) ⇒ Object
- #update_call(uuid, params) ⇒ Object
- #update_number(params) ⇒ Object
- #update_settings(params) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/nexmo.rb', line 16 def initialize( = {}) @key = .fetch(:key) { ENV.fetch('NEXMO_API_KEY') } @secret = .fetch(:secret) { ENV.fetch('NEXMO_API_SECRET') } @signature_secret = .fetch(:signature_secret) { ENV['NEXMO_SIGNATURE_SECRET'] } @application_id = [:application_id] @private_key = [:private_key] @host = .fetch(:host) { 'rest.nexmo.com' } @api_host = .fetch(:api_host) { 'api.nexmo.com' } @sns_host = .fetch(:sns_host) { 'sns.nexmo.com' } @user_agent = "ruby-nexmo/#{VERSION}/#{RUBY_VERSION}" if .key?(:app_name) && .key?(:app_version) @user_agent << "/#{[:app_name]}/#{[:app_version]}" end end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
14 15 16 |
# File 'lib/nexmo.rb', line 14 def key @key end |
#secret ⇒ Object
Returns the value of attribute secret.
14 15 16 |
# File 'lib/nexmo.rb', line 14 def secret @secret end |
Instance Method Details
#buy_number(params) ⇒ Object
80 81 82 |
# File 'lib/nexmo.rb', line 80 def buy_number(params) post(@host, '/number/buy', params) end |
#cancel_number(params) ⇒ Object
84 85 86 |
# File 'lib/nexmo.rb', line 84 def cancel_number(params) post(@host, '/number/cancel', params) end |
#cancel_verification(request_id) ⇒ Object
188 189 190 |
# File 'lib/nexmo.rb', line 188 def cancel_verification(request_id) post(@api_host, '/verify/control/json', request_id: request_id, cmd: 'cancel') end |
#check_signature(params) ⇒ Object
270 271 272 |
# File 'lib/nexmo.rb', line 270 def check_signature(params) Signature.check(params, @signature_secret) end |
#check_verification(request_id, params) ⇒ Object
168 169 170 |
# File 'lib/nexmo.rb', line 168 def check_verification(request_id, params) post(@api_host, '/verify/check/json', params.merge(request_id: request_id)) end |
#check_verification_request(params) ⇒ Object
172 173 174 175 176 |
# File 'lib/nexmo.rb', line 172 def check_verification_request(params) Kernel.warn "#{self.class}##{__method__} is deprecated (use #check_verification instead)." post(@api_host, '/verify/check/json', params) end |
#control_verification_request(params) ⇒ Object
196 197 198 199 200 |
# File 'lib/nexmo.rb', line 196 def control_verification_request(params) Kernel.warn "#{self.class}##{__method__} is deprecated." post(@api_host, '/verify/control/json', params) end |
#create_application(params) ⇒ Object
222 223 224 |
# File 'lib/nexmo.rb', line 222 def create_application(params) post(@api_host, '/v1/applications', params) end |
#create_call(params) ⇒ Object
234 235 236 |
# File 'lib/nexmo.rb', line 234 def create_call(params) api_request(Net::HTTP::Post, '/v1/calls', params) end |
#delete_application(id) ⇒ Object
230 231 232 |
# File 'lib/nexmo.rb', line 230 def delete_application(id) delete(@api_host, "/v1/applications/#{id}") end |
#get_account_numbers(params) ⇒ Object
72 73 74 |
# File 'lib/nexmo.rb', line 72 def get_account_numbers(params) get(@host, '/account/numbers', params) end |
#get_application(id) ⇒ Object
218 219 220 |
# File 'lib/nexmo.rb', line 218 def get_application(id) get(@api_host, "/v1/applications/#{id}") end |
#get_applications(params = {}) ⇒ Object
214 215 216 |
# File 'lib/nexmo.rb', line 214 def get_applications(params = {}) get(@api_host, '/v1/applications', params) end |
#get_available_numbers(country_code, params = {}) ⇒ Object
76 77 78 |
# File 'lib/nexmo.rb', line 76 def get_available_numbers(country_code, params = {}) get(@host, '/number/search', {country: country_code}.merge(params)) end |
#get_balance ⇒ Object
44 45 46 |
# File 'lib/nexmo.rb', line 44 def get_balance get(@host, '/account/get-balance') end |
#get_basic_number_insight(params) ⇒ Object
202 203 204 |
# File 'lib/nexmo.rb', line 202 def get_basic_number_insight(params) get(@api_host, '/number/format/json', params) end |
#get_call(uuid) ⇒ Object
242 243 244 |
# File 'lib/nexmo.rb', line 242 def get_call(uuid) api_request(Net::HTTP::Get, "/v1/calls/#{uuid}") end |
#get_calls(params = nil) ⇒ Object
238 239 240 |
# File 'lib/nexmo.rb', line 238 def get_calls(params = nil) api_request(Net::HTTP::Get, '/v1/calls', params) end |
#get_country_pricing(country_code) ⇒ Object
48 49 50 |
# File 'lib/nexmo.rb', line 48 def get_country_pricing(country_code) get(@host, '/account/get-pricing/outbound', country: country_code) end |
#get_event_alert_numbers ⇒ Object
124 125 126 |
# File 'lib/nexmo.rb', line 124 def get_event_alert_numbers get(@host, '/sc/us/alert/opt-in/query/json') end |
#get_message(id) ⇒ Object
92 93 94 |
# File 'lib/nexmo.rb', line 92 def (id) get(@host, '/search/message', id: id) end |
#get_message_rejections(params) ⇒ Object
96 97 98 |
# File 'lib/nexmo.rb', line 96 def (params) get(@host, '/search/rejections', params) end |
#get_number_insight(params) ⇒ Object
206 207 208 |
# File 'lib/nexmo.rb', line 206 def get_number_insight(params) get(@api_host, '/number/lookup/json', params) end |
#get_prefix_pricing(prefix) ⇒ Object
52 53 54 |
# File 'lib/nexmo.rb', line 52 def get_prefix_pricing(prefix) get(@host, '/account/get-prefix-pricing/outbound', prefix: prefix) end |
#get_sms_pricing(number) ⇒ Object
56 57 58 |
# File 'lib/nexmo.rb', line 56 def get_sms_pricing(number) get(@host, '/account/get-phone-pricing/outbound/sms', phone: number) end |
#get_verification(request_id) ⇒ Object
178 179 180 |
# File 'lib/nexmo.rb', line 178 def get_verification(request_id) get(@api_host, '/verify/search/json', request_id: request_id) end |
#get_verification_request(id) ⇒ Object
182 183 184 185 186 |
# File 'lib/nexmo.rb', line 182 def get_verification_request(id) Kernel.warn "#{self.class}##{__method__} is deprecated (use #get_verification instead)." get(@api_host, '/verify/search/json', request_id: id) end |
#get_voice_pricing(number) ⇒ Object
60 61 62 |
# File 'lib/nexmo.rb', line 60 def get_voice_pricing(number) get(@host, '/account/get-phone-pricing/outbound/voice', phone: number) end |
#initiate_call(params) ⇒ Object
140 141 142 143 144 |
# File 'lib/nexmo.rb', line 140 def initiate_call(params) Kernel.warn "#{self.class}##{__method__} is deprecated (use the Voice API instead)." post(@host, '/call/json', params) end |
#initiate_tts_call(params) ⇒ Object
146 147 148 149 150 |
# File 'lib/nexmo.rb', line 146 def initiate_tts_call(params) Kernel.warn "#{self.class}##{__method__} is deprecated (use the Voice API instead)." post(@api_host, '/tts/json', params) end |
#initiate_tts_prompt_call(params) ⇒ Object
152 153 154 155 156 |
# File 'lib/nexmo.rb', line 152 def initiate_tts_prompt_call(params) Kernel.warn "#{self.class}##{__method__} is deprecated (use the Voice API instead)." post(@api_host, '/tts-prompt/json', params) end |
#request_number_insight(params) ⇒ Object
210 211 212 |
# File 'lib/nexmo.rb', line 210 def request_number_insight(params) post(@host, '/ni/json', params) end |
#resubscribe_event_alert_number(params) ⇒ Object
128 129 130 |
# File 'lib/nexmo.rb', line 128 def resubscribe_event_alert_number(params) post(@host, '/sc/us/alert/opt-in/manage/json', params) end |
#search_messages(params) ⇒ Object
100 101 102 |
# File 'lib/nexmo.rb', line 100 def (params) get(@host, '/search/messages', Hash === params ? params : {ids: Array(params)}) end |
#send_2fa_message(params) ⇒ Object
112 113 114 |
# File 'lib/nexmo.rb', line 112 def (params) post(@host, '/sc/us/2fa/json', params) end |
#send_audio(uuid, params) ⇒ Object
250 251 252 |
# File 'lib/nexmo.rb', line 250 def send_audio(uuid, params) api_request(Net::HTTP::Put, "/v1/calls/#{uuid}/stream", params) end |
#send_dtmf(uuid, params) ⇒ Object
266 267 268 |
# File 'lib/nexmo.rb', line 266 def send_dtmf(uuid, params) api_request(Net::HTTP::Put, "/v1/calls/#{uuid}/dtmf", params) end |
#send_event_alert_message(params) ⇒ Object
116 117 118 |
# File 'lib/nexmo.rb', line 116 def (params) post(@host, '/sc/us/alert/json', params) end |
#send_marketing_message(params) ⇒ Object
120 121 122 |
# File 'lib/nexmo.rb', line 120 def (params) post(@host, '/sc/us/marketing/json', params) end |
#send_message(params) ⇒ Object
40 41 42 |
# File 'lib/nexmo.rb', line 40 def (params) post(@host, '/sms/json', params) end |
#send_speech(uuid, params) ⇒ Object
258 259 260 |
# File 'lib/nexmo.rb', line 258 def send_speech(uuid, params) api_request(Net::HTTP::Put, "/v1/calls/#{uuid}/talk", params) end |
#send_ussd_prompt_message(params) ⇒ Object
108 109 110 |
# File 'lib/nexmo.rb', line 108 def (params) post(@host, '/ussd-prompt/json', params) end |
#send_ussd_push_message(params) ⇒ Object
104 105 106 |
# File 'lib/nexmo.rb', line 104 def (params) post(@host, '/ussd/json', params) end |
#send_verification_request(params) ⇒ Object
162 163 164 165 166 |
# File 'lib/nexmo.rb', line 162 def send_verification_request(params) Kernel.warn "#{self.class}##{__method__} is deprecated (use #start_verification instead)." post(@api_host, '/verify/json', params) end |
#sns_publish(message, params) ⇒ Object
132 133 134 |
# File 'lib/nexmo.rb', line 132 def sns_publish(, params) post(@sns_host, '/sns/json', {cmd: 'publish', message: }.merge(params)) end |
#sns_subscribe(recipient, params) ⇒ Object
136 137 138 |
# File 'lib/nexmo.rb', line 136 def sns_subscribe(recipient, params) post(@sns_host, '/sns/json', {cmd: 'subscribe', to: recipient}.merge(params)) end |
#start_verification(params) ⇒ Object
158 159 160 |
# File 'lib/nexmo.rb', line 158 def start_verification(params) post(@api_host, '/verify/json', params) end |
#stop_audio(uuid) ⇒ Object
254 255 256 |
# File 'lib/nexmo.rb', line 254 def stop_audio(uuid) api_request(Net::HTTP::Delete, "/v1/calls/#{uuid}/stream") end |
#stop_speech(uuid) ⇒ Object
262 263 264 |
# File 'lib/nexmo.rb', line 262 def stop_speech(uuid) api_request(Net::HTTP::Delete, "/v1/calls/#{uuid}/talk") end |
#topup(params) ⇒ Object
68 69 70 |
# File 'lib/nexmo.rb', line 68 def topup(params) post(@host, '/account/top-up', params) end |
#trigger_next_verification_event(request_id) ⇒ Object
192 193 194 |
# File 'lib/nexmo.rb', line 192 def trigger_next_verification_event(request_id) post(@api_host, '/verify/control/json', request_id: request_id, cmd: 'trigger_next_event') end |
#update_application(id, params) ⇒ Object
226 227 228 |
# File 'lib/nexmo.rb', line 226 def update_application(id, params) put(@api_host, "/v1/applications/#{id}", params) end |
#update_call(uuid, params) ⇒ Object
246 247 248 |
# File 'lib/nexmo.rb', line 246 def update_call(uuid, params) api_request(Net::HTTP::Put, "/v1/calls/#{uuid}", params) end |
#update_number(params) ⇒ Object
88 89 90 |
# File 'lib/nexmo.rb', line 88 def update_number(params) post(@host, '/number/update', params) end |
#update_settings(params) ⇒ Object
64 65 66 |
# File 'lib/nexmo.rb', line 64 def update_settings(params) post(@host, '/account/settings', params) end |