Class: Bitly::API::Organization

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

Overview

An Organization is the top level of the Bitly user hierarchy. Both Users and Groups live within an organization.

Defined Under Namespace

Classes: List

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) ⇒ Bitly::API::Organization

Creates a new ‘Bitly::API::Organization` object

Examples:

organization = Bitly::API::Organization.new(data: org_data, client: client)

Parameters:

  • data (Hash<String, String|Boolean>)

    Data returned from the API about the organization

  • client (Bitly::API::Client)

    An authorized API client

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

    The response object from an API call



80
81
82
83
84
# File 'lib/bitly/api/organization.rb', line 80

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

Class Method Details

.attributesArray<Symbol>

organization

Returns:

  • (Array<Symbol>)

    The attributes the API returns for an



57
58
59
# File 'lib/bitly/api/organization.rb', line 57

def self.attributes
  [:name, :guid, :is_active, :tier, :tier_family, :tier_display_name, :role, :bsds]
end

.fetch(client:, organization_guid:) ⇒ Bitly::API::Organization

Retrieve an organization from the API. It receives an authorized ‘Bitly::API::Client` object and an organization guid and uses it to

request the `/organizations/:organization_guid` endpoint.

[‘GET /v4/organizations/organization_guid`](dev.bitly.com/api-reference/#getOrganization)

Examples:

organization = Bitly::API::Organization.fetch(client: client, organization_guid: guid)

Parameters:

  • client (Bitly::API::Client)

    An authorized API client

  • organization_guid (String)

    An organization guid

Returns:



50
51
52
53
# File 'lib/bitly/api/organization.rb', line 50

def self.fetch(client:, organization_guid:)
  response = client.request(path: "/organizations/#{organization_guid}")
  Organization.new(data: response.body, client: client, response: response)
end

.list(client:) ⇒ Bitly::API::Organization::List

Get a list of organizations from the API. It receives an authorized ‘Bitly::API::Client` object and uses it to request the `/organizations` endpoint. [`GET /v4/organizations`](dev.bitly.com/api-reference/#getOrganizations)

Examples:

organizations = Bitly::API::Organization.list(client: client)

Parameters:

Returns:



29
30
31
32
33
34
35
# File 'lib/bitly/api/organization.rb', line 29

def self.list(client:)
  response = client.request(path: '/organizations')
  organizations = response.body['organizations'].map do |org|
    Organization.new(data: org, client: client)
  end
  List.new(items: organizations, response: response)
end

.time_attributesArray<Symbol>

converted to ‘Time` objects.

Returns:

  • (Array<Symbol>)

    The attributes the API returns that need to be



62
63
64
# File 'lib/bitly/api/organization.rb', line 62

def self.time_attributes
  [:created, :modified]
end

Instance Method Details

#groupsBitly::API::Group::List



87
88
89
# File 'lib/bitly/api/organization.rb', line 87

def groups
  @groups ||= Group.list(client: @client, organization: self)
end

#shorten_countsBitly::API::ShortenCounts

Shorten counts by organization [‘GET /v4/organizations/organization_guid/shorten_counts`](dev.bitly.com/api-reference/#getOrganizationShortenCounts)

Examples:

shorten_counts = organization.shorten_counts

Returns:



99
100
101
# File 'lib/bitly/api/organization.rb', line 99

def shorten_counts
  ShortenCounts.by_organization(client: @client, organization_guid: guid)
end