Class: NumverifyClient::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/numverify/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query: {}, https: false) ⇒ Request

Returns a new instance of Request.



17
18
19
20
21
22
# File 'lib/numverify/request.rb', line 17

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

#connectionObject (readonly)

Returns the value of attribute connection.



24
25
26
# File 'lib/numverify/request.rb', line 24

def connection
  @connection
end

#pathObject (readonly)

Returns the value of attribute path.



24
25
26
# File 'lib/numverify/request.rb', line 24

def path
  @path
end

#queryObject (readonly)

Returns the value of attribute query.



24
25
26
# File 'lib/numverify/request.rb', line 24

def query
  @query
end

Instance Method Details

#perform(**args) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/numverify/request.rb', line 26

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