Class: NumverifyLayer::Client
- Inherits:
-
Object
- Object
- NumverifyLayer::Client
- Includes:
- HTTParty
- Defined in:
- lib/phone_number_validation.rb
Instance Method Summary collapse
-
#initialize(access_key) ⇒ Client
constructor
A new instance of Client.
- #validate(number, options = {}) ⇒ Object
Constructor Details
#initialize(access_key) ⇒ Client
Returns a new instance of Client.
18 19 20 21 22 23 24 25 26 |
# File 'lib/phone_number_validation.rb', line 18 def initialize(access_key) if access_key.nil? raise NumverifyLayer::MissingArgumentException.new 'access_key' end @access_key = access_key end |
Instance Method Details
#validate(number, options = {}) ⇒ Object
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 |
# File 'lib/phone_number_validation.rb', line 29 def validate(number, = {}) if number.nil? raise NumverifyLayer::MissingArgumentException.new 'number' return end # Create a shallow copy so we don't manipulate the original reference q = .dup # Populate the Query q.access_key = @access_key q.number = number # We then create the Request req = NumverifyLayer::ValidateRequest.new(q) # We create a Hash of the request so we can send it via HTTP req_dto = req.to_dh begin # We make the actual request res = self.class.get('/validate', req_dto) # We ensure that we tap the response so we can use the results res.inspect if (res[NumverifyLayer::ValidateResponse::ERROR_EXPR]) raise NumverifyLayer::ValidateException.new res[NumverifyLayer::ValidateResponse::ERROR_EXPR] end # We just return the parsed binary response return res.parsed_response rescue => e puts e.inspect return end end |