Class: Bitly::API::ClickMetric

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/bitly/api/click_metric.rb

Defined Under Namespace

Classes: List, Referrers

Instance Attribute Summary

Attributes included from Base

#response

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#assign_attributes

Constructor Details

#initialize(data:) ⇒ ClickMetric

Returns a new instance of ClickMetric.



176
177
178
# File 'lib/bitly/api/click_metric.rb', line 176

def initialize(data:)
  assign_attributes(data)
end

Class Method Details

.attributesObject



171
172
173
# File 'lib/bitly/api/click_metric.rb', line 171

def self.attributes
  [:clicks, :value]
end

Get metrics for a Bitlink by country [‘GET /v4/bitlinks/bitlink/countries`](dev.bitly.com/api-reference/#getMetricsForBitlinkByCountries)

Parameters:

  • client (Bitly::API::Client)

    An authorized API client

  • bitlink (String)

    The bitlink you want information about

  • 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:



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/bitly/api/click_metric.rb', line 119

def self.list_countries_by_bitlink(client:, bitlink:, unit: nil, units: nil, size: nil, unit_reference: nil)
  bitlink = Bitlink::Utils.normalise_bitlink(bitlink: bitlink)
  list_metrics(
    client: client,
    path: "/bitlinks/#{bitlink}/countries",
    unit: unit,
    units: units,
    unit_reference: unit_reference,
    size: size
  )
end

.list_countries_by_group(client:, group_guid:, unit: nil, units: nil, size: nil, unit_reference: nil) ⇒ Bitly::API::ClickMetric::List

Gets the country click metrics for the group. [‘GET /v4/groups/group_guid/countries`](dev.bitly.com/api-reference/#getGroupMetricsByCountries)

Parameters:

  • client (Bitly::API::Client)

    An authorized API client

  • group_guid (String)

    The guid of the group

  • 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:



80
81
82
83
84
85
86
87
88
89
# File 'lib/bitly/api/click_metric.rb', line 80

def self.list_countries_by_group(client:, group_guid:, unit: nil, units: nil, size: nil, unit_reference: nil)
  list_metrics(
    client: client,
    path: "/groups/#{group_guid}/countries",
    unit: unit,
    units: units,
    unit_reference: unit_reference,
    size: size
  )
end

.list_referrers(client:, bitlink:, unit: nil, units: nil, size: nil, unit_reference: nil) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/bitly/api/click_metric.rb', line 91

def self.list_referrers(client:, bitlink:, unit: nil, units: nil, size: nil, unit_reference: nil)
  bitlink = Bitlink::Utils.normalise_bitlink(bitlink: bitlink)
  list_metrics(
    client: client,
    path: "/bitlinks/#{bitlink}/referrers",
    unit: unit,
    units: units,
    unit_reference: unit_reference,
    size: size
  )
end

.list_referrers_by_domain(client:, bitlink:, unit: nil, units: nil, size: nil, unit_reference: nil) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/bitly/api/click_metric.rb', line 143

def self.list_referrers_by_domain(client:, bitlink:, unit: nil, units: nil, size: nil, unit_reference: nil)
  bitlink = Bitlink::Utils.normalise_bitlink(bitlink: bitlink)
  response = client.request(
    path: "/bitlinks/#{bitlink}/referrers_by_domains",
    params: {
      "unit" => unit,
      "units" => units,
      "unit_reference" => unit_reference,
      "size" => size
    }
  )
  body = response.body
  referrers = body["referrers_by_domain"].map do |referrer|
    click_metrics = referrer["referrers"].map do |metric|
      ClickMetric.new(data: metric)
    end
    Referrers.new(items: click_metrics, response: response, network: referrer["network"])
  end
  List.new(
    items: referrers,
    response: response,
    unit: body["unit"],
    units: body["units"],
    unit_reference: body["unit_reference"],
    facet: body["facet"]
  )
end

.list_referring_domains(client:, bitlink:, unit: nil, units: nil, size: nil, unit_reference: nil) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/bitly/api/click_metric.rb', line 131

def self.list_referring_domains(client:, bitlink:, unit: nil, units: nil, size: nil, unit_reference: nil)
  bitlink = Bitlink::Utils.normalise_bitlink(bitlink: bitlink)
  list_metrics(
    client: client,
    path: "/bitlinks/#{bitlink}/referring_domains",
    unit: unit,
    units: units,
    unit_reference: unit_reference,
    size: size
  )
end

.list_referring_networks(client:, group_guid:, unit: nil, units: nil, size: nil, unit_reference: nil) ⇒ Bitly::API::ClickMetric::List

Gets the referring networks for the group. [‘GET /v4/groups/group_guid/referring_networks`](dev.bitly.com/api-reference/#GetGroupMetricsByReferringNetworks)

Parameters:

  • client (Bitly::API::Client)

    An authorized API client

  • group_guid (String)

    The guid of the group

  • 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:



53
54
55
56
57
58
59
60
61
62
# File 'lib/bitly/api/click_metric.rb', line 53

def self.list_referring_networks(client:, group_guid:, unit: nil, units: nil, size: nil, unit_reference: nil)
  list_metrics(
    client: client,
    path: "/groups/#{group_guid}/referring_networks",
    unit: unit,
    units: units,
    unit_reference: unit_reference,
    size: size
  )
end