Class: SMSCentre::Provider
- Inherits:
-
Object
- Object
- SMSCentre::Provider
- Defined in:
- lib/sms_centre/provider.rb
Instance Method Summary collapse
-
#initialize(login, password) ⇒ Provider
constructor
A new instance of Provider.
-
#request(opts = {}) ⇒ Object
Perform API call.
Constructor Details
#initialize(login, password) ⇒ Provider
Returns a new instance of Provider.
3 4 5 6 |
# File 'lib/sms_centre/provider.rb', line 3 def initialize(login, password) @login = login @password = password end |
Instance Method Details
#request(opts = {}) ⇒ Object
Perform API call
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sms_centre/provider.rb', line 14 def request(opts = {}) opts = default_opts.merge(opts) params = default_params.merge(opts.fetch(:params, {})) data = URI.encode_www_form(params) resp = perform_request(opts, data) JSON.parse(resp.body || '') rescue Errno::ECONNREFUSED => e raise ConnectionError.new(e.) rescue JSON::ParserError => e raise ServerError.new("response json parsing failed: #{e.}") end |