Class: TeamboxAPI::Task
- Defined in:
- lib/teambox/teambox-api.rb
Class Method Summary collapse
- .collection_path(task_list_path, prefix_options = {}, query_options = nil) ⇒ Object
- .find_every(options) ⇒ Object
- .instantiate_collection(collection, prefix_options = {}) ⇒ Object
Instance Method Summary collapse
- #collection_path(options = nil) ⇒ Object
- #create ⇒ Object
- #encode(options = {}) ⇒ Object
- #update ⇒ Object
Methods inherited from Base
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, = {}, = nil) , = () if .nil? "#{prefix()}#{task_list_path}#{collection_name}.#{format.extension}#{query_string()}" 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() #add :count => 0 in order to retrieve objects with no limits. Default is 20 objects per request. [:params].merge!(:count => 0) begin case from = [:from] when Symbol self.instantiate_collection(get(from, [:params])) when String path = "#{from}#{query_string([:params])}" self.instantiate_collection(connection.get(path, headers) || []) else , = ([:params]) path = self.collection_path(nil, , ) self.instantiate_collection( (connection.get(path, headers) || []), ) 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, = {}) objects = collection["objects"] objects.collect! { |record| instantiate_record(record, ) } end |
Instance Method Details
#collection_path(options = nil) ⇒ Object
195 196 197 198 |
# File 'lib/teambox/teambox-api.rb', line 195 def collection_path( = nil) task_list_path = "task_lists/#{attributes[:task_list_id]}/" self.class.collection_path(task_list_path, || ) end |
#create ⇒ Object
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(={}) val = [] attributes.each_pair do |key, value| val << "#{URI.escape key}=#{URI.escape value}" rescue nil end val.join('&') end |
#update ⇒ Object
213 214 215 216 217 |
# File 'lib/teambox/teambox-api.rb', line 213 def update connection.put(element_path() + '?' + encode, nil, self.class.headers).tap do |response| load_attributes_from_response(response) end end |