inbox 0.14.1 → 0.15.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 +45 -1
- data/lib/message.rb +0 -2
- data/lib/namespace.rb +84 -1
- data/lib/restful_model.rb +1 -0
- data/lib/version.rb +1 -1
- metadata +27 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3652da240e2694c7a33df379517cfbba41c0e261
|
4
|
+
data.tar.gz: a5f78de8bec34983c4089c307a3c2bb6bdd1df07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f67b33d142fa9dd408163e6c5a4143ffffe1af4a0c7b4868acea45dd8c4632af03f92f9344f4445b999c73f18514756c03d075a7036084dbb5cbcd72ab39b4f0
|
7
|
+
data.tar.gz: 44b42c080c6a92b8f979bec267c0821082b47825f9e223076448ab8c9e6d8e5fd3ba495fb8e36e5da1a20be446a820f156bd9e40fb0935bec9354be0ebd6253f
|
data/README.md
CHANGED
@@ -43,7 +43,7 @@ Generally, you should store your App ID and Secret into environment variables to
|
|
43
43
|
|
44
44
|
### Authentication
|
45
45
|
|
46
|
-
The Nilas REST API uses server-side (three-legged) OAuth, and the Ruby gem provides convenience methods that simplify the OAuth process. For more information about authenticating with Nilas, visit the [Developer Documentation](https://www.nilas.com/docs/
|
46
|
+
The Nilas REST API uses server-side (three-legged) OAuth, and the Ruby gem provides convenience methods that simplify the OAuth process. For more information about authenticating with Nilas, visit the [Developer Documentation](https://www.nilas.com/docs/knowledgebase#authentication).
|
47
47
|
|
48
48
|
**Step 1: Redirect the user to Nilas:**
|
49
49
|
|
@@ -262,6 +262,50 @@ new_event.when = {:start_time => 1407542195, :end_time => 1407543195}
|
|
262
262
|
new_event.save!
|
263
263
|
```
|
264
264
|
|
265
|
+
## Using the Delta sync API
|
266
|
+
|
267
|
+
The delta sync API allows fetching all the changes that occured since a specified time. [Read this](https://nilas.com/docs/api#sync-protocol) for more details about the API.
|
268
|
+
|
269
|
+
````ruby
|
270
|
+
# Get all the messages starting from timestamp
|
271
|
+
#
|
272
|
+
# we first need to get a cursor object a cursor is simply the id of
|
273
|
+
# an individual change.
|
274
|
+
cursor = inbox.namespaces.first.get_cursor(1407543195)
|
275
|
+
|
276
|
+
last_cursor = nil
|
277
|
+
inbox.namespaces.first.deltas(cursor) do |event, object|
|
278
|
+
if event == "create" or event == "modify"
|
279
|
+
if object.is_a?(Inbox::Contact)
|
280
|
+
puts "#{object.name} - #{object.email}"
|
281
|
+
elsif object.is_a?(Inbox::Event)
|
282
|
+
puts "Event!"
|
283
|
+
end
|
284
|
+
elsif event == "delete"
|
285
|
+
# In the case of a deletion, the API only returns the ID of the object.
|
286
|
+
# In this case, the Ruby SDK returns a dummy object with only the id field
|
287
|
+
# set.
|
288
|
+
puts "Deleting from collection #{object.class.name}, id: #{object}"
|
289
|
+
end
|
290
|
+
last_cursor = object.cursor
|
291
|
+
end
|
292
|
+
|
293
|
+
# Don't forget to save the last cursor so that we can pick up changes
|
294
|
+
# from where we left.
|
295
|
+
save_to_db(last_cursor)
|
296
|
+
```
|
297
|
+
|
298
|
+
### Exclude changes from a specific type --- get only messages
|
299
|
+
inbox.namespaces.first.deltas(cursor, exclude=[Inbox::Contact,
|
300
|
+
Inbox::Event,
|
301
|
+
Inbox::File,
|
302
|
+
Inbox::Tag,
|
303
|
+
Inbox::Thread]) do |event, object|
|
304
|
+
if event == 'create' or event == 'modify"
|
305
|
+
puts object.subject
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
265
309
|
### Handling Errors
|
266
310
|
The Nilas API uses conventional HTTP response codes to indicate success or failure of an API request. The ruby gem raises these as native exceptions.
|
267
311
|
|
data/lib/message.rb
CHANGED
data/lib/namespace.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'restful_model'
|
2
|
+
require 'account'
|
2
3
|
require 'tag'
|
3
4
|
require 'message'
|
4
5
|
require 'draft'
|
@@ -58,5 +59,87 @@ module Inbox
|
|
58
59
|
@events ||= RestfulModelCollection.new(Event, @_api, @id)
|
59
60
|
end
|
60
61
|
|
62
|
+
def get_cursor(timestamp)
|
63
|
+
# Get the cursor corresponding to a specific timestamp.
|
64
|
+
path = @_api.url_for_path("n/#{@namespace_id}/delta/generate_cursor")
|
65
|
+
data = { :start => timestamp }
|
66
|
+
|
67
|
+
cursor = nil
|
68
|
+
|
69
|
+
RestClient.post(path, data.to_json, :content_type => :json) do |response,request,result|
|
70
|
+
json = Inbox.interpret_response(result, response, {:expected_class => Object})
|
71
|
+
cursor = json["cursor"]
|
72
|
+
end
|
73
|
+
|
74
|
+
return cursor
|
75
|
+
end
|
76
|
+
|
77
|
+
OBJECTS_TABLE = {
|
78
|
+
"account" => Inbox::Account,
|
79
|
+
"calendar" => Inbox::Calendar,
|
80
|
+
"draft" => Inbox::Draft,
|
81
|
+
"thread" => Inbox::Thread,
|
82
|
+
"account" => Inbox::Account,
|
83
|
+
"calendar" => Inbox::Calendar,
|
84
|
+
"contact" => Inbox::Contact,
|
85
|
+
"draft" => Inbox::Draft,
|
86
|
+
"event" => Inbox::Event,
|
87
|
+
"file" => Inbox::File,
|
88
|
+
"message" => Inbox::Message,
|
89
|
+
"namespace" => Inbox::Namespace,
|
90
|
+
"tag" => Inbox::Tag,
|
91
|
+
"thread" => Inbox::Thread
|
92
|
+
}
|
93
|
+
|
94
|
+
def deltas(cursor, exclude_types=[])
|
95
|
+
exclude_string = ""
|
96
|
+
|
97
|
+
if not exclude_types.empty?
|
98
|
+
exclude_string = "&exclude_types="
|
99
|
+
|
100
|
+
exclude_types.each do |value|
|
101
|
+
count = 0
|
102
|
+
if OBJECTS_TABLE.has_value?(value)
|
103
|
+
param_name = OBJECTS_TABLE.key(value)
|
104
|
+
exclude_string += "#{param_name},"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
exclude_string = exclude_string[0..-2]
|
110
|
+
|
111
|
+
# loop and yield deltas until we've come to the end.
|
112
|
+
loop do
|
113
|
+
path = @_api.url_for_path("n/#{@namespace_id}/delta?cursor=#{cursor}#{exclude_string}")
|
114
|
+
json = nil
|
115
|
+
|
116
|
+
RestClient.get(path) do |response,request,result|
|
117
|
+
json = Inbox.interpret_response(result, response, {:expected_class => Object})
|
118
|
+
end
|
119
|
+
|
120
|
+
start_cursor = json["cursor_start"]
|
121
|
+
end_cursor = json["cursor_end"]
|
122
|
+
|
123
|
+
json["deltas"].each do |delta|
|
124
|
+
cls = OBJECTS_TABLE[delta['object']]
|
125
|
+
obj = cls.new(@_api, @namespace_id)
|
126
|
+
|
127
|
+
case delta["event"]
|
128
|
+
when 'create', 'modify'
|
129
|
+
obj.inflate(delta['attributes'])
|
130
|
+
obj.cursor = delta["cursor"]
|
131
|
+
yield delta["event"], obj
|
132
|
+
when 'delete'
|
133
|
+
obj.id = delta["id"]
|
134
|
+
obj.cursor = delta["cursor"]
|
135
|
+
yield delta["event"], obj
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
break if start_cursor == end_cursor
|
140
|
+
cursor = end_cursor
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
61
144
|
end
|
62
|
-
end
|
145
|
+
end
|
data/lib/restful_model.rb
CHANGED
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,153 +1,153 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.15.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Gotow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.7'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: shoulda
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rdoc
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '3.12'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.12'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: bundler
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 1.3.5
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 1.3.5
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: jeweler
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ~>
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: 1.8.4
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ~>
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 1.8.4
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: pry
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: pry-nav
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - '>='
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - '>='
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: pry-stack_explorer
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - '>='
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - '>='
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: webmock
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- -
|
143
|
+
- - '>='
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '0'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- -
|
150
|
+
- - '>='
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
description: 'Gem for interacting with the Inbox API that allows you to create and
|
@@ -160,8 +160,6 @@ extra_rdoc_files:
|
|
160
160
|
- LICENSE.txt
|
161
161
|
- README.md
|
162
162
|
files:
|
163
|
-
- LICENSE.txt
|
164
|
-
- README.md
|
165
163
|
- lib/account.rb
|
166
164
|
- lib/calendar.rb
|
167
165
|
- lib/contact.rb
|
@@ -179,6 +177,8 @@ files:
|
|
179
177
|
- lib/thread.rb
|
180
178
|
- lib/time_attr_accessor.rb
|
181
179
|
- lib/version.rb
|
180
|
+
- LICENSE.txt
|
181
|
+
- README.md
|
182
182
|
homepage: http://github.com/inboxapp/inbox-ruby
|
183
183
|
licenses:
|
184
184
|
- MIT
|
@@ -189,17 +189,17 @@ require_paths:
|
|
189
189
|
- lib
|
190
190
|
required_ruby_version: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
|
-
- -
|
192
|
+
- - '>='
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
196
|
requirements:
|
197
|
-
- -
|
197
|
+
- - '>='
|
198
198
|
- !ruby/object:Gem::Version
|
199
199
|
version: '0'
|
200
200
|
requirements: []
|
201
201
|
rubyforge_project:
|
202
|
-
rubygems_version: 2.
|
202
|
+
rubygems_version: 2.0.14
|
203
203
|
signing_key:
|
204
204
|
specification_version: 4
|
205
205
|
summary: Gem for interacting with the Inbox API
|