Class: NumverifyClient::Request
- Inherits:
-
Object
- Object
- NumverifyClient::Request
- Defined in:
- lib/numverify/request.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
-
#initialize(query: {}, https: false) ⇒ Request
constructor
A new instance of Request.
- #perform(**args) ⇒ Object
Constructor Details
#initialize(query: {}, https: false) ⇒ Request
Returns a new instance of Request.
19 20 21 22 23 24 |
# File 'lib/numverify/request.rb', line 19 def initialize(query: {}, https: false) @base_uri = "#{protocol(https)}://apilayer.net" @query = query @path = '/api/validate' @connection = Excon.new(@base_uri) end |
Instance Attribute Details
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
26 27 28 |
# File 'lib/numverify/request.rb', line 26 def connection @connection end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
26 27 28 |
# File 'lib/numverify/request.rb', line 26 def path @path end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
26 27 28 |
# File 'lib/numverify/request.rb', line 26 def query @query end |
Instance Method Details
#perform(**args) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/numverify/request.rb', line 28 def perform(**args) response = connection.request(args.merge(path: path, query: query)) parsed_response = JSON.parse(response.body) if parsed_response.key?('error') handle_error(parsed_response['error']) else NumverifyClient::Result.new(parsed_response) end end |