Class: TeamboxAPI::Task

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inherited

Class Method Details

.collection_path(task_list_path, prefix_options = {}, query_options = nil) ⇒ Object



178
179
180
181
# File 'lib/teambox/teambox-api.rb', line 178

def self.collection_path(task_list_path, prefix_options = {}, query_options = nil)
  prefix_options, query_options = split_options(prefix_options) if query_options.nil?
  "#{prefix(prefix_options)}#{task_list_path}#{collection_name}.#{format.extension}#{query_string(query_options)}"
end

.find_every(options) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/teambox/teambox-api.rb', line 214

def self.find_every(options)
  #add :count => 0 in order to retrieve objects with no limits. Default is 20 objects per request.
  options[:params].merge!(:count => 0)
  begin
    case from = options[:from]
    when Symbol
      self.instantiate_collection(get(from, options[:params]))
    when String
      path = "#{from}#{query_string(options[:params])}"
      self.instantiate_collection(connection.get(path, headers) || [])
    else
      prefix_options, query_options = split_options(options[:params])
      path = self.collection_path(nil, prefix_options, query_options)
      self.instantiate_collection( (connection.get(path, headers) || []), prefix_options )
    end
  rescue ActiveResource::ResourceNotFound
    # Swallowing ResourceNotFound exceptions and return nil - as per
    # ActiveRecord.
    nil
  end
end

.instantiate_collection(collection, prefix_options = {}) ⇒ Object



188
189
190
191
# File 'lib/teambox/teambox-api.rb', line 188

def self.instantiate_collection(collection, prefix_options = {})
  objects = collection["objects"]
  objects.collect! { |record| instantiate_record(record, prefix_options) }
end

Instance Method Details

#collection_path(options = nil) ⇒ Object



183
184
185
186
# File 'lib/teambox/teambox-api.rb', line 183

def collection_path(options = nil)
  task_list_path = "task_lists/#{attributes[:task_list_id]}/"
  self.class.collection_path(task_list_path, options || prefix_options)
end

#createObject



207
208
209
210
211
212
# File 'lib/teambox/teambox-api.rb', line 207

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

#encode(options = {}) ⇒ Object



193
194
195
196
197
198
199
# File 'lib/teambox/teambox-api.rb', line 193

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

#updateObject



201
202
203
204
205
# File 'lib/teambox/teambox-api.rb', line 201

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