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



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

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:



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

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

#find_my_active_ticketsObject

:nodoc:



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

def find_my_active_tickets #:nodoc:
  ass = self.find({ :assigned_to => @me, :status => "New"})
  test = self.find({ :assigned_to => @me, :status => "Test"})
  accepted = self.find({ :assigned_to => @me, :status => "Accepted"})
  ((accepted + ass) - test)
end

#find_with_status(status = "New") ⇒ Object

:nodoc:



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

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

#find_with_summary(text) ⇒ Object

:nodoc:



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

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

Prints the tickets to STDOUT



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

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_description(id, description) ⇒ Object



121
122
123
124
125
# File 'lib/assembla.rb', line 121

def update_tickets_description(id, description)
  request = prepare_request(id)
  request.body = "<ticket><description>#{description}</description></ticket>"
  send_request(request)
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.



114
115
116
117
118
# File 'lib/assembla.rb', line 114

def update_tickets_status(id, status)
  request = prepare_request(id)
  request.body = "<ticket><status type='integer'>#{get_id_from_status(status)}</status></ticket>"
  send_request(request)
end