Class: Bitly::API::Bitlink::LinkClick

Inherits:
Object
  • Object
show all
Includes:
Bitly::API::Base
Defined in:
lib/bitly/api/bitlink/link_click.rb

Defined Under Namespace

Classes: List

Instance Attribute Summary

Attributes included from Bitly::API::Base

#response

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Bitly::API::Base

#assign_attributes

Constructor Details

#initialize(data:) ⇒ LinkClick

Returns a new instance of LinkClick.



71
72
73
# File 'lib/bitly/api/bitlink/link_click.rb', line 71

def initialize(data:)
  assign_attributes(data)
end

Class Method Details

.attributesObject



63
64
65
# File 'lib/bitly/api/bitlink/link_click.rb', line 63

def self.attributes
  [:clicks]
end

.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

.time_attributesObject



66
67
68
# File 'lib/bitly/api/bitlink/link_click.rb', line 66

def self.time_attributes
  [:date]
end