Class: Soteria::Push

Inherits:
Object
  • Object
show all
Defined in:
lib/soteria/push.rb

Instance Method Summary collapse

Instance Method Details

#get_push_request_body(user_id, options) ⇒ Hash

Creates the body for a send push request.

Parameters:

  • user_id (String)

    The id of the user to send the push to

  • options (Hash)

Returns:

  • (Hash)

    A hash representing the body of the soap request to send a push notification.



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, options)

  # add in required values
  message = {
      '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 options == nil
    message[:'vip:pushAuthData'] = ''
    return message
  end

  #check if the user passed a pin, if so add it
  if options.key?(:pin)
    message[:'vip:pin'] = options[:pin]
  end

  # check for all push auth data options and add them
  if options.key?(:title) || options.key?(:message) || options.key?(:profile) || options.key?(:time_out)
    inner = []
    if options.key?(:title)
      inner.push({'vip:Key': 'display.message.title', 'vip:Value': options[:title]})
    end
    if options.key?(:message)
      inner.push({'vip:Key': 'display.message.text', 'vip:Value': options[:message]})
    end
    if options.key?(:profile)
      inner.push({'vip:Key': 'display.message.profile', 'vip:Value': options[:profile]})
    end

    # Add the options to the push auth data
    if options.key?(:time_out)
      message[:'vip:pushAuthData'] = {
          'vip:displayParameters': inner,
          'vip:requestParameters':
              {
                  'vip:Key': 'request.timeout',
                  'vip:Value': options[:time_out]
              }
      }

    else
      message[:'vip:pushAuthData'] = {'vip:displayParameters': inner}
    end

  else
    # dont add any push auth data
    message[:'vip:pushAuthData'] = ''
  end

  # if options.key?(:level)
  #   message['authContext'] = {'params': {'Key': 'authLevel.level', 'Value': options[:level]}}
  # end

  message
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.

Parameters:

  • client (Savon::Client)

    A Savon client object to make the call with. This needs to be created with the VIP query WSDL.

  • transaction_id (String)

    The id of the push transaction. id is in the hash returned from the send_push call

  • interval (Int)

    An integer value in seconds that is the interval between polling VIP Services for a push response.

  • time_out (Int)

    An integer value in seconds that is the timeout for polling. This should match the timeout that was set for the push message.

Returns:

  • (Hash)

    A hash with information on if the authentication was successful.



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.

Parameters:

  • client (Savon::Client)

    A Savon client object to make the call with.

  • user_id (String)

    The id of the user to send the push to

  • options (Hash)

See Also:

  • Savon::Client


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, options)

  # get the body of the request
  request_body = get_push_request_body(user_id, options)
  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