Class: Teambox::Resource
- Inherits:
-
Object
- Object
- Teambox::Resource
- Includes:
- ReferenceList
- Defined in:
- lib/teambox-client/teambox.rb
Overview
Represents an object located on Teambox.
Most resources belonging to a Teambox::Project can be modified, in which case you can use the save, destroy, and reload methods.
All attributes are exposed by the method_missing handler.
Direct Known Subclasses
Activity, Comment, Conversation, Divider, Invitation, Membership, Note, Organization, Page, PageSlot, Person, Project, Task, TaskList, TeamboxData, Upload, User
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#list ⇒ Object
Returns the value of attribute list.
-
#references ⇒ Object
readonly
Returns the value of attribute references.
Instance Method Summary collapse
-
#created_at ⇒ Object
The time this object was created.
-
#destroy ⇒ Object
Destroys the resource on teambox.
- #id ⇒ Object
-
#initialize(data, result_list = nil) ⇒ Resource
constructor
A new instance of Resource.
- #inspect ⇒ Object
-
#method_missing(method, *args, &block) ⇒ Object
:nodoc:.
-
#next ⇒ Object
:nodoc:.
-
#prev ⇒ Object
:nodoc:.
-
#reload ⇒ Object
Reloads the resource from source data @returns self.
-
#save ⇒ Object
Saves the resource to teambox @returns true if saved.
-
#updated_at ⇒ Object
The last time this object was updated.
-
#url ⇒ Object
Location of this object on teambox, used for updating.
Methods included from ReferenceList
#generate_references, #get_or_make_reference, #get_or_make_references, #get_reference, #set_reference
Constructor Details
#initialize(data, result_list = nil) ⇒ Resource
Returns a new instance of Resource.
213 214 215 216 217 218 219 220 221 |
# File 'lib/teambox-client/teambox.rb', line 213 def initialize(data, result_list=nil) @data = data @list = result_list || ResultSet.new(nil, nil, [], []) if @data['references'] generate_references(@data['references']) else @references = result_list ? result_list.references : {} end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
:nodoc:
278 279 280 |
# File 'lib/teambox-client/teambox.rb', line 278 def method_missing(method, *args, &block) #:nodoc: @data.include?(method.to_s) ? @data[method.to_s] : super end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
210 211 212 |
# File 'lib/teambox-client/teambox.rb', line 210 def data @data end |
#list ⇒ Object
Returns the value of attribute list.
210 211 212 |
# File 'lib/teambox-client/teambox.rb', line 210 def list @list end |
#references ⇒ Object (readonly)
Returns the value of attribute references.
211 212 213 |
# File 'lib/teambox-client/teambox.rb', line 211 def references @references end |
Instance Method Details
#created_at ⇒ Object
The time this object was created
228 229 230 |
# File 'lib/teambox-client/teambox.rb', line 228 def created_at @data.has_key?('created_at') ? Time.parse(data['created_at']) : nil end |
#destroy ⇒ Object
Destroys the resource on teambox
273 274 275 276 |
# File 'lib/teambox-client/teambox.rb', line 273 def destroy @list.client.delete(url) if @list.client && url true end |
#id ⇒ Object
223 224 225 |
# File 'lib/teambox-client/teambox.rb', line 223 def id @data['id'] end |
#inspect ⇒ Object
282 283 284 |
# File 'lib/teambox-client/teambox.rb', line 282 def inspect "#<#{self.class} @data=#{@data.inspect} list=#{@list.object_id}>" end |
#next ⇒ Object
:nodoc:
237 238 239 |
# File 'lib/teambox-client/teambox.rb', line 237 def next #:nodoc: nil end |
#prev ⇒ Object
:nodoc:
241 242 243 |
# File 'lib/teambox-client/teambox.rb', line 241 def prev #:nodoc: nil end |
#reload ⇒ Object
Reloads the resource from source data
@returns self
252 253 254 255 256 257 258 259 260 |
# File 'lib/teambox-client/teambox.rb', line 252 def reload if @list.client && url updated = @list.client.get(url) rescue nil unless updated.nil? @data = updated.data end end self end |
#save ⇒ Object
Saves the resource to teambox
@returns true if saved
264 265 266 267 268 269 270 |
# File 'lib/teambox-client/teambox.rb', line 264 def save if @list.client && url updated = @list.client.put(url, @data) rescue nil return true unless updated.nil? end false end |
#updated_at ⇒ Object
The last time this object was updated
233 234 235 |
# File 'lib/teambox-client/teambox.rb', line 233 def updated_at @data.has_key?('updated_at') ? Time.parse(data['updated_at']) : nil end |
#url ⇒ Object
Location of this object on teambox, used for updating
246 247 248 |
# File 'lib/teambox-client/teambox.rb', line 246 def url nil end |