nylas 4.0.0.rc2 → 4.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +5 -5
  2. data/lib/nylas.rb +48 -5
  3. data/lib/nylas/account.rb +31 -0
  4. data/lib/nylas/api.rb +86 -2
  5. data/lib/nylas/calendar.rb +27 -0
  6. data/lib/nylas/collection.rb +46 -19
  7. data/lib/nylas/constraints.rb +12 -4
  8. data/lib/nylas/contact.rb +10 -2
  9. data/lib/nylas/current_account.rb +1 -4
  10. data/lib/nylas/delta.rb +46 -0
  11. data/lib/nylas/deltas.rb +17 -0
  12. data/lib/nylas/deltas_collection.rb +36 -0
  13. data/lib/nylas/draft.rb +51 -0
  14. data/lib/nylas/email_address.rb +1 -5
  15. data/lib/nylas/errors.rb +13 -0
  16. data/lib/nylas/event.rb +42 -0
  17. data/lib/nylas/event_collection.rb +13 -0
  18. data/lib/nylas/file.rb +58 -0
  19. data/lib/nylas/folder.rb +22 -0
  20. data/lib/nylas/http_client.rb +38 -29
  21. data/lib/nylas/im_address.rb +0 -5
  22. data/lib/nylas/label.rb +22 -0
  23. data/lib/nylas/message.rb +45 -0
  24. data/lib/nylas/message_headers.rb +25 -0
  25. data/lib/nylas/message_tracking.rb +11 -0
  26. data/lib/nylas/model.rb +75 -24
  27. data/lib/nylas/model/attributable.rb +2 -2
  28. data/lib/nylas/model/attributes.rb +3 -1
  29. data/lib/nylas/native_authentication.rb +31 -0
  30. data/lib/nylas/new_message.rb +29 -0
  31. data/lib/nylas/nylas_date.rb +5 -2
  32. data/lib/nylas/participant.rb +10 -0
  33. data/lib/nylas/phone_number.rb +0 -5
  34. data/lib/nylas/physical_address.rb +0 -5
  35. data/lib/nylas/raw_message.rb +15 -0
  36. data/lib/nylas/recurrence.rb +9 -0
  37. data/lib/nylas/rsvp.rb +18 -0
  38. data/lib/nylas/search_collection.rb +8 -0
  39. data/lib/nylas/thread.rb +52 -0
  40. data/lib/nylas/timespan.rb +18 -0
  41. data/lib/nylas/types.rb +62 -9
  42. data/lib/nylas/version.rb +1 -1
  43. data/lib/nylas/web_page.rb +0 -5
  44. data/lib/nylas/webhook.rb +19 -0
  45. metadata +31 -7
data/lib/nylas/rsvp.rb ADDED
@@ -0,0 +1,18 @@
1
+ module Nylas
2
+ # Allows RSVPing to a particular event
3
+ # @see https://docs.nylas.com/reference#rsvping-to-invitations
4
+ class Rsvp
5
+ include Model
6
+ allows_operations(creatable: true)
7
+
8
+ attribute :account_id, :string
9
+ attribute :event_id, :string
10
+ attribute :status, :string
11
+ attr_accessor :notify_participants
12
+
13
+ def save
14
+ api.execute(method: :post, path: "/send-rsvp", payload: attributes.serialize,
15
+ query: { notify_participants: notify_participants })
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ module Nylas
2
+ # Ensures our search requests hit the right path
3
+ class SearchCollection < Collection
4
+ def resources_path
5
+ "#{model.resources_path(api: api)}/search"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,52 @@
1
+ module Nylas
2
+ # Ruby representation of the Nylas /threads API
3
+ # @see https://docs.nylas.com/reference#threads
4
+ class Thread
5
+ include Model
6
+ allows_operations(searchable: true, filterable: true, listable: true, updatable: true)
7
+
8
+ self.resources_path = "/threads"
9
+
10
+ attribute :id, :string
11
+ attribute :object, :string
12
+ attribute :account_id, :string
13
+ has_n_of_attribute :draft_ids, :string
14
+ attribute :first_message_timestamp, :unix_timestamp
15
+ attribute :has_attachments, :boolean
16
+
17
+ attribute :last_message_timestamp, :unix_timestamp
18
+ attribute :last_message_received_timestamp, :unix_timestamp
19
+ attribute :last_message_sent_timestamp, :unix_timestamp
20
+
21
+ has_n_of_attribute :labels, :label
22
+ has_n_of_attribute :folders, :folder
23
+ has_n_of_attribute :message_ids, :string
24
+ has_n_of_attribute :participants, :participant
25
+ attribute :snippet, :string
26
+ attribute :starred, :boolean
27
+ attribute :subject, :string
28
+ attribute :unread, :boolean
29
+ attribute :version, :integer
30
+ attribute :folder_id, :string
31
+
32
+ has_n_of_attribute :label_ids, :string
33
+
34
+ UPDATABLE_ATTRIBUTES = %i[label_ids folder_id starred unread].freeze
35
+ def update(data)
36
+ unupdatable_attributes = data.keys.reject { |name| UPDATABLE_ATTRIBUTES.include?(name) }
37
+ unless unupdatable_attributes.empty?
38
+ raise ArgumentError, "Cannot update #{unupdatable_attributes} only " \
39
+ "#{UPDATABLE_ATTRIBUTES} are updatable"
40
+ end
41
+ super(data)
42
+ end
43
+
44
+ def starred?
45
+ starred
46
+ end
47
+
48
+ def unread?
49
+ unread
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,18 @@
1
+ module Nylas
2
+ # Structure to represent a Nylas Timespan.
3
+ # @see https://docs.nylas.com/reference#section-timespan
4
+ class Timespan
5
+ extend Forwardable
6
+
7
+ include Model::Attributable
8
+ attribute :object, :string
9
+ attribute :start_time, :unix_timestamp
10
+ attribute :end_time, :unix_timestamp
11
+
12
+ def_delegators :range, :cover?
13
+
14
+ def range
15
+ @range ||= Range.new(start_time, end_time)
16
+ end
17
+ end
18
+ end
data/lib/nylas/types.rb CHANGED
@@ -5,23 +5,29 @@ module Nylas
5
5
  @registry ||= Registry.new
