Class: AcunoteSprint
- Inherits:
-
Object
- Object
- AcunoteSprint
- Defined in:
- lib/acunote_sprint.rb
Overview
API for accessing Acunote sprints.
Class Method Summary collapse
- .acu_conn ⇒ Object
- .create(proj_id, name, opts = {}) ⇒ Object
- .export_csv(proj_id, sprint_id) ⇒ Object
-
.find_by_name(proj_id, name) ⇒ Object
NAME can be a literal string or a regex.
-
.find_id_by_name(proj_id, name) ⇒ Object
NAME can be a literal string or a regex.
-
.find_task_id_by_name(proj_id, sprint_id, task_name) ⇒ Object
Note: This is extremely brittle to the structure of the acunote sprint page, but I couldn’t find any other way to do it.
- .upload_csv(proj_id, sprint_id, raw_data) ⇒ Object
- .url(proj_id, sprint_id) ⇒ Object
Class Method Details
.acu_conn ⇒ Object
5 6 7 |
# File 'lib/acunote_sprint.rb', line 5 def self.acu_conn AcunoteConnection.instance end |
.create(proj_id, name, opts = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/acunote_sprint.rb', line 13 def self.create(proj_id, name, opts = {}) opts[:type] ||= 'Backlog' opts[:start_date] ||= Date.today opts[:end_date] ||= opts[:start_date] + 365 unless acu_conn.logged_in STDERR.puts "Must login before creating a sprint." if DEBUG return false end sprint_page = acu_conn.get_page(url(proj_id, 'new')) # Check that the project could be found. unless sprint_page STDERR.puts "Spcified project could not be found." if DEBUG return false end sprint_form = sprint_page.forms_with({:name => 'sprint_new_dialog'}).first if opts[:type] == 'Backlog' (sprint_form.(:value => /Backlog/).first && sprint_form.(:value => /Backlog/).first.check) else sprint_form.(:value => /Iteration/).first.check sprint_form.fields_with(:id => 'sprint_start_date').first.value = opts[:start_date].to_s end sprint_form.fields_with(:id => 'sprint_name').first.value = name sprint_form.fields_with(:id => 'sprint_end_date').first.value = opts[:end_date].to_s sprint_form.submit end |
.export_csv(proj_id, sprint_id) ⇒ Object
95 96 97 |
# File 'lib/acunote_sprint.rb', line 95 def self.export_csv(proj_id, sprint_id) acu_conn.get_page(url(proj_id,sprint_id) + '/export').body end |
.find_by_name(proj_id, name) ⇒ Object
NAME can be a literal string or a regex.
54 55 56 57 |
# File 'lib/acunote_sprint.rb', line 54 def self.find_by_name(proj_id, name) sprints = acu_conn.get_page(url(proj_id, '')) sprints.links_with(:text => name).first if sprints end |
.find_id_by_name(proj_id, name) ⇒ Object
NAME can be a literal string or a regex.
46 47 48 49 50 51 |
# File 'lib/acunote_sprint.rb', line 46 def self.find_id_by_name(proj_id, name) link = find_by_name(proj_id, name) if(link && link.uri.to_s =~ /\/sprints\/([0-9]*)/) $1 end end |
.find_task_id_by_name(proj_id, sprint_id, task_name) ⇒ Object
Note: This is extremely brittle to the structure of the acunote sprint page, but I couldn’t find any other way to do it.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/acunote_sprint.rb', line 61 def self.find_task_id_by_name(proj_id, sprint_id, task_name) sprint_page = acu_conn.get_page(url(proj_id,sprint_id)+'/show') all_tasks = sprint_page.parser.search('span.descr_edit') matches = all_tasks.select { |task_node| task_node.text.match(task_name) } STDOUT.puts("Found #{all_tasks.size} tasks in this sprint. Out of those #{matches.size} matched the task name provided.") if DEBUG if matches.size == 1 STDOUT.puts("Found match: #{matches[0]}") if DEBUG prop = matches[0].search('span.task_properties')[0] prop_id_str = prop.attribute('id').text STDOUT.puts("Found a properties span with: #{prop_id_str}") if DEBUG if prop_id_str =~ /^task_propertires_([0-9]*)$/ task_prop = $1 links = sprint_page.links_with(:id => "issue_number_for_#{task_prop}") STDOUT.puts "Found the following links matching the property for this task: #{links.inspect}" if DEBUG if links.size == 1 links[0].text else nil end else nil end else nil end end |
.upload_csv(proj_id, sprint_id, raw_data) ⇒ Object
88 89 90 91 92 93 |
# File 'lib/acunote_sprint.rb', line 88 def self.upload_csv(proj_id, sprint_id, raw_data) import_page = acu_conn.get_page(url(proj_id,sprint_id)+"/import") import_form = import_page.form_with({:name => 'import_form'}) import_form.field_with(:id => 'data_to_import').value = raw_data.to_s import_form.submit end |
.url(proj_id, sprint_id) ⇒ Object
9 10 11 |
# File 'lib/acunote_sprint.rb', line 9 def self.url(proj_id, sprint_id) "#{acu_conn.home_url}/projects/#{proj_id}/sprints/#{sprint_id}" end |