Class: MingleAPI
- Inherits:
-
Object
- Object
- MingleAPI
- Defined in:
- lib/mingle-api.rb,
lib/mingle-api/http.rb,
lib/mingle-api/macro.rb,
lib/mingle-api/version.rb
Defined Under Namespace
Constant Summary collapse
- PROJECT =
[:name, :identifier, :description]
- CARD =
[:name, :description, { "card_type name" => :type, 'properties property' => lambda do |node| name = text(node, 'name') value = case node[:type_description] when /team list/ text(node, 'value login') else text(node, 'value') end [name.downcase, value] end } ]
- VERSION =
"0.0.3"
Instance Attribute Summary collapse
-
#site ⇒ Object
readonly
Returns the value of attribute site.
Instance Method Summary collapse
- #card(project, number) ⇒ Object
- #cards(project) ⇒ Object
- #create_card(project, attrs) ⇒ Object
- #create_project(name, options = {}) ⇒ Object
-
#initialize(site, credentials) ⇒ MingleAPI
constructor
A new instance of MingleAPI.
- #project(identifier) ⇒ Object
- #projects ⇒ Object
- #site_api_url ⇒ Object
- #site_url ⇒ Object
Constructor Details
Instance Attribute Details
#site ⇒ Object (readonly)
Returns the value of attribute site.
10 11 12 |
# File 'lib/mingle-api.rb', line 10 def site @site end |
Instance Method Details
#card(project, number) ⇒ Object
57 58 59 |
# File 'lib/mingle-api.rb', line 57 def card(project, number) ostruct(fetch(:projects, project_identifier(project), :cards, number), CARD) end |
#cards(project) ⇒ Object
53 54 55 |
# File 'lib/mingle-api.rb', line 53 def cards(project) list(fetch(:projects, project_identifier(project), :cards), CARD) end |
#create_card(project, attrs) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/mingle-api.rb', line 61 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 |, i| path, content_type = 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 = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mingle-api.rb', line 41 def create_project(name, ={}) identifier = name.downcase.gsub(/[^a-z0-9_]/, '_') @http.post(v2(:projects), { "project[name]" => name, "project[identifier]" => identifier, "project[description]" => [:description], "project[template]" => false, "template_name" => [:template] ? "yml_#{[:template]}_template" : nil }) OpenStruct.new(:identifier => identifier, :name => name, :url => url('projects', identifier)) end |
#project(identifier) ⇒ Object
37 38 39 |
# File 'lib/mingle-api.rb', line 37 def project(identifier) ostruct(fetch(:projects, identifier), PROJECT) end |
#projects ⇒ Object
33 34 35 |
# File 'lib/mingle-api.rb', line 33 def projects list(fetch(:projects), PROJECT) end |
#site_api_url ⇒ Object
81 82 83 |
# File 'lib/mingle-api.rb', line 81 def site_api_url gen_site_url(api_host) end |
#site_url ⇒ Object
85 86 87 |
# File 'lib/mingle-api.rb', line 85 def site_url gen_site_url(host) end |