lib/helpers/sprintly.rb in overview-0.0.6.pre.24 vs lib/helpers/sprintly.rb in overview-0.0.7.pre.26

- old
+ new

@@ -8,10 +8,25 @@ Logging.appenders.stdout, Logging.appenders.file("#{self.class.name}.log") end end + class SprintlyEmbeddedURL < String + def initialize(s) + super s + end + + def to_s + inspect + end + + def inspect + return "<#{self}|#{self}>" + end + end + + class SprintlyItem require 'uri' attr_accessor :title attr_accessor :date @@ -19,10 +34,11 @@ attr_accessor :source attr_accessor :author attr_accessor :id attr_accessor :hackpads attr_accessor :url + attr_accessor :parent HACKPADURL = "hackpad.com" def initialize(json) @@ -38,31 +54,23 @@ @source = "Sprint.ly" @type = json["type"] @status = json["status"] @author = author @url = json["short_url"] + @parent = SprintlyItem.new(json["parent"]) if json["parent"] urls = URI.extract(@description) - urls.select! { |u| u.include?(HACKPADURL)} + @hackpads = urls.select { |u| u.include?(HACKPADURL)}.collect {|u| SprintlyEmbeddedURL.new(u)} - @hackpads = urls - # json["deployed_to"]) + end - # @title = title.delete("\n") - # @description = description - # @sha = sha - # @date = date - # @id = id - # @source = source - # @type = type - # @status = status - # @author = author - # @environments = environments + def to_s + inspect end def inspect - "<#{@source} #{@type.upcase} ##{@id} : #{self.status} : #{@title}>" + return "<#{url}|##{@id} - #{@title}>" end def environments return @environments.any? ? @environments : nil end @@ -88,10 +96,28 @@ end def released? return self.environments.join.scan(/v(\d+)/).any? unless self.environments.nil? end + + def is_story? + return @type.upcase == "STORY" + end + + def all_hackpads + hackpads = Array.new + hackpads.push(self.hackpads) + hackpads.push(self.parent.all_hackpads) if self.parent + return hackpads.flatten.uniq + end + + def all_items + items = Array.new + items.push(self) + items.push(self.parent) if self.parent + return items.flatten.uniq + end end class Sprintly < Base require 'typhoeus' @@ -103,10 +129,10 @@ @product_id = product_id @end_point = "https://sprint.ly/api/products/" end - def sprintlyItem(id) + def sprintly_item(id) url = @end_point + @product_id.to_s + "/items/" + id.to_s + ".json" response = Typhoeus::Request.get(url, userpwd: @auth) item = SprintlyItem.new(JSON.parse(response.body)) return item