Class: Ip2Geo::Methods::GetConversions

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

Class Method Summary collapse

Class Method Details

.call(options = {}) ⇒ Hash?

Retrieve multiple conversions by their IDs.

Parameters:

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

    The options for retrieving conversions

Options Hash (options):

  • :conversion_ids (Array<String>)

    An array of unique identifiers to retrieve (required)

  • :select (Array<String>)

    Optional array of property names to return

Returns:

  • (Hash, nil)

    The API response containing conversions data, or nil if the request fails



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

def call(options = {})
  conversion_ids = options[:conversion_ids]
  select = options[:select]

  unless conversion_ids.is_a?(Array) && !conversion_ids.empty?
    return error_response(
      Data.translate('conversions.conversion-ids-are-required')
    )
  end

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

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

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