Class: TrackerApi::Endpoints::Memberships

Inherits:
Object
  • Object
show all
Defined in:
lib/tracker_api/endpoints/memberships.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Memberships

Returns a new instance of Memberships.



6
7
8
# File 'lib/tracker_api/endpoints/memberships.rb', line 6

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/tracker_api/endpoints/memberships.rb', line 4

def client
  @client
end

Instance Method Details

#add(project_id, params = {}) ⇒ Object



19
20
21
22
23
# File 'lib/tracker_api/endpoints/memberships.rb', line 19

def add(project_id, params={})
  data = client.post("/projects/#{project_id}/memberships", params: params).body

  Resources::ProjectMembership.new({ project_id: project_id }.merge(data))
end

#get(project_id, params = {}) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/tracker_api/endpoints/memberships.rb', line 10

def get(project_id, params={})
  data = client.paginate("/projects/#{project_id}/memberships", params: params)
  raise Errors::UnexpectedData, 'Array of memberships expected' unless data.is_a? Array

  data.map do |membership|
    Resources::ProjectMembership.new({ project_id: project_id }.merge(membership))
  end
end