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
178 179 180 181 |
# File 'lib/teambox/teambox-api.rb', line 178 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
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() #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
188 189 190 191 |
# File 'lib/teambox/teambox-api.rb', line 188 def self.instantiate_collection(collection, = {}) objects = collection["objects"] objects.collect! { |record| instantiate_record(record, ) } end |
Instance Method Details
#collection_path(options = nil) ⇒ Object
183 184 185 186 |
# File 'lib/teambox/teambox-api.rb', line 183 def collection_path( = nil) task_list_path = "task_lists/#{attributes[:task_list_id]}/" self.class.collection_path(task_list_path, || ) end |
#create ⇒ Object
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(={}) val = [] attributes.each_pair do |key, value| val << "#{URI.escape key}=#{URI.escape value}" rescue nil end val.join('&') end |
#update ⇒ Object
201 202 203 204 205 |
# File 'lib/teambox/teambox-api.rb', line 201 def update connection.put(element_path() + '?' + encode, nil, self.class.headers).tap do |response| load_attributes_from_response(response) end end |