Class: Net::SMS::BulkSMS::Account
- Inherits:
-
Object
- Object
- Net::SMS::BulkSMS::Account
- Defined in:
- lib/net/sms/bulksms/account.rb
Overview
Wraps up the functionality for a user account on the system
Constant Summary collapse
- SERVICE_PORT =
The port the account service runs on
7512
- SERVICE_PATH =
Path to the account service gateway
'/eapi/1.0/get_credits.mc'
Instance Method Summary collapse
-
#credits ⇒ Object
Returns the number of credits left on a users account as a float to 2 decimal places.
-
#initialize(username, password, country = 'uk') ⇒ Account
constructor
A new instance of Account.
-
#to_http_query ⇒ Object
Returns the account credentials in the form of a http query string for use by other gateway services.
Constructor Details
#initialize(username, password, country = 'uk') ⇒ Account
Returns a new instance of Account.
17 18 19 20 |
# File 'lib/net/sms/bulksms/account.rb', line 17 def initialize(username, password, country = 'uk') @username, @password = username, password @country = country end |
Instance Method Details
#credits ⇒ Object
Returns the number of credits left on a users account as a float to 2 decimal places. Will raise an AccountError if the credentials are wrong
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/net/sms/bulksms/account.rb', line 25 def credits Net::HTTP.start(Service.bulksms_gateway(@country), SERVICE_PORT) do |http| response = http.post SERVICE_PATH, self.to_http_query if response.body.include?('|') rsp = Response.parse(response.body) raise AccountError, rsp.description, caller end response.body.to_f end end |
#to_http_query ⇒ Object
Returns the account credentials in the form of a http query string for use by other gateway services
38 39 40 |
# File 'lib/net/sms/bulksms/account.rb', line 38 def to_http_query URI.encode("username=#{@username}&password=#{@password}") end |