| Class | JIRA::Base |
| In: |
lib/jira/base.rb
|
| Parent: | Object |
This class provides the basic object <-> REST mapping for all JIRA::Resource subclasses, i.e. the Create, Retrieve, Update, Delete lifecycle methods.
Note that not all lifecycle methods are available for all resources, for example some resources cannot be updated or deleted.
client.Resource.all
client.Resource.find(id)
resource = client.Resource.build({'name' => '')
resource.save
resource = client.Resource.find(id)
resource.save('updated_attribute' => 'new value')
resource = client.Resource.find(id) resource.delete
Some resources are not defined in the top level of the URL namespace within the JIRA API, but are always nested under the context of another resource. For example, a JIRA::Resource::Comment always belongs to a JIRA::Resource::Issue.
These resources must be indexed and built from an instance of the class they are nested under:
issue = client.Issue.find(id) comments = issue.comments new_comment = issue.comments.build
| QUERY_PARAMS_FOR_SINGLE_FETCH | = | Set.new [:expand, :fields] |
| QUERY_PARAMS_FOR_SEARCH | = | Set.new [:expand, :fields, :startAt, :maxResults] |
| expanded | -> | expanded? |
| deleted | -> | deleted? |
| attrs | [RW] | The hash of attributes belonging to this instance. An exact representation of the JSON returned from the JIRA API |
| client | [R] | A reference to the JIRA::Client used to initialize this resource. |
| deleted | [RW] | Returns true if this instance has been deleted from the server |
| expanded | [RW] | Returns true if this instance has been fetched from the server |
The class methods are never called directly, they are always invoked from a BaseFactory subclass instance.
Returns the full path for a collection of this resource. E.g.
JIRA::Resource::Issue.collection_path
# => /jira/rest/api/2/issue
Returns the name of this resource for use in URL components. E.g.
JIRA::Resource::Issue.endpoint_name
# => issue
Declares that this class contains a collection of another resource within the JSON returned from the JIRA API.
class Example < JIRA::Base
has_many :children
end
example = client.Example.find(1)
example.children # Returns an instance of Jira::Resource::HasManyProxy,
# which behaves exactly like an array of
# Jira::Resource::Child
The following options can be used to override the default behaviour of the relationship:
has_many :children # => {"id":"123",{"children":[{"id":"456"},{"id":"789"}]}}
Use this option if the key in the JSON is named differently.
# Respond to resource.children, but return the value of resource.attrs['kids']
has_many :children, :attribute_key => 'kids' # => {"id":"123",{"kids":[{"id":"456"},{"id":"789"}]}}
has_many :children, :class => JIRA::Resource::Kid
# Specify a single depth of nesting.
has_many :children, :nested_under => 'foo'
# => Looks for {"foo":{"children":{}}}
# Specify deeply nested JSON
has_many :children, :nested_under => ['foo', 'bar', 'baz']
# => Looks for {"foo":{"bar":{"baz":{"children":{}}}}}
Declares that this class contains a singular instance of another resource within the JSON returned from the JIRA API.
class Example < JIRA::Base
has_one :child
end
example = client.Example.find(1)
example.child # Returns a JIRA::Resource::Child
The following options can be used to override the default behaviour of the relationship:
has_one :child # => {"id":"123",{"child":{"id":"456"}}}
Use this option if the key in the JSON is named differently.
# Respond to resource.child, but return the value of resource.attrs['kid']
has_one :child, :attribute_key => 'kid' # => {"id":"123",{"kid":{"id":"456"}}}
has_one :child, :class => JIRA::Resource::Kid
# Specify a single depth of nesting.
has_one :child, :nested_under => 'foo'
# => Looks for {"foo":{"child":{}}}
# Specify deeply nested JSON
has_one :child, :nested_under => ['foo', 'bar', 'baz']
# => Looks for {"foo":{"bar":{"baz":{"child":{}}}}}
Returns the singular path for the resource with the given key. E.g.
JIRA::Resource::Issue.singular_path('123')
# => /jira/rest/api/2/issue/123
If a prefix parameter is provided it will be injected between the base path and the endpoint. E.g.
JIRA::Resource::Comment.singular_path('456','/issue/123/')
# => /jira/rest/api/2/issue/123/comment/456
Fetches the attributes for the specified resource from JIRA unless the resource is already expanded and the optional force reload flag is not set
Each resource has a unique key attribute, this method returns the value of that key for this instance.
Overrides method_missing to check the attribute hash for resources matching method_name and proxies the call to the superclass if no match is found.
This method fixes issue that there is no / prefix in url. It is happened when we call for instance Looks like this issue is actual only in case if you use atlassian sdk your app path is not root (like /jira in example below) issue.save() for existing resource. As a result we got error 400 from JIRA API:
After applying this fix we have normal response:
This returns the URL path component that is specific to this instance, for example for Issue id 123 it returns ’/issue/123’. For an unsaved issue it returns ’/issue‘
Checks if method_name is set in the attributes hash and returns true when found, otherwise proxies the call to the superclass.
Saves the specified resource attributes by sending either a POST or PUT request to JIRA, depending on resource.new_record?
Accepts an attributes hash of the values to be saved. Will return false if the request fails.
Saves the specified resource attributes by sending either a POST or PUT request to JIRA, depending on resource.new_record?
Accepts an attributes hash of the values to be saved. Will throw a JIRA::HTTPError if the request fails (response is not HTTP 2xx).
Set the current attributes from a hash. If clobber is true, any existing hash values will be clobbered by the new hash, otherwise the hash will be deeply merged into attrs. The target paramater is for internal use only and should not be used.
Sets the attributes hash from a HTTPResponse object from JIRA if it is not nil or is not a json response.