nylas 5.6.0 → 5.6.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bcbd7a865f3b26271776f6e5358647e8e8d9d92d29b9e33f1e942bb0153ea80
4
- data.tar.gz: 8a16ead2bc3cccb8f29dcdcf97cbb128722f0f68acf843a96788426c440fbe6c
3
+ metadata.gz: 54c46b764fd777bee7eb27539bd6dc54ad253b76a242db3cfa9c969e128c05e4
4
+ data.tar.gz: 2c0876d20db34b5796ec2d6c21c487de8d661cd6041a899604b6dcf594ffa8f1
5
5
  SHA512:
6
- metadata.gz: 2678a4be307e3870b12d605f5cac42878a884ac97e562ce9cb372d2db54135d9f12ebec4422910efff329e81f4beffa59fe485192f8974832a8d8957cf622431
7
- data.tar.gz: 8f77887a487ee85104aae6557bbdf6a39f2fd96bd5fc5265f68e7923655fed39eb2269d9a59d6fc0209ead37cc3cc8b272fbe496ad08e027e64f2c5ab841ed6e
6
+ metadata.gz: f70e5d14160b41bb0b50fddc2a17141fd16405fc9f0460a0fbdeaf7ac9ff356332a0400167322c63e7c0a1d0673a1b234a57e1427d9682c8bf88e59e0ca2a5c6
7
+ data.tar.gz: f4494a94a6bf17fc43be9af8961ce9ceb0ce9b97e76b06e598bf4214934d81561378f3519c3715a536d2b8703194bfe6ba047496e1ab425b3bdb99b18e46bc90
data/lib/nylas/draft.rb CHANGED
@@ -27,6 +27,7 @@ module Nylas
27
27
  attribute :body, :string
28
28
  attribute :starred, :boolean
29
29
  attribute :unread, :boolean
30
+ attribute :metadata, :hash
30
31
 
31
32
  has_n_of_attribute :events, :event
32
33
  has_n_of_attribute :files, :file, read_only: true
@@ -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
- def to_h(keys: attribute_definitions.keys)
32
- keys.each_with_object({}) do |key, casted_data|
33
- value = attribute_definitions[key].serialize(self[key])
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
- def serialize(keys: attribute_definitions.keys)
41
- JSON.dump(to_h(keys: keys))
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
- api_keys = keys.delete_if { |key| attribute_definitions[key].read_only == true }
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
- list.map { |item| type.serialize(item) }
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
@@ -20,6 +20,7 @@ module Nylas
20
20
  attribute :subject, :string
21
21
  attribute :body, :string
22
22
  attribute :reply_to_message_id, :string
23
+ attribute :metadata, :hash
23
24
 
24
25
  has_n_of_attribute :file_ids, :string
25
26
 
@@ -7,6 +7,6 @@ module Nylas
7
7
  attribute :name, :string
8
8
  attribute :email, :string
9
9
  attribute :comment, :string
10
- attribute :status, :string
10
+ attribute :status, :string, read_only: true
11
11
  end
12
12
  end
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nylas
4
- VERSION = "5.6.0"
4
+ VERSION = "5.6.1"
5
5
  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: 5.6.0
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-22 00:00:00.000000000 Z
11
+ date: 2021-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler