nylas 5.6.0 → 5.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nylas/draft.rb +1 -0
- data/lib/nylas/model/attributable.rb +2 -2
- data/lib/nylas/model/attribute_definition.rb +1 -1
- data/lib/nylas/model/attributes.rb +32 -8
- data/lib/nylas/model/list_attribute_definition.rb +10 -2
- data/lib/nylas/new_message.rb +1 -0
- data/lib/nylas/participant.rb +1 -1
- data/lib/nylas/types.rb +27 -18
- data/lib/nylas/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54c46b764fd777bee7eb27539bd6dc54ad253b76a242db3cfa9c969e128c05e4
|
4
|
+
data.tar.gz: 2c0876d20db34b5796ec2d6c21c487de8d661cd6041a899604b6dcf594ffa8f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f70e5d14160b41bb0b50fddc2a17141fd16405fc9f0460a0fbdeaf7ac9ff356332a0400167322c63e7c0a1d0673a1b234a57e1427d9682c8bf88e59e0ca2a5c6
|
7
|
+
data.tar.gz: f4494a94a6bf17fc43be9af8961ce9ceb0ce9b97e76b06e598bf4214934d81561378f3519c3715a536d2b8703194bfe6ba047496e1ab425b3bdb99b18e46bc90
|
data/lib/nylas/draft.rb
CHANGED
@@ -17,8 +17,8 @@ module Nylas
|
|
17
17
|
end
|
18
18
|
|
19
19
|
# @return [Hash] Representation of the model with values serialized into primitives based on their Type
|
20
|
-
def to_h
|
21
|
-
attributes.to_h
|
20
|
+
def to_h(enforce_read_only: false)
|
21
|
+
attributes.to_h(enforce_read_only: enforce_read_only)
|
22
22
|
end
|
23
23
|
|
24
24
|
protected
|
@@ -5,7 +5,7 @@ module Nylas
|
|
5
5
|
# Define a particular attribute for a given model
|
6
6
|
class AttributeDefinition
|
7
7
|
extend Forwardable
|
8
|
-
def_delegators :type, :cast, :serialize
|
8
|
+
def_delegators :type, :cast, :serialize, :serialize_for_api
|
9
9
|
attr_accessor :type_name, :read_only, :default
|
10
10
|
|
11
11
|
def initialize(type_name:, read_only:, default:)
|
@@ -28,23 +28,34 @@ module Nylas
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
# Convert the object to hash
|
32
|
+
# @param keys [Array<String>] The keys included
|
33
|
+
# @param enforce_read_only [Boolean] Whether to enforce read_only property (serializing for API)
|
34
|
+
# @return [Hash] The hash representation of the object
|
35
|
+
def to_h(keys: attribute_definitions.keys, enforce_read_only: false)
|
36
|
+
casted_data = {}
|
37
|
+
keys.each do |key|
|
38
|
+
value = attribute_to_hash(key, enforce_read_only)
|
34
39
|
# If the value is an empty hash but we specify that it is valid (via default value), serialize it
|
35
40
|
casted_data[key] = value unless value.nil? || (value.respond_to?(:empty?) && value.empty? &&
|
36
41
|
!(attribute_definitions[key].default == value && value.is_a?(Hash)))
|
37
42
|
end
|
43
|
+
casted_data
|
38
44
|
end
|
39
45
|
|
40
|
-
|
41
|
-
|
46
|
+
# Serialize the object
|
47
|
+
# @param keys [Array<String>] The keys included
|
48
|
+
# @param enforce_read_only [Boolean] Whether to enforce read_only property (serializing for API)
|
49
|
+
# @return [String] The serialized object as a JSON string
|
50
|
+
def serialize(keys: attribute_definitions.keys, enforce_read_only: false)
|
51
|
+
JSON.dump(to_h(keys: keys, enforce_read_only: enforce_read_only))
|
42
52
|
end
|
43
53
|
|
54
|
+
# Serialize the object to an API-compatible JSON string
|
55
|
+
# @param keys [Array<String>] The keys included
|
56
|
+
# @return [String] The serialized object as a JSON string
|
44
57
|
def serialize_for_api(keys: attribute_definitions.keys)
|
45
|
-
|
46
|
-
|
47
|
-
serialize(keys: api_keys)
|
58
|
+
serialize(keys: keys, enforce_read_only: true)
|
48
59
|
end
|
49
60
|
|
50
61
|
def serialize_all_for_api(keys: attribute_definitions.keys)
|
@@ -68,6 +79,19 @@ module Nylas
|
|
68
79
|
def default_attributes
|
69
80
|
attribute_definitions.keys.zip([]).to_h
|
70
81
|
end
|
82
|
+
|
83
|
+
# Convert the attribute value as a hash
|
84
|
+
# @param key [String] The attribute's key
|
85
|
+
# @param enforce_read_only [Boolean] Whether to enforce read_only property (serializing for API)
|
86
|
+
# @return [nil | Hash] The appropriately serialized value
|
87
|
+
def attribute_to_hash(key, enforce_read_only)
|
88
|
+
attribute_definition = attribute_definitions[key]
|
89
|
+
if enforce_read_only
|
90
|
+
attribute_definition.read_only == true ? nil : attribute_definition.serialize_for_api(self[key])
|
91
|
+
else
|
92
|
+
attribute_definition.serialize(self[key])
|
93
|
+
end
|
94
|
+
end
|
71
95
|
end
|
72
96
|
end
|
73
97
|
end
|
@@ -18,9 +18,17 @@ module Nylas
|
|
18
18
|
list.map { |item| type.cast(item) }
|
19
19
|
end
|
20
20
|
|
21
|
-
def serialize(list)
|
21
|
+
def serialize(list, enforce_read_only: false)
|
22
22
|
list = default if list.nil? || list.empty?
|
23
|
-
|
23
|
+
if enforce_read_only
|
24
|
+
list.map { |item| type.serialize_for_api(item) }
|
25
|
+
else
|
26
|
+
list.map { |item| type.serialize(item) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def serialize_for_api(list)
|
31
|
+
serialize(list, enforce_read_only: true)
|
24
32
|
end
|
25
33
|
|
26
34
|
def type
|
data/lib/nylas/new_message.rb
CHANGED
data/lib/nylas/participant.rb
CHANGED
data/lib/nylas/types.rb
CHANGED
@@ -7,8 +7,27 @@ module Nylas
|
|
7
7
|
@registry ||= Registry.new
|
8
8
|
end
|
9
9
|
|
10
|
+
# Base type for attributes
|
11
|
+
class ValueType
|
12
|
+
def cast(object)
|
13
|
+
object
|
14
|
+
end
|
15
|
+
|
16
|
+
def serialize(object)
|
17
|
+
object
|
18
|
+
end
|
19
|
+
|
20
|
+
def deseralize(object)
|
21
|
+
object
|
22
|
+
end
|
23
|
+
|
24
|
+
def serialize_for_api(object)
|
25
|
+
serialize(object)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
10
29
|
# Casts/Serializes data that is persisted and used natively as a Hash
|
11
|
-
class HashType
|
30
|
+
class HashType < ValueType
|
12
31
|
def serialize(object)
|
13
32
|
object.to_h
|
14
33
|
end
|
@@ -22,10 +41,11 @@ module Nylas
|
|
22
41
|
|
23
42
|
# Type for attributes that are persisted in the API as a hash but exposed in ruby as a particular
|
24
43
|
# {Model} or Model-like thing.
|
25
|
-
class ModelType
|
44
|
+
class ModelType < ValueType
|
26
45
|
attr_accessor :model
|
27
46
|
|
28
47
|
def initialize(model:)
|
48
|
+
super()
|
29
49
|
self.model = model
|
30
50
|
end
|
31
51
|
|
@@ -33,6 +53,10 @@ module Nylas
|
|
33
53
|
object.to_h
|
34
54
|
end
|
35
55
|
|
56
|
+
def serialize_for_api(object)
|
57
|
+
object&.to_h(enforce_read_only: true)
|
58
|
+
end
|
59
|
+
|
36
60
|
def cast(value)
|
37
61
|
return model.new if value.nil?
|
38
62
|
return value if already_cast?(value)
|
@@ -56,23 +80,8 @@ module Nylas
|
|
56
80
|
end
|
57
81
|
end
|
58
82
|
|
59
|
-
# Type for attributes that do not require casting/serializing/deserializing.
|
60
|
-
class ValueType
|
61
|
-
def cast(object)
|
62
|
-
object
|
63
|
-
end
|
64
|
-
|
65
|
-
def serialize(object)
|
66
|
-
object
|
67
|
-
end
|
68
|
-
|
69
|
-
def deseralize(object)
|
70
|
-
object
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
83
|
# Type for attributes represented as a unix timestamp in the API and Time in Ruby
|
75
|
-
class UnixTimestampType
|
84
|
+
class UnixTimestampType < ValueType
|
76
85
|
def cast(object)
|
77
86
|
return object if object.is_a?(Time) || object.nil?
|
78
87
|
return Time.at(object.to_i) if object.is_a?(String)
|
data/lib/nylas/version.rb
CHANGED
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: 5.6.
|
4
|
+
version: 5.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nylas, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|