nylas 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58db1f5a454d2d5e46fd1d98a38a5445fbc4fedf
4
- data.tar.gz: d956107466fb9ff8900b3fa725904ae7cd48207a
3
+ metadata.gz: ce94f4eb8a8cbdc721ceea8db3c208c77f948ea3
4
+ data.tar.gz: 2c582674b75b99e96bfd94ecf8aae0d1ed749202
5
5
  SHA512:
6
- metadata.gz: 9679436918c2dc6318096723605a59806102de7b9d87c365249782d6832e048e7831e710d818457cbaddd64e9d3b4542590d5a638e1f2646ce009dfac2cfc3db
7
- data.tar.gz: ead866ffe64c3a2a2d9d8e656cbce576782573f16d2a0ac2fad2482b0126004b15ba34ed698e4035e03c5f8b7288dc5d92648d3c959fc98d18270a57edccfe03
6
+ metadata.gz: 1823490cc7c1b0e16b0dfe001d7f94490196fd5b213b93b3dc233278ac19cd6e3a48498a9e2b04532aa28897fd29c56013e8af997b889af61e1816af6ae01605
7
+ data.tar.gz: 0b3ad38237c4cf3e50f2f9d2c1943023baa9ae92ef7844544d0b0817d7f3cc874c2e90865752bc1e3e2c18cea2a86015935fbc7eba018716356d7d4c33d56a72
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 tagged `inbox`
145
+ # List all threads in the inbox
146
146
  # (paginating 50 at a time until no more are returned.)
147
- nylas.threads.where(:tag => 'inbox').each do |thread|
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(:tag => 'unread').range(0,4).each do |thread|
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
- # Archive
184
- thread.archive!
183
+ # Mark as unread
184
+ thread.mark_as_unread!
185
185
 
186
- # Add or remove arbitrary tags (DEPRECATED --- you should use the new labels and folders API)
187
- tagsToAdd = ['inbox', 'cfa1233ef123acd12']
188
- tagsToRemove = []
189
- thread.update_tags!(tagsToAdd, tagsToRemove)
186
+ # Star
187
+ thread.star!
190
188
 
191
- # Add a new label to a message
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.display_name == 'Important'
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, Contacts, etc.
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 do leverage all that Ruby's `Enumerable` has to offer.
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
@@ -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
 
@@ -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
  }
@@ -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 ||= []
@@ -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
+
@@ -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
  }
@@ -1,3 +1,3 @@
1
1
  module Inbox
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nylas
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.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-11-30 00:00:00.000000000 Z
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
data/lib/tag.rb DELETED
@@ -1,9 +0,0 @@
1
- require 'restful_model'
2
-
3
- module Inbox
4
- class Tag < RestfulModel
5
-
6
- parameter :name
7
-
8
- end
9
- end