Module: Code42::API::Org

Included in:
Client
Defined in:
lib/code42/api/org.rb

Instance Method Summary collapse

Instance Method Details

#activate_org(id = 'my', attrs = {}) ⇒ Object



70
71
72
# File 'lib/code42/api/org.rb', line 70

def activate_org(id = 'my', attrs = {})
  object_from_response(Code42::Org, :delete, "OrgDeactivation/#{id}", attrs)
end

#block_org(id = 'my', attrs = {}) ⇒ Object



78
79
80
# File 'lib/code42/api/org.rb', line 78

def block_org(id = 'my', attrs = {})
  object_from_response(Code42::Org, :put, "orgBlock/#{id}", attrs)
end

#create_org(attrs = {}) ⇒ Code42::Org

Creates an org

Examples:

client.create_org(:name => 'Acme Org', :parent_id => 2)

Parameters:

  • attrs (Hash) (defaults to: {})

    A hash of attributes to assign to created org

Returns:



20
21
22
# File 'lib/code42/api/org.rb', line 20

def create_org(attrs = {})
  object_from_response(Code42::Org, :post, "org", attrs)
end

#create_pro_org(attrs = {}) ⇒ Code42::Org

Creates blue org as well as user for the org

Examples:

client.create_org(:company => "test", :email => "[email protected]", :firstname => "test", :lastname => "test")

Parameters:

  • attrs (Hash) (defaults to: {})

    A hash of attributes to assign to created org

Returns:



11
12
13
# File 'lib/code42/api/org.rb', line 11

def create_pro_org(attrs = {})
  object_from_response(Code42::Org, :post, "proOrgChannel", attrs)
end

#deactivate_org(id = 'my', attrs = {}) ⇒ Object



74
75
76
# File 'lib/code42/api/org.rb', line 74

def deactivate_org(id = 'my', attrs = {})
  object_from_response(Code42::Org, :put, "OrgDeactivation/#{id}", attrs)
end

#find_inactive_org_by_name(name, params = {}) ⇒ Object

Returns the first org that starts with a given name. Since orgs are renamed when they are deactivated, it is impossible to guarantee a match by name alone.

Parameters:

  • name (String)

    A Code42 org name

  • params (Hash) (defaults to: {})

    Additional params used by the server for filtering, output, etc.



46
47
48
# File 'lib/code42/api/org.rb', line 46

def find_inactive_org_by_name(name, params = {})
  search_orgs(name, params.merge!(:active => false)).first
end

#find_org_by_name(name, params = {}) ⇒ Code42::Org

Returns an org for a given name. If multiple orgs are found, the first found will be returned. FIXME: This needs to change when the API implements a better way.

Parameters:

  • name (String)

    A Code42 org name

  • params (Hash) (defaults to: {})

    Additional params used by the server for filtering, output, etc.

Returns:



37
38
39
# File 'lib/code42/api/org.rb', line 37

def find_org_by_name(name, params = {})
  search_orgs(name, params).select { |o| o.name == name }.first
end

#org(id = "my", params = {}) ⇒ Code42::Org

Returns information for a given org

Parameters:

  • id (String, Integer) (defaults to: "my")

    A code42 user ID

Returns:



27
28
29
# File 'lib/code42/api/org.rb', line 27

def org(id = "my", params = {})
  object_from_response(Code42::Org, :get, "org/#{id}", params)
end

#org_share_destinations(id) ⇒ Object



86
87
88
# File 'lib/code42/api/org.rb', line 86

def org_share_destinations(id)
  get("orgShareDestinations/#{id}")['data']
end

#orgs(params = {}) ⇒ Array

Returns a list of up to 100 orgs

Parameters:

  • params (Hash) (defaults to: {})

    A hash of parameters to match results against

Returns:

  • (Array)

    An array of matching orgs



61
62
63
64
# File 'lib/code42/api/org.rb', line 61

def orgs(params = {})
  params.merge!(key: 'orgs')
  objects_from_response(Code42::Org, :get, 'org', params)
end

#search_orgs(query, params = {}) ⇒ Array

Searches orgs for a query string

Parameters:

  • query (String)

    A string to search for

Returns:

  • (Array)

    An array of matching orgs



53
54
55
56
# File 'lib/code42/api/org.rb', line 53

def search_orgs(query, params = {})
  params.merge!(q: query)
  orgs(params)
end

#unblock_org(id = 'my', attrs = {}) ⇒ Object



82
83
84
# File 'lib/code42/api/org.rb', line 82

def unblock_org(id = 'my', attrs = {})
  object_from_response(Code42::Org, :delete, "orgBlock/#{id}", attrs)
end

#update_org(id = 'my', attrs = {}) ⇒ Object



66
67
68
# File 'lib/code42/api/org.rb', line 66

def update_org(id = 'my', attrs = {})
  object_from_response(Code42::Org, :put, "org/#{id}", attrs)
end