inbox 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +44 -13
- data/lib/api_thread.rb +6 -32
- data/lib/inbox.rb +0 -6
- data/lib/message.rb +3 -0
- data/lib/mixins.rb +26 -0
- data/lib/nylas.rb +0 -6
- data/lib/version.rb +1 -1
- metadata +3 -3
- data/lib/tag.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0b6984a5e605532a22d7f884478155114856e0c
|
4
|
+
data.tar.gz: 387c6b20f67ae5e836f4ad20fb791f85c1c43b79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 399247811e80bc82d7934b19073cd37f4acb54593608b6992cb8394fea1f34a9e9480d9b389809daa7177fb7872a427a601b63a5df6caca8ba58928e681b9727
|
7
|
+
data.tar.gz: 9a6493e1b86fef9772faaf72621043f9a121308a415bd7f9bf5dbf20307cdba266e1edab53f0f42659152b880050c6f8024b21d94e2aa395351be1f4874b6d2c
|
data/README.md
CHANGED
@@ -142,14 +142,14 @@ thread = nylas.threads.first
|
|
142
142
|
# Fetch a specific thread
|
143
143
|
thread = nylas.threads.find('ac123acd123ef123')
|
144
144
|
|
145
|
-
# List all threads
|
145
|
+
# List all threads in the inbox
|
146
146
|
# (paginating 50 at a time until no more are returned.)
|
147
|
-
nylas.threads.where(:
|
147
|
+
nylas.threads.where(:in => 'inbox').each do |thread|
|
148
148
|
puts thread.subject
|
149
149
|
end
|
150
150
|
|
151
151
|
# List the 5 most recent unread threads
|
152
|
-
nylas.threads.where(:
|
152
|
+
nylas.threads.where(:unread => true).range(0,4).each do |thread|
|
153
153
|
puts thread.subject
|
154
154
|
end
|
155
155
|
|
@@ -180,23 +180,35 @@ end
|
|
180
180
|
# Mark as read
|
181
181
|
thread.mark_as_read!
|
182
182
|
|
183
|
-
#
|
184
|
-
thread.
|
183
|
+
# Mark as unread
|
184
|
+
thread.mark_as_unread!
|
185
185
|
|
186
|
-
#
|
187
|
-
|
188
|
-
tagsToRemove = []
|
189
|
-
thread.update_tags!(tagsToAdd, tagsToRemove)
|
186
|
+
# Star
|
187
|
+
thread.star!
|
190
188
|
|
191
|
-
#
|
189
|
+
# Remove star
|
190
|
+
thread.unstar!
|
192
191
|
|
192
|
+
# Adding a new label to a thread
|
193
|
+
|
194
|
+
# First, find the id of the important label.
|
195
|
+
#
|
196
|
+
# A note here: all labels have a display_name
|
197
|
+
# property, which contains a label's name.
|
198
|
+
# Some very specific labels (e.g: Inbox, Trash, etc.)
|
199
|
+
# also have a name property, which is a canonical name
|
200
|
+
# for the label. This is important because folder names
|
201
|
+
# can change depending the user's locale (e.g: "Boîte de réception"
|
202
|
+
# means "Inbox" in french). See https://nylas.com/docs/platform#labels
|
203
|
+
# for more details.
|
193
204
|
important = nil
|
194
205
|
nylas.labels.each do |label|
|
195
|
-
if label.
|
206
|
+
if label.name == 'important'
|
196
207
|
important = label
|
197
208
|
end
|
198
209
|
end
|
199
210
|
|
211
|
+
# Then, add it to the thread.
|
200
212
|
thread = nylas.threads.where(:from => "helena@nylas.com").first
|
201
213
|
thread.labels.push(important)
|
202
214
|
thread.save!
|
@@ -257,7 +269,26 @@ fld.display_name = 'Renamed folder'
|
|
257
269
|
fld.save!
|
258
270
|
```
|
259
271
|
|
260
|
-
### Working with Messages
|
272
|
+
### Working with Messages
|
273
|
+
|
274
|
+
```ruby
|
275
|
+
puts msg.subject
|
276
|
+
puts msg.from
|
277
|
+
|
278
|
+
# Mark as read
|
279
|
+
msg.mark_as_read!
|
280
|
+
|
281
|
+
# Mark as unread
|
282
|
+
msg.mark_as_unread!
|
283
|
+
|
284
|
+
# Star
|
285
|
+
msg.star!
|
286
|
+
|
287
|
+
# Remove star
|
288
|
+
msg.unstar!
|
289
|
+
```
|
290
|
+
|
291
|
+
### Working with API Objects
|
261
292
|
|
262
293
|
#### Filtering
|
263
294
|
|
@@ -284,7 +315,7 @@ The `#where` method accepts a hash of filters, as documented in the [Filters Doc
|
|
284
315
|
#### Enumerator methods
|
285
316
|
|
286
317
|
Every object API object has an `each` method which returns an `Enumerator` if you don't pass it a block.
|
287
|
-
This allows you to
|
318
|
+
This allows you to leverage all that Ruby's `Enumerable` has to offer.
|
288
319
|
For example, this is the previous example rewritten to use an `Enumerator`:
|
289
320
|
|
290
321
|
```ruby
|
data/lib/api_thread.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'restful_model'
|
2
2
|
require 'time_attr_accessor'
|
3
|
+
require 'mixins'
|
3
4
|
|
4
5
|
module Inbox
|
5
6
|
class Thread < RestfulModel
|
@@ -8,14 +9,18 @@ module Inbox
|
|
8
9
|
parameter :subject
|
9
10
|
parameter :participants
|
10
11
|
parameter :snippet
|
11
|
-
parameter :tags
|
12
12
|
parameter :message_ids
|
13
13
|
parameter :draft_ids
|
14
14
|
parameter :labels
|
15
15
|
parameter :folder
|
16
|
+
parameter :starred
|
17
|
+
parameter :unread
|
18
|
+
parameter :has_attachments
|
16
19
|
time_attr_accessor :last_message_timestamp
|
17
20
|
time_attr_accessor :first_message_timestamp
|
18
21
|
|
22
|
+
include ReadUnreadMethods
|
23
|
+
|
19
24
|
def inflate(json)
|
20
25
|
super
|
21
26
|
@labels ||= []
|
@@ -44,37 +49,6 @@ module Inbox
|
|
44
49
|
@drafts ||= RestfulModelCollection.new(Draft, @_api, {:thread_id=>@id})
|
45
50
|
end
|
46
51
|
|
47
|
-
def update_tags!(tags_to_add = [], tags_to_remove = [])
|
48
|
-
update('PUT', '', {
|
49
|
-
:add_tags => tags_to_add,
|
50
|
-
:remove_tags => tags_to_remove
|
51
|
-
})
|
52
|
-
end
|
53
|
-
|
54
|
-
def mark_as_read!
|
55
|
-
update_tags!([], ['unread'])
|
56
|
-
end
|
57
|
-
|
58
|
-
def mark_as_seen!
|
59
|
-
update_tags!([], ['unseen'])
|
60
|
-
end
|
61
|
-
|
62
|
-
def archive!
|
63
|
-
update_tags!(['archive'], ['inbox'])
|
64
|
-
end
|
65
|
-
|
66
|
-
def unarchive!
|
67
|
-
update_tags!(['inbox'], ['archive'])
|
68
|
-
end
|
69
|
-
|
70
|
-
def star!
|
71
|
-
update_tags!(['starred'], [''])
|
72
|
-
end
|
73
|
-
|
74
|
-
def unstar!
|
75
|
-
update_tags!([], ['starred'])
|
76
|
-
end
|
77
|
-
|
78
52
|
def as_json(options = {})
|
79
53
|
hash = {}
|
80
54
|
|
data/lib/inbox.rb
CHANGED
@@ -9,7 +9,6 @@ require 'api_account'
|
|
9
9
|
require 'api_thread'
|
10
10
|
require 'calendar'
|
11
11
|
require 'account'
|
12
|
-
require 'tag'
|
13
12
|
require 'message'
|
14
13
|
require 'draft'
|
15
14
|
require 'contact'
|
@@ -149,10 +148,6 @@ module Inbox
|
|
149
148
|
@threads ||= RestfulModelCollection.new(Thread, self)
|
150
149
|
end
|
151
150
|
|
152
|
-
def tags
|
153
|
-
@tags ||= RestfulModelCollection.new(Tag, self)
|
154
|
-
end
|
155
|
-
|
156
151
|
def messages
|
157
152
|
@messages ||= RestfulModelCollection.new(Message, self)
|
158
153
|
end
|
@@ -248,7 +243,6 @@ module Inbox
|
|
248
243
|
"event" => Inbox::Event,
|
249
244
|
"file" => Inbox::File,
|
250
245
|
"message" => Inbox::Message,
|
251
|
-
"tag" => Inbox::Tag,
|
252
246
|
"folder" => Inbox::Folder,
|
253
247
|
"label" => Inbox::Label,
|
254
248
|
}
|
data/lib/message.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'restful_model'
|
2
2
|
require 'file'
|
3
|
+
require 'mixins'
|
3
4
|
|
4
5
|
module Inbox
|
5
6
|
class Message < RestfulModel
|
@@ -18,6 +19,8 @@ module Inbox
|
|
18
19
|
parameter :folder
|
19
20
|
parameter :labels
|
20
21
|
|
22
|
+
include Inbox::ReadUnreadMethods
|
23
|
+
|
21
24
|
def inflate(json)
|
22
25
|
super
|
23
26
|
@to ||= []
|
data/lib/mixins.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Inbox
|
2
|
+
module ReadUnreadMethods
|
3
|
+
def update_param!(param, value)
|
4
|
+
update('PUT', '', {
|
5
|
+
param => value,
|
6
|
+
})
|
7
|
+
end
|
8
|
+
|
9
|
+
def mark_as_read!
|
10
|
+
update_param!(:unread, false)
|
11
|
+
end
|
12
|
+
|
13
|
+
def mark_as_unread!
|
14
|
+
update_param!(:unread, true)
|
15
|
+
end
|
16
|
+
|
17
|
+
def star!
|
18
|
+
update_param!(:starred, true)
|
19
|
+
end
|
20
|
+
|
21
|
+
def unstar!
|
22
|
+
update_param!(:starred, false)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
data/lib/nylas.rb
CHANGED
@@ -9,7 +9,6 @@ require 'api_account'
|
|
9
9
|
require 'api_thread'
|
10
10
|
require 'calendar'
|
11
11
|
require 'account'
|
12
|
-
require 'tag'
|
13
12
|
require 'message'
|
14
13
|
require 'draft'
|
15
14
|
require 'contact'
|
@@ -149,10 +148,6 @@ module Inbox
|
|
149
148
|
@threads ||= RestfulModelCollection.new(Thread, self)
|
150
149
|
end
|
151
150
|
|
152
|
-
def tags
|
153
|
-
@tags ||= RestfulModelCollection.new(Tag, self)
|
154
|
-
end
|
155
|
-
|
156
151
|
def messages
|
157
152
|
@messages ||= RestfulModelCollection.new(Message, self)
|
158
153
|
end
|
@@ -248,7 +243,6 @@ module Inbox
|
|
248
243
|
"event" => Inbox::Event,
|
249
244
|
"file" => Inbox::File,
|
250
245
|
"message" => Inbox::Message,
|
251
|
-
"tag" => Inbox::Tag,
|
252
246
|
"folder" => Inbox::Folder,
|
253
247
|
"label" => Inbox::Label,
|
254
248
|
}
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Gotow
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|
@@ -214,11 +214,11 @@ files:
|
|
214
214
|
- lib/inbox.rb
|
215
215
|
- lib/label.rb
|
216
216
|
- lib/message.rb
|
217
|
+
- lib/mixins.rb
|
217
218
|
- lib/nylas.rb
|
218
219
|
- lib/parameters.rb
|
219
220
|
- lib/restful_model.rb
|
220
221
|
- lib/restful_model_collection.rb
|
221
|
-
- lib/tag.rb
|
222
222
|
- lib/time_attr_accessor.rb
|
223
223
|
- lib/version.rb
|
224
224
|
- LICENSE.txt
|