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 SprintlyItem require 'uri' attr_accessor :title attr_accessor :date attr_accessor :description attr_accessor :source attr_accessor :author attr_accessor :id attr_accessor :hackpads attr_accessor :url HACKPADURL = "hackpad.com" def initialize(json) 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"] urls = URI.extract(@description) urls.select! { |u| u.include?(HACKPADURL)} @hackpads = urls # json["deployed_to"]) # @title = title.delete("\n") # @description = description # @sha = sha # @date = date # @id = id # @source = source # @type = type # @status = status # @author = author # @environments = environments end def inspect "<#{@source} #{@type.upcase} ##{@id} : #{self.status} : #{@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 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 sprintlyItem(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