module Helpers class Base require 'logging' def initialize @logger = Logging.logger[self] @logger.add_appenders \ 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 attr_accessor :description attr_accessor :source attr_accessor :type attr_accessor :author attr_accessor :id attr_accessor :specs attr_accessor :url attr_accessor :parent attr_accessor :specs def initialize(json) @specurls = %w(hackpad.com notes.dropbox.com) type ||="NA" status ||="UNKNOWN" author ||="UNKNOWN" environments ||= [] @title = json["title"] @id = json["number"] @description = json["description"] @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) @specs = urls.select { |u| @specurls.any? {|specurl| u.include?(specurl)}}.collect {|u| SprintlyEmbeddedURL.new(u)} end def to_s inspect end def inspect return "<#{url}|##{@id} - #{@title}>" end def environments return @environments.any? ? @environments : nil end def sha return @sha end def id return @id end def status return @status.nil? ? "NA" : @status.upcase end def complete? return %w(COMPLETED ACCEPTED).include?(self.status) end def built? return self.environments.join.scan(/#(\d+)/).any? unless self.environments.nil? end def released? return self.environments.join.scan(/v(\d+)/).any? unless self.environments.nil? end def is_defect? return @type.upcase == "DEFECT" end def is_story? return @type.upcase == "STORY" end def all_specs hackpads = Array.new hackpads.push(self.specs) hackpads.push(self.parent.all_specs) 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' def initialize(product_id, sprintlyUser = ENV['SPRINTLY_USER'], sprintlyAPIKey = ENV['SPRINTLY_API_KEY'], cache=nil) super() Typhoeus::Config.cache = cache @auth = "#{sprintlyUser}:#{sprintlyAPIKey}" @product_id = product_id @end_point = "https://sprint.ly/api/products/" end 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 end end end