Sha256: 483b1dedda119c64fbcb163f690eeb355d66831469b18a2e3b26b8e4639a8f7b

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

# encoding: utf-8
module Jiralicious
  class Issue < Hashie::Trash
    include Jiralicious::Parsers::FieldParser

    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.request(:get, "#{Jiralicious.rest_path}/issue/#{key}", :handler => handler)
      new(response)
    end

    def self.get_transitions(transitions_url)
      Jiralicious.session.request(:get, transitions_url, :handler => handler)
    end

    def self.transition(transitions_url, data)
      Jiralicious.session.request(:post, transitions_url,
                                  :handler => handler,
                                  :body => data.to_json)
    end

    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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jiralicious-0.1.0 lib/jiralicious/issue.rb