nylas-legacy 5.17.0 → 5.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nylas-legacy/account.rb +56 -0
  3. data/lib/nylas-legacy/api.rb +265 -0
  4. data/lib/nylas-legacy/application_details.rb +13 -0
  5. data/lib/nylas-legacy/calendar.rb +46 -0
  6. data/lib/nylas-legacy/calendar_collection.rb +144 -0
  7. data/lib/nylas-legacy/categorize.rb +14 -0
  8. data/lib/nylas-legacy/collection.rb +175 -0
  9. data/lib/nylas-legacy/component.rb +35 -0
  10. data/lib/nylas-legacy/component_collection.rb +10 -0
  11. data/lib/nylas-legacy/constraints.rb +56 -0
  12. data/lib/nylas-legacy/contact.rb +53 -0
  13. data/lib/nylas-legacy/contact_group.rb +23 -0
  14. data/lib/nylas-legacy/current_account.rb +23 -0
  15. data/lib/nylas-legacy/delta.rb +56 -0
  16. data/lib/nylas-legacy/deltas.rb +19 -0
  17. data/lib/nylas-legacy/deltas_collection.rb +40 -0
  18. data/lib/nylas-legacy/draft.rb +101 -0
  19. data/lib/nylas-legacy/email_address.rb +12 -0
  20. data/lib/nylas-legacy/errors.rb +111 -0
  21. data/lib/nylas-legacy/event.rb +144 -0
  22. data/lib/nylas-legacy/event_collection.rb +15 -0
  23. data/lib/nylas-legacy/event_conferencing.rb +12 -0
  24. data/lib/nylas-legacy/event_conferencing_autocreate.rb +10 -0
  25. data/lib/nylas-legacy/event_conferencing_details.rb +14 -0
  26. data/lib/nylas-legacy/event_notification.rb +17 -0
  27. data/lib/nylas-legacy/file.rb +75 -0
  28. data/lib/nylas-legacy/filter_attributes.rb +25 -0
  29. data/lib/nylas-legacy/folder.rb +26 -0
  30. data/lib/nylas-legacy/free_busy.rb +13 -0
  31. data/lib/nylas-legacy/free_busy_collection.rb +48 -0
  32. data/lib/nylas-legacy/http_client.rb +280 -0
  33. data/lib/nylas-legacy/im_address.rb +11 -0
  34. data/lib/nylas-legacy/job_status.rb +27 -0
  35. data/lib/nylas-legacy/job_status_collection.rb +21 -0
  36. data/lib/nylas-legacy/label.rb +27 -0
  37. data/lib/nylas-legacy/logging.rb +41 -0
  38. data/lib/nylas-legacy/message.rb +98 -0
  39. data/lib/nylas-legacy/message_headers.rb +27 -0
  40. data/lib/nylas-legacy/message_tracking.rb +13 -0
  41. data/lib/nylas-legacy/model/attributable.rb +89 -0
  42. data/lib/nylas-legacy/model/attribute_definition.rb +24 -0
  43. data/lib/nylas-legacy/model/attributes.rb +97 -0
  44. data/lib/nylas-legacy/model/list_attribute_definition.rb +39 -0
  45. data/lib/nylas-legacy/model/transferable.rb +53 -0
  46. data/lib/nylas-legacy/model.rb +217 -0
  47. data/lib/nylas-legacy/native_authentication.rb +39 -0
  48. data/lib/nylas-legacy/neural.rb +87 -0
  49. data/lib/nylas-legacy/neural_categorizer.rb +29 -0
  50. data/lib/nylas-legacy/neural_clean_conversation.rb +33 -0
  51. data/lib/nylas-legacy/neural_contact_link.rb +11 -0
  52. data/lib/nylas-legacy/neural_contact_name.rb +11 -0
  53. data/lib/nylas-legacy/neural_message_options.rb +35 -0
  54. data/lib/nylas-legacy/neural_ocr.rb +16 -0
  55. data/lib/nylas-legacy/neural_sentiment_analysis.rb +17 -0
  56. data/lib/nylas-legacy/neural_signature_contact.rb +81 -0
  57. data/lib/nylas-legacy/neural_signature_extraction.rb +18 -0
  58. data/lib/nylas-legacy/new_message.rb +41 -0
  59. data/lib/nylas-legacy/nylas_date.rb +25 -0
  60. data/lib/nylas-legacy/open_hours.rb +15 -0
  61. data/lib/nylas-legacy/outbox.rb +116 -0
  62. data/lib/nylas-legacy/outbox_job_status.rb +19 -0
  63. data/lib/nylas-legacy/outbox_message.rb +17 -0
  64. data/lib/nylas-legacy/participant.rb +13 -0
  65. data/lib/nylas-legacy/phone_number.rb +11 -0
  66. data/lib/nylas-legacy/physical_address.rb +17 -0
  67. data/lib/nylas-legacy/raw_message.rb +25 -0
  68. data/lib/nylas-legacy/recurrence.rb +11 -0
  69. data/lib/nylas-legacy/registry.rb +42 -0
  70. data/lib/nylas-legacy/room_resource.rb +19 -0
  71. data/lib/nylas-legacy/rsvp.rb +24 -0
  72. data/lib/nylas-legacy/scheduler.rb +51 -0
  73. data/lib/nylas-legacy/scheduler_booking_confirmation.rb +24 -0
  74. data/lib/nylas-legacy/scheduler_booking_request.rb +17 -0
  75. data/lib/nylas-legacy/scheduler_collection.rb +104 -0
  76. data/lib/nylas-legacy/scheduler_config.rb +20 -0
  77. data/lib/nylas-legacy/scheduler_time_slot.rb +14 -0
  78. data/lib/nylas-legacy/search_collection.rb +14 -0
  79. data/lib/nylas-legacy/send_grid_verified_status.rb +12 -0
  80. data/lib/nylas-legacy/services/tunnel.rb +128 -0
  81. data/lib/nylas-legacy/thread.rb +66 -0
  82. data/lib/nylas-legacy/time_slot.rb +16 -0
  83. data/lib/nylas-legacy/time_slot_capacity.rb +13 -0
  84. data/lib/nylas-legacy/timespan.rb +20 -0
  85. data/lib/nylas-legacy/token_info.rb +20 -0
  86. data/lib/nylas-legacy/types.rb +169 -0
  87. data/lib/nylas-legacy/version.rb +5 -0
  88. data/lib/nylas-legacy/web_page.rb +11 -0
  89. data/lib/nylas-legacy/webhook.rb +111 -0
  90. data/lib/nylas-legacy/when.rb +75 -0
  91. data/lib/nylas-legacy.rb +164 -0
  92. metadata +175 -3
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NylasLegacy
4
+ # Additional methods for some of Scheduler's other functionality
5
+ # @see https://developer.nylas.com/docs/api/scheduler#overview
6
+ class SchedulerCollection < Collection
7
+ # Retrieve Google availability
8
+ # @return [Hash] Returns the availability
9
+ def get_google_availability
10
+ execute_provider_availability("google")
11
+ end
12
+
13
+ # Retrieve Office 365 availability
14
+ # @return [Hash] Returns the availability
15
+ def get_office_365_availability
16
+ execute_provider_availability("o365")
17
+ end
18
+
19
+ # Retrieve public config for a scheduling page
20
+ # @param slug [String] The Scheduler page slug
21
+ # @return [Scheduler] Returns the Scheduler object representing the page configuration
22
+ def get_page_slug(slug)
23
+ page_response = api.execute(
24
+ method: :get,
25
+ path: "/schedule/#{slug}/info"
26
+ )
27
+
28
+ Scheduler.new(**page_response.merge(api: api))
29
+ end
30
+
31
+ # Retrieve available time slots
32
+ # @param slug [String] The Scheduler page slug
33
+ # @return [Array<SchedulerTimeSlot>] Returns the list of available timeslots
34
+ def get_available_time_slots(slug)
35
+ response = api.execute(
36
+ method: :get,
37
+ path: "/schedule/#{slug}/timeslots"
38
+ )
39
+
40
+ timeslots = []
41
+ response.each do |available_slot|
42
+ timeslots.push(SchedulerTimeSlot.new(**available_slot.merge(api: api)))
43
+ end
44
+ timeslots
45
+ end
46
+
47
+ # Book a time slot
48
+ # @param slug [String] The Scheduler page slug
49
+ # @param timeslot [SchedulerBookingRequest] The time slot booking request
50
+ # @return [SchedulerBookingConfirmation] Returns the booking confirmation
51
+ def book_time_slot(slug, timeslot)
52
+ payload = timeslot.to_h
53
+ # The booking endpoint requires additional_values and additional_emails
54
+ # to exist regardless if they are empty or not
55
+ payload[:additional_values] = {} unless payload[:additional_values]
56
+ payload[:additional_emails] = [] unless payload[:additional_emails]
57
+ booking_response = api.execute(
58
+ method: :post,
59
+ path: "/schedule/#{slug}/timeslots",
60
+ payload: JSON.dump(payload)
61
+ )
62
+
63
+ SchedulerBookingConfirmation.new(**booking_response.merge(api: api))
64
+ end
65
+
66
+ # Cancel a booking
67
+ # @param slug [String] The Scheduler page slug
68
+ # @param edit_hash [String] The token used for editing the booked time slot
69
+ # @param reason [String] The reason for cancelling the booking
70
+ # @return [Hash] Returns a hash of a boolean representing success of cancellation
71
+ def cancel_booking(slug, edit_hash, reason)
72
+ api.execute(
73
+ method: :post,
74
+ path: "/schedule/#{slug}/#{edit_hash}/cancel",
75
+ payload: JSON.dump(reason: reason)
76
+ )
77
+ end
78
+
79
+ # Confirm a booking
80
+ # @param slug [String] The Scheduler page slug
81
+ # @param edit_hash [String] The token used for editing the booked time slot
82
+ # @return [SchedulerBookingConfirmation] Returns the confirmed booking confirmation
83
+ def confirm_booking(slug, edit_hash)
84
+ booking_response = api.execute(
85
+ method: :post,
86
+ path: "/schedule/#{slug}/#{edit_hash}/confirm",
87
+ payload: {}
88
+ )
89
+
90
+ SchedulerBookingConfirmation.new(**booking_response.merge(api: api))
91
+ end
92
+
93
+ private
94
+
95
+ # Retrieve provider availability
96
+ # @return [Hash] Returns the availability
97
+ def execute_provider_availability(provider)
98
+ api.execute(
99
+ method: :get,
100
+ path: "/schedule/availability/#{provider}"
101
+ )
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NylasLegacy
4
+ # Configuration settings for a Scheduler page
5
+ # @see https://developer.nylas.com/docs/api/scheduler
6
+ class SchedulerConfig
7
+ include Model::Attributable
8
+
9
+ attribute :appearance, :hash
10
+ attribute :booking, :hash
11
+ attribute :calendar_ids, :hash
12
+ attribute :event, :hash
13
+ attribute :expire_after, :hash
14
+ attribute :locale, :string
15
+ attribute :locale_for_guests, :string
16
+ attribute :timezone, :string
17
+
18
+ has_n_of_attribute :reminders, :hash
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NylasLegacy
4
+ # Structure to represent the time slot object from the Scheduler API
5
+ class SchedulerTimeSlot
6
+ include Model::Attributable
7
+ attribute :account_id, :string
8
+ attribute :calendar_id, :string
9
+ attribute :host_name, :string
10
+ attribute :start, :unix_timestamp
11
+ attribute :end, :unix_timestamp
12
+ has_n_of_attribute :emails, :string
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NylasLegacy
4
+ # Ensures our search requests hit the right path
5
+ class SearchCollection < Collection
6
+ def resources_path
7
+ "#{model.resources_path(api: api)}/search"
8
+ end
9
+
10
+ def count
11
+ self.class.new(model: model, api: api, constraints: constraints).find_each.map.count
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NylasLegacy
4
+ # Ruby representation of a Nylas Send Grid verified status object
5
+ # @see https://docs.nylas.com/reference#drafts
6
+ class SendGridVerifiedStatus
7
+ include Model::Attributable
8
+
9
+ attribute :domain_verified, :boolean
10
+ attribute :sender_verified, :boolean
11
+ end
12
+ end
@@ -0,0 +1,128 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+ require "faye/websocket"
5
+ require "eventmachine"
6
+
7
+ module NylasLegacy
8
+ # Class containing methods to spin up a developmental websocket connection to test webhooks
9
+ class Tunnel
10
+ # Open a webhook tunnel and register it with the Nylas API
11
+ # 1. Creates a UUID
12
+ # 2. Opens a websocket connection to Nylas' webhook forwarding service, with the UUID as a header
13
+ # 3. Creates a new webhook pointed at the forwarding service with the UUID as the path
14
+ # When an event is received by the forwarding service, it will push directly to this websocket connection
15
+ #
16
+ # @param api [NylasLegacy::API] The configured Nylas API client
17
+ # @param config [Hash] Configuration for the webhook tunnel, including callback functions, region, and
18
+ # events to subscribe to
19
+ def self.open_webhook_tunnel(api, config = {})
20
+ tunnel_id = SecureRandom.uuid
21
+ triggers = config[:triggers] || WebhookTrigger.constants(false).map { |c| WebhookTrigger.const_get c }
22
+ region = config[:region] || "us"
23
+ websocket_domain = "tunnel.nylas.com"
24
+ callback_domain = "cb.nylas.com"
25
+
26
+ EM.run do
27
+ setup_websocket_client(websocket_domain, api, tunnel_id, region, config)
28
+ register_webhook_callback(api, callback_domain, tunnel_id, triggers)
29
+ end
30
+ end
31
+
32
+ # Register callback with the Nylas forwarding service which will pass messages to the websocket
33
+ # @param api [NylasLegacy::API] The configured Nylas API client
34
+ # @param callback_domain [String] The domain name of the callback
35
+ # @param tunnel_path [String] The path to the tunnel
36
+ # @param triggers [Array<WebhookTrigger>] The list of triggers to subscribe to
37
+ # @return [NylasLegacy::Webhook] The webhook details response from the API
38
+ def self.register_webhook_callback(api, callback_domain, tunnel_path, triggers)
39
+ callback_url = "https://#{callback_domain}/#{tunnel_path}"
40
+
41
+ api.webhooks.create(
42
+ callback_url: callback_url,
43
+ state: WebhookState::ACTIVE,
44
+ triggers: triggers
45
+ )
46
+ end
47
+
48
+ # Setup the websocket client and register the callbacks
49
+ # @param websocket_domain [String] The domain of the websocket to connect to
50
+ # @param api [NylasLegacy::API] The configured Nylas API client
51
+ # @param tunnel_id [String] The ID of the tunnel
52
+ # @param region [String] The Nylas region to configure for
53
+ # @param config [Hash] The object containing all the callback methods
54
+ # @return [WebSocket::Client] The configured websocket client
55
+ def self.setup_websocket_client(websocket_domain, api, tunnel_id, region, config)
56
+ ws = Faye::WebSocket::Client.new(
57
+ "wss://#{websocket_domain}",
58
+ [],
59
+ {
60
+ headers: {
61
+ "Client-Id" => api.client.app_id,
62
+ "Client-Secret" => api.client.app_secret,
63
+ "Tunnel-Id" => tunnel_id,
64
+ "Region" => region
65
+ }
66
+ }
67
+ )
68
+
69
+ ws.on :open do |event|
70
+ config[:on_open].call(event) if callable(config[:on_open])
71
+ end
72
+
73
+ ws.on :close do |close|
74
+ config[:on_close].call(close) if callable(config[:on_close])
75
+ EM.stop
76
+ end
77
+
78
+ ws.on :error do |error|
79
+ config[:on_error].call(error) if callable(config[:on_error])
80
+ end
81
+
82
+ ws.on :message do |message|
83
+ deltas = parse_deltas_from_message(message)
84
+ next if deltas.nil?
85
+
86
+ deltas.each do |delta|
87
+ delta = merge_and_create_delta(delta)
88
+ config[:on_message].call(delta) if callable(config[:on_message])
89
+ end
90
+ end
91
+
92
+ ws
93
+ end
94
+
95
+ # Check if the object is a method
96
+ # @param obj [Any] The object to check
97
+ # @return [Boolean] True if the object is a method
98
+ def self.callable(obj)
99
+ !obj.nil? && obj.respond_to?(:call)
100
+ end
101
+
102
+ # Parse deltas from the message object
103
+ # @param message [Any] The message object containing the deltas
104
+ # @return [Hash] The parsed list of deltas
105
+ def self.parse_deltas_from_message(message)
106
+ return unless message.data
107
+
108
+ json = JSON.parse(message.data)
109
+ JSON.parse(json["body"])["deltas"]
110
+ end
111
+
112
+ # Clean up and create the delta object
113
+ # @param delta [Hash] The hash containing the delta attributes from the API
114
+ # @return [NylasLegacy::Delta] The delta object
115
+ def self.merge_and_create_delta(delta)
116
+ object_data = delta.delete("object_data")
117
+ attributes = object_data.delete("attributes")
118
+ object_data["object_attributes"] = attributes
119
+ delta = delta.merge(object_data).transform_keys(&:to_sym)
120
+ Delta.new(**delta)
121
+ end
122
+
123
+ private_class_method :setup_websocket_client,
124
+ :callable,
125
+ :parse_deltas_from_message,
126
+ :merge_and_create_delta
127
+ end
128
+ end
@@ -0,0 +1,66 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NylasLegacy
4
+ # Ruby representation of the Nylas /threads API
5
+ # @see https://docs.nylas.com/reference#threads
6
+ class Thread
7
+ include Model
8
+ self.searchable = true
9
+ self.listable = true
10
+ self.filterable = true
11
+ self.updatable = true
12
+ self.id_listable = true
13
+ self.countable = true
14
+
15
+ self.resources_path = "/threads"
16
+
17
+ attribute :id, :string
18
+ attribute :object, :string
19
+ attribute :account_id, :string
20
+ has_n_of_attribute :draft_ids, :string
21
+ attribute :first_message_timestamp, :unix_timestamp
22
+ attribute :has_attachments, :boolean
23
+
24
+ attribute :last_message_timestamp, :unix_timestamp
25
+ attribute :last_message_received_timestamp, :unix_timestamp
26
+ attribute :last_message_sent_timestamp, :unix_timestamp
27
+
28
+ has_n_of_attribute :labels, :label
29
+ has_n_of_attribute :folders, :folder
30
+ has_n_of_attribute :message_ids, :string
31
+ has_n_of_attribute :messages, :message
32
+ has_n_of_attribute :participants, :participant
33
+ attribute :snippet, :string
34
+ attribute :starred, :boolean
35
+ attribute :subject, :string
36
+ attribute :unread, :boolean
37
+ attribute :version, :integer
38
+ attribute :folder_id, :string
39
+
40
+ has_n_of_attribute :label_ids, :string
41
+
42
+ transfer :api, to: %i[labels folders]
43
+
44
+ UPDATABLE_ATTRIBUTES = %i[label_ids folder_id starred unread].freeze
45
+ def update(data)
46
+ unupdatable_attributes = data.keys.reject { |name| UPDATABLE_ATTRIBUTES.include?(name) }
47
+ unless unupdatable_attributes.empty?
48
+ raise ArgumentError, "Cannot update #{unupdatable_attributes} only " \
49
+ "#{UPDATABLE_ATTRIBUTES} are updatable"
50
+ end
51
+ super(**data)
52
+ end
53
+
54
+ def update_folder(folder_id)
55
+ update(folder_id: folder_id)
56
+ end
57
+
58
+ def starred?
59
+ starred
60
+ end
61
+
62
+ def unread?
63
+ unread
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NylasLegacy
4
+ # Query free/busy information for a calendar during a certain time period
5
+ # @see https://docs.nylas.com/reference#calendars-free-busy
6
+ class TimeSlot
7
+ include Model::Attributable
8
+
9
+ attribute :object, :string
10
+ attribute :status, :string
11
+ attribute :start_time, :unix_timestamp
12
+ attribute :end_time, :unix_timestamp
13
+ attribute :capacity, :time_slot_capacity
14
+ has_n_of_attribute :emails, :string
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NylasLegacy
4
+ # Capacity values for a timeslot
5
+ # @see https://docs.nylas.com/reference#calendars-free-busy
6
+ class TimeSlotCapacity
7
+ include Model::Attributable
8
+
9
+ attribute :event_id, :string
10
+ attribute :current_capacity, :integer
11
+ attribute :max_capacity, :integer
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NylasLegacy
4
+ # Structure to represent a Nylas Timespan.
5
+ # @see https://docs.nylas.com/reference#section-timespan
6
+ class Timespan
7
+ extend Forwardable
8
+
9
+ include Model::Attributable
10
+ attribute :object, :string
11
+ attribute :start_time, :unix_timestamp
12
+ attribute :end_time, :unix_timestamp
13
+
14
+ def_delegators :range, :cover?
15
+
16
+ def range
17
+ @range ||= Range.new(start_time, end_time)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NylasLegacy
4
+ # Structure to represent information about a Nylas access token.
5
+ # @see https://developer.nylas.com/docs/api/#post/a/client_id/accounts/id/token-info
6
+ class TokenInfo
7
+ include Model::Attributable
8
+
9
+ attribute :scopes, :string
10
+ attribute :state, :string
11
+ attribute :created_at, :unix_timestamp
12
+ attribute :updated_at, :unix_timestamp
13
+
14
+ # Returns the state of the token as a boolean
15
+ # @return [Boolean] If the token is active
16
+ def valid?
17
+ state == "valid"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,169 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NylasLegacy
4
+ # Collection of attribute types
5
+ module Types
6
+ def self.registry
7
+ @registry ||= Registry.new
8
+ end
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
+
29
+ # Casts/Serializes data that is persisted and used natively as a Hash
30
+ class HashType < ValueType
31
+ def serialize(object)
32
+ object.to_h
33
+ end
34
+
35
+ def cast(value)
36
+ return JSON.parse(value, symbolize_names: true) if value.is_a?(String)
37
+
38
+ value if value.respond_to?(:key)
39
+ end
40
+ end
41
+ Types.registry[:hash] = HashType.new
42
+
43
+ # Type for attributes that are persisted in the API as a hash but exposed in ruby as a particular
44
+ # {Model} or Model-like thing.
45
+ class ModelType < ValueType
46
+ attr_accessor :model
47
+
48
+ def initialize(model:)
49
+ super()
50
+ self.model = model
51
+ end
52
+
53
+ def serialize(object)
54
+ object.to_h
55
+ end
56
+
57
+ def serialize_for_api(object)
58
+ object&.to_h(enforce_read_only: true)
59
+ end
60
+
61
+ def cast(value)
62
+ return model.new if value.nil?
63
+ return value if already_cast?(value)
64
+ return model.new(**actual_attributes(value)) if value.respond_to?(:key?)
65
+
66
+ raise TypeError, "Unable to cast #{value} to a #{model}"
67
+ end
68
+
69
+ def already_cast?(value)
70
+ model.attribute_definitions.keys.all? { |attribute_name| value.respond_to?(attribute_name) }
71
+ end
72
+
73
+ def actual_attributes(hash)
74
+ model.attribute_definitions.keys.each_with_object({}) do |attribute_name, attributes|
75
+ attributes[attribute_name] = hash[json_key_from_attribute_name(attribute_name)]
76
+ end
77
+ end
78
+
79
+ def json_key_from_attribute_name(name)
80
+ name
81
+ end
82
+ end
83
+
84
+ # Type for attributes represented as a unix timestamp in the API and Time in Ruby
85
+ class UnixTimestampType < ValueType
86
+ def cast(object)
87
+ return object if object.is_a?(Time) || object.nil?
88
+ return Time.at(object.to_i) if object.is_a?(String)
89
+ return Time.at(object) if object.is_a?(Numeric)
90
+ return object.to_time if object.is_a?(Date)
91
+
92
+ raise TypeError, "Unable to cast #{object} to Time"
93
+ end
94
+
95
+ def deserialize(object)
96
+ cast(object)
97
+ end
98
+
99
+ def serialize(object)
100
+ return nil if object.nil?
101
+
102
+ object.to_i
103
+ end
104
+ end
105
+ Types.registry[:unix_timestamp] = UnixTimestampType.new
106
+
107
+ # Type for attributes represented as an iso8601 dates in the API and Date in Ruby
108
+ class DateType < ValueType
109
+ def cast(value)
110
+ return nil if value.nil?
111
+
112
+ Date.parse(value)
113
+ end
114
+
115
+ def serialize(value)
116
+ return value.iso8601 if value.respond_to?(:iso8601)
117
+
118
+ value
119
+ end
120
+ end
121
+ Types.registry[:date] = DateType.new
122
+
123
+ # Type for attributes represented as pure strings both within the API and in Ruby
124
+ class StringType < ValueType
125
+ # @param value [Object] Casts the passed in object to a string using #to_s
126
+ def cast(value)
127
+ return value if value.nil?
128
+
129
+ value.to_s
130
+ end
131
+ end
132
+ Types.registry[:string] = StringType.new
133
+
134
+ # Type for attributes represented as pure integers both within the API and in Ruby
135
+ class IntegerType < ValueType
136
+ # @param value [Object] Casts the passed in object to an integer using to_i
137
+ def cast(value)
138
+ return nil if value.nil?
139
+
140
+ value.to_i
141
+ end
142
+ end
143
+ Types.registry[:integer] = IntegerType.new
144
+
145
+ # Type for attributes represented as booleans.
146
+ class BooleanType < ValueType
147
+ # @param value [Object] Strictly casts the passed in value to a boolean (must be true, not "" or 1)
148
+ def cast(value)
149
+ return nil if value.nil?
150
+ return true if value == true
151
+ return false if value == false
152
+
153
+ raise TypeError, "#{value} must be either true or false"
154
+ end
155
+ end
156
+ Types.registry[:boolean] = BooleanType.new
157
+
158
+ # Type for attributes represented as floats.
159
+ class FloatType < ValueType
160
+ # @param value [Object] Strictly casts the passed in value to a boolean (must be true, not "" or 1)
161
+ def cast(value)
162
+ return nil if value.nil?
163
+
164
+ value.to_f
165
+ end
166
+ end
167
+ Types.registry[:float] = FloatType.new
168
+ end
169
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NylasLegacy
4
+ VERSION = "5.18.0"
5
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module NylasLegacy
4
+ # Structure to represent the Web Page Schema
5
+ # @see https://docs.nylas.com/reference#contactsid
6
+ class WebPage
7
+ include Model::Attributable
8
+ attribute :type, :string
9
+ attribute :url, :string
10
+ end
11
+ end