Class: Telesignature::Verify
- Inherits:
-
Object
- Object
- Telesignature::Verify
- Includes:
- Helpers
- Defined in:
- lib/telesignature/verify.rb
Instance Attribute Summary collapse
-
#conn ⇒ Object
Returns the value of attribute conn.
-
#customer_id ⇒ Object
Returns the value of attribute customer_id.
-
#secret_key ⇒ Object
Returns the value of attribute secret_key.
Instance Method Summary collapse
- #call(opts = {}) ⇒ Object
-
#initialize(opts = {}) ⇒ Verify
constructor
A new instance of Verify.
-
#sms(opts = {}) ⇒ Object
You can use this verification factor in combination with username & password to provide two-factor authentication for higher security.
- #status(ref_id, verify_code = nil) ⇒ Object
Methods included from Helpers
#random_with_N_digits, #validate_response
Constructor Details
#initialize(opts = {}) ⇒ Verify
Returns a new instance of Verify.
7 8 9 10 11 |
# File 'lib/telesignature/verify.rb', line 7 def initialize opts = {} @conn = opts[:conn] @customer_id = opts[:customer_id] @secret_key = opts[:secret_key] end |
Instance Attribute Details
#conn ⇒ Object
Returns the value of attribute conn.
5 6 7 |
# File 'lib/telesignature/verify.rb', line 5 def conn @conn end |
#customer_id ⇒ Object
Returns the value of attribute customer_id.
5 6 7 |
# File 'lib/telesignature/verify.rb', line 5 def customer_id @customer_id end |
#secret_key ⇒ Object
Returns the value of attribute secret_key.
5 6 7 |
# File 'lib/telesignature/verify.rb', line 5 def secret_key @secret_key end |
Instance Method Details
#call(opts = {}) ⇒ Object
100 101 102 103 104 105 106 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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/telesignature/verify.rb', line 100 def call opts = {} phone_number = opts[:phone_number] verify_code = opts[:verify_code] language = opts[:language] || 'en-US' # Calls the specified phone number, and using speech synthesis, speaks the verification code to the user. # * - Parameters # - # * - `phone_number` # - The phone number to receive the text message. You must specify the phone number in its entirety. That is, it must begin with the country code, followed by the area code, and then by the local number. For example, you would specify the phone number (310) 555-1212 as 13105551212. # * - `verify_code` # - (optional) The verification code to send to the user. If omitted, TeleSign will automatically generate a random value for you. # * - `language` # - (optional) The written language used in the message. The default is English. # **Example**:: # from telesign.api import Verify # from telesign.exceptions import AuthorizationError, TelesignError # cust_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890" # secret_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==" # phone_number = "13107409700" # verify = Verify(cust_id, secret_key) # Instantiate a Verify object. # try: # phone_info = verify.call(phone_number) # except AuthorizationError as ex: # # API authorization failed, the API response should tell you the reason # ... # except TelesignError as ex: # # failed to execute the Verify service, check the API response for details # ... # # When the user inputs the validation code, you can verify that it matches the one that you sent. # if (phone_info != None): # try: # status_info = verify.status(phone_info.data["reference_id"], verify_code=phone_info.verify_code) # except AuthorizationError as ex: # ... # except TelesignError as ex: # ... if verify_code.nil? verify_code = random_with_N_digits(5) end resource = '/v1/verify/call' method = 'POST' fields = { phone_number: phone_number, language: language, verify_code: verify_code} headers = Telesignature::Auth.generate_auth_headers( customer_id: @customer_id, secret_key: @secret_key, resource: resource, method: method, fields: fields) response = @conn.post do |req| req.url resource req.body = URI.encode_www_form(fields) req.headers = headers # proxies=@proxy end return Telesignature::Response.new validate_response(response), response, verify_code end |
#sms(opts = {}) ⇒ Object
You can use this verification factor in combination with username & password to provide two-factor authentication for higher security.
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/telesignature/verify.rb', line 22 def sms opts = {} phone_number = opts[:phone_number] verify_code = opts[:verify_code] language = opts[:language] || 'en-US' template = opts[:template] || '' # Sends a text message containing the verification code, to the specified phone number (supported for mobile phones only). # * - Parameters # - # * - `phone_number` # - The phone number to receive the text message. You must specify the phone number in its entirety. That is, it must begin with the country code, followed by the area code, and then by the local number. For example, you would specify the phone number (310) 555-1212 as 13105551212. # * - `verify_code` # - (optional) The verification code to send to the user. If omitted, TeleSign will automatically generate a random value for you. # * - `language` # - (optional) The written language used in the message. The default is English. # * - `template` # - (optional) A standard form for the text message. It must contain the token ``$$CODE$$``, which TeleSign auto-populates with the verification code. # **Example**:: # from telesign.api import Verify # from telesign.exceptions import AuthorizationError, TelesignError # cust_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890" # secret_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==" # phone_number = "13107409700" # verify = Verify(cust_id, secret_key) # Instantiate a Verify object. # try: # phone_info = verify.sms(phone_number) # except AuthorizationError as ex: # # API authorization failed, the API response should tell you the reason # ... # except TelesignError as ex: # # failed to execute the Verify service, check the API response for details # ... # # When the user inputs the validation code, you can verify that it matches the one that you sent. # if (phone_info != None): # try: # status_info = verify.status(phone_info.data["reference_id"], verify_code=phone_info.verify_code) # except AuthorizationError as ex: # ... # except TelesignError as ex: # ... if verify_code.nil? verify_code = random_with_N_digits(5) end resource = '/v1/verify/sms' method = 'POST' fields = { phone_number: phone_number, language: language, verify_code: verify_code, template: template} headers = Telesignature::Auth.generate_auth_headers( customer_id: @customer_id, secret_key: @secret_key, resource: resource, method: method, fields: fields) response = @conn.post do |req| req.url resource req.body = URI.encode_www_form(fields) req.headers = headers # proxies=@proxy end return Telesignature::Response.new validate_response(response), response, verify_code end |
#status(ref_id, verify_code = nil) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/telesignature/verify.rb', line 175 def status ref_id, verify_code=nil # Retrieves the verification result. You make this call in your web application after users complete the authentication transaction (using either a call or sms). # * - Parameters # - # * - `ref_id` # - The Reference ID returned in the response from the TeleSign server, after you called either **call** or **sms**. # * - `verify_code` # - The verification code received from the user. # **Example**:: # from telesign.api import Verify # from telesign.exceptions import AuthorizationError, TelesignError # cust_id = "FFFFFFFF-EEEE-DDDD-1234-AB1234567890" # secret_key = "EXAMPLE----TE8sTgg45yusumoN6BYsBVkh+yRJ5czgsnCehZaOYldPJdmFh6NeX8kunZ2zU1YWaUw/0wV6xfw==" # phone_number = "13107409700" # verify = Verify(cust_id, secret_key) # Instantiate a Verify object. # phone_info = verify.sms(phone_number) # Send a text message that contains an auto-generated validation code, to the user. # # When the user inputs the validation code, you can verify that it matches the one that you sent. # if (phone_info != None): # try: # status_info = verify.status(phone_info.data["reference_id"], verify_code=phone_info.verify_code) # except AuthorizationError as ex: # ... # except TelesignError as ex: # ... resource = "/v1/verify/%s" % ref_id method = 'GET' headers = Telesignature::Auth.generate_auth_headers( customer_id: @customer_id, secret_key: @secret_key, resource: resource, method: method) fields = nil if !verify_code.nil? fields = {verify_code: verify_code} end response = @conn.get do |req| req.url resource fields.each{|k,v| req.params[k] = v} if fields req.headers = headers # proxies=@proxy end return Telesignature::Response.new validate_response(response), response end |