class Mingle
Constants
- CARD
- PROJECT
Attributes
site[R]
Public Class Methods
new(site, credentials)
click to toggle source
# File lib/mingle.rb, line 28 def initialize(site, credentials) @site, @http = site, Http.new(credentials) end
Public Instance Methods
card(project, number)
click to toggle source
# File lib/mingle.rb, line 56 def card(project, number) ostruct(fetch(:projects, project_identifier(project), :cards, number), CARD) end
cards(project)
click to toggle source
# File lib/mingle.rb, line 52 def cards(project) list(fetch(:projects, project_identifier(project), :cards), CARD) end
create_card(project, attrs)
click to toggle source
# File lib/mingle.rb, line 60 def create_card(project, attrs) params = [ ["card[name]", attrs[:name]], ["card[card_type_name]", attrs[:type]], ["card[description]", attrs[:description]] ] Array(attrs[:attachments]).each_with_index do |attachment, i| path, content_type = attachment params << ["attachments[#{i}]", UploadIO.new(File.new(path), content_type, File.basename(path))] end Array(attrs[:properties]).each_with_index do |prop, i| name, value = prop params << ["card[properties][][name]", name] params << ["card[properties][][value]", value] end resp = @http.post(v2(:projects, project_identifier(project), :cards), params) number = resp[2]["location"].split("/").last.split('.').first OpenStruct.new(:number => number, :url => url('projects', project_identifier(project), 'cards', number)) end
create_project(name, options={})
click to toggle source
# File lib/mingle.rb, line 40 def create_project(name, options={}) identifier = name.downcase.gsub(/[^a-z0-9_]/, '_') @http.post(v2(:projects), { "project[name]" => name, "project[identifier]" => identifier, "project[description]" => options[:description], "project[template]" => false, "template_name" => options[:template] ? "yml_#{options[:template]}_template" : nil }) OpenStruct.new(:identifier => identifier, :name => name, :url => url('projects', identifier)) end
project(identifier)
click to toggle source
# File lib/mingle.rb, line 36 def project(identifier) ostruct(fetch(:projects, identifier), PROJECT) end
projects()
click to toggle source
# File lib/mingle.rb, line 32 def projects list(fetch(:projects), PROJECT) end
site_api_url()
click to toggle source
# File lib/mingle.rb, line 80 def site_api_url gen_site_url(api_host) end
site_url()
click to toggle source
# File lib/mingle.rb, line 84 def site_url gen_site_url(host) end
Private Instance Methods
api_host()
click to toggle source
# File lib/mingle.rb, line 97 def api_host 'mingle-api.thoughtworks.com' || ENV['MINGLE_API_HOST'] end
dom(xml)
click to toggle source
# File lib/mingle.rb, line 120 def dom(xml) Nokogiri::XML(xml) do |config| config.options = Nokogiri::XML::ParseOptions::NOBLANKS | Nokogiri::XML::ParseOptions::STRICT | Nokogiri::XML::ParseOptions::NONET end end
fetch(*resources)
click to toggle source
# File lib/mingle.rb, line 105 def fetch(*resources) dom(@http.get(v2(*resources))[1]).root end
gen_site_url(h)
click to toggle source
# File lib/mingle.rb, line 130 def gen_site_url(h) site =~ /^http/i ? site : "https://#{site}.#{h}" end
host()
click to toggle source
# File lib/mingle.rb, line 101 def host 'mingle.thoughtworks.com' || ENV['MINGLE_HOST'] end
list(dom, attrs)
click to toggle source
# File lib/mingle.rb, line 109 def list(dom, attrs) dom.children.map do |child| ostruct(child, attrs) end end
ostruct(node, attrs)
click to toggle source
# File lib/mingle.rb, line 115 def ostruct(node, attrs) macro = Macro.new OpenStruct.new(Hash[*macro.apply(node, attrs)]) end
project_identifier(proj)
click to toggle source
# File lib/mingle.rb, line 89 def project_identifier(proj) proj.respond_to?(:identifier) ? proj.identifier : proj.to_s end
url(*parts)
click to toggle source
# File lib/mingle.rb, line 93 def url(*parts) File.join(site_url, *parts) end
v2(*parts)
click to toggle source
# File lib/mingle.rb, line 126 def v2(*parts) [File.join(site_api_url, 'api/v2', *parts.map(&:to_s)), 'xml'].join('.') end