Class: Smsified::OneAPI
- Inherits:
-
Object
- Object
- Smsified::OneAPI
- Includes:
- HTTParty, Helpers
- Defined in:
- lib/smsified/oneapi.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ OneAPI
constructor
Intantiate a new class to work with OneAPI.
-
#method_missing(method, *args) ⇒ Object
Dispatches method calls to other objects for subscriptions and reporting.
-
#send_sms(options) ⇒ Object
Send an SMS to one or more addresses.
Constructor Details
#initialize(options) ⇒ OneAPI
Intantiate a new class to work with OneAPI
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/smsified/oneapi.rb', line 25 def initialize() raise ArgumentError, 'an options Hash is required' if !.instance_of?(Hash) raise ArgumentError, ':username required' if [:username].nil? raise ArgumentError, ':password required' if [:password].nil? self.class.debug_output $stdout if [:debug] self.class.base_uri [:base_uri] || SMSIFIED_ONEAPI_PUBLIC_URI @auth = { :username => [:username], :password => [:password] } @destination_address = [:destination_address] @sender_address = [:sender_address] @subscriptions = Subscriptions.new() @reporting = Reporting.new() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Dispatches method calls to other objects for subscriptions and reporting
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/smsified/oneapi.rb', line 75 def method_missing(method, *args) if method.to_s.match /subscription/ if args.size == 2 @subscriptions.send method, args[0], args[1] else @subscriptions.send method, args[0] end else if method == :delivery_status || method == :retrieve_sms || method == :search_sms @reporting.send method, args[0] else raise RuntimeError, 'Unknown method' end end end |
Instance Method Details
#send_sms(options) ⇒ Object
Send an SMS to one or more addresses
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/smsified/oneapi.rb', line 56 def send_sms() raise ArgumentError, 'an options Hash is required' if !.instance_of?(Hash) raise ArgumentError, ':sender_address is required' if [:sender_address].nil? && @sender_address.nil? raise ArgumentError, ':address is required' if [:address].nil? raise ArgumentError, ':message is required' if [:message].nil? [:sender_address] = [:sender_address] || @sender_address = .clone .delete(:sender_address) = camelcase_keys() Response.new self.class.post("/smsmessaging/outbound/#{[:sender_address]}/requests", :body => build_query_string(), :basic_auth => @auth, :headers => SMSIFIED_HTTP_HEADERS) end |