Class: Bitly::API::Group::Preferences

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

Overview

The Preferences object represents the account preferences of a Group. It includes the ability to find the domain preference for the group and to update it.

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:, client:, response: nil) ⇒ Preferences

Creates a new Bitly::API::Group::Preferences object from the data, API client and optional response. [‘GET /v4/groups/group_guid/preferences`](dev.bitly.com/api-reference/#updateGroupPreferences)

Examples:

preferences = Bitly::API::Group::Preferences.new(data: data, client: client)

Parameters:

  • data (Hash<String, String>)

    The preferences data from the API

  • client (Bitly::API::Client)

    An authorized API client

  • response (Bitly::HTTP::Response) (defaults to: nil)

    The API response object



44
45
46
47
48
# File 'lib/bitly/api/group/preferences.rb', line 44

def initialize(data:, client:, response: nil)
  assign_attributes(data)
  @client = client
  @response = response
end

Class Method Details

.attributesArray<Symbol>

Returns The attributes the API returns for a group.

Returns:

  • (Array<Symbol>)

    The attributes the API returns for a group



15
# File 'lib/bitly/api/group/preferences.rb', line 15

def self.attributes ; [:group_guid, :domain_preference] ; end

.fetch(client:, group_guid:) ⇒ Bitly::API::Group::Preferences

Retrieve the preferences for a Group, given by the group guid

Examples:

preferences = Bitly::API::Group::Preferences.fetch(client: client, group_guid: group_guid)

Parameters:

  • client (Bitly::API::Client)

    An authorized API client

  • group_guid (String)

    The guid of the groups

Returns:



28
29
30
31
# File 'lib/bitly/api/group/preferences.rb', line 28

def self.fetch(client:, group_guid:)
  response = client.request(path: "/groups/#{group_guid}/preferences")
  new(data: response.body, client: client, response: response)
end

Instance Method Details

#update(domain_preference:) ⇒ Bitly::API::Group::Preferences

Updates the preferences via the API [‘PATCH /v4/groups/group_guid/preferences`](dev.bitly.com/api-reference/#updateGroupPreferences)

Examples:

preferences.update(domain_preference: 'bit.ly')

Parameters:

  • domain_preference (String)

    The new domain preference for this group

Returns:



61
62
63
64
65
66
67
68
69
# File 'lib/bitly/api/group/preferences.rb', line 61

def update(domain_preference:)
  @response = @client.request(
    path: "/groups/#{group_guid}/preferences",
    method: "PATCH",
    params: { domain_preference: domain_preference }
  )
  assign_attributes(response.body)
  self
end