Class: Nexmo::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/nexmo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



18
19
20
21
22
23
24
25
26
# File 'lib/nexmo.rb', line 18

def initialize(options = {})
  @key = options.fetch(:key) { ENV.fetch('NEXMO_API_KEY') }

  @secret = options.fetch(:secret) { ENV.fetch('NEXMO_API_SECRET') }

  @host = options.fetch(:host) { 'rest.nexmo.com' }

  @api_host = options.fetch(:api_host) { 'api.nexmo.com' }
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



16
17
18
# File 'lib/nexmo.rb', line 16

def key
  @key
end

#secretObject

Returns the value of attribute secret.



16
17
18
# File 'lib/nexmo.rb', line 16

def secret
  @secret
end

Instance Method Details

#buy_number(params) ⇒ Object



68
69
70
# File 'lib/nexmo.rb', line 68

def buy_number(params)
  post(@host, '/number/buy', params)
end

#cancel_number(params) ⇒ Object



72
73
74
# File 'lib/nexmo.rb', line 72

def cancel_number(params)
  post(@host, '/number/cancel', params)
end

#cancel_verification(request_id) ⇒ Object



156
157
158
# File 'lib/nexmo.rb', line 156

def cancel_verification(request_id)
  post(@api_host, '/verify/control/json', request_id: request_id, cmd: 'cancel')
end

#check_verification(request_id, params) ⇒ Object



140
141
142
# File 'lib/nexmo.rb', line 140

def check_verification(request_id, params)
  post(@api_host, '/verify/check/json', params.merge(request_id: request_id))
end

#check_verification_request(params) ⇒ Object



144
145
146
# File 'lib/nexmo.rb', line 144

def check_verification_request(params)
  post(@api_host, '/verify/check/json', params)
end

#control_verification_request(params) ⇒ Object



164
165
166
# File 'lib/nexmo.rb', line 164

def control_verification_request(params)
  post(@api_host, '/verify/control/json', params)
end

#get_account_numbers(params) ⇒ Object



60
61
62
# File 'lib/nexmo.rb', line 60

def (params)
  get(@host, '/account/numbers', params)
end

#get_available_numbers(country_code, params = {}) ⇒ Object



64
65
66
# File 'lib/nexmo.rb', line 64

def get_available_numbers(country_code, params = {})
  get(@host, '/number/search', {country: country_code}.merge(params))
end

#get_balanceObject



32
33
34
# File 'lib/nexmo.rb', line 32

def get_balance
  get(@host, '/account/get-balance')
end

#get_basic_number_insight(params) ⇒ Object



168
169
170
# File 'lib/nexmo.rb', line 168

def get_basic_number_insight(params)
  get(@api_host, '/number/format/json', params)
end

#get_country_pricing(country_code) ⇒ Object



36
37
38
# File 'lib/nexmo.rb', line 36

def get_country_pricing(country_code)
  get(@host, '/account/get-pricing/outbound', country: country_code)
end

#get_event_alert_numbersObject



112
113
114
# File 'lib/nexmo.rb', line 112

def get_event_alert_numbers
  get(@host, '/sc/us/alert/opt-in/query/json')
end

#get_message(id) ⇒ Object



80
81
82
# File 'lib/nexmo.rb', line 80

def get_message(id)
  get(@host, '/search/message', id: id)
end

#get_message_rejections(params) ⇒ Object



84
85
86
# File 'lib/nexmo.rb', line 84

def get_message_rejections(params)
  get(@host, '/search/rejections', params)
end

#get_number_insight(params) ⇒ Object



172
173
174
# File 'lib/nexmo.rb', line 172

def get_number_insight(params)
  get(@api_host, '/number/lookup/json', params)
end

#get_prefix_pricing(prefix) ⇒ Object



40
41
42
# File 'lib/nexmo.rb', line 40

def get_prefix_pricing(prefix)
  get(@host, '/account/get-prefix-pricing/outbound', prefix: prefix)
end

#get_sms_pricing(number) ⇒ Object



44
45
46
# File 'lib/nexmo.rb', line 44

def get_sms_pricing(number)
  get(@host, '/account/get-phone-pricing/outbound/sms', phone: number)
end

