Permalink
Browse files

added rest for exception analyzer

  • Loading branch information...
1 parent a57a982 commit b06c98dae22606afa4e1e1e89a5f74ddd001223d anna.zhdan committed Dec 15, 2011
@@ -2,7 +2,7 @@
require "net/http"
require "cgi"
-class YouTrackConnection
+class Connection
attr_reader :rest_path
@@ -22,7 +22,7 @@ def login(login, password)
def request(method_name, url, params = {}, body = nil)
path = url
- if !params.empty?
+ unless params.empty?
path = "#{url}?#{url_encode(params)}"
end
req = nil
@@ -31,6 +31,8 @@ def request(method_name, url, params = {}, body = nil)
req = Net::HTTP::Get.new(path, @headers)
when :post
req = Net::HTTP::Post.new(path, @headers)
+ else
+ #TODO handle this
end
@connection.start do |http|
resp = http.request(req)
View
@@ -0,0 +1,48 @@
+require "rexml/xpath"
+require "rexml/document"
+
+module Entities
+
+ class User
+
+ attr_reader :login, :password
+ attr_accessor :fullName, :email, :jabber
+
+ def initialize(connection, login)
+ @login = login
+ @conn = connection
+ end
+
+ def put
+ [self.email, self.fullName].each{|var| raise ArgumentError if var.to_s.empty?}
+ @conn.request(:put, self.path, self.user_properties).value
+ end
+
+ def post
+ @conn.request(:post, self.path, self.user_properties).value
+ end
+
+ def get
+ user_element = REXML::XPath.first(REXML::Document.new(@conn.request(:get, path).body), "//user")
+ [:email, :fullName, :jabber].each{|elem| self.instance_variable_set("@#{elem}", user_element.attributes[elem.to_s])}
+ self
+ end
+
+ private
+
+ def path
+ "#{@conn.rest_path}/admin/user/#{self.login}"
+ end
+
+ def user_properties
+ props = {}
+ [:fullName, :email, :jabber].each{|var|
+ value = self.instance_variable_get("@#{var}")
+ props[var] = value if !value.nil?
+ }
+ end
+
+ end
+
+
+end
File renamed without changes.
@@ -0,0 +1,44 @@
+require "rexml/xpath"
+require "rexml/document"
+
+module EAEntities
+
+ class Exception
+ attr_reader :project, :id, :params
+ attr_accessor :trace
+
+ def initialize(conn, exception_id, lang, project_id = nil, trace = "", additional_params = {})
+ @conn = conn
+ if project_id.nil?
+ @id = issue_id[/(\w+)-(\d+)/, 2]
+ @project = issue_id[/(\w+)-(\d+)/, 1]
+ else
+ @project = project_id
+ @id = exception_id
+ end
+ @trace = trace
+ @params = additional_params
+ end
+
+ def get
+ exception = REXML::XPath.first(REXML::Document.new(@conn.request(:get, self.path).body), "//exception")
+ exception.attributes.each { |name, value| self.instance_variable_set(name, value) }
+ end
+
+ def put
+
+ end
+
+ private
+
+ def path
+ "#{@conn.rest_path}/exception/#{self.project}-#{self.id}"
+ end
+
+ end
+
+ class ExceptionProject
+
+ end
+
+end
@@ -3,47 +3,6 @@
module YouTrackEntities
- class User
-
- attr_reader :login, :password
- attr_accessor :fullName, :email, :jabber
-
- def initialize(connection, login)
- @login = login
- @conn = connection
- end
-
- def put
- [self.email, self.fullName].each{|var| raise ArgumentError if var.to_s.empty?}
- @conn.request(:put, self.path, self.user_properties).value
- end
-
- def post
- @conn.request(:post, self.path, self.user_properties).value
- end
-
- def get
- user_element = REXML::XPath.first(REXML::Document.new(@conn.request(:get, path).body), "//user")
- [:email, :fullName, :jabber].each{|elem| self.instance_variable_set("@#{elem}", user_element.attributes[elem.to_s])}
- self
- end
-
- private
-
- def path
- "#{@conn.rest_path}/admin/user/#{self.login}"
- end
-
- def user_properties
- props = {}
- [:fullName, :email, :jabber].each{|var|
- value = self.instance_variable_get("@#{var}")
- props[var] = value if !value.nil?
- }
- end
-
- end
-
class Issue
attr_reader :project_id, :issue_id

0 comments on commit b06c98d

Please sign in to comment.