Class: Ip2Geo::Methods::ListConversions

Inherits:
Object
  • Object
show all
Defined in:
lib/ip2geo/methods/list_conversions.rb

Class Method Summary collapse

Class Method Details

.call(options = {}) ⇒ Hash?

List conversions with pagination and optional filtering.

Parameters:

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

    The options for listing conversions

Options Hash (options):

  • :offset (Integer)

    The number of conversions to skip (default: 0)

  • :limit (Integer)

    The maximum number of conversions to return (default: 50, max: 50)

  • :select (Array<String>)

    Optional array of property names to return

  • :ip_search (String)

    Filter conversions by IP address

Returns:

  • (Hash, nil)

    The API response containing conversions list with pagination info, or nil if fails



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ip2geo/methods/list_conversions.rb', line 15

def call(options = {})
  offset = options.fetch(:offset, 0)
  limit = options.fetch(:limit, 50)
  select = options[:select]
  ip_search = options[:ip_search]

  params = []
  params << "offset=#{offset}" if offset.positive?
  params << "limit=#{limit}" if limit != 50
  params << "select=#{select.map { |f| "data.#{f}" }.join(',')}" if select.is_a?(Array) && !select.empty?
  params << "ipSearch=#{ip_search}" if ip_search

  query_string = params.empty? ? '' : "?#{params.join('&')}"
  url = "#{Data::API_ENDPOINT}#{Data::ENDPOINTS[:CONVERSIONS][:LIST]}#{query_string}"

  Helpers::Http.request(url)
rescue StandardError => e
  warn "[Ip2Geo::ListConversions] Error: #{e.message}"
  nil
end