Class: Bitly::API::Group
- Inherits:
-
Object
- Object
- Bitly::API::Group
- Includes:
- Base
- Defined in:
- lib/bitly/api/group.rb,
lib/bitly/api/group/preferences.rb
Overview
A Group represents a subdivision of an Organization. Most API actions are taken on behalf of a user and group and groups become a container for Bitlinks and metrics.
Defined Under Namespace
Classes: List, Preferences
Instance Attribute Summary
Attributes included from Base
Class Method Summary collapse
-
.attributes ⇒ Array<Symbol>
The attributes the API returns for a group.
-
.fetch(client:, group_guid:) ⇒ Bitly::API::Group
Retrieve a group from the API.
-
.list(client:, organization_guid: nil) ⇒ Bitly::API::Group::List
Get a list of groups from the API.
-
.time_attributes ⇒ Array<Symbol>
converted to ‘Time` objects.
Instance Method Summary collapse
-
#bitlinks ⇒ Bitly::API::Bitlink::List
Gets the Bitlinks for the group.
-
#countries(unit: nil, units: nil, unit_reference: nil, size: nil) ⇒ Bitly::API::ClickMetric::List
Gets the country click metrics for the group.
-
#initialize(data:, client:, response: nil, organization: nil) ⇒ Bitly::API::Group
constructor
Creates a new ‘Bitly::API::Group` object.
-
#organization ⇒ Bitly::API::Organization
Fetch the organization for the group.
-
#preferences ⇒ Bitly::API::Group::Preferences
Fetch the group’s preferences.
-
#referring_networks(unit: nil, units: nil, unit_reference: nil, size: nil) ⇒ Bitly::API::ClickMetric::List
Gets the referring networks for the group.
-
#shorten_counts ⇒ Bitly::API::ShortenCounts
Get the shorten counts for the group.
-
#tags ⇒ Array<String>
Fetch the group’s tags [‘GET /v4/groups/group_guid/tags`](dev.bitly.com/api-reference/#getGroupTags).
-
#update(name: nil, organization_guid: nil, bsds: nil) ⇒ Bitly::API::Group
Allows you to update the group’s name, organization or BSDs.
Methods included from Base
Constructor Details
#initialize(data:, client:, response: nil, organization: nil) ⇒ Bitly::API::Group
Creates a new ‘Bitly::API::Group` object.
87 88 89 90 91 92 |
# File 'lib/bitly/api/group.rb', line 87 def initialize(data:, client:, response: nil, organization: nil) assign_attributes(data) @client = client @response = response @organization = organization end |
Class Method Details
.attributes ⇒ Array<Symbol>
Returns The attributes the API returns for a group.
62 63 64 |
# File 'lib/bitly/api/group.rb', line 62 def self.attributes [:name, :guid, :is_active, :role, :bsds, :organization_guid] end |
.fetch(client:, group_guid:) ⇒ Bitly::API::Group
Retrieve a group from the API. It receives an authorized ‘Bitly::API::Client` object and a group guid and uses it to request
the `/groups/:group_guid` endpoint.
[‘GET /v4/groups/group_guid`](dev.bitly.com/api-reference/#getGroup)
56 57 58 59 |
# File 'lib/bitly/api/group.rb', line 56 def self.fetch(client:, group_guid:) response = client.request(path: "/groups/#{group_guid}") Group.new(data: response.body, client: client, response: response) end |
.list(client:, organization_guid: nil) ⇒ Bitly::API::Group::List
Get a list of groups from the API. It receives an authorized ‘Bitly::API::Client` object and uses it to request the `/groups` endpoint, optionally passing an organization guid. [`GET /v4/groups`](dev.bitly.com/api-reference/#getGroups)
34 35 36 37 38 39 40 41 |
# File 'lib/bitly/api/group.rb', line 34 def self.list(client:, organization_guid: nil) params = { "organization_guid" => organization_guid } response = client.request(path: "/groups", params: params) groups = response.body["groups"].map do |group| Group.new(data: group, client: client) end List.new(items: groups, response: response) end |
.time_attributes ⇒ Array<Symbol>
converted to ‘Time` objects.
67 68 69 |
# File 'lib/bitly/api/group.rb', line 67 def self.time_attributes [:created, :modified] end |
Instance Method Details
#bitlinks ⇒ Bitly::API::Bitlink::List
Gets the Bitlinks for the group. [‘GET /v4/groups/group_guid/bitlinks`](dev.bitly.com/api-reference/#getBitlinksByGroup)
164 165 166 |
# File 'lib/bitly/api/group.rb', line 164 def bitlinks Bitly::API::Bitlink.list(client: @client, group_guid: guid) end |
#countries(unit: nil, units: nil, unit_reference: nil, size: 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)
207 208 209 210 211 212 213 214 215 216 |
# File 'lib/bitly/api/group.rb', line 207 def countries(unit: nil, units: nil, unit_reference: nil, size: nil) ClickMetric.list_countries_by_group( client: @client, group_guid: guid, unit: unit, units: units, unit_reference: unit_reference, size: size ) end |
#organization ⇒ Bitly::API::Organization
Fetch the organization for the group. [‘GET /v4/organizations/organization_guid`)](dev.bitly.com/api-reference/#getOrganization)
99 100 101 |
# File 'lib/bitly/api/group.rb', line 99 def organization @organization ||= Organization.fetch(client: @client, organization_guid: organization_guid) end |
#preferences ⇒ Bitly::API::Group::Preferences
Fetch the group’s preferences. [‘GET /v4/groups/group_guid/preferences`](dev.bitly.com/api-reference/#getGroupPreferences)
108 109 110 |
# File 'lib/bitly/api/group.rb', line 108 def preferences @preferences ||= Group::Preferences.fetch(client: @client, group_guid: guid) end |
#referring_networks(unit: nil, units: nil, unit_reference: nil, size: 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)
182 183 184 185 186 187 188 189 190 191 |
# File 'lib/bitly/api/group.rb', line 182 def referring_networks(unit: nil, units: nil, unit_reference: nil, size: nil) ClickMetric.list_referring_networks( client: @client, group_guid: guid, unit: unit, units: units, unit_reference: unit_reference, size: size ) end |
#shorten_counts ⇒ Bitly::API::ShortenCounts
Get the shorten counts for the group. # [‘GET /v4/groups/group_guid/shorten_counts`](dev.bitly.com/api-reference/#getGroupShortenCounts)
155 156 157 |
# File 'lib/bitly/api/group.rb', line 155 def shorten_counts ShortenCounts.by_group(client: @client, group_guid: guid) end |
#tags ⇒ Array<String>
Fetch the group’s tags [‘GET /v4/groups/group_guid/tags`](dev.bitly.com/api-reference/#getGroupTags)
117 118 119 |
# File 'lib/bitly/api/group.rb', line 117 def @tags ||= @client.request(path: "/groups/#{guid}/tags").body["tags"] end |
#update(name: nil, organization_guid: nil, bsds: nil) ⇒ Bitly::API::Group
Allows you to update the group’s name, organization or BSDs. If you update the organization guid and have already loaded the organization, it is nilled out so it can be reloaded with the correct guid [‘PATCH /v4/groups/group_guid`](dev.bitly.com/api-reference/#updateGroup)
136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/bitly/api/group.rb', line 136 def update(name: nil, organization_guid: nil, bsds: nil) params = { "name" => name, "bsds" => bsds } if organization_guid params["organization_guid"] = organization_guid @organization = nil end @response = @client.request(path: "/groups/#{guid}", method: "PATCH", params: params) assign_attributes(@response.body) self end |