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



190
191
192
193
# File 'lib/teambox/teambox-api.rb', line 190

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



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/teambox/teambox-api.rb', line 226

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



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

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



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

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



219
220
221
222
223
224
# File 'lib/teambox/teambox-api.rb', line 219

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



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

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

#updateObject



213
214
215
216
217
# File 'lib/teambox/teambox-api.rb', line 213

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