Class: Zendesk2::Memberships

Inherits:
Object
  • Object
show all
Extended by:
Attributes
Includes:
Collection, PagedCollection
Defined in:
lib/zendesk2/memberships.rb

Instance Method Summary collapse

Methods included from Attributes

assoc_accessor, assoc_reader, assoc_writer

Methods included from PagedCollection

#all_entries, #collection_method, #collection_root, #create, #create!, #each_entry, #each_page, #get, #get!, included, #model_method, #model_root, #new_page, #next_page, #previous_page

Methods included from Collection

cistern_included, #collection_method, #collection_root, #create, #create!, #get, #get!, included, #model_method, #model_root, #namespace, #new

Instance Method Details

#all(params = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/zendesk2/memberships.rb', line 20

def all(params = {})
  requires_one :user_id, :organization_id

  body = if user_id && organization_id
           {
             'organization_memberships' => [
               cistern.get_membership(
                 'user_id' => user_id,
                 'organization_id' => organization_id,
               ).body['organization_membership'],
             ],
           }
         elsif user_id
           request_params = { 'membership' => { 'user_id' => user_id } }.merge(params)
           cistern.get_user_memberships(request_params).body
         else
           request_params = { 'membership' => { 'organization_id' => organization_id } }.merge(params)
           cistern.get_organization_memberships(request_params).body
         end

  load(body[collection_root])
  merge_attributes(Cistern::Hash.slice(body, 'count', 'next_page', 'previous_page'))
  self
end