Class: CodasetAPI::Project

Inherits:
Base
  • Object
show all
Defined in:
lib/codaset/codaset-api.rb

Overview

Find projects

CodasetAPI::Project.find(:all) # find all projects for the current account.
CodasetAPI::Project.find('my-project')   # find individual project by slug

Creating a Project

project = CodasetAPI::Project.new(:name => 'Ninja Whammy Jammy')
project.save
# => true

Updating a Project

project = CodasetAPI::Project.find('my-project')
project.name = "Codaset Issues"
project.public = false
project.save

Finding tickets

project = CodasetAPI::Project.find('my-project')
project.tickets

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inherited

Class Method Details

.element_path(id, prefix_options = {}, query_options = nil) ⇒ Object

begin monkey patches



132
133
134
135
# File 'lib/codaset/codaset-api.rb', line 132

def self.element_path(id, prefix_options = {}, query_options = nil)
   prefix_options, query_options = split_options(prefix_options) if query_options.nil?
   "#{prefix(prefix_options)}#{URI.escape id.to_s}.#{format.extension}#{query_string(query_options)}"
end

Instance Method Details

#createObject



155
156
157
158
159
160
# File 'lib/codaset/codaset-api.rb', line 155

def create
  connection.post(collection_path + '?' + encode, nil, self.class.headers).tap do |response|
    self.id = id_from_response(response)
    load_attributes_from_response(response)
  end
end

#element_path(options = nil) ⇒ Object



137
138
139
# File 'lib/codaset/codaset-api.rb', line 137

def element_path(options = nil)
  self.class.element_path(self.slug, options)
end

#encode(options = {}) ⇒ Object



141
142
143
144
145
146
147
# File 'lib/codaset/codaset-api.rb', line 141

def encode(options={})
  val = []
  attributes.each_pair do |key, value|
    val << "values[#{URI.escape key}]=#{URI.escape value}" rescue nil
  end
  val.join('&')
end

#idObject



168
169
170
# File 'lib/codaset/codaset-api.rb', line 168

def id
  @attributes['slug']
end

#tickets(options = {}) ⇒ Object

end monkey patches



164
165
166
# File 'lib/codaset/codaset-api.rb', line 164

def tickets(options = {})
  Ticket.find(:all, :params => options.update(:slug => slug))
end

#updateObject



149
150
151
152
153
# File 'lib/codaset/codaset-api.rb', line 149

def update
    connection.put(element_path(prefix_options) + '?' + encode, nil, self.class.headers).tap do |response|
       load_attributes_from_response(response)
    end
end