Class: Nexmo::Client
- Inherits:
-
Object
- Object
- Nexmo::Client
- Defined in:
- lib/nexmo.rb
Instance Attribute Summary collapse
-
#http ⇒ Object
Returns the value of attribute http.
-
#key ⇒ Object
Returns the value of attribute key.
-
#oauth_access_token ⇒ Object
Returns the value of attribute oauth_access_token.
-
#secret ⇒ Object
Returns the value of attribute secret.
Instance Method Summary collapse
- #get_account_numbers(params) ⇒ Object
- #get_balance ⇒ Object
- #get_country_pricing(country_code) ⇒ Object
- #get_message(id) ⇒ Object
- #get_message_rejections(params) ⇒ Object
- #get_prefix_pricing(prefix) ⇒ Object
-
#initialize(key = ENV['NEXMO_API_KEY'], secret = ENV['NEXMO_API_SECRET'], options = {}, &block) ⇒ Client
constructor
A new instance of Client.
- #number_search(country_code, params = {}) ⇒ Object
- #search_messages(params) ⇒ Object
- #send_message(params) ⇒ Object
- #send_message!(params) ⇒ Object
Constructor Details
#initialize(key = ENV['NEXMO_API_KEY'], secret = ENV['NEXMO_API_SECRET'], options = {}, &block) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/nexmo.rb', line 8 def initialize(key = ENV['NEXMO_API_KEY'], secret = ENV['NEXMO_API_SECRET'], = {}, &block) @key, @secret, @block = key, secret, block if .has_key?(:json) Kernel.warn '[nexmo] :json option is deprecated' @json = [:json] else @json = JSON end @http = Net::HTTP.new('rest.nexmo.com', Net::HTTP.https_default_port) @http.use_ssl = true end |
Instance Attribute Details
#http ⇒ Object
Returns the value of attribute http.
24 25 26 |
# File 'lib/nexmo.rb', line 24 def http @http end |
#key ⇒ Object
Returns the value of attribute key.
24 25 26 |
# File 'lib/nexmo.rb', line 24 def key @key end |
#oauth_access_token ⇒ Object
Returns the value of attribute oauth_access_token.
24 25 26 |
# File 'lib/nexmo.rb', line 24 def oauth_access_token @oauth_access_token end |
#secret ⇒ Object
Returns the value of attribute secret.
24 25 26 |
# File 'lib/nexmo.rb', line 24 def secret @secret end |
Instance Method Details
#get_account_numbers(params) ⇒ Object
60 61 62 |
# File 'lib/nexmo.rb', line 60 def get_account_numbers(params) get('/account/numbers', params) end |
#get_balance ⇒ Object
48 49 50 |
# File 'lib/nexmo.rb', line 48 def get_balance get('/account/get-balance') end |
#get_country_pricing(country_code) ⇒ Object
52 53 54 |
# File 'lib/nexmo.rb', line 52 def get_country_pricing(country_code) get('/account/get-pricing/outbound', {:country => country_code}) end |
#get_message(id) ⇒ Object
68 69 70 |
# File 'lib/nexmo.rb', line 68 def (id) get('/search/message', {:id => id}) end |
#get_message_rejections(params) ⇒ Object
72 73 74 |
# File 'lib/nexmo.rb', line 72 def (params) get('/search/rejections', params) end |
#get_prefix_pricing(prefix) ⇒ Object
56 57 58 |
# File 'lib/nexmo.rb', line 56 def get_prefix_pricing(prefix) get('/account/get-prefix-pricing/outbound', {:prefix => prefix}) end |
#number_search(country_code, params = {}) ⇒ Object
64 65 66 |
# File 'lib/nexmo.rb', line 64 def number_search(country_code, params = {}) get('/number/search', {:country => country_code}.merge(params)) end |
#search_messages(params) ⇒ Object
76 77 78 |
# File 'lib/nexmo.rb', line 76 def (params) get('/search/messages', Hash === params ? params : {:ids => Array(params)}) end |
#send_message(params) ⇒ Object
26 27 28 |
# File 'lib/nexmo.rb', line 26 def (params) post('/sms/json', params) end |
#send_message!(params) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/nexmo.rb', line 30 def (params) response = (params) if response.ok? && response.json? item = response.object['messages'].first status = item['status'].to_i if status == 0 item['message-id'] else raise Error, "#{item['error-text']} (status=#{status})" end else raise Error, "Unexpected HTTP response (code=#{response.code})" end end |