Class: Ip2Geo::Methods::GetConversion

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

Class Method Summary collapse

Class Method Details

.call(options = {}) ⇒ Hash?

Retrieve a single conversion by its ID.

Parameters:

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

    The options for retrieving the conversion

Options Hash (options):

  • :conversion_id (String)

    The unique identifier of the conversion to retrieve (required)

  • :select (Array<String>)

    Optional array of property names to return

Returns:

  • (Hash, nil)

    The API response containing conversion 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_conversion.rb', line 13

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

  unless conversion_id
    return error_response(
      Data.translate('conversions.conversion-id-is-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, { conversionId: conversion_id })
rescue StandardError => e
  warn "[Ip2Geo::GetConversion] Error: #{e.message}"
  nil
end