Class: Readiness::GitLab::Namespaces

Inherits:
Client
  • Object
show all
Defined in:
lib/support_readiness/gitlab/namespaces.rb

Overview

Defines the class Namespaces within the module Readiness::GitLab.

Author:

  • Jason Colyer

Since:

  • 1.0.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries

Constructor Details

#initialize(object = {}) ⇒ Namespaces

Creates a new Readiness::GitLab::Namespaces instance

Examples:

require 'support_readiness'
Readiness::GitLab::Namespaces.new

Parameters:

Author:

  • Jason Colyer

Since:

  • 1.0.0



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/support_readiness/gitlab/namespaces.rb', line 24

def initialize(object = {})
  @avatar_url = object['avatar_url']
  @billable_members_count = object['billable_members_count']
  @end_date = object['end_date']
  @full_path = object['full_path']
  @id = object['id']
  @kind = object['kind']
  @max_seats_used = object['max_seats_used']
  @members_count_with_descendants = object['members_count_with_descendants']
  @name = object['name']
  @parent_id = object['parent_id']
  @path = object['path']
  @plan = object['plan']
  @root_repository_size = object['root_repository_size']
  @seats_in_use = object['seats_in_use']
  @trial_ends_on = object['trial_ends_on']
  @trial = object['trial']
  @web_url = object['web_url']
end

Instance Attribute Details

#avatar_urlObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/gitlab/namespaces.rb', line 13

def avatar_url
  @avatar_url
end

#billable_members_countObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/gitlab/namespaces.rb', line 13

def billable_members_count
  @billable_members_count
end

#end_dateObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/gitlab/namespaces.rb', line 13

def end_date
  @end_date
end

#full_pathObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/gitlab/namespaces.rb', line 13

def full_path
  @full_path
end

#idObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/gitlab/namespaces.rb', line 13

def id
  @id
end

#kindObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/gitlab/namespaces.rb', line 13

def kind
  @kind
end

#max_seats_usedObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/gitlab/namespaces.rb', line 13

def max_seats_used
  @max_seats_used
end

#members_count_with_descendantsObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/gitlab/namespaces.rb', line 13

def members_count_with_descendants
  @members_count_with_descendants
end

#nameObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/gitlab/namespaces.rb', line 13

def name
  @name
end

#parent_idObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/gitlab/namespaces.rb', line 13

def parent_id
  @parent_id
end

#pathObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/gitlab/namespaces.rb', line 13

def path
  @path
end

#planObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/gitlab/namespaces.rb', line 13

def plan
  @plan
end

#root_repository_sizeObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/gitlab/namespaces.rb', line 13

def root_repository_size
  @root_repository_size
end

#seats_in_useObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/gitlab/namespaces.rb', line 13

def seats_in_use
  @seats_in_use
end

#trialObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/gitlab/namespaces.rb', line 13

def trial
  @trial
end

#trial_ends_onObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/gitlab/namespaces.rb', line 13

def trial_ends_on
  @trial_ends_on
end

#web_urlObject

Since:

  • 1.0.0



13
14
15
# File 'lib/support_readiness/gitlab/namespaces.rb', line 13

def web_url
  @web_url
end

Class Method Details

.exists?(client, name) ⇒ Boolean

Checks if a namespace exists

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
pp Readiness::GitLab::Namespaces.exists?(client, 'jason_rocks')
# => true
pp Readiness::GitLab::Namespaces.exists?(client, 'jason_does_not_rock')
# => false

Parameters:

  • client (Object)

    An instance of Client

  • name (String)

    The namespace to check for

Returns:

  • (Boolean)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



87
88
89
90
91
# File 'lib/support_readiness/gitlab/namespaces.rb', line 87

def self.exists?(client, name)
  response = client.connection.get "namespaces/#{name}/exists"
  handle_request_error(0, 'GitLab', response.status) unless response.status == 200
  Oj.load(response.body)['exists']
end

.find(client, nid) ⇒ Hash

Locates a namespace within GitLab. This will not exit on error (except Authentication errors)

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
namespace = Readiness::GitLab::Namespaces.find(client, 123)
pp namespace.web_url
# => "https://gitlab.com/groups/group123"

Parameters:

  • client (Object)

    An instance of Client

  • nid (Integer)

    The namespace ID to find

Returns:

  • (Hash)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



