Class: IPinfo::Adapter
- Inherits:
-
Object
- Object
- IPinfo::Adapter
- Defined in:
- lib/ipinfo/adapter.rb
Constant Summary collapse
- HOST =
'https://ipinfo.io'
- HOST_V6 =
'https://v6.ipinfo.io'
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
Instance Method Summary collapse
- #get(uri, host_type = :v4) ⇒ Object
-
#initialize(token = nil, adapter = :net_http) ⇒ Adapter
constructor
A new instance of Adapter.
- #post(uri, body, timeout = 2) ⇒ Object
Constructor Details
#initialize(token = nil, adapter = :net_http) ⇒ Adapter
Returns a new instance of Adapter.
14 15 16 17 |
# File 'lib/ipinfo/adapter.rb', line 14 def initialize(token = nil, adapter = :net_http) @token = token @conn = connection(adapter) end |
Instance Attribute Details
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
12 13 14 |
# File 'lib/ipinfo/adapter.rb', line 12 def conn @conn end |
Instance Method Details
#get(uri, host_type = :v4) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/ipinfo/adapter.rb', line 19 def get(uri, host_type= :v4) host = (host_type == :v6) ? HOST_V6 : HOST @conn.get(host + 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 |
#post(uri, body, timeout = 2) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/ipinfo/adapter.rb', line 29 def post(uri, body, timeout = 2) @conn.post(HOST + uri) do |req| req.body = body req..timeout = timeout end end |