6
6
  end
7
7
 
8
- # Type for attributes that are persisted in the API as a hash but exposed in ruby as a particular
9
- # structure
8
+ # Casts/Serializes data that is persisted and used natively as a Hash
10
9
  class HashType
11
10
  def serialize(object)
12
11
  object.to_h
13
12
  end
14
13
 
15
- def self.casts_to(model)
16
- @casts_to_model = model
14
+ def cast(value)
15
+ return JSON.parse(value, symbolize_names: true) if value.is_a?(String)
16
+ return value if value.respond_to?(:key)
17
17
  end
18
+ end
19
+ Types.registry[:hash] = HashType.new
18
20
 
19
- class << self
20
- attr_reader :casts_to_model
21
+ # Type for attributes that are persisted in the API as a hash but exposed in ruby as a particular
22
+ # {Model} or Model-like thing.
23
+ class ModelType
24
+ attr_accessor :model
25
+ def initialize(model:)
26
+ self.model = model
21
27
  end
22
28
 
23
- def model
24
- self.class.casts_to_model
29
+ def serialize(object)
30
+ object.to_h
25
31
  end
26
32
 
27
33
  def cast(value)
@@ -37,9 +43,13 @@ module Nylas
37
43
 
38
44
  def actual_attributes(hash)
39
45
  model.attribute_definitions.keys.each_with_object({}) do |attribute_name, attributes|
40
- attributes[attribute_name] = hash[attribute_name]
46
+ attributes[attribute_name] = hash[json_key_from_attribute_name(attribute_name)]
41
47
  end
42
48
  end
49
+
50
+ def json_key_from_attribute_name(name)
51
+ name
52
+ end
43
53
  end
44
54
 
45
55
  # Type for attributes that do not require casting/serializing/deserializing.
@@ -57,6 +67,26 @@ module Nylas
57
67
  end
58
68
  end
59
69
 
70
+ # Type for attributes represented as a unix timestamp in the API and Time in Ruby
71
+ class UnixTimestampType
72
+ def cast(object)
73
+ return object if object.is_a?(Time) || object.nil?
74
+ return Time.at(object.to_i) if object.is_a?(String)
75
+ return Time.at(object) if object.is_a?(Numeric)
76
+ return object.to_time if object.is_a?(Date)
77
+ raise TypeError, "Unable to cast #{object} to Time"
78
+ end
79
+
80
+ def deserialize(object)
81
+ cast(object)
82
+ end
83
+
84
+ def serialize(object)
85
+ object.to_i
86
+ end
87
+ end
88
+ Types.registry[:unix_timestamp] = UnixTimestampType.new
89
+
60
90
  # Type for attributes represented as an iso8601 dates in the API and Date in Ruby
61
91
  class DateType < ValueType
62
92
  def cast(value)
@@ -75,9 +105,32 @@ module Nylas
75
105
  class StringType < ValueType
76
106
  # @param value [Object] Casts the passed in object to a string using #to_s
77
107
  def cast(value)
108
+ return value if value.nil?
78
109
  value.to_s
79
110
  end
80
111
  end
81
112
  Types.registry[:string] = StringType.new
