Class: SMSCentre::Provider

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

Instance Method Summary collapse

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(, password)
  @login    = 
  @password = password
end

Instance Method Details

#request(opts = {}) ⇒ Object

Perform API call

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :timeout (Fixnum)

    Timeout for API call

  • :path (String) — default: 'sys/send.php'

    Remote script path

  • :host (String)

    SMS Centre gateway API host

  • :ssl (Boolean)

    Use HTTPS for 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.message)
rescue JSON::ParserError => e
  raise ServerError.new("response json parsing failed: #{e.message}")
end