Class: Bulksms::Account
- Inherits:
-
Object
- Object
- Bulksms::Account
- Defined in:
- lib/bulksms/account.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #credits ⇒ Object
-
#initialize(opts = {}) ⇒ Account
constructor
A new instance of Account.
- #request(path, params = {}) ⇒ Object
- #to_params ⇒ Object
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
#host ⇒ Object (readonly)
Returns the value of attribute host.
13 14 15 |
# File 'lib/bulksms/account.rb', line 13 def host @host end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
13 14 15 |
# File 'lib/bulksms/account.rb', line 13 def password @password end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
13 14 15 |
# File 'lib/bulksms/account.rb', line 13 def port @port end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
13 14 15 |
# File 'lib/bulksms/account.rb', line 13 def username @username end |
Instance Method Details
#credits ⇒ Object
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_params ⇒ Object
23 24 25 |
# File 'lib/bulksms/account.rb', line 23 def to_params { 'username' => @username, 'password' => @password } end |