nylas 4.0.0.rc2 → 4.0.0.rc3
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 +5 -5
- data/lib/nylas.rb +48 -5
- data/lib/nylas/account.rb +31 -0
- data/lib/nylas/api.rb +86 -2
- data/lib/nylas/calendar.rb +27 -0
- data/lib/nylas/collection.rb +46 -19
- data/lib/nylas/constraints.rb +12 -4
- data/lib/nylas/contact.rb +10 -2
- data/lib/nylas/current_account.rb +1 -4
- data/lib/nylas/delta.rb +46 -0
- data/lib/nylas/deltas.rb +17 -0
- data/lib/nylas/deltas_collection.rb +36 -0
- data/lib/nylas/draft.rb +51 -0
- data/lib/nylas/email_address.rb +1 -5
- data/lib/nylas/errors.rb +13 -0
- data/lib/nylas/event.rb +42 -0
- data/lib/nylas/event_collection.rb +13 -0
- data/lib/nylas/file.rb +58 -0
- data/lib/nylas/folder.rb +22 -0
- data/lib/nylas/http_client.rb +38 -29
- data/lib/nylas/im_address.rb +0 -5
- data/lib/nylas/label.rb +22 -0
- data/lib/nylas/message.rb +45 -0
- data/lib/nylas/message_headers.rb +25 -0
- data/lib/nylas/message_tracking.rb +11 -0
- data/lib/nylas/model.rb +75 -24
- data/lib/nylas/model/attributable.rb +2 -2
- data/lib/nylas/model/attributes.rb +3 -1
- data/lib/nylas/native_authentication.rb +31 -0
- data/lib/nylas/new_message.rb +29 -0
- data/lib/nylas/nylas_date.rb +5 -2
- data/lib/nylas/participant.rb +10 -0
- data/lib/nylas/phone_number.rb +0 -5
- data/lib/nylas/physical_address.rb +0 -5
- data/lib/nylas/raw_message.rb +15 -0
- data/lib/nylas/recurrence.rb +9 -0
- data/lib/nylas/rsvp.rb +18 -0
- data/lib/nylas/search_collection.rb +8 -0
- data/lib/nylas/thread.rb +52 -0
- data/lib/nylas/timespan.rb +18 -0
- data/lib/nylas/types.rb +62 -9
- data/lib/nylas/version.rb +1 -1
- data/lib/nylas/web_page.rb +0 -5
- data/lib/nylas/webhook.rb +19 -0
- metadata +31 -7
data/lib/nylas/im_address.rb
CHANGED
data/lib/nylas/label.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Nylas
|
2
|
+
# Structure to represent the Label Schema
|
3
|
+
# @see https://docs.nylas.com/reference#labels
|
4
|
+
class Label
|
5
|
+
include Model
|
6
|
+
self.resources_path = "/labels"
|
7
|
+
self.creatable = true
|
8
|
+
self.listable = true
|
9
|
+
self.showable = true
|
10
|
+
self.filterable = false
|
11
|
+
self.updatable = true
|
12
|
+
self.destroyable = true
|
13
|
+
|
14
|
+
attribute :id, :string
|
15
|
+
attribute :account_id, :string
|
16
|
+
|
17
|
+
attribute :object, :string
|
18
|
+
|
19
|
+
attribute :name, :string
|
20
|
+
attribute :display_name, :string
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Nylas
|
2
|
+
# Ruby representatin of a Nylas Message object
|
3
|
+
# @see https://docs.nylas.com/reference#messages
|
4
|
+
class Message
|
5
|
+
include Model
|
6
|
+
self.raw_mime_type = "message/rfc822"
|
7
|
+
self.resources_path = "/messages"
|
8
|
+
allows_operations(showable: true, listable: true, filterable: true, searchable: true, updatable: true)
|
9
|
+
|
10
|
+
attribute :id, :string
|
11
|
+
attribute :object, :string
|
12
|
+
attribute :account_id, :string
|
13
|
+
attribute :thread_id, :string
|
14
|
+
|
15
|
+
attribute :headers, :message_headers
|
16
|
+
|
17
|
+
has_n_of_attribute :to, :email_address
|
18
|
+
has_n_of_attribute :from, :email_address
|
19
|
+
has_n_of_attribute :cc, :email_address
|
20
|
+
has_n_of_attribute :bcc, :email_address
|
21
|
+
has_n_of_attribute :reply_to, :email_address
|
22
|
+
|
23
|
+
attribute :date, :unix_timestamp
|
24
|
+
# This is only used when receiving a message received notification via a webhook
|
25
|
+
attribute :received_date, :unix_timestamp
|
26
|
+
attribute :subject, :string
|
27
|
+
attribute :snippet, :string
|
28
|
+
attribute :body, :string
|
29
|
+
attribute :starred, :boolean
|
30
|
+
attribute :unread, :boolean
|
31
|
+
|
32
|
+
has_n_of_attribute :events, :event
|
33
|
+
has_n_of_attribute :files, :file
|
34
|
+
attribute :folder, :label
|
35
|
+
has_n_of_attribute :labels, :label
|
36
|
+
|
37
|
+
def starred?
|
38
|
+
starred
|
39
|
+
end
|
40
|
+
|
41
|
+
def unread?
|
42
|
+
unread
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Nylas
|
2
|
+
# Translates message headers into a Ruby object
|
3
|
+
# @see https://docs.nylas.com/reference#section-message-views
|
4
|
+
class MessageHeaders
|
5
|
+
include Model::Attributable
|
6
|
+
attribute :in_reply_to, :string
|
7
|
+
attribute :message_id, :string
|
8
|
+
has_n_of_attribute :references, :string
|
9
|
+
end
|
10
|
+
|
11
|
+
# Serializes, Deserializes between {MessageHeaders} objects and a Hash
|
12
|
+
class MessageHeadersType < Types::ModelType
|
13
|
+
def initialize
|
14
|
+
super(model: MessageHeaders)
|
15
|
+
end
|
16
|
+
RUBY_KEY_TO_JSON_KEY_MAP = {
|
17
|
+
in_reply_to: :"In-Reply-To",
|
18
|
+
message_id: :"Message-Id",
|
19
|
+
references: :References
|
20
|
+
}.freeze
|
21
|
+
def json_key_from_attribute_name(attribute_name)
|
22
|
+
RUBY_KEY_TO_JSON_KEY_MAP.fetch(attribute_name)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Nylas
|
2
|
+
# Message tracking features
|
3
|
+
# @see https://docs.nylas.com/reference#message-tracking-overview
|
4
|
+
class MessageTracking
|
5
|
+
include Model::Attributable
|
6
|
+
attribute :links, :boolean
|
7
|
+
attribute :opens, :boolean
|
8
|
+
attribute :thread_replies, :boolean
|
9
|
+
attribute :payload, :string
|
10
|
+
end
|
11
|
+
end
|
data/lib/nylas/model.rb
CHANGED
@@ -7,33 +7,51 @@ module Nylas
|
|
7
7
|
module Model
|
8
8
|
attr_accessor :api
|
9
9
|
|
10
|
+
def model_class
|
11
|
+
self.class
|
12
|
+
end
|
13
|
+
|
10
14
|
def self.included(model)
|
11
15
|
model.include(Attributable)
|
12
16
|
model.extend(ClassMethods)
|
13
|
-
model.
|
14
|
-
model.searchable
|
15
|
-
|
17
|
+
model.extend(Forwardable)
|
18
|
+
model.def_delegators :model_class, :creatable?, :filterable?, :listable?, :searchable?, :showable?,
|
19
|
+
:updatable?, :destroyable?
|
20
|
+
model.allows_operations
|
16
21
|
end
|
17
22
|
|
18
23
|
def save
|
19
|
-
|
20
|
-
|
21
|
-
|
24
|
+
result = if persisted?
|
25
|
+
raise ModelNotUpdatableError, self unless updatable?
|
26
|
+
execute(method: :put, payload: attributes.serialize, path: resource_path)
|
22
27
|
else
|
23
|
-
|
28
|
+
create
|
24
29
|
end
|
25
30
|
attributes.merge(result)
|
26
31
|
end
|
27
32
|
|
33
|
+
def persisted?
|
34
|
+
!id.nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
def execute(method:, payload: nil, path:)
|
38
|
+
api.execute(method: method, payload: payload, path: path)
|
39
|
+
end
|
40
|
+
|
41
|
+
def create
|
42
|
+
raise ModelNotCreatableError, self unless creatable?
|
43
|
+
execute(method: :post, payload: attributes.serialize, path: resources_path)
|
44
|
+
end
|
45
|
+
|
28
46
|
def update(**data)
|
29
|
-
|
47
|
+
raise ModelNotUpdatableError, model_class unless updatable?
|
30
48
|
attributes.merge(**data)
|
31
|
-
|
49
|
+
execute(method: :put, payload: attributes.serialize(keys: data.keys), path: resource_path)
|
32
50
|
true
|
33
51
|
end
|
34
52
|
|
35
53
|
def reload
|
36
|
-
attributes.merge(
|
54
|
+
attributes.merge(execute(method: :get, path: resource_path))
|
37
55
|
true
|
38
56
|
end
|
39
57
|
|
@@ -42,11 +60,12 @@ module Nylas
|
|
42
60
|
end
|
43
61
|
|
44
62
|
def resources_path
|
45
|
-
self.class.resources_path
|
63
|
+
self.class.resources_path(api: api)
|
46
64
|
end
|
47
65
|
|
48
66
|
def destroy
|
49
|
-
|
67
|
+
raise ModelNotDestroyableError, self unless destroyable?
|
68
|
+
execute(method: :delete, path: resource_path)
|
50
69
|
end
|
51
70
|
|
52
71
|
# @return [String] JSON String of the model.
|
@@ -54,28 +73,60 @@ module Nylas
|
|
54
73
|
JSON.dump(to_h)
|
55
74
|
end
|
56
75
|
|
57
|
-
def raise_if_read_only
|
58
|
-
self.class.raise_if_read_only
|
59
|
-
end
|
60
|
-
|
61
76
|
# Allows you to narrow in exactly what kind of model you're working with
|
62
77
|
module ClassMethods
|
63
|
-
attr_accessor :
|
78
|
+
attr_accessor :raw_mime_type, :creatable, :showable, :filterable, :searchable, :listable, :updatable,
|
79
|
+
:destroyable
|
80
|
+
attr_writer :resources_path
|
81
|
+
|
82
|
+
# rubocop:disable Metrics/ParameterLists
|
83
|
+
def allows_operations(creatable: false, showable: false, listable: false, filterable: false,
|
84
|
+
searchable: false, updatable: false, destroyable: false)
|
85
|
+
|
86
|
+
self.creatable ||= creatable
|
87
|
+
self.showable ||= showable
|
88
|
+
self.listable ||= listable
|
89
|
+
self.filterable ||= filterable
|
90
|
+
self.searchable ||= searchable
|
91
|
+
self.updatable ||= updatable
|
92
|
+
self.destroyable ||= destroyable
|
93
|
+
end
|
64
94
|
|
65
|
-
|
66
|
-
|
95
|
+
# rubocop:enable Metrics/ParameterLists
|
96
|
+
def creatable?
|
97
|
+
creatable
|
67
98
|
end
|
68
99
|
|
69
|
-
def
|
70
|
-
|
100
|
+
def showable?
|
101
|
+
showable
|
102
|
+
end
|
103
|
+
|
104
|
+
def listable?
|
105
|
+
listable
|
106
|
+
end
|
107
|
+
|
108
|
+
def filterable?
|
109
|
+
filterable
|
71
110
|
end
|
72
111
|
|
73
112
|
def searchable?
|
74
|
-
searchable
|
113
|
+
searchable
|
114
|
+
end
|
115
|
+
|
116
|
+
def updatable?
|
117
|
+
updatable
|
118
|
+
end
|
119
|
+
|
120
|
+
def destroyable?
|
121
|
+
destroyable
|
122
|
+
end
|
123
|
+
|
124
|
+
def resources_path(*)
|
125
|
+
@resources_path
|
75
126
|
end
|
76
127
|
|
77
|
-
def
|
78
|
-
|
128
|
+
def exposable_as_raw?
|
129
|
+
!raw_mime_type.nil?
|
79
130
|
end
|
80
131
|
|
81
132
|
def from_json(json, api:)
|
@@ -23,14 +23,14 @@ module Nylas
|
|
23
23
|
|
24
24
|
# Methods to call when tweaking Attributable classes
|
25
25
|
module ClassMethods
|
26
|
-
# rubocop:disable
|
26
|
+
# rubocop:disable Naming/PredicateName
|
27
27
|
def has_n_of_attribute(name, type_name, exclude_when: [], default: [])
|
28
28
|
attribute_definitions[name] = ListAttributeDefinition.new(type_name: type_name,
|
29
29
|
exclude_when: exclude_when,
|
30
30
|
default: default)
|
31
31
|
define_accessors(name)
|
32
32
|
end
|
33
|
-
# rubocop:enable
|
33
|
+
# rubocop:enable Naming/PredicateName
|
34
34
|
|
35
35
|
def attribute(name, type_name, exclude_when: [], default: nil)
|
36
36
|
attribute_definitions[name] = AttributeDefinition.new(type_name: type_name,
|
@@ -19,6 +19,8 @@ module Nylas
|
|
19
19
|
|
20
20
|
private def cast(key, value)
|
21
21
|
attribute_definitions[key].cast(value)
|
22
|
+
rescue TypeError => e
|
23
|
+
raise TypeError, "#{key} #{e.message}"
|
22
24
|
end
|
23
25
|
|
24
26
|
# Merges data into the registry while casting input types correctly
|
@@ -31,7 +33,7 @@ module Nylas
|
|
31
33
|
def to_h(keys: attribute_definitions.keys)
|
32
34
|
keys.each_with_object({}) do |key, casted_data|
|
33
35
|
value = attribute_definitions[key].serialize(self[key])
|
34
|
-
casted_data[key] = value unless value.nil? || value.empty?
|
36
|
+
casted_data[key] = value unless value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Nylas
|
2
|
+
# Authenticate your application using the native interface
|
3
|
+
# @see https://docs.nylas.com/reference#native-authentication-1
|
4
|
+
class NativeAuthentication
|
5
|
+
attr_accessor :api
|
6
|
+
def initialize(api:)
|
7
|
+
self.api = api
|
8
|
+
end
|
9
|
+
|
10
|
+
def authenticate(name:, email_address:, provider:, settings:, reauth_account_id: nil)
|
11
|
+
code = retrieve_code(name: name, email_address: email_address, provider: provider,
|
12
|
+
settings: settings, reauth_account_id: reauth_account_id)
|
13
|
+
|
14
|
+
exchange_code_for_access_token(code)
|
15
|
+
end
|
16
|
+
|
17
|
+
private def retrieve_code(name:, email_address:, provider:, settings:, reauth_account_id:)
|
18
|
+
payload = { client_id: api.client.app_id, name: name, email_address: email_address,
|
19
|
+
provider: provider, settings: settings }
|
20
|
+
payload[:reauth_account_id] = reauth_account_id
|
21
|
+
response = api.execute(method: :post, path: "/connect/authorize", payload: JSON.dump(payload))
|
22
|
+
response[:code]
|
23
|
+
end
|
24
|
+
|
25
|
+
private def exchange_code_for_access_token(code)
|
26
|
+
payload = { client_id: api.client.app_id, client_secret: api.client.app_secret, code: code }
|
27
|
+
response = api.execute(method: :post, path: "/connect/token", payload: JSON.dump(payload))
|
28
|
+
response[:access_token]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Nylas
|
2
|
+
# Data structure for seending a message via the Nylas API
|
3
|
+
class NewMessage
|
4
|
+
include Model
|
5
|
+
self.creatable = false
|
6
|
+
self.showable = false
|
7
|
+
self.listable = false
|
8
|
+
self.filterable = false
|
9
|
+
self.updatable = false
|
10
|
+
self.destroyable = false
|
11
|
+
|
12
|
+
has_n_of_attribute :to, :email_address
|
13
|
+
has_n_of_attribute :from, :email_address
|
14
|
+
has_n_of_attribute :cc, :email_address
|
15
|
+
has_n_of_attribute :bcc, :email_address
|
16
|
+
|
17
|
+
attribute :subject, :string
|
18
|
+
attribute :body, :string
|
19
|
+
attribute :reply_to_message_id, :string
|
20
|
+
|
21
|
+
has_n_of_attribute :file_ids, :string
|
22
|
+
|
23
|
+
attribute :tracking, :message_tracking
|
24
|
+
|
25
|
+
def send!
|
26
|
+
Message.new(api.execute(method: :post, path: "/send", payload: to_json).merge(api: api))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/nylas/nylas_date.rb
CHANGED
@@ -11,8 +11,11 @@ module Nylas
|
|
11
11
|
end
|
12
12
|
|
13
13
|
# Serializes, Deserializes between {NylasDate} objects and a {Hash}
|
14
|
-
class NylasDateType < Types::
|
15
|
-
|
14
|
+
class NylasDateType < Types::ModelType
|
15
|
+
def initialize
|
16
|
+
super(model: NylasDate)
|
17
|
+
end
|
18
|
+
|
16
19
|
def cast(value)
|
17
20
|
value.is_a?(String) ? super({ object: "date", date: value }) : super
|
18
21
|
end
|
data/lib/nylas/phone_number.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Nylas
|
2
|
+
# Allows sending of email with nylas from an rfc822 compatible string
|
3
|
+
class RawMessage
|
4
|
+
attr_accessor :api, :mime_compatible_string
|
5
|
+
def initialize(mime_compatible_string, api:)
|
6
|
+
self.api = api
|
7
|
+
self.mime_compatible_string = mime_compatible_string
|
8
|
+
end
|
9
|
+
|
10
|
+
def send!
|
11
|
+
Message.new(api.execute(method: :post, path: "/send", payload: mime_compatible_string,
|
12
|
+
headers: { "Content-type" => "message/rfc822" }).merge(api: api))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|