Class: AssEmBlr

Inherits:
Object show all
Defined in:
lib/assembla.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file = "~/.assembla") ⇒ AssEmBlr

Returns a new instance of AssEmBlr.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/assembla.rb', line 22

def initialize(config_file = "~/.assembla")
  config = YAML::parse( File.open(File.expand_path(config_file)))
  @url      = config["url"].value
  @user     = config["user"].value
  @password = config["password"].value
  @me       = config["me"].value

  # For testing purposes if the url has no HTTP in it we assume
  # that assembla space is saved to a local file
  (@url =~ /http/) ? \
  self.page = Hpricot(open(@url, :http_basic_authentication=>[@user, @password])) \
  : self.page = Hpricot(open(@url))

  tickets
end

Instance Attribute Details

#pageObject

Returns the value of attribute page.



20
21
22
# File 'lib/assembla.rb', line 20

def page
  @page
end

#parsedObject

Returns the value of attribute parsed.



20
21
22
# File 'lib/assembla.rb', line 20

def parsed
  @parsed
end

#passwordObject

Returns the value of attribute password.



20
21
22
# File 'lib/assembla.rb', line 20

def password
  @password
end

#urlObject

Returns the value of attribute url.



20
21
22
# File 'lib/assembla.rb', line 20

def url
  @url
end

#userObject

Returns the value of attribute user.



20
21
22
# File 'lib/assembla.rb', line 20

def user
  @user
end

Instance Method Details

#find(args) ⇒ Object

Find operates with different arguments:

  • :id - ticket’s id number

  • :status - The same as Assembla ticket status [“New”, “Accepted”, “Test”, “Fixed”, “Invalid”]

  • :summary - ticket description

  • :assigned_to - the person to whom the ticket is assigned to

Also you can use params in pairs, like this:

  • :assigned_to and :status



51
52
53
54
55
56
57
58
59
60
# File 'lib/assembla.rb', line 51

def find(args)
  if args.length == 1
    return find_id(args[:id]) if (args[:id])
    return find_with_status(args[:status]) if (args[:status])
    return find_with_summary(args[:summary]) if (args[:summary])
    return find_assigned_to(args[:assigned_to]) if (args[:assigned_to])
  elsif args.length == 2
    return find_assigned_and_with_status(args[:assigned_to], args[:status]) if (args[:status] && args[:assigned_to])
  end
end

#find_assigned_and_with_status(to, status) ⇒ Object

This function uses OR condition for search I commented it out for now - because I can see no use for it. def find_assigned_or_with_status(to, status)

st = Status.new
as = AssignedTo.new
st.evaluate(self.parsed, status) | as.evaluate(self.parsed, to)

end



105
106
107
108
109
# File 'lib/assembla.rb', line 105

def find_assigned_and_with_status(to, status) #:nodoc:
  st = Status.new
  as = AssignedTo.new
  st.evaluate(self.parsed, status) & as.evaluate(self.parsed, to)
end

#find_assigned_to(to = @me) ⇒ Object

:nodoc:



62
63
64
65
# File 'lib/assembla.rb', line 62

def find_assigned_to(to = @me) #:nodoc:
  ass = AssignedTo.new
  assigned_to = ass.evaluate(self.parsed, to)
end

#find_id(id) ⇒ Object

:nodoc:



91
92
93
94
# File 'lib/assembla.rb', line 91

def find_id(id) #:nodoc:
  result = Id.new
  result.evaluate(self.parsed, id).first
end

#find_my_active_ticketsObject

:nodoc:



67
68
69
70
71
72
73
# File 'lib/assembla.rb', line 67

def find_my_active_tickets #:nodoc:
  ass = find_assigned_to(@me)
  new = find_with_status("New")
  test = find_with_status("Test")
  accepted = find_with_status("Accepted")
  ((accepted + new + ass) - test).uniq
end

#find_with_status(status = "New") ⇒ Object

:nodoc:



75
76
77
78
# File 'lib/assembla.rb', line 75

def find_with_status(status = "New") #:nodoc:
  st = Status.new
  active = st.evaluate(self.parsed, status)
end

#find_with_summary(text) ⇒ Object

:nodoc:



80
81
82
83
# File 'lib/assembla.rb', line 80

def find_with_summary(text) #:nodoc:
  sum = Summary.new
  summary = sum.evaluate(self.parsed, text)
end

Prints the tickets to STDOUT



86
87
88
89
# File 'lib/assembla.rb', line 86

def print(tickets)
  puts_title_line
  tickets.each { |t| puts t.to_s }
end

#ticketsObject

This method parsess all active tickets in your Assembla space



39
40
41
42
# File 'lib/assembla.rb', line 39

def tickets
  all = All.new
  self.parsed = all.evaluate(self.page) 
end

#update_tickets_status(id, status) ⇒ Object

This method uses Assembla’s Ticket REST API www.assembla.com/wiki/show/breakoutdocs/Ticket_REST_API to change tickets status. It returns text of http response from Aseembla server.



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/assembla.rb', line 115

def update_tickets_status(id, status)
  status_number = get_id_from_status(status)
  space = @url.gsub(/https:\/\/www\.assembla.com(.+)/, '\1')
  url = space + '/' + id.to_s
  request = Net::HTTP::Put.new(url, initheader = {'Content-Type' => 'application/xml', 'Accept' => 'application/xml'})
  request.body = "<ticket><status type='integer'>#{status_number}</status></ticket>"
  request.basic_auth @user, @password
  Net::HTTP.start("www.assembla.com", 80 ) do |http|
    response = http.request(request)
    puts response      
  end
end