Class: NumverifyLayer::Client
- Inherits:
-
Object
- Object
- NumverifyLayer::Client
- Includes:
- HTTParty
- Defined in:
- lib/phone_number_validation.rb
Instance Method Summary collapse
- #countries(options = {}) ⇒ Object
-
#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.
21 22 23 24 25 26 27 28 29 |
# File 'lib/phone_number_validation.rb', line 21 def initialize(access_key) if access_key.nil? raise NumverifyLayer::MissingArgumentException.new 'access_key' end @access_key = access_key end |
Instance Method Details
#countries(options = {}) ⇒ Object
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 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/phone_number_validation.rb', line 74 def countries( = {}) # Create a shallow copy so we don't manipulate the original reference q = .dup # Populate the Query q.access_key = @access_key # We then create the Request req = NumverifyLayer::CountriesRequest.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('/countries', req_dto) # We ensure that we tap the response so we can use the results res.inspect if (res[NumverifyLayer::CountriesResponse::ERROR_EXPR]) raise NumverifyLayer::CountriesException.new res[NumverifyLayer::CountriesResponse::ERROR_EXPR] end # We just return the parsed binary response return res.parsed_response rescue => e puts e.inspect return end end |
#validate(number, options = {}) ⇒ Object
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 |
# File 'lib/phone_number_validation.rb', line 32 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 |