110
111
112
113
114
115
116
# File 'lib/support_readiness/gitlab/namespaces.rb', line 110

def self.find(client, nid)
  response = client.connection.get "namespaces/#{nid}"
  handle_request_error(0, 'GitLab', response.status,  { action: 'get', id: nid }) unless response.status == 200
  return Namespaces.new(Oj.load(response.body)) if response.status == 200

  Oj.load(response.body)
end

.find!(client, nid) ⇒ Object

Locates a namespace within GitLab. This will exit on error

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
namespace = Readiness::GitLab::Namespaces.find!(client, 123)
pp namespace.web_url
# => "https://gitlab.com/groups/group123"

Parameters:

  • client (Object)

    An instance of Client

  • nid (Integer)

    The namespace ID to find

Returns:

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



135
136
137
138
139
# File 'lib/support_readiness/gitlab/namespaces.rb', line 135

def self.find!(client, nid)
  response = client.connection.get "namespaces/#{nid}"
  handle_request_error(1, 'GitLab', response.status, { action: 'Find namespace', id: nid }) unless response.status == 200
  Namespaces.new(Oj.load(response.body))
end

.is_paid?(client, namespace) ⇒ Boolean

Determines if a given namespace is paid or not

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
namespace = Readiness::GitLab::Namespaces.find!(client, 123)
pp Readiness::GitLab::Namespaces.is_paid?(client, namespace)
# => true

Parameters:

Returns:

  • (Boolean)

Author:

  • Jason Colyer

Since:

  • 1.0.12



205
206
207
208
209
# File 'lib/support_readiness/gitlab/namespaces.rb', line 205

def self.is_paid?(client, namespace)
  return true if %w[bronze silver gold premium ultimate].include? namespace.plan

  false
end

.owners(client, namespace) ⇒ Array

Locates the group owners for a namespace within GitLab

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
namespace = Readiness::GitLab::Namespaces.find!(client, 123)
owners = Readiness::GitLab::Namespaces.owners(client, namespace)
pp owners.last['user']['name']
# => "John Smith"

Parameters:

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



159
160
161
162
163
# File 'lib/support_readiness/gitlab/namespaces.rb', line 159

def self.owners(client, namespace)
  response = client.connection.get "internal/gitlab_subscriptions/namespaces/#{namespace.id}/owners"
  handle_request_error(0, 'GitLab', response.status,  { action: 'get', id: namespace.id }) unless response.status == 200
  Oj.load(response.body)
end

.search(client, query, filters = []) ⇒ Array

Search for a namespace by name. This method can take a long time to run depending on the number of results found or permission level used.

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
namespaces = Readiness::GitLab::Namespaces.search(client, 'jason_rocks', ["owned_only=true"])
pp namespaces.first.full_path
# => "jason-group/jason-rocks"

Parameters:

  • client (Object)

    An instance of Client

  • query (String)

    The name to search for

  • filters (Array) (defaults to: [])

    An array of filter Strings to use. Should be in the format of key=value

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



63
64
65
66
67
# File 'lib/support_readiness/gitlab/namespaces.rb', line 63

def self.search(client, query, filters = [])
  response = client.connection.get "namespaces?search=#{query}&#{to_param_string(filters)}"
  handle_request_error(0, 'GitLab', response.status) unless response.status == 200
  Oj.load(response.body).map { |n| Namespaces.new(n) }
end

.subscription(client, namespace) ⇒ Array

Locates the subscription for a namespace within GitLab

Examples:

require 'support_readiness'
config = Readiness::GitLab::Configuration.new
config.token = 'test123abc'
client = Readiness::GitLab::Client.new(config)
namespace = Readiness::GitLab::Namespaces.find!(client, 123)
sub = Readiness::GitLab::Namespaces.subscription(client, namespace)
pp sub['plan']['code']
# => "ultimate"

Parameters:

Returns:

  • (Array)

See Also:

Author:

  • Jason Colyer

Since:

  • 1.0.0



183
184
185
186
187
# File 'lib/support_readiness/gitlab/namespaces.rb', line 183

def self.subscription(client, namespace)
  response = client.connection.get "internal/gitlab_subscriptions/namespaces/#{namespace.id}/gitlab_subscription"
  handle_request_error(0, 'GitLab', response.status,  { action: 'get', id: namespace.id }) unless response.status == 200
  Oj.load(response.body)
end