113
+
114
+ # Type for attributes represented as pure integers both within the API and in Ruby
115
+ class IntegerType < ValueType
116
+ # @param value [Object] Casts the passed in object to an integer using to_i
117
+ def cast(value)
118
+ return nil if value.nil?
119
+ value.to_i
120
+ end
121
+ end
122
+ Types.registry[:integer] = IntegerType.new
123
+
124
+ # Type for attributes represented as booleans.
125
+ class BooleanType < ValueType
126
+ # @param value [Object] Strictly casts the passed in value to a boolean (must be true, not "" or 1)
127
+ def cast(value)
128
+ return nil if value.nil?
129
+ return true if value == true
130
+ return false if value == false
131
+ raise TypeError, "#{value} must be either true or false"
132
+ end
133
+ end
134
+ Types.registry[:boolean] = BooleanType.new
82
135
  end
83
136
  end
data/lib/nylas/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Nylas
2
- VERSION = "4.0.0.rc2".freeze
2
+ VERSION = "4.0.0.rc3".freeze
3
3
  end
@@ -6,9 +6,4 @@ module Nylas
6
6
  attribute :type, :string
7
7
  attribute :url, :string
8
8
  end
9
-
10
- # Serializes, Deserializes between {WebPage} objects and a {Hash}
11
- class WebPageType < Types::HashType
12
- casts_to WebPage
13
- end
14
9
  end
@@ -0,0 +1,19 @@
1
+ module Nylas
2
+ # Represents a webhook attached to your application.
3
+ # @see https://docs.nylas.com/reference#webhooks
4
+ class Webhook
5
+ include Model
6
+ allows_operations(listable: true, showable: true)
7
+ attribute :id, :string
8
+ attribute :application_id, :string
9
+
10
+ attribute :callback_url, :string
11
+ attribute :state, :string
12
+ attribute :version, :string
13
+ has_n_of_attribute :triggers, :string
14
+
15
+ def self.resources_path(api:)
16
+ "/a/#{api.app_id}/webhooks"
17
+ end
18
+ end
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nylas
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0.rc2
4
+ version: 4.0.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nylas, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-11 00:00:00.000000000 Z
11
+ date: 2018-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,28 +72,28 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.46.0
75
+ version: 0.52.0
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
- version: 0.46.0
82
+ version: 0.52.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rubocop-rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 1.8.0
89
+ version: 1.20.1
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
- version: 1.8.0
96
+ version: 1.20.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: overcommit
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -247,28 +247,52 @@ extensions: []
247
247
  extra_rdoc_files: []
248
248
  files:
249
249
  - lib/nylas.rb
250
+ - lib/nylas/account.rb
250
251
  - lib/nylas/api.rb
252
+ - lib/nylas/calendar.rb
251
253
  - lib/nylas/collection.rb
252
254
  - lib/nylas/constraints.rb
253
255
  - lib/nylas/contact.rb
254
256
  - lib/nylas/current_account.rb
257
+ - lib/nylas/delta.rb
258
+ - lib/nylas/deltas.rb
259
+ - lib/nylas/deltas_collection.rb
260
+ - lib/nylas/draft.rb
255
261
  - lib/nylas/email_address.rb
256
262
  - lib/nylas/errors.rb
263
+ - lib/nylas/event.rb
264
+ - lib/nylas/event_collection.rb
265
+ - lib/nylas/file.rb
266
+ - lib/nylas/folder.rb
257
267
  - lib/nylas/http_client.rb
258
268
  - lib/nylas/im_address.rb
269
+ - lib/nylas/label.rb
259
270
  - lib/nylas/logging.rb
271
+ - lib/nylas/message.rb
272
+ - lib/nylas/message_headers.rb
273
+ - lib/nylas/message_tracking.rb
260
274
  - lib/nylas/model.rb
261
275
  - lib/nylas/model/attributable.rb
262
276
  - lib/nylas/model/attribute_definition.rb
263
277
  - lib/nylas/model/attributes.rb
264
278
  - lib/nylas/model/list_attribute_definition.rb
279
+ - lib/nylas/native_authentication.rb
280
+ - lib/nylas/new_message.rb
265
281
  - lib/nylas/nylas_date.rb
282
+ - lib/nylas/participant.rb
266
283
  - lib/nylas/phone_number.rb
267
284
  - lib/nylas/physical_address.rb
285
+ - lib/nylas/raw_message.rb
286
+ - lib/nylas/recurrence.rb
268
287
  - lib/nylas/registry.rb
288
+ - lib/nylas/rsvp.rb
289
+ - lib/nylas/search_collection.rb
290
+ - lib/nylas/thread.rb
291
+ - lib/nylas/timespan.rb
269
292
  - lib/nylas/types.rb
270
293
  - lib/nylas/version.rb
271
294
  - lib/nylas/web_page.rb
295
+ - lib/nylas/webhook.rb
272
296
  homepage:
273
297
  licenses:
274
298
  - MIT
@@ -295,7 +319,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
295
319
  version: 1.3.1
296
320
  requirements: []
297
321
  rubyforge_project:
298
- rubygems_version: 2.6.13
322
+ rubygems_version: 2.7.4
299
323
  signing_key:
300
324
  specification_version: 4
301
325
  summary: Gem for interacting with the Nylas API