class RtrPushApi::PushApi
Public Class Methods
new(username, password, service_key, url='https://connect.runthered.com:10443/public_api/service')
click to toggle source
# File lib/push_api/rtr_push_api.rb, line 31 def initialize(username, password, service_key, url='https://connect.runthered.com:10443/public_api/service') @url = url @username = username @password = password @service_key = service_key end
Public Instance Methods
do_json_request(data)
click to toggle source
# File lib/push_api/rtr_push_api.rb, line 38 def do_json_request(data) uri = URI.parse(@url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if uri.scheme == 'https' request = Net::HTTP::Post.new(uri.request_uri) request.body = data.to_json request.basic_auth @username, @password response = http.request(request) if response.code != '200' raise PushApiException, response.body else data = JSON.parse response.body if !data.has_key?("result") error = data['error'] message = error['message'] code = error['code'] raise PushApiException, message end return data end return response end
push_message(message, to, from_number=nil, push_id=1)
click to toggle source
Send a message to Run The Red @param message [String] the message to send @param to [String] the mobile number to send to @param from_number [String] the shortcode the message will come from @param push_id [Integer] the push_id sent by the client to comply with the JSON-RPC 2.0 spec @return [PushApiResponse] a response object with the status, msg_id and id as attributes
# File lib/push_api/rtr_push_api.rb, line 68 def push_message(message, to, from_number=nil, push_id=1) json_data = {"jsonrpc" => "2.0", "method" => "sendsms", "params" => {"service_key" => @service_key, "to" => to, "body" => message}, "id" => push_id} unless from_number.nil? json_data["params"]["frm"] = from_number end data = do_json_request(json_data) push_id = data['id'] result = data['result'] status = result['status'] msg_id = result['msg_id'] return PushApiResponse.new(status, msg_id, push_id) end
query_dlr(msg_id, push_id=1)
click to toggle source
Query a delivery receipt using the message id supplied by Run The Red @param msg_id [String] the message id of the message to check the delivery status of @param push_id [Integer] the push_id sent by the client to comply with the JSON-RPC 2.0 spec @return [DlrQueryResponse] an object with the status, reason_code and id as attributes
# File lib/push_api/rtr_push_api.rb, line 85 def query_dlr(msg_id, push_id=1) json_data = {"jsonrpc" => "2.0", "method" => "querydlr", "params" => {"service_key" => @service_key, "msg_id" => msg_id}, "id" => push_id} data = do_json_request(json_data) push_id = data['id'] result = data['result'] status = result['status'] reason_code = result['reason'] msg_id = result['msg_id'] return DlrQueryResponse.new(status, reason_code, push_id) end