Method: Bitly::API::Bitlink::LinkClick.list

Defined in:
lib/bitly/api/bitlink/link_click.rb

.list(client:, bitlink:, unit: nil, units: nil, size: nil, unit_reference: nil) ⇒ Bitly::API::Bitlink::LinkClick::List

Get the clicks for a bitlink. [‘GET /v4/bitlink/bitlink/clicks`](dev.bitly.com/api-reference/#getClicksForBitlink)

Parameters:

  • client (Bitly::API::Client)

    An authorized API client

  • bitlink (String)

    The Bitlink for which you want the clicks

  • sort (String)

    The data to sort on. Default and only option is “clicks”.

  • unit (String) (defaults to: nil)

    A unit of time. Default is “day” and can be “minute”, “hour”, “day”, “week” or “month”

  • units (Integer) (defaults to: nil)

    An integer representing the time units to query data for. pass -1 to return all units of time. Defaults to -1.

  • unit_reference (String) (defaults to: nil)

    An ISO-8601 timestamp, indicating the most recent time for which to pull metrics. Will default to current time.

  • size (Integer) (defaults to: nil)

    The number of links to be returned. Defaults to 50

Returns:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/bitly/api/bitlink/link_click.rb', line 41

def self.list(client:, bitlink:, unit: nil, units: nil, size: nil, unit_reference: nil)
  bitlink = Utils.normalise_bitlink(bitlink: bitlink)
  response = client.request(
    path: "/bitlinks/#{bitlink}/clicks",
    params: {
      "unit" => unit,
      "units" => units,
      "unit_reference" => unit_reference,
      "size" => size
    }
  )
  body = response.body
  items = body["link_clicks"].map { |link_click| new(data: link_click) }
  Bitly::API::Bitlink::LinkClick::List.new(
    items: items,
    response: response,
    unit: body["unit"],
    units: body["units"],
    unit_reference: body["unit_reference"]
  )
end