Class: Sms50X::Client
- Inherits:
-
Object
- Object
- Sms50X::Client
- Defined in:
- lib/sms50X/client.rb
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#country_code ⇒ Object
Returns the value of attribute country_code.
-
#host ⇒ Object
Returns the value of attribute host.
Instance Method Summary collapse
- #balance ⇒ Object
- #bulk_send(message, phone_numbers) ⇒ Object
- #get_replies(date = Date.today, output_format = :json) ⇒ Object
- #get_stats(month = Date.today.month) ⇒ Object
-
#initialize(*args) ⇒ Client
constructor
A new instance of Client.
- #send_message(phone, message) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sms50X/client.rb', line 11 def initialize(*args) = args.last.is_a?(Hash) ? args.pop : {} @api_key = get_api_key(args[0]) @country_code = get_country_code(args[1]) if [@api_key, @country_code].any? { |k| k.nil? } raise ArgumentError, 'API key and country code are required' end @host = get_host end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/sms50X/client.rb', line 9 def api_key @api_key end |
#country_code ⇒ Object
Returns the value of attribute country_code.
9 10 11 |
# File 'lib/sms50X/client.rb', line 9 def country_code @country_code end |
#host ⇒ Object
Returns the value of attribute host.
9 10 11 |
# File 'lib/sms50X/client.rb', line 9 def host @host end |
Instance Method Details
#balance ⇒ Object
30 31 32 33 |
# File 'lib/sms50X/client.rb', line 30 def balance response = Faraday.get("#{host}/balance/#{api_key}") response.body.to_i end |
#bulk_send(message, phone_numbers) ⇒ Object
45 46 47 48 |
# File 'lib/sms50X/client.rb', line 45 def bulk_send(, phone_numbers) response = Faraday.post("#{host}/xml", build_bulk_xml(, phone_numbers)) response.body end |
#get_replies(date = Date.today, output_format = :json) ⇒ Object
40 41 42 43 |
# File 'lib/sms50X/client.rb', line 40 def get_replies(date = Date.today, output_format = :json) response = Faraday.get("#{host}/smsin/#{api_key}/#{output_format.to_s}/#{date.strftime("%d-%m-%Y")}") response.body end |
#get_stats(month = Date.today.month) ⇒ Object
35 36 37 38 |
# File 'lib/sms50X/client.rb', line 35 def get_stats(month = Date.today.month) response = Faraday.get("#{host}/stat/#{api_key}/#{month}") response.body.to_i end |
#send_message(phone, message) ⇒ Object
25 26 27 28 |
# File 'lib/sms50X/client.rb', line 25 def (phone, ) response = Faraday.get("#{host}/sms/#{api_key}/t=#{phone}&m=#{escape()}") response.body.to_i end |