Class: ZenSend::Client
- Inherits:
-
Object
- Object
- ZenSend::Client
- Defined in:
- lib/zensend/client.rb
Constant Summary collapse
- ZENSEND_URL =
"https://api.zensend.io"- VALID_OPTIONS =
Sends an sms message
Named paramters:
originator: the originator to send from body: the body of the sms messagenumbers: an array of numbers to send to. they must not contain the ‘,’ character
originator_type: :alpha or :msisdn (not required) timetolive_in_minutes: number of minutes before message expires (not required) encoding: :ucs2 or :gsm (not required defaults to automatic)A ZenSend::ZenSendException or StandardError or ArgumentError can be raised by this method. StandardError is raised by net/http. It may be one of the following subclasses:
- Errno::ETIMEDOUT, Errno::ECONNRESET, Errno::EHOSTUNREACH, SocketError, Net::ReadTimeout, Net::OpenTimeout
-
This list is not exhaustive.
An ArgumentError can be raised if any of the numbers includes a ‘,’ character or a required parameter is not specified or an unknown parameter is specified.
[:originator, :body, :numbers, :originator_type, :timetolive_in_minutes, :encoding]
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#http_opts ⇒ Object
Returns the value of attribute http_opts.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #check_balance ⇒ Object
- #get_prices ⇒ Object
-
#initialize(api_key, http_opts = {open_timeout: 60, read_timeout: 60}, url = ZENSEND_URL) ⇒ Client
constructor
A new instance of Client.
- #lookup_operator(msisdn) ⇒ Object
- #send_sms(options) ⇒ Object
Constructor Details
#initialize(api_key, http_opts = {open_timeout: 60, read_timeout: 60}, url = ZENSEND_URL) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 |
# File 'lib/zensend/client.rb', line 13 def initialize(api_key, http_opts = {open_timeout: 60, read_timeout: 60}, url = ZENSEND_URL) @api_key = api_key @url = url @http_opts = http_opts end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
11 12 13 |
# File 'lib/zensend/client.rb', line 11 def api_key @api_key end |
#http_opts ⇒ Object
Returns the value of attribute http_opts.
11 12 13 |
# File 'lib/zensend/client.rb', line 11 def http_opts @http_opts end |
#url ⇒ Object
Returns the value of attribute url.
11 12 13 |
# File 'lib/zensend/client.rb', line 11 def url @url end |
Instance Method Details
#check_balance ⇒ Object
68 69 70 71 |
# File 'lib/zensend/client.rb', line 68 def check_balance response = make_request("/v3/checkbalance", :get) response["balance"] end |
#get_prices ⇒ Object
73 74 75 76 |
# File 'lib/zensend/client.rb', line 73 def get_prices response = make_request("/v3/prices", :get) response["prices_in_pence"] end |
#lookup_operator(msisdn) ⇒ Object
78 79 80 81 82 |
# File 'lib/zensend/client.rb', line 78 def lookup_operator(msisdn) operator_lookup_response = OperatorLookupResponse.new operator_lookup_response.set_from_response(make_request("/v3/operator_lookup?" + URI.encode_www_form({"NUMBER" => msisdn}), :get)) operator_lookup_response end |
#send_sms(options) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/zensend/client.rb', line 40 def send_sms() originator = required_param(, :originator) body = required_param(, :body) numbers = required_param(, :numbers) raise ArgumentError.new("invalid character in numbers") if numbers.any? {|x| x.include?(",")} .keys.each do |key| raise ArgumentError.new("unknown option: #{key}") if !VALID_OPTIONS.include?(key) end sms_response = SmsResponse.new params = {"ORIGINATOR" => originator, "BODY" => body, "NUMBERS" => numbers.join(",")} add_optional_param(params, , "ORIGINATOR_TYPE", :originator_type) add_optional_param(params, , "TIMETOLIVE", :timetolive_in_minutes) add_optional_param(params, , "ENCODING", :encoding) sms_response.set_from_response(make_request("/v3/sendsms", :post, params)) sms_response end |