Class: Geoip2::Client

Inherits:
Object
  • Object
show all
Includes:
Api::City, Api::CityIspOrg, Api::Country, Api::Insights, Api::Omni
Defined in:
lib/geoip2/client.rb

Instance Method Summary collapse

Methods included from Api::Omni

#omni

Methods included from Api::City

#city

Methods included from Api::Country

#country

Methods included from Api::Insights

#insights

Methods included from Api::CityIspOrg

#city_isp_org

Constructor Details

#initialize(config) ⇒ Client

Creates a new instance of Geoip2::Client

Parameters:

  • config (Hash)

    includes all of the config from the



25
26
27
28
29
30
31
# File 'lib/geoip2/client.rb', line 25

def initialize(config)
  @base_url = "https://#{config[:host]}"
  @base_path = config[:base_path]
  @parallel_requests = config[:parallel_requests]
  @user = config[:user_id]
  @password = config[:license_key]
end

Instance Method Details

#get(url, params = {}, faraday_options = {}) ⇒ Object

Does a GET request to the url with the params

Parameters:

  • url (String)

    the relative path in the Geoip2 API

  • params (Hash) (defaults to: {})

    the url params that should be passed in the request



38
39
40
41
42
43
# File 'lib/geoip2/client.rb', line 38

def get(url, params = {}, faraday_options = {})
  params = params.inject({}){|memo,(k,v)| memo[k.to_s] = v; memo}
  preform(@base_path + url, :get, params: params) do
    return connection(faraday_options).get(@base_path + url, params).body
  end
end

#in_parallelObject

Does a parallel request to the api for all of the requests in the block

Examples:

block

Geoip2.in_parallel do
  Geoip2.create_review(review_params)
  Geoip2.()
end


53
54
55
56
57
# File 'lib/geoip2/client.rb', line 53

def in_parallel
  connection.in_parallel do
    yield
  end
end