Class: IPinfo::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/ipinfo/adapter.rb

Constant Summary collapse

HOST =
'ipinfo.io'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token = nil, adapter = :net_http) ⇒ Adapter

Returns a new instance of Adapter.



11
12
13
14
# File 'lib/ipinfo/adapter.rb', line 11

def initialize(token = nil, adapter = :net_http)
  @token = token
  @conn = connection(adapter)
end

Instance Attribute Details

#connObject (readonly)

Returns the value of attribute conn.



9
10
11
# File 'lib/ipinfo/adapter.rb', line 9

def conn
  @conn
end

Instance Method Details

#get(uri) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/ipinfo/adapter.rb', line 16

def get(uri)
  @conn.get(uri) do |req|
    default_headers.each_pair do |key, value|
      req.headers[key] = value
    end
    req.params['token'] = CGI::escape(token) if token
  end
end