Class: Bulksms::Account

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Account

Returns a new instance of Account.



15
16
17
18
19
20
21
# File 'lib/bulksms/account.rb', line 15

def initialize(opts = {})
  opts ||= { }
  @username = opts[:username] || Bulksms.config.username
  @password = opts[:password] || Bulksms.config.password
  @host     = opts[:host] || Bulksms.config.host
  @port     = opts[:port] || Bulksms.config.port
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



13
14
15
# File 'lib/bulksms/account.rb', line 13

def host
  @host
end

#passwordObject (readonly)

Returns the value of attribute password.



13
14
15
# File 'lib/bulksms/account.rb', line 13

def password
  @password
end

#portObject (readonly)

Returns the value of attribute port.



13
14
15
# File 'lib/bulksms/account.rb', line 13

def port
  @port
end

#usernameObject (readonly)

Returns the value of attribute username.



13
14
15
# File 'lib/bulksms/account.rb', line 13

def username
  @username
end

Instance Method Details

#creditsObject

Raises:



27
28
29
30
31
# File 'lib/bulksms/account.rb', line 27

def credits
  res = request Bulksms.config.credits_path
  raise(AccountError, res.result, caller) if res.code != 0
  res.result.to_f
end

#request(path, params = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/bulksms/account.rb', line 33

def request(path, params = {})
  response = nil
  connection do |http|
    if params.is_a?(Array)
      response = params.map{|p| post(http, path, p)}
    else
      response = post(http, path, params)
    end
  end
  response
end

#to_paramsObject



23
24
25
# File 'lib/bulksms/account.rb', line 23

def to_params
  { 'username' => @username, 'password' => @password }
end