Module: Cyclid::Client::Organization

Included in:
Tilapia
Defined in:
lib/cyclid/client/organization.rb

Overview

Organization related methods

Instance Method Summary collapse

Instance Method Details

#org_add(name, email) ⇒ Hash

Create a new organization. The organization is created without any members; use org_modify to add a set of users to the organization after it has been created.

Examples:

Create a new organization ‘example’

new_org = org_add('example', '[email protected]')

Parameters:

  • name (String)

    organization name.

  • email (String)

    organization owners email address.

Returns:

  • (Hash)

    Decoded server response object.

See Also:



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cyclid/client/organization.rb', line 57

def org_add(name, email)
  # Create the organization object
  org = { 'name' => name, 'owner_email' => email }
  @logger.debug org

  # Sign & send the request
  uri = server_uri('/organizations')
  res_data = api_json_post(uri, org)
  @logger.debug res_data

  return res_data
end

#org_config_get(name, type, plugin) ⇒ Hash

Get a plugin configuration for an organization. organization

org_config_get('example', 'api', 'foo')

Examples:

Get the plugin config & schema for the ‘foo’ ‘api’ type plugin, for the ‘example’

Parameters:

  • name (String)

    organization name.

  • type (String)

    plugin ‘type’

  • plugin (String)

    plugin name.

Returns:

  • (Hash)

    Decoded server response object.

See Also:



151
152
153
154
155
156
157
# File 'lib/cyclid/client/organization.rb', line 151

def org_config_get(name, type, plugin)
  uri = server_uri("/organizations/#{name}/configs/#{type}/#{plugin}")
  res_data = api_get(uri)
  @logger.debug res_data

  return res_data
end

#org_config_set(name, type, plugin, config) ⇒ Hash

Update a plugin configuration for an organization.

Parameters:

  • name (String)

    organization name.

  • type (String)

    plugin ‘type’

  • plugin (String)

    plugin name.

  • config (Hash)

    plugin configuration data.

Returns:

  • (Hash)

    Decoded server response object.

See Also:



166
167
168
169
170
171
172
# File 'lib/cyclid/client/organization.rb', line 166

def org_config_set(name, type, plugin, config)
  uri = server_uri("/organizations/#{name}/configs/#{type}/#{plugin}")
  res_data = api_json_put(uri, config)
  @logger.debug res_data

  return res_data
end

#org_delete(name) ⇒ Hash

Note:

The API does not currently support deleting an organization and this method will always fail.

Delete an organization

Parameters:

  • name (String)

    organization name.

Returns:

  • (Hash)

    Decoded server response object.

See Also:



180
181
182
183
184
185
186
# File 'lib/cyclid/client/organization.rb', line 180

def org_delete(name)
  uri = server_uri("/organizations/#{name}")
  res_data = api_delete(uri)
  @logger.debug res_data

  return res_data
end

#org_get(name) ⇒ Hash

Get details of a specific organization

Parameters:

  • name (String)

    organization name.

Returns:

  • (Hash)

    Decoded server response object.



39
40
41
42
43
44
45
# File 'lib/cyclid/client/organization.rb', line 39

def org_get(name)
  uri = server_uri("/organizations/#{name}")
  res_data = api_get(uri)
  @logger.debug res_data

  return res_data
end

#org_listArray

Retrieve the list of organizations from a server

Returns:

  • (Array)

    List of organization names.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cyclid/client/organization.rb', line 23

def org_list
  uri = server_uri('/organizations')
  res_data = api_get(uri)
  @logger.debug res_data

  orgs = []
  res_data.each do |item|
    orgs << item['name']
  end

  return orgs
end

#org_modify(name, args) ⇒ Hash

Note:

Setting the organization members will overwrite the existing set; you should ensure the set of members is complete before you set it.

Modify an organization. Only the owner email address and organization members can be changed; you can not change the name of an organization once it has been created.

Parameters:

  • name (String)

    organization name.

  • args (Hash)

    options to modify the organization.

Options Hash (args):

  • owner_email (String)

    Organization owners email address.

  • members (Array)

    Set of users who will be organization members.

Returns:

  • (Hash)

    Decoded server response object.

See Also:



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/cyclid/client/organization.rb', line 83

def org_modify(name, args)
  # Create the organization object
  org = {}

  # Add the owner email address if one was supplied
  org['owner_email'] = args[:owner_email] \
    if args.key? :owner_email and args[:owner_email]

  # Add the list of members if it was supplied
  org['users'] = args[:members] \
    if args.key? :members and args[:members]

  @logger.debug org

  # Sign & send the request
  uri = server_uri("/organizations/#{name}")
  res_data = api_json_put(uri, org)
  @logger.debug res_data

  return res_data
end

#org_user_get(name, username) ⇒ Hash

Get details of an organization member

Parameters:

  • name (String)

    organization name.

  • username (String)

    member username.

Returns:

  • (Hash)

    Decoded server response object.

See Also:



110
111
112
113
114
115
116
# File 'lib/cyclid/client/organization.rb', line 110

def org_user_get(name, username)
  uri = server_uri("/organizations/#{name}/members/#{username}")
  res_data = api_get(uri)
  @logger.debug res_data

  return res_data
end

#org_user_permissions(name, username, permissions) ⇒ Hash

Modify the permissions for an organization member

Examples:

Give the user ‘leslie’ read & write permission to the ‘example’ organization

perms = {admin: false, write: true, read: true}
org_user_permissions('example', 'leslie', perms)

Parameters:

  • name (String)

    organization name.

  • username (String)

    member username.

  • permissions (Hash)

    permissions to apply to the member.

Options Hash (permissions):

  • admin (Boolean)

    organization ‘admin’ permission.

  • write (Boolean)

    organization ‘write’ permission.

  • read (Boolean)

    organization ‘read’ permission.

Returns:

  • (Hash)

    Decoded server response object.

See Also:



130
131
132
133
134
135
136
137
138
139
140
# File 'lib/cyclid/client/organization.rb', line 130

def org_user_permissions(name, username, permissions)
  perms = { 'permissions' => permissions }

  @logger.debug perms

  uri = server_uri("/organizations/#{name}/members/#{username}")
  res_data = api_json_put(uri, perms)
  @logger.debug res_data

  return res_data
end