class EventMachine::Smsified::Base
Attributes
Public Class Methods
Intantiate a new class to work with OneAPI
@param [required, Hash] params to create the user @option params [required, String] :username username to authenticate with @option params [required, String] :password to authenticate with @option params [optional, String] :base_uri of an alternative location of SMSified @option params [optional, String] :destination_address to use with subscriptions @option params [optional, String] :sender_address to use with subscriptions @option params [optional, Boolean] :debug to turn on the HTTparty debugging to stdout @raise [ArgumentError] if :username is not passed as an option @raise [ArgumentError] if :password is not passed as an option
# File lib/em-smsified/base.rb, line 21 def initialize(options) raise ArgumentError, 'an options Hash is required' if !options.instance_of?(Hash) raise ArgumentError, ':username required' if options[:username].nil? raise ArgumentError, ':password required' if options[:password].nil? @base_uri = options[:base_uri] || SMSIFIED_ONEAPI_PUBLIC_URI @auth = { :username => options[:username], :password => options[:password] } @destination_address = options[:destination_address] @sender_address = options[:sender_address] end
Public Instance Methods
HTTP DELETE’s a request @param [required, String] :url to GET from
# File lib/em-smsified/base.rb, line 55 def delete(url, headers) conn = create_connection_object(url) http = conn.delete(:head => add_authorization_to_header(headers, @auth)) action = proc do response = Response.new(http.response.parsed, http)#.response.raw) yield response if block_given? end http.callback &action http.errback &action end
HTTP GET’s a request @param [required, String] :url to GET from
# File lib/em-smsified/base.rb, line 37 def get(url, headers) conn = create_connection_object(url) http = conn.get(:head => add_authorization_to_header(headers, @auth)) action = proc do response = Response.new(http.response.parsed, http)#.response.raw) yield response if block_given? end http.callback &action http.errback &action end
HTTP POST’s a request @param [required, String] :url to GET from
# File lib/em-smsified/base.rb, line 73 def post(url, body, headers) conn = create_connection_object(url) http = conn.post(:body => body, :head => add_authorization_to_header(headers, @auth)) action = proc do response = Response.new(http.response.parsed, http)#.response.raw) yield response if block_given? end http.callback &action http.errback &action end
Private Instance Methods
# File lib/em-smsified/base.rb, line 89 def create_connection_object(url) conn = EM::HttpRequest.new(SMSIFIED_ONEAPI_PUBLIC_URI + url) conn.use JSONify return conn end