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.



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

#connectionObject (readonly)

Returns the value of attribute connection.



26
27
28
# File 'lib/numverify/request.rb', line 26

def connection
  @connection
end

#pathObject (readonly)

Returns the value of attribute path.



26
27
28
# File 'lib/numverify/request.rb', line 26

def path
  @path
end

#queryObject (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