diff --git a/lib/tracker_api/endpoints/epic.rb b/lib/tracker_api/endpoints/epic.rb index 9f29309..a585e1c 100644 --- a/lib/tracker_api/endpoints/epic.rb +++ b/lib/tracker_api/endpoints/epic.rb @@ -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 diff --git a/lib/tracker_api/resources/epic.rb b/lib/tracker_api/resources/epic.rb index d53b259..9309056 100644 --- a/lib/tracker_api/resources/epic.rb +++ b/lib/tracker_api/resources/epic.rb @@ -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 @@ -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 diff --git a/lib/tracker_api/resources/project.rb b/lib/tracker_api/resources/project.rb index dcdfb70..dc90fbd 100644 --- a/lib/tracker_api/resources/project.rb +++ b/lib/tracker_api/resources/project.rb @@ -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