inbox 1.3.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +32 -17
- data/lib/inbox.rb +24 -29
- data/lib/message.rb +1 -0
- data/lib/nylas.rb +24 -29
- data/lib/restful_model_collection.rb +17 -13
- data/lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0eed0e8c05ccc5058757a802114677ef14f3d290
|
4
|
+
data.tar.gz: d8561281e5cac7dc75c2d940f602a05b3b022fd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1520cdba3b742d01486e28820830ed6db74748c9f35146c254bdf4e17167286acece7fb9da28ab44e7f17f05e6d5c4a2166129cda211d6764492146fa424411e
|
7
|
+
data.tar.gz: 3ffd9f2218a91713f9011de687dd79de1ce852f32c9b3fbe2505dace03ef3b95cc65f258308236584719c104fac1dcf6f72fb84b23d2df7bd2b1ad2ca98d281c
|
data/README.md
CHANGED
@@ -83,7 +83,9 @@ def login
|
|
83
83
|
# This URL must be registered with your application in the developer portal
|
84
84
|
callback_url = url_for(:action => 'login_callback')
|
85
85
|
|
86
|
-
|
86
|
+
# You can also optionally pass state, an optional arbitrary string that
|
87
|
+
# will be passed back to us at the end of the auth flow.
|
88
|
+
redirect_to nylas.url_for_authentication(callback_url, user_email, {:state => 'ben auth'})
|
87
89
|
end
|
88
90
|
```
|
89
91
|
|
@@ -458,23 +460,36 @@ The streaming API will receive deltas in real time, without needing to repeatedl
|
|
458
460
|
```ruby
|
459
461
|
cursor = nylas.latest_cursor
|
460
462
|
|
461
|
-
|
462
|
-
nylas.delta_stream(cursor) do |event, object|
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
463
|
+
EventMachine.run do
|
464
|
+
nylas.delta_stream(cursor) do |event, object|
|
465
|
+
if event == "create" or event == "modify"
|
466
|
+
if object.is_a?(Nylas::Contact)
|
467
|
+
puts "#{object.name} - #{object.email}"
|
468
|
+
elsif object.is_a?(Nylas::Event)
|
469
|
+
puts "Event!"
|
470
|
+
end
|
471
|
+
elsif event == "delete"
|
472
|
+
# In the case of a deletion, the API only returns the ID of the object.
|
473
|
+
# In this case, the Ruby SDK returns a dummy object with only the id field
|
474
|
+
# set.
|
475
|
+
puts "Deleting from collection #{object.class.name}, id: #{object}"
|
468
476
|
end
|
469
|
-
elsif event == "delete"
|
470
|
-
# In the case of a deletion, the API only returns the ID of the object.
|
471
|
-
# In this case, the Ruby SDK returns a dummy object with only the id field
|
472
|
-
# set.
|
473
|
-
puts "Deleting from collection #{object.class.name}, id: #{object}"
|
474
477
|
end
|
475
|
-
|
478
|
+
end
|
479
|
+
```
|
480
|
+
|
481
|
+
To receive streams from multiple accounts, call `delta_stream` for each of them inside an `EventMachine.run` block.
|
476
482
|
|
477
|
-
|
483
|
+
```ruby
|
484
|
+
api_handles = [] # a list of Nylas::API objects
|
485
|
+
|
486
|
+
EventMachine.run do
|
487
|
+
api_handles.each do |a|
|
488
|
+
cursor = a.latest_cursor()
|
489
|
+
a.delta_stream(cursor) do |event, object|
|
490
|
+
puts object
|
491
|
+
end
|
492
|
+
end
|
478
493
|
end
|
479
494
|
```
|
480
495
|
|
@@ -541,9 +556,9 @@ nylas = Nylas::API.new(nil, nil, nil, 'http://localhost:5555/')
|
|
541
556
|
# going to use.
|
542
557
|
account_id = nylas.accounts.first.id
|
543
558
|
|
544
|
-
# Display the
|
559
|
+
# Display the body of the first message for the first account
|
545
560
|
nylas = Nylas::API.new(nil, nil, account_id, 'http://localhost:5555/')
|
546
|
-
puts nylas.messages.first.
|
561
|
+
puts nylas.messages.first.body
|
547
562
|
```
|
548
563
|
|
549
564
|
|
data/lib/inbox.rb
CHANGED
@@ -3,6 +3,7 @@ require 'rest-client'
|
|
3
3
|
require 'yajl'
|
4
4
|
require 'em-http'
|
5
5
|
require 'ostruct'
|
6
|
+
require 'active_support/core_ext/hash'
|
6
7
|
|
7
8
|
require 'account'
|
8
9
|
require 'api_account'
|
@@ -113,11 +114,20 @@ module Inbox
|
|
113
114
|
end
|
114
115
|
|
115
116
|
def url_for_authentication(redirect_uri, login_hint = '', options = {})
|
116
|
-
|
117
|
-
|
118
|
-
|
117
|
+
params = {
|
118
|
+
:client_id => @app_id,
|
119
|
+
:trial => options.fetch(:trial, false),
|
120
|
+
:response_type => 'code',
|
121
|
+
:scope => 'email',
|
122
|
+
:login_hint => login_hint,
|
123
|
+
:redirect_uri => redirect_uri,
|
124
|
+
}
|
125
|
+
|
126
|
+
if options.has_key?(:state) then
|
127
|
+
params[:state] = options[:state]
|
119
128
|
end
|
120
|
-
|
129
|
+
|
130
|
+
"https://#{@service_domain}/oauth/authorize?" + params.to_query
|
121
131
|
end
|
122
132
|
|
123
133
|
def url_for_management
|
@@ -203,23 +213,6 @@ module Inbox
|
|
203
213
|
end
|
204
214
|
end
|
205
215
|
|
206
|
-
def get_cursor(timestamp)
|
207
|
-
# Get the cursor corresponding to a specific timestamp.
|
208
|
-
warn "Nylas#get_cursor is deprecated. Use Nylas#latest_cursor instead."
|
209
|
-
|
210
|
-
path = self.url_for_path("/delta/generate_cursor")
|
211
|
-
data = { :start => timestamp }
|
212
|
-
|
213
|
-
cursor = nil
|
214
|
-
|
215
|
-
RestClient.post(path, data.to_json, :content_type => :json) do |response,request,result|
|
216
|
-
json = Inbox.interpret_response(result, response, {:expected_class => Object})
|
217
|
-
cursor = json["cursor"]
|
218
|
-
end
|
219
|
-
|
220
|
-
cursor
|
221
|
-
end
|
222
|
-
|
223
216
|
def latest_cursor
|
224
217
|
# Get the cursor corresponding to a specific timestamp.
|
225
218
|
path = self.url_for_path("/delta/latest_cursor")
|
@@ -364,15 +357,17 @@ module Inbox
|
|
364
357
|
end
|
365
358
|
end
|
366
359
|
|
367
|
-
EventMachine.
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
http.errback do
|
373
|
-
raise UnexpectedResponse.new http.error
|
374
|
-
end
|
360
|
+
http = EventMachine::HttpRequest.new(path, :connect_timeout => 0, :inactivity_timeout => timeout).get(:keepalive => true)
|
361
|
+
|
362
|
+
# set a callback on the HTTP stream that parses incoming chunks as they come in
|
363
|
+
http.stream do |chunk|
|
364
|
+
parser << chunk
|
375
365
|
end
|
366
|
+
|
367
|
+
http.errback do
|
368
|
+
raise UnexpectedResponse.new http.error
|
369
|
+
end
|
370
|
+
|
376
371
|
end
|
377
372
|
end
|
378
373
|
end
|
data/lib/message.rb
CHANGED
data/lib/nylas.rb
CHANGED
@@ -3,6 +3,7 @@ require 'rest-client'
|
|
3
3
|
require 'yajl'
|
4
4
|
require 'em-http'
|
5
5
|
require 'ostruct'
|
6
|
+
require 'active_support/core_ext/hash'
|
6
7
|
|
7
8
|
require 'account'
|
8
9
|
require 'api_account'
|
@@ -113,11 +114,20 @@ module Inbox
|
|
113
114
|
end
|
114
115
|
|
115
116
|
def url_for_authentication(redirect_uri, login_hint = '', options = {})
|
116
|
-
|
117
|
-
|
118
|
-
|
117
|
+
params = {
|
118
|
+
:client_id => @app_id,
|
119
|
+
:trial => options.fetch(:trial, false),
|
120
|
+
:response_type => 'code',
|
121
|
+
:scope => 'email',
|
122
|
+
:login_hint => login_hint,
|
123
|
+
:redirect_uri => redirect_uri,
|
124
|
+
}
|
125
|
+
|
126
|
+
if options.has_key?(:state) then
|
127
|
+
params[:state] = options[:state]
|
119
128
|
end
|
120
|
-
|
129
|
+
|
130
|
+
"https://#{@service_domain}/oauth/authorize?" + params.to_query
|
121
131
|
end
|
122
132
|
|
123
133
|
def url_for_management
|
@@ -203,23 +213,6 @@ module Inbox
|
|
203
213
|
end
|
204
214
|
end
|
205
215
|
|
206
|
-
def get_cursor(timestamp)
|
207
|
-
# Get the cursor corresponding to a specific timestamp.
|
208
|
-
warn "Nylas#get_cursor is deprecated. Use Nylas#latest_cursor instead."
|
209
|
-
|
210
|
-
path = self.url_for_path("/delta/generate_cursor")
|
211
|
-
data = { :start => timestamp }
|
212
|
-
|
213
|
-
cursor = nil
|
214
|
-
|
215
|
-
RestClient.post(path, data.to_json, :content_type => :json) do |response,request,result|
|
216
|
-
json = Inbox.interpret_response(result, response, {:expected_class => Object})
|
217
|
-
cursor = json["cursor"]
|
218
|
-
end
|
219
|
-
|
220
|
-
cursor
|
221
|
-
end
|
222
|
-
|
223
216
|
def latest_cursor
|
224
217
|
# Get the cursor corresponding to a specific timestamp.
|
225
218
|
path = self.url_for_path("/delta/latest_cursor")
|
@@ -364,15 +357,17 @@ module Inbox
|
|
364
357
|
end
|
365
358
|
end
|
366
359
|
|
367
|
-
EventMachine.
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
http.errback do
|
373
|
-
raise UnexpectedResponse.new http.error
|
374
|
-
end
|
360
|
+
http = EventMachine::HttpRequest.new(path, :connect_timeout => 0, :inactivity_timeout => timeout).get(:keepalive => true)
|
361
|
+
|
362
|
+
# set a callback on the HTTP stream that parses incoming chunks as they come in
|
363
|
+
http.stream do |chunk|
|
364
|
+
parser << chunk
|
375
365
|
end
|
366
|
+
|
367
|
+
http.errback do
|
368
|
+
raise UnexpectedResponse.new http.error
|
369
|
+
end
|
370
|
+
|
376
371
|
end
|
377
372
|
end
|
378
373
|
end
|
@@ -15,16 +15,17 @@ module Inbox
|
|
15
15
|
def each
|
16
16
|
return enum_for(:each) unless block_given?
|
17
17
|
|
18
|
-
offset = 0
|
19
|
-
|
18
|
+
@filters[:offset] = 0 unless @filters.key?(:offset)
|
19
|
+
@filters[:limit] = 100 unless @filters.key?(:limit)
|
20
|
+
|
20
21
|
finished = false
|
21
22
|
while (!finished) do
|
22
|
-
results = get_model_collection(
|
23
|
+
results = get_model_collection()
|
23
24
|
results.each { |item|
|
24
25
|
yield item
|
25
26
|
}
|
26
|
-
offset += results.length
|
27
|
-
finished = results.length <
|
27
|
+
@filters[:offset] += results.length
|
28
|
+
finished = results.length < @filters[:limit]
|
28
29
|
end
|
29
30
|
end
|
30
31
|
|
@@ -64,12 +65,17 @@ module Inbox
|
|
64
65
|
finished = false
|
65
66
|
chunk_size = 100
|
66
67
|
|
67
|
-
if limit < chunk_size
|
68
|
-
chunk_size = limit
|
69
|
-
end
|
70
|
-
|
71
68
|
while (!finished && accumulated.length < limit) do
|
72
|
-
|
69
|
+
@filters[:offset] = offset + accumulated.length
|
70
|
+
|
71
|
+
# if the total items we want, minus how many we already have, is fewer than we plan to grab...
|
72
|
+
remaining = limit - accumulated.length
|
73
|
+
if remaining < chunk_size
|
74
|
+
chunk_size = remaining
|
75
|
+
end
|
76
|
+
@filters[:limit] = chunk_size
|
77
|
+
|
78
|
+
results = get_model_collection()
|
73
79
|
accumulated = accumulated.concat(results)
|
74
80
|
|
75
81
|
# we're done if we have more than 'limit' items, or if we asked for 50 and got less than 50...
|
@@ -136,10 +142,8 @@ module Inbox
|
|
136
142
|
model
|
137
143
|
end
|
138
144
|
|
139
|
-
def get_model_collection
|
145
|
+
def get_model_collection
|
140
146
|
filters = @filters.clone
|
141
|
-
filters[:offset] = offset
|
142
|
-
filters[:limit] = limit
|
143
147
|
models = []
|
144
148
|
|
145
149
|
RestClient.get(url, :params => filters){ |response,request,result|
|
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:
|
4
|
+
version: 2.0.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:
|
13
|
+
date: 2016-02-06 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|