Class: RTM::List

Inherits:
Object
  • Object
show all
Defined in:
lib/rtmilk/api/lists.rb

Overview

more friendly class.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ List

attr_reader :name, :smart, :id, :archived, :deleted, :position, :locked



85
86
87
88
89
90
91
92
93
# File 'lib/rtmilk/api/lists.rb', line 85

def initialize(arg)
   if arg.class == String # name
      @hash = RTM::Lists::Add.new(RTM::API.token, arg).invoke
   elsif arg.class == Hash # already constructed 
      @hash = arg
   else
      raise RTM::Error, "invalid argument"
   end
end

Class Method Details

.alive_allObject

find all alive Lists.



158
159
160
161
162
163
164
165
# File 'lib/rtmilk/api/lists.rb', line 158

def List.alive_all
   lists = RTM::Lists::GetList.new(RTM::API.token).invoke
   lists.find_all do |list|
      list['archived'] == '0' && list['deleted'] == '0'
   end.collect do |x|
      List.new(x)
   end
end

.find(name, alive_only = true) ⇒ Object

find a List by name.



132
133
134
135
136
137
138
139
140
141
# File 'lib/rtmilk/api/lists.rb', line 132

def List.find(name, alive_only=true) # by name
   lists = RTM::Lists::GetList.new(RTM::API.token).invoke
   lists.find do |list|
      if alive_only
         list['name'] == name && list['archived'] == '0' && list['deleted'] == '0'
      else
         list['name'] == name
      end
   end
end

.find_all(name, alive_only = true) ⇒ Object

find all Lists.



144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/rtmilk/api/lists.rb', line 144

def List.find_all(name, alive_only=true) # by name
   lists = RTM::Lists::GetList.new(RTM::API.token).invoke
   lists.find_all do |list|
      if alive_only
         list['name'] == name && list['archived'] == '0' && list['deleted'] == '0'
      else
         list['name'] == name
      end
   end.collect do |x|
      List.new(x)
   end
end

.getObject



168
169
# File 'lib/rtmilk/api/lists.rb', line 168

def List.get
end

.inboxObject



171
172
173
# File 'lib/rtmilk/api/lists.rb', line 171

def List.inbox
   List.find('Inbox')
end

Instance Method Details

#archiveObject



109
110
# File 'lib/rtmilk/api/lists.rb', line 109

def archive
end

#archived?Boolean

Returns:

  • (Boolean)


99
# File 'lib/rtmilk/api/lists.rb', line 99

def archived?; @hash['archived'] == '1'; end

#deleteObject



118
119
120
# File 'lib/rtmilk/api/lists.rb', line 118

def delete
   deleted = RTM::Lists::Delete.new(RTM::API.token, @hash['id']).invoke
end

#deleted?Boolean

Returns:

  • (Boolean)


101
# File 'lib/rtmilk/api/lists.rb', line 101

def deleted?; @hash['deleted'] == '1'; end

#idObject



96
# File 'lib/rtmilk/api/lists.rb', line 96

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

#locked?Boolean

Returns:

  • (Boolean)


100
# File 'lib/rtmilk/api/lists.rb', line 100

def locked?; @hash['locked'] == '1'; end

#nameObject



95
# File 'lib/rtmilk/api/lists.rb', line 95

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

#name=(new_name) ⇒ Object



103
104
105
# File 'lib/rtmilk/api/lists.rb', line 103

def name=(new_name)
   RTM::API::SetName(RTM::API.token, @id, new_name)
end

#positionObject



97
# File 'lib/rtmilk/api/lists.rb', line 97

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

#set_defaultObject



124
125
# File 'lib/rtmilk/api/lists.rb', line 124

def set_default
end

#smart?Boolean

Returns:

  • (Boolean)


98
# File 'lib/rtmilk/api/lists.rb', line 98

def smart?; @hash['smart'] == '1'; end

#unarchiveObject

unarchive this list.



113
114
# File 'lib/rtmilk/api/lists.rb', line 113

def unarchive
end