lib/jiralicious/issue.rb in jiralicious-0.0.6 vs lib/jiralicious/issue.rb in jiralicious-0.1.0

- old
+ new

@@ -6,51 +6,43 @@ property :jira_key, :from => :key property :expand property :jira_self, :from => :self property :fields property :transitions + property :id def initialize(decoded_json, default = nil, &blk) super(decoded_json) parse!(decoded_json["fields"]) end def self.find(key, options = {}) - response = Jiralicious.session.perform_request do - Jiralicious::Session.get("#{Jiralicious.rest_path}/issue/#{key}") - end - - if response.code == 200 - response = JSON.parse(response.body) - else - raise Jiralicious::IssueNotFound - end - + response = Jiralicious.session.request(:get, "#{Jiralicious.rest_path}/issue/#{key}", :handler => handler) new(response) end def self.get_transitions(transitions_url) - response = Jiralicious.session.perform_request do - Jiralicious::Session.get(transitions_url) - end - JSON.parse(response.body) + Jiralicious.session.request(:get, transitions_url, :handler => handler) end def self.transition(transitions_url, data) - response = Jiralicious.session.perform_request do - Jiralicious::Session.post(transitions_url, :body => data.to_json) - end + Jiralicious.session.request(:post, transitions_url, + :handler => handler, + :body => data.to_json) + end - case response.code - when 204 - response.body - when 400 - error = JSON.parse(response.body) - raise Jiralicious::TransitionError.new(error['errorMessages'].join('\n')) - when 404 - error = JSON.parse(response.body) - raise Jiralicious::IssueNotFound.new(error['errorMessages'].join('\n')) + def self.handler + Proc.new do |response| + case response.code + when 200..204 + response + when 400 + raise Jiralicious::TransitionError.new(response['errorMessages'].join('\n')) + when 404 + raise Jiralicious::IssueNotFound.new(response['errorMessages'].join('\n')) + else + raise Jiralicious::JiraError.new(response['errorMessages'].join('\n')) + end end end - end end