class Smart::REST::Client
Constants
- HTTP_HEADERS
Attributes
access_code[R]
creation_time[R]
mobile_number[R]
nonce[R]
path_to_cert[R]
sp_id[R]
sp_password[R]
sp_service_id[R]
trans_id[R]
Public Instance Methods
headers()
click to toggle source
# File lib/smart/rest/client.rb, line 32 def headers HTTP_HEADERS.merge! ({ 'X-WSSE' => %{ "UsernameToken Username="#{self.sp_id}",PasswordDigest="#{self.sp_password}",Nonce="#{self.nonce}", Created="#{self.creation_time}"}, 'X-RequestHeader' => %{ "request TransId="",ServiceId="#{self.service_id}" } }) end
send_sms(args = {})
click to toggle source
# File lib/smart/rest/client.rb, line 39 def send_sms(args = {}) request = setup_connection(args) response = connect(request) end
Private Instance Methods
connect(request)
click to toggle source
# File lib/smart/rest/client.rb, line 67 def connect(request) response = @http.request(request) if response.body and !response.body.empty? object = JSON.parse(response.body) end if response.kind_of? Net::HTTPClientError error = Smart::REST::Response.new(object["requestError"]["serviceException"]["messageId"]) raise error.to_s end response end
setup_connection(args)
click to toggle source
# File lib/smart/rest/client.rb, line 50 def setup_connection(args) uri = URI.parse(setup_sms_outbound_endpoint) @http = Net::HTTP.new(uri.host, uri.port) @http.use_ssl = true @http.verify_mode = OpenSSL::SSL::VERIFY_NONE @http.open_timeout = 3 # in seconds @http.read_timeout = 3 # in seconds store = OpenSSL::X509::Store.new store.add_cert(OpenSSL::X509::Certificate.new(File.read(self.path_to_cert))) @http.cert_store = store request = Net::HTTP::Post.new(uri.request_uri, initheader = headers) request.body = args.to_json request end
setup_sms_outbound_endpoint()
click to toggle source
# File lib/smart/rest/client.rb, line 46 def setup_sms_outbound_endpoint "https://#{self.host}/1/smsmessaging/outbound/#{self.access_code}/requests" end