Module: Unfuddle::HasTickets
Instance Method Summary collapse
- #construct_ticket_query(*conditions) ⇒ Object
- #create_condition_string(key, value) ⇒ Object
- #find_ticket_by_number(number) ⇒ Object
- #find_tickets!(*conditions) ⇒ Object
- #prepare_key_and_value_for_conditions_string(key, value) ⇒ Object
Instance Method Details
#construct_ticket_query(*conditions) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/unfuddle/has_tickets.rb', line 35 def construct_ticket_query(*conditions) conditions_string = [] conditions.each do |condition| case condition when Hash conditions_string.concat(condition.map { |key, value| Array.wrap(value).map { |value| create_condition_string(key, value) }.join("|") }) when Array key, value = condition conditions_string.push(Array.wrap(value).map { |value| create_condition_string(key, value) }.join("|")) else conditions_string.push(condition) end end conditions_string.join("%2C") end |
#create_condition_string(key, value) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/unfuddle/has_tickets.rb', line 51 def create_condition_string(key, value) comparison = "eq" comparison, value = "neq", value.value if value.is_a?(Neq) key, value = prepare_key_and_value_for_conditions_string(key, value) "#{key}-#{comparison}-#{value}" end |
#find_ticket_by_number(number) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/unfuddle/has_tickets.rb', line 7 def find_ticket_by_number(number) response = get("tickets/by_number/#{number}") return nil if response.status == 404 Unfuddle.assert_response!(200, response) response.json end |
#find_tickets!(*conditions) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/unfuddle/has_tickets.rb', line 16 def find_tickets!(*conditions) raise ArgumentError.new("No conditions supplied: that's probably not good") if conditions.none? path = "ticket_reports/dynamic.json" path << "?conditions_string=#{construct_ticket_query(*conditions)}" fields = %w{number summary description reporter_email resolution milestone_id created_at due_on severity_id component_id} fields << "associations" if Unfuddle.include_associations? fields << "closed_on" if Unfuddle.include_closed_on? path << "&fields_string=#{fields.join(",")}" if fields.any? response = get(path) Unfuddle.assert_response!(200, response) ticket_report = response.json group0 = ticket_report.fetch("groups", [])[0] || {} group0.fetch("tickets", []) end |
#prepare_key_and_value_for_conditions_string(key, value) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/unfuddle/has_tickets.rb', line 58 def prepare_key_and_value_for_conditions_string(key, value) # If the value is an id, convert it to a number value = value.to_i if value.is_a?(String) && value =~ /^\d+$/ [key, value] end |