Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/tracker_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ module Endpoints
autoload :Tasks, 'tracker_api/endpoints/tasks'
autoload :Comments, 'tracker_api/endpoints/comments'
autoload :Comment, 'tracker_api/endpoints/comment'
autoload :Blockers, 'tracker_api/endpoints/blockers'
autoload :Blocker, 'tracker_api/endpoints/blocker'
autoload :Webhook, 'tracker_api/endpoints/webhook'
autoload :Webhooks, 'tracker_api/endpoints/webhooks'
autoload :StoryTransitions, 'tracker_api/endpoints/story_transitions'
Expand Down Expand Up @@ -90,6 +92,7 @@ module Shared
autoload :Task, 'tracker_api/resources/task'
autoload :TimeZone, 'tracker_api/resources/time_zone'
autoload :Comment, 'tracker_api/resources/comment'
autoload :Blocker, 'tracker_api/resources/blocker'
autoload :Webhook, 'tracker_api/resources/webhook'
autoload :StoryTransition, 'tracker_api/resources/story_transition'
autoload :FileAttachment, 'tracker_api/resources/file_attachment'
Expand Down
33 changes: 33 additions & 0 deletions lib/tracker_api/endpoints/blocker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module TrackerApi
module Endpoints
class Blocker
attr_accessor :client

def initialize(client)
@client = client
end

def create(project_id, story_id, params={})
data = client.post("/projects/#{project_id}/stories/#{story_id}/blockers", params: params).body
Resources::Blocker.new({ client: client, project_id: project_id }.merge(data))
end

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

path = "/projects/#{blocker.project_id}/stories/#{blocker.story_id}/blockers/#{blocker.id}"
data = client.put(path, params: params).body

blocker.attributes = data
blocker.clean!
blocker
end

def delete(blocker)
raise ArgumentError, 'Valid blocker required to update.' unless blocker.instance_of?(Resources::Blocker)

client.delete("/projects/#{blocker.project_id}/stories/#{blocker.story_id}/blockers/#{blocker.id}").body
end
end
end
end
22 changes: 22 additions & 0 deletions lib/tracker_api/endpoints/blockers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module TrackerApi
module Endpoints
class Blockers
attr_accessor :client

def initialize(client)
@client = client
end

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

data.map do |blocker|
Resources::Blocker.new({ client: client,
project_id: project_id,
story_id: story_id }.merge(blocker))
end
end
end
end
end
36 changes: 36 additions & 0 deletions lib/tracker_api/resources/blocker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module TrackerApi
module Resources
class Blocker
include Shared::Base

attribute :client

attribute :project_id, Integer
attribute :story_id, Integer
attribute :description, String
attribute :resolved, Boolean
attribute :created_at, DateTime
attribute :updated_at, DateTime
attribute :kind, String

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

property :id
property :description
end

def save
raise ArgumentError, 'Cannot update a blcoker with an unknown story_id.' if story_id.nil?

Endpoints::Blocker.new(client).update(self, UpdateRepresenter.new(Blocker.new(self.dirty_attributes)))
end

def delete
raise ArgumentError, 'Cannot delete a blcoker with an unknown story_id.' if story_id.nil?

Endpoints::Blocker.new(client).delete(self)
end
end
end
end
18 changes: 18 additions & 0 deletions lib/tracker_api/resources/story.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ def comments(reload: false)
end
end

# Provides a list of all the comments on the story.
#
# @param [Hash] params
# @return [Array[Comment]]
def blockers(reload: false)
if !reload && @blockers.present?
@blockers
else
@blockers = Endpoints::Blockers.new(client).get(project_id, id)
end
end

# Provides a list of all the tasks on the story.
#
# @param [Hash] params
Expand Down Expand Up @@ -180,6 +192,12 @@ def create_comment(params)
comment
end

# @param [Hash] params attributes to create the comment with
# @return [Comment] newly created Comment
def create_blocker(params)
Endpoints::Blocker.new(client).create(project_id, id, params)
end

# Save changes to an existing Story.
def save
raise ArgumentError, 'Can not update a story with an unknown project_id.' if project_id.nil?
Expand Down