Skip to content

Commit

Permalink
Merge pull request #53 from erbunao/epic-create-update
Browse files Browse the repository at this point in the history
Add epic creation and update
  • Loading branch information
forest committed Aug 4, 2015
2 parents df1906c + b7fb91a commit a4eda90
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/tracker_api/endpoints/epic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,21 @@ def initialize(client)
def get(project_id, id, params={})
data = client.get("/projects/#{project_id}/epics/#{id}", params: params).body

Resources::Epic.new({ project_id: project_id }.merge(data))
Resources::Epic.new({ client: client, project_id: project_id }.merge(data))
end

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

Resources::Epic.new({ client: client }.merge(data))
end

def update(epic, params={})
raise ArgumentError, 'Valid epic required to update.' unless epic.instance_of?(Resources::Epic)

data = client.put("/projects/#{epic.project_id}/epics/#{epic.id}", params: params).body

epic.attributes = data
end
end
end
Expand Down
17 changes: 17 additions & 0 deletions lib/tracker_api/resources/epic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module Resources
class Epic
include Shared::HasId

attribute :client

attribute :comment_ids, Array[Integer]
attribute :comments, Array[Comment]
attribute :created_at, DateTime
Expand All @@ -16,6 +18,21 @@ class Epic
attribute :project_id, Integer
attribute :updated_at, DateTime
attribute :url, String

class UpdateRepresenter < Representable::Decorator
include Representable::JSON

property :name
property :description
property :label, class: Label, decorator: Label::UpdateRepresenter, render_empty: true
end

# Save changes to an existing Epic.
def save
raise ArgumentError, 'Can not update an epic with an unknown project_id.' if project_id.nil?

Endpoints::Epic.new(client).update(self, UpdateRepresenter.new(self))
end
end
end
end
16 changes: 16 additions & 0 deletions lib/tracker_api/resources/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@ def create_story(params)
Endpoints::Story.new(client).create(id, params)
end

# Find a epic by id for the project.
#
# @param [Fixnum] epic_id id of epic to get
# @return [Epic] epic with given id
def epic(epic_id, params={})
Endpoints::Epic.new(client).get(id, epic_id, params)
end

# Create a new epic in the project.
#
# @param [Hash] params attributes to create the epic with
# @return [epic] newly created Epic
def create_epic(params)
Endpoints::Epic.new(client).create(id, params)
end

# Add a new membership for the project.
#
# @param [Hash] params attributes to add a member; must have at least email or user_id
Expand Down

0 comments on commit a4eda90

Please sign in to comment.