Class: Soteria::Push
- Inherits:
-
Object
- Object
- Soteria::Push
- Defined in:
- lib/soteria/push.rb
Instance Method Summary collapse
-
#get_push_request_body(user_id, options) ⇒ Hash
Creates the body for a send push request.
-
#poll_for_response(client, transaction_id, interval, time_out) ⇒ Hash
Polls for the status of the push notification.
-
#send_push(client, user_id, options) ⇒ Object
Send a push notification to the specified user for authentication.
Instance Method Details
#get_push_request_body(user_id, options) ⇒ Hash
Creates the body for a send push request.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 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 67 68 69 70 |
# File 'lib/soteria/push.rb', line 12 def get_push_request_body(user_id, ) # add in required values = { 'vip:requestId': Utilities.get_request_id('send_push_request'), 'vip:userId': user_id, } # no extra options so set the push auth data to nothing # and return the body if == nil [:'vip:pushAuthData'] = '' return end #check if the user passed a pin, if so add it if .key?(:pin) [:'vip:pin'] = [:pin] end # check for all push auth data options and add them if .key?(:title) || .key?(:message) || .key?(:profile) || .key?(:time_out) inner = [] if .key?(:title) inner.push({'vip:Key': 'display.message.title', 'vip:Value': [:title]}) end if .key?(:message) inner.push({'vip:Key': 'display.message.text', 'vip:Value': [:message]}) end if .key?(:profile) inner.push({'vip:Key': 'display.message.profile', 'vip:Value': [:profile]}) end # Add the options to the push auth data if .key?(:time_out) [:'vip:pushAuthData'] = { 'vip:displayParameters': inner, 'vip:requestParameters': { 'vip:Key': 'request.timeout', 'vip:Value': [:time_out] } } else [:'vip:pushAuthData'] = {'vip:displayParameters': inner} end else # dont add any push auth data [:'vip:pushAuthData'] = '' end # if options.key?(:level) # message['authContext'] = {'params': {'Key': 'authLevel.level', 'Value': options[:level]}} # end end |
#poll_for_response(client, transaction_id, interval, time_out) ⇒ Hash
Polls for the status of the push notification. This is necessary because VIP does not have push support. This will poll until the response is no longer push in progress, then it will return a hash with the results.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/soteria/push.rb', line 107 def poll_for_response(client, transaction_id, interval, time_out) 1.upto(time_out/interval) do response = client.call(:poll_push_status, message: { 'vip:requestId': Utilities.get_request_id("poll_push_status"), 'vip:transactionId': transaction_id }) # The status of the push is called transaciton status transaction_status = response.body[:poll_push_status_response][:transaction_status] call_status = response.body[:poll_push_status_response] # 7001 is in progress so we are waiting for that to change if transaction_status[:status] != '7001' success = transaction_status[:status] == '7000' return { success: success, message: transaction_status[:status_message], id: call_status[:request_id] } end sleep interval end end |
#send_push(client, user_id, options) ⇒ Object
Send a push notification to the specified user for authentication.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/soteria/push.rb', line 79 def send_push(client, user_id, ) # get the body of the request request_body = get_push_request_body(user_id, ) push_res = client.call(:authenticate_user_with_push, message: request_body) result_hash = push_res.body[:authenticate_user_with_push_response] # 6040 is the status code for a push being sent, any other code the push was not sent success = result_hash[:status] == '6040' { success: success, id: result_hash[:request_id], transaction_id: result_hash[:transaction_id], message: result_hash[:status_message] } end |