#get_verification(request_id) ⇒ Object



148
149
150
# File 'lib/nexmo.rb', line 148

def get_verification(request_id)
  get(@api_host, '/verify/search/json', request_id: request_id)
end

#get_verification_request(id) ⇒ Object



152
153
154
# File 'lib/nexmo.rb', line 152

def get_verification_request(id)
  get(@api_host, '/verify/search/json', request_id: id)
end

#get_voice_pricing(number) ⇒ Object



48
49
50
# File 'lib/nexmo.rb', line 48

def get_voice_pricing(number)
  get(@host, '/account/get-phone-pricing/outbound/voice', phone: number)
end

#initiate_call(params) ⇒ Object



120
121
122
# File 'lib/nexmo.rb', line 120

def initiate_call(params)
  post(@host, '/call/json', params)
end

#initiate_tts_call(params) ⇒ Object



124
125
126
# File 'lib/nexmo.rb', line 124

def initiate_tts_call(params)
  post(@api_host, '/tts/json', params)
end

#initiate_tts_prompt_call(params) ⇒ Object



128
129
130
# File 'lib/nexmo.rb', line 128

def initiate_tts_prompt_call(params)
  post(@api_host, '/tts-prompt/json', params)
end

#request_number_insight(params) ⇒ Object



176
177
178
# File 'lib/nexmo.rb', line 176

def request_number_insight(params)
  post(@host, '/ni/json', params)
end

#resubscribe_event_alert_number(params) ⇒ Object



116
117
118
# File 'lib/nexmo.rb', line 116

def resubscribe_event_alert_number(params)
  post(@host, '/sc/us/alert/opt-in/manage/json', params)
end

#search_messages(params) ⇒ Object



88
89
90
# File 'lib/nexmo.rb', line 88

def search_messages(params)
  get(@host, '/search/messages', Hash === params ? params : {ids: Array(params)})
end

#send_2fa_message(params) ⇒ Object



100
101
102
# File 'lib/nexmo.rb', line 100

def send_2fa_message(params)
  post(@host, '/sc/us/2fa/json', params)
end

#send_event_alert_message(params) ⇒ Object



104
105
106
# File 'lib/nexmo.rb', line 104

def send_event_alert_message(params)
  post(@host, '/sc/us/alert/json', params)
end

#send_marketing_message(params) ⇒ Object



108
109
110
# File 'lib/nexmo.rb', line 108

def send_marketing_message(params)
  post(@host, '/sc/us/marketing/json', params)
end

#send_message(params) ⇒ Object



28
29
30
# File 'lib/nexmo.rb', line 28

def send_message(params)
  post(@host, '/sms/json', params)
end

#send_ussd_prompt_message(params) ⇒ Object



96
97
98
# File 'lib/nexmo.rb', line 96

def send_ussd_prompt_message(params)
  post(@host, '/ussd-prompt/json', params)
end

#send_ussd_push_message(params) ⇒ Object



92
93
94
# File 'lib/nexmo.rb', line 92

def send_ussd_push_message(params)
  post(@host, '/ussd/json', params)
end

#send_verification_request(params) ⇒ Object



136
137
138
# File 'lib/nexmo.rb', line 136

def send_verification_request(params)
  post(@api_host, '/verify/json', params)
end

#start_verification(params) ⇒ Object



132
133
134
# File 'lib/nexmo.rb', line 132

def start_verification(params)
  post(@api_host, '/verify/json', params)
end

#topup(params) ⇒ Object



56
57
58
# File 'lib/nexmo.rb', line 56

def topup(params)
  post(@host, '/account/top-up', params)
end

#trigger_next_verification_event(request_id) ⇒ Object



160
161
162
# File 'lib/nexmo.rb', line 160

def trigger_next_verification_event(request_id)
  post(@api_host, '/verify/control/json', request_id: request_id, cmd: 'trigger_next_event')
end

#update_number(params) ⇒ Object



76
77
78
# File 'lib/nexmo.rb', line 76

def update_number(params)
  post(@host, '/number/update', params)
end

#update_settings(params) ⇒ Object



52
53
54
# File 'lib/nexmo.rb', line 52

def update_settings(params)
  post(@host, '/account/settings', params)
end