Class: RTM::Note

Inherits:
Object
  • Object
show all
Includes:
Test::Unit::Assertions
Defined in:
lib/rtmilk/api/notes.rb

Overview

a Note.

belongs to Task (TaskSeries).

usage:

  • n = RTM::Note.new(:task=>task, :title=>‘yeah’, :body=>‘you’)

  • n.title = ‘newtitle’

  • n.body = ‘newbody’

  • n.delete

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ Note

Returns a new instance of Note.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/rtmilk/api/notes.rb', line 76

def initialize(arg)
   assert_equal(Hash, arg.class)

   if arg.has_key? :hash # already constructed
      @hash = arg[:hash]
   else # from scratch
      assert(arg.has_key?(:task))
      assert_equal(RTM::Task, arg[:task].class)
      assert(arg.has_key?(:title))
      assert(arg.has_key?(:body))

      @hash, transaction = RTM::Tasks::Notes::Add.new(
         RTM::API.token, 
         RTM::Timeline.new(RTM::API.token).to_s,
         arg[:task].list, arg[:task].id,
         arg[:task].chunks.first.id, # XXX: Note belongs to TaskSeries, why need Task id ?
         arg[:title],
         arg[:body]).invoke
   end
end

Class Method Details

.update(arg) ⇒ Object



130
131
132
133
134
135
136
137
# File 'lib/rtmilk/api/notes.rb', line 130

def Note.update(arg)
   ret, transaction = RTM::Tasks::Notes::Edit.new(
      RTM::API.token, 
      RTM::Timeline.new(RTM::API.token).to_s,
      arg[:id],
      arg[:title],
      arg[:body]).invoke
end

Instance Method Details

#bodyObject



73
# File 'lib/rtmilk/api/notes.rb', line 73

def body; @hash['content']; end

#body=(text) ⇒ Object

alter body field.



110
111
112
113
114
115
116
117
118
119
# File 'lib/rtmilk/api/notes.rb', line 110

def body=(text)
   ret, transaction = RTM::Tasks::Notes::Edit.new(
      RTM::API.token, 
      RTM::Timeline.new(RTM::API.token).to_s,
      id,
      title,
      text).invoke
   assert(ret['id'], id)
   @hash['content'] = text
end

#createdObject



74
# File 'lib/rtmilk/api/notes.rb', line 74

def created; @hash['created']; end

#deleteObject

delete this note. after deleted, should not touch this object.



123
124
125
126
127
128
# File 'lib/rtmilk/api/notes.rb', line 123

def delete
   RTM::Tasks::Notes::Delete.new(
      RTM::API.token, 
      RTM::Timeline.new(RTM::API.token).to_s,
      id).invoke
end

#idObject



70
# File 'lib/rtmilk/api/notes.rb', line 70

def id; @hash['id']; end

#modifiedObject



72
# File 'lib/rtmilk/api/notes.rb', line 72

def modified; @hash['modified']; end

#titleObject



71
# File 'lib/rtmilk/api/notes.rb', line 71

def title; @hash['title']; end

#title=(text) ⇒ Object

alter title field.



98
99
100
101
102
103
104
105
106
107
# File 'lib/rtmilk/api/notes.rb', line 98

def title=(text)
   ret, transaction = RTM::Tasks::Notes::Edit.new(
      RTM::API.token, 
      RTM::Timeline.new(RTM::API.token).to_s,
      id,
      text,
      body).invoke
   assert(ret['id'], id)
   @hash['title'] = text
end