Class: Every8d::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/every8d/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
# File 'lib/every8d/client.rb', line 7

def initialize(options = {})
  @uid = options.fetch(:UID) { ENV.fetch('EVERY8d_ACCOUNT') }

  @pwd = options.fetch(:PWD) { ENV.fetch('EVERY8d_PASSWORD') }

  @host = options.fetch(:host) { 'http://api.every8d.com/API21/HTTP' }
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



5
6
7
# File 'lib/every8d/client.rb', line 5

def 
  @account
end

#passwordObject

Returns the value of attribute password.



5
6
7
# File 'lib/every8d/client.rb', line 5

def password
  @password
end

Instance Method Details

#get_balanceObject



19
20
21
# File 'lib/every8d/client.rb', line 19

def get_balance
  http_post('getCredit.ashx')
end

#get_message(options = {}) ⇒ Object



15
16
17
# File 'lib/every8d/client.rb', line 15

def get_message(options = {})
  http_post('getDeliveryStatus.ashx', options)
end

#http_post(url, data = {}) ⇒ Object



27
28
29
# File 'lib/every8d/client.rb', line 27

def http_post(url, data = {})
  Net::HTTP.post_form(URI.parse("#{@host}/#{url}"), data.merge(UID: @uid, PWD: @pwd)).body
end

#send_sms(options = {}) ⇒ Object



23
24
25
# File 'lib/every8d/client.rb', line 23

def send_sms(options = {})
  http_post('sendSMS.ashx', options)
end