From 1cf2d3d78894fe4f0c961be00af6ef8e6a61254f Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Tue, 12 Mar 2019 10:44:40 +0100 Subject: [PATCH] Rubocop auto-corrected --- Gemfile | 2 ++ bin/rspec | 2 +- bin/rubocop | 2 +- bin/yard | 2 +- bin/yardoc | 2 +- bin/yri | 2 +- gem_config.rb | 12 +++++++----- lib/nylas-streaming.rb | 3 +++ lib/nylas.rb | 2 ++ lib/nylas/account.rb | 2 ++ lib/nylas/api.rb | 5 ++++- lib/nylas/calendar.rb | 2 ++ lib/nylas/collection.rb | 9 +++++++++ lib/nylas/constraints.rb | 3 +++ lib/nylas/contact.rb | 3 +++ lib/nylas/contact_group.rb | 2 ++ lib/nylas/current_account.rb | 2 ++ lib/nylas/delta.rb | 3 +++ lib/nylas/deltas.rb | 2 ++ lib/nylas/deltas_collection.rb | 3 +++ lib/nylas/draft.rb | 2 ++ lib/nylas/email_address.rb | 2 ++ lib/nylas/errors.rb | 2 ++ lib/nylas/event.rb | 2 ++ lib/nylas/event_collection.rb | 2 ++ lib/nylas/file.rb | 5 +++++ lib/nylas/folder.rb | 2 ++ lib/nylas/http_client.rb | 18 ++++++++++-------- lib/nylas/im_address.rb | 2 ++ lib/nylas/label.rb | 2 ++ lib/nylas/logging.rb | 3 +++ lib/nylas/message.rb | 2 ++ lib/nylas/message_headers.rb | 2 ++ lib/nylas/message_tracking.rb | 2 ++ lib/nylas/model.rb | 6 ++++++ lib/nylas/model/attributable.rb | 2 ++ lib/nylas/model/attribute_definition.rb | 2 ++ lib/nylas/model/attributes.rb | 2 ++ lib/nylas/model/list_attribute_definition.rb | 3 +++ lib/nylas/native_authentication.rb | 4 +++- lib/nylas/new_message.rb | 2 ++ lib/nylas/nylas_date.rb | 2 ++ lib/nylas/participant.rb | 2 ++ lib/nylas/phone_number.rb | 2 ++ lib/nylas/physical_address.rb | 2 ++ lib/nylas/raw_message.rb | 2 ++ lib/nylas/recurrence.rb | 2 ++ lib/nylas/registry.rb | 2 ++ lib/nylas/rsvp.rb | 2 ++ lib/nylas/search_collection.rb | 2 ++ lib/nylas/thread.rb | 2 ++ lib/nylas/timespan.rb | 2 ++ lib/nylas/types.rb | 9 +++++++++ lib/nylas/version.rb | 4 +++- lib/nylas/web_page.rb | 2 ++ lib/nylas/webhook.rb | 2 ++ nylas-streaming.gemspec | 2 ++ nylas.gemspec | 2 ++ spec/nylas/account_spec.rb | 4 +++- spec/nylas/api_spec.rb | 2 ++ spec/nylas/collection_spec.rb | 10 ++++++---- spec/nylas/contact_spec.rb | 4 +++- spec/nylas/current_account_spec.rb | 2 ++ spec/nylas/deltas_collection_spec.rb | 2 ++ spec/nylas/deltas_spec.rb | 2 ++ spec/nylas/draft_spec.rb | 2 ++ spec/nylas/folder_spec.rb | 2 ++ spec/nylas/label_spec.rb | 2 ++ spec/nylas/message_spec.rb | 2 ++ spec/nylas/model_spec.rb | 2 ++ spec/nylas/native_authentication_spec.rb | 20 +++++++++++--------- spec/nylas/thread_spec.rb | 2 ++ spec/spec_helper.rb | 2 ++ tasks/rspec.rake | 2 ++ 74 files changed, 203 insertions(+), 36 deletions(-) diff --git a/Gemfile b/Gemfile index 651e15b7..f9ce3016 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source "https://rubygems.org" gemspec name: "nylas-streaming" diff --git a/bin/rspec b/bin/rspec index 94449d27..aeb8c15f 100755 --- a/bin/rspec +++ b/bin/rspec @@ -8,7 +8,7 @@ # this file is here to facilitate running it. # -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path("bundle", __dir__) load(bundle_binstub) if File.file?(bundle_binstub) require "pathname" diff --git a/bin/rubocop b/bin/rubocop index 9f4e0ca5..95122cb3 100755 --- a/bin/rubocop +++ b/bin/rubocop @@ -8,7 +8,7 @@ # this file is here to facilitate running it. # -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path("bundle", __dir__) load(bundle_binstub) if File.file?(bundle_binstub) require "pathname" diff --git a/bin/yard b/bin/yard index ee6b6d28..f667663b 100755 --- a/bin/yard +++ b/bin/yard @@ -8,7 +8,7 @@ # this file is here to facilitate running it. # -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path("bundle", __dir__) load(bundle_binstub) if File.file?(bundle_binstub) require "pathname" diff --git a/bin/yardoc b/bin/yardoc index 2fa863a2..bc9cfe3f 100755 --- a/bin/yardoc +++ b/bin/yardoc @@ -8,7 +8,7 @@ # this file is here to facilitate running it. # -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path("bundle", __dir__) load(bundle_binstub) if File.file?(bundle_binstub) require "pathname" diff --git a/bin/yri b/bin/yri index dbecba48..de7081d0 100755 --- a/bin/yri +++ b/bin/yri @@ -8,7 +8,7 @@ # this file is here to facilitate running it. # -bundle_binstub = File.expand_path("../bundle", __FILE__) +bundle_binstub = File.expand_path("bundle", __dir__) load(bundle_binstub) if File.file?(bundle_binstub) require "pathname" diff --git a/gem_config.rb b/gem_config.rb index 81edb3bd..c47047b6 100644 --- a/gem_config.rb +++ b/gem_config.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "./lib/nylas/version" # Consistently apply nylas' standard gem data across gems @@ -23,12 +25,12 @@ def self.append_nylas_data(gem) def self.metadata { - "bug_tracker_uri" => "https://github.com/nylas/nylas-ruby/issues", - "changelog_uri" => "https://github.com/nylas/nylas-ruby/blob/master/CHANGELOG.md", + "bug_tracker_uri" => "https://github.com/nylas/nylas-ruby/issues", + "changelog_uri" => "https://github.com/nylas/nylas-ruby/blob/master/CHANGELOG.md", "documentation_uri" => "http://www.rubydoc.info/gems/nylas", - "homepage_uri" => "https://www.nylas.com", - "source_code_uri" => "https://github.com/nylas/nylas-ruby", - "wiki_uri" => "https://github.com/nylas/nylas-ruby/wiki" + "homepage_uri" => "https://www.nylas.com", + "source_code_uri" => "https://github.com/nylas/nylas-ruby", + "wiki_uri" => "https://github.com/nylas/nylas-ruby/wiki" } end diff --git a/lib/nylas-streaming.rb b/lib/nylas-streaming.rb index a869fa71..bfe94406 100644 --- a/lib/nylas-streaming.rb +++ b/lib/nylas-streaming.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "yajl" require "em-http" require "nylas" @@ -72,6 +74,7 @@ def http_error_handler(client) def parser return @parser if @parser + @parser = Yajl::Parser.new(symbolize_keys: true) @parser end diff --git a/lib/nylas.rb b/lib/nylas.rb index 8f82db6c..27e1a64b 100644 --- a/lib/nylas.rb +++ b/lib/nylas.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "json" require "rest-client" diff --git a/lib/nylas/account.rb b/lib/nylas/account.rb index ff3e5876..f5e051dd 100644 --- a/lib/nylas/account.rb +++ b/lib/nylas/account.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Representation of the accounts for Account management purposes. # @see https://docs.nylas.com/reference#account-management diff --git a/lib/nylas/api.rb b/lib/nylas/api.rb index 86e77350..32f8b6fb 100644 --- a/lib/nylas/api.rb +++ b/lib/nylas/api.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Methods to retrieve data from the Nylas API as Ruby objects class API @@ -32,7 +34,7 @@ def authenticate(name:, email_address:, provider:, settings:, reauth_account_id: provider: provider, settings: settings, reauth_account_id: reauth_account_id, - scopes: scopes, + scopes: scopes ) end @@ -126,6 +128,7 @@ def webhooks private def prevent_calling_if_missing_access_token(method_name) return if client.access_token && !client.access_token.empty? + raise NoAuthToken, method_name end end diff --git a/lib/nylas/calendar.rb b/lib/nylas/calendar.rb index 848700fe..f5384785 100644 --- a/lib/nylas/calendar.rb +++ b/lib/nylas/calendar.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Ruby bindings for the Nylas Calendar API # @see https://docs.nylas.com/reference#calendars diff --git a/lib/nylas/collection.rb b/lib/nylas/collection.rb index 93fc166e..9e717a5e 100644 --- a/lib/nylas/collection.rb +++ b/lib/nylas/collection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # An enumerable for working with index and search endpoints class Collection @@ -27,11 +29,13 @@ def create(**attributes) # @return [Collection] def where(filters) raise ModelNotFilterableError, model unless model.filterable? + self.class.new(model: model, api: api, constraints: constraints.merge(where: filters)) end def search(query) raise ModelNotSearchableError, model unless model.searchable? + SearchCollection.new(model: model, api: api, constraints: constraints.merge(where: { q: query })) end @@ -40,6 +44,7 @@ def search(query) # @return [Collection] def raw raise ModelNotAvailableAsRawError, model unless model.exposable_as_raw? + self.class.new(model: model, api: api, constraints: constraints.merge(accept: model.raw_mime_type)) end @@ -61,6 +66,7 @@ def ids # Iterates over a single page of results based upon current pagination settings def each return enum_for(:each) unless block_given? + execute.each do |result| yield(model.new(result.merge(api: api))) end @@ -77,6 +83,7 @@ def offset(start) # Iterates over every result that meets the filters, retrieving a page at a time def find_each return enum_for(:find_each) unless block_given? + query = self accumulated = 0 @@ -92,6 +99,7 @@ def find_each def next_page(accumulated:, current_page:) return nil unless more_pages?(accumulated, current_page) + self.class.new(model: model, api: api, constraints: constraints.next_page) end @@ -99,6 +107,7 @@ def more_pages?(accumulated, current_page) return false if current_page.empty? return false if constraints.limit && accumulated >= constraints.limit return false if constraints.per_page && current_page.length < constraints.per_page + true end diff --git a/lib/nylas/constraints.rb b/lib/nylas/constraints.rb index eb7de556..0601e583 100644 --- a/lib/nylas/constraints.rb +++ b/lib/nylas/constraints.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # The constraints a particular GET request will include in their query params class Constraints @@ -48,6 +50,7 @@ def self.from_constraints(constraints = Constraints.new) return constraints if constraints.is_a?(Constraints) return new(**constraints) if constraints.respond_to?(:key?) return new if constraints.nil? + raise TypeError, "passed in constraints #{constraints} cannot be cast to a set of constraints" end end diff --git a/lib/nylas/contact.rb b/lib/nylas/contact.rb index aeef48c7..7e757f8a 100644 --- a/lib/nylas/contact.rb +++ b/lib/nylas/contact.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # ActiveModel compliant interface for interacting with the Contacts API # @see https://docs.nylas.com/reference#contacts @@ -40,6 +42,7 @@ class Contact # to retrieve it from nylas every time. def picture return @picture_tempfile if @picture_tempfile + @picture_tempfile = Tempfile.new @picture_tempfile.write(api.get(path: "#{resource_path}/picture")) @picture_tempfile.close diff --git a/lib/nylas/contact_group.rb b/lib/nylas/contact_group.rb index cd1bf6b2..12b1f1f2 100644 --- a/lib/nylas/contact_group.rb +++ b/lib/nylas/contact_group.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Structure to represent the Contact Group schema # @see https://docs.nylas.com/reference#contactsid diff --git a/lib/nylas/current_account.rb b/lib/nylas/current_account.rb index 36933c55..cf7a7ee5 100644 --- a/lib/nylas/current_account.rb +++ b/lib/nylas/current_account.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Ruby representation of the Nylas /account API # @see https://docs.nylas.com/reference#account diff --git a/lib/nylas/delta.rb b/lib/nylas/delta.rb index 0603ced3..ace5e453 100644 --- a/lib/nylas/delta.rb +++ b/lib/nylas/delta.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Ruby object to represent a single change. Used both when receiving a webhook, as well as the deltas API. # @see https://docs.nylas.com/reference#receiving-notifications @@ -18,6 +20,7 @@ class Delta def model return nil if object.nil? + @model ||= Types.registry[object.to_sym].cast(object_attributes_with_ids) end diff --git a/lib/nylas/deltas.rb b/lib/nylas/deltas.rb index a59742b6..35d046af 100644 --- a/lib/nylas/deltas.rb +++ b/lib/nylas/deltas.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Ruby object to represent a collection of changes. Used both when receiving a webhook, as well as the # deltas API. diff --git a/lib/nylas/deltas_collection.rb b/lib/nylas/deltas_collection.rb index 002e3549..1f2a5ecd 100644 --- a/lib/nylas/deltas_collection.rb +++ b/lib/nylas/deltas_collection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Special collection for delta objects class DeltasCollection < Collection @@ -24,6 +26,7 @@ def since(cursor) def next_page(*) return nil if empty? + where(cursor: cursor_end) end diff --git a/lib/nylas/draft.rb b/lib/nylas/draft.rb index 3a64dd8a..49ab5c6d 100644 --- a/lib/nylas/draft.rb +++ b/lib/nylas/draft.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Ruby representatin of a Nylas Draft object # @see https://docs.nylas.com/reference#drafts diff --git a/lib/nylas/email_address.rb b/lib/nylas/email_address.rb index b0121a0b..8caf6f17 100644 --- a/lib/nylas/email_address.rb +++ b/lib/nylas/email_address.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Structure to represent the Email Address Schema # @see https://docs.nylas.com/reference#contactsid diff --git a/lib/nylas/errors.rb b/lib/nylas/errors.rb index 1642ff76..ddbbfbab 100644 --- a/lib/nylas/errors.rb +++ b/lib/nylas/errors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas Error = Class.new(::StandardError) diff --git a/lib/nylas/event.rb b/lib/nylas/event.rb index f6d0b6b2..ccbdc118 100644 --- a/lib/nylas/event.rb +++ b/lib/nylas/event.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Structure to represent a the Event Schema. # @see https://docs.nylas.com/reference#events diff --git a/lib/nylas/event_collection.rb b/lib/nylas/event_collection.rb index dbc5a2fd..451ecbe6 100644 --- a/lib/nylas/event_collection.rb +++ b/lib/nylas/event_collection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Syntactical sugar methods for some of the Event's filters # @see https://docs.nylas.com/reference#get-events diff --git a/lib/nylas/file.rb b/lib/nylas/file.rb index bac57ad0..058891ea 100644 --- a/lib/nylas/file.rb +++ b/lib/nylas/file.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Structure to represent a the File Schema. # @see https://docs.nylas.com/reference#events @@ -22,12 +24,14 @@ class File # @return [Tempfile] - Local copy of the file def download return file if file + self.file = retrieve_file end # Redownloads a file even if it's been cached. Closes and unlinks the tempfile to help memory usage. def download! return download if file.nil? + file.close file.unlink self.file = nil @@ -40,6 +44,7 @@ def create def save raise ModelNotUpdatableError if persisted? + response = api.execute(path: "/files", method: :post, headers: { multipart: true }, payload: { file: file }) attributes.merge(response.first) diff --git a/lib/nylas/folder.rb b/lib/nylas/folder.rb index c830f432..3bbca6cc 100644 --- a/lib/nylas/folder.rb +++ b/lib/nylas/folder.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Structure to represent the Folder Schema # @see https://docs.nylas.com/reference#folders diff --git a/lib/nylas/http_client.rb b/lib/nylas/http_client.rb index 2a727799..8b26182c 100644 --- a/lib/nylas/http_client.rb +++ b/lib/nylas/http_client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Plain HTTP client that can be used to interact with the Nylas API sans any type casting. class HttpClient @@ -16,12 +18,12 @@ class HttpClient }.freeze ENDPOINT_TIMEOUTS = { - "/oauth/authorize" => 345, - "/messages/search" => 350, - "/threads/search" => 350, - "/delta" => 3650, - "/delta/longpoll" => 3650, - "/delta/streaming" => 3650 + "/oauth/authorize" => 345, + "/messages/search" => 350, + "/threads/search" => 350, + "/delta" => 3650, + "/delta/longpoll" => 3650, + "/delta/streaming" => 3650 }.freeze include Logging @@ -43,6 +45,7 @@ def initialize(app_id:, app_secret:, access_token: nil, api_server: "https://api unless api_server.include?("://") raise "When overriding the Nylas API server address, you must include https://" end + @api_server = api_server @access_token = access_token @app_secret = app_secret @@ -90,7 +93,6 @@ def build_request(method:, path: nil, headers: {}, query: {}, payload: nil, time resulting_headers = default_headers.merge(headers) { method: method, url: url, payload: payload, headers: resulting_headers, timeout: timeout } end - # rubocop:enable Metrics/ParameterLists # Syntactical sugar for making GET requests via the API. # @see #execute @@ -115,7 +117,6 @@ def put(path: nil, payload:, headers: {}, query: {}) def delete(path: nil, payload: nil, headers: {}, query: {}) execute(method: :delete, path: path, headers: headers, query: query, payload: payload) end - # rubocop:enable Metrics/ParameterList private def rest_client_execute(method:, url:, headers:, payload:, timeout:, &block) ::RestClient::Request.execute(method: method, url: url, payload: payload, @@ -155,6 +156,7 @@ def url_for_path(path) private def handle_anticipated_failure_mode(http_code:, response:) return if http_code == 200 return unless response.is_a?(Hash) + exception = HTTP_CODE_TO_EXCEPTIONS.fetch(http_code, APIError) raise exception.new(response[:type], response[:message], response.fetch(:server_error, nil)) end diff --git a/lib/nylas/im_address.rb b/lib/nylas/im_address.rb index be4d3d98..9d55936f 100644 --- a/lib/nylas/im_address.rb +++ b/lib/nylas/im_address.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Structure to represent the IM Address Schema # @see https://docs.nylas.com/reference#contactsid diff --git a/lib/nylas/label.rb b/lib/nylas/label.rb index ce691de1..1ee6755d 100644 --- a/lib/nylas/label.rb +++ b/lib/nylas/label.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Structure to represent the Label Schema # @see https://docs.nylas.com/reference#labels diff --git a/lib/nylas/logging.rb b/lib/nylas/logging.rb index 0443c040..17cd673a 100644 --- a/lib/nylas/logging.rb +++ b/lib/nylas/logging.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # We are explicitely choosing to allow clients to use or not use informed at their discretion # rubocop:disable Lint/HandleExceptions begin @@ -20,6 +22,7 @@ def self.included(object) def self.logger return @logger if @logger + @logger = Logger.new(STDOUT) @logger.level = level @logger diff --git a/lib/nylas/message.rb b/lib/nylas/message.rb index 53cae7e6..dfb681c6 100644 --- a/lib/nylas/message.rb +++ b/lib/nylas/message.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Ruby representatin of a Nylas Message object # @see https://docs.nylas.com/reference#messages diff --git a/lib/nylas/message_headers.rb b/lib/nylas/message_headers.rb index 7ed2145d..28bf844c 100644 --- a/lib/nylas/message_headers.rb +++ b/lib/nylas/message_headers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Translates message headers into a Ruby object # @see https://docs.nylas.com/reference#section-message-views diff --git a/lib/nylas/message_tracking.rb b/lib/nylas/message_tracking.rb index 79227235..c1c0a130 100644 --- a/lib/nylas/message_tracking.rb +++ b/lib/nylas/message_tracking.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Message tracking features # @see https://docs.nylas.com/reference#message-tracking-overview diff --git a/lib/nylas/model.rb b/lib/nylas/model.rb index cd258d0d..d46d0026 100644 --- a/lib/nylas/model.rb +++ b/lib/nylas/model.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "model/attribute_definition" require_relative "model/list_attribute_definition" require_relative "model/attributable" @@ -23,6 +25,7 @@ def self.included(model) def save result = if persisted? raise ModelNotUpdatableError, self unless updatable? + execute(method: :put, payload: attributes.serialize, path: resource_path) else create @@ -40,11 +43,13 @@ def execute(method:, payload: nil, path:) def create raise ModelNotCreatableError, self unless creatable? + execute(method: :post, payload: attributes.serialize, path: resources_path) end def update(**data) raise ModelNotUpdatableError, model_class unless updatable? + attributes.merge(**data) execute(method: :put, payload: attributes.serialize(keys: data.keys), path: resource_path) true @@ -67,6 +72,7 @@ def resources_path def destroy raise ModelNotDestroyableError, self unless destroyable? + execute(method: :delete, path: resource_path) end diff --git a/lib/nylas/model/attributable.rb b/lib/nylas/model/attributable.rb index b0bfd371..ab94c8b3 100644 --- a/lib/nylas/model/attributable.rb +++ b/lib/nylas/model/attributable.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas module Model # Allows defining of tyypecastable attributes on a model diff --git a/lib/nylas/model/attribute_definition.rb b/lib/nylas/model/attribute_definition.rb index fd7be6f7..eb4a7af6 100644 --- a/lib/nylas/model/attribute_definition.rb +++ b/lib/nylas/model/attribute_definition.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas module Model # Define a particular attribute for a given model diff --git a/lib/nylas/model/attributes.rb b/lib/nylas/model/attributes.rb index a7eb324f..01ad2915 100644 --- a/lib/nylas/model/attributes.rb +++ b/lib/nylas/model/attributes.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas module Model # Stores the actual model data to allow for type casting and clean/dirty checking diff --git a/lib/nylas/model/list_attribute_definition.rb b/lib/nylas/model/list_attribute_definition.rb index 233f574b..83c9ed32 100644 --- a/lib/nylas/model/list_attribute_definition.rb +++ b/lib/nylas/model/list_attribute_definition.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas module Model # Allows models to have an attribute which is a lists of another type of thing @@ -12,6 +14,7 @@ def initialize(type_name:, exclude_when:, default:) def cast(list) return default if list.nil? || list.empty? + list.map { |item| type.cast(item) } end diff --git a/lib/nylas/native_authentication.rb b/lib/nylas/native_authentication.rb index 8e458e54..498d604d 100644 --- a/lib/nylas/native_authentication.rb +++ b/lib/nylas/native_authentication.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Authenticate your application using the native interface # @see https://docs.nylas.com/reference#native-authentication-1 @@ -9,7 +11,7 @@ def initialize(api:) def authenticate(name:, email_address:, provider:, settings:, reauth_account_id: nil, scopes: nil) - scopes ||= ["email", "calendar", "contacts"] + scopes ||= %w[email calendar contacts] scopes = scopes.join(",") unless scopes.is_a?(String) code = retrieve_code(name: name, email_address: email_address, provider: provider, settings: settings, reauth_account_id: reauth_account_id, scopes: scopes) diff --git a/lib/nylas/new_message.rb b/lib/nylas/new_message.rb index 15e3337c..96d7efb0 100644 --- a/lib/nylas/new_message.rb +++ b/lib/nylas/new_message.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Data structure for seending a message via the Nylas API class NewMessage diff --git a/lib/nylas/nylas_date.rb b/lib/nylas/nylas_date.rb index b6423377..977bdc54 100644 --- a/lib/nylas/nylas_date.rb +++ b/lib/nylas/nylas_date.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Structure to represent Nylas's more complex Date Schema # @see https://docs.nylas.com/reference#contactsid diff --git a/lib/nylas/participant.rb b/lib/nylas/participant.rb index 8c5774fa..aee6fa05 100644 --- a/lib/nylas/participant.rb +++ b/lib/nylas/participant.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Structure to represent the Participant class Participant diff --git a/lib/nylas/phone_number.rb b/lib/nylas/phone_number.rb index ae413c48..8b8a0e40 100644 --- a/lib/nylas/phone_number.rb +++ b/lib/nylas/phone_number.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Structure to represent the Phone Number Schema # @see https://docs.nylas.com/reference#contactsid diff --git a/lib/nylas/physical_address.rb b/lib/nylas/physical_address.rb index 5a24f688..dd5bbddd 100644 --- a/lib/nylas/physical_address.rb +++ b/lib/nylas/physical_address.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Structure to represent the Physical Address schema # @see https://docs.nylas.com/reference#contactsid diff --git a/lib/nylas/raw_message.rb b/lib/nylas/raw_message.rb index 9c9c99c8..70c0af20 100644 --- a/lib/nylas/raw_message.rb +++ b/lib/nylas/raw_message.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Allows sending of email with nylas from an rfc822 compatible string class RawMessage diff --git a/lib/nylas/recurrence.rb b/lib/nylas/recurrence.rb index e377f675..5b10d999 100644 --- a/lib/nylas/recurrence.rb +++ b/lib/nylas/recurrence.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Representation of a Recurrence object # @see https://docs.nylas.com/reference#section-recurrence diff --git a/lib/nylas/registry.rb b/lib/nylas/registry.rb index 087c790a..9615c572 100644 --- a/lib/nylas/registry.rb +++ b/lib/nylas/registry.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Used to create a hash-like structure which defaults to raising an exception in the event the key to # retrieve does not exist. diff --git a/lib/nylas/rsvp.rb b/lib/nylas/rsvp.rb index 0bdb6ba1..0f095337 100644 --- a/lib/nylas/rsvp.rb +++ b/lib/nylas/rsvp.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Allows RSVPing to a particular event # @see https://docs.nylas.com/reference#rsvping-to-invitations diff --git a/lib/nylas/search_collection.rb b/lib/nylas/search_collection.rb index 484a88f6..fe651a22 100644 --- a/lib/nylas/search_collection.rb +++ b/lib/nylas/search_collection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Ensures our search requests hit the right path class SearchCollection < Collection diff --git a/lib/nylas/thread.rb b/lib/nylas/thread.rb index a960325d..8230cdab 100644 --- a/lib/nylas/thread.rb +++ b/lib/nylas/thread.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Ruby representation of the Nylas /threads API # @see https://docs.nylas.com/reference#threads diff --git a/lib/nylas/timespan.rb b/lib/nylas/timespan.rb index 8c990e6e..c85f3dcf 100644 --- a/lib/nylas/timespan.rb +++ b/lib/nylas/timespan.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Structure to represent a Nylas Timespan. # @see https://docs.nylas.com/reference#section-timespan diff --git a/lib/nylas/types.rb b/lib/nylas/types.rb index c08c3340..725b8c2c 100644 --- a/lib/nylas/types.rb +++ b/lib/nylas/types.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Collection of attribute types module Types @@ -34,6 +36,7 @@ def cast(value) return model.new if value.nil? return value if already_cast?(value) return model.new(**actual_attributes(value)) if value.respond_to?(:key?) + raise TypeError, "Unable to cast #{value} to a #{model}" end @@ -74,6 +77,7 @@ def cast(object) return Time.at(object.to_i) if object.is_a?(String) return Time.at(object) if object.is_a?(Numeric) return object.to_time if object.is_a?(Date) + raise TypeError, "Unable to cast #{object} to Time" end @@ -91,11 +95,13 @@ def serialize(object) class DateType < ValueType def cast(value) return nil if value.nil? + Date.parse(value) end def serialize(value) return value.iso8601 if value.respond_to?(:iso8601) + value end end @@ -106,6 +112,7 @@ class StringType < ValueType # @param value [Object] Casts the passed in object to a string using #to_s def cast(value) return value if value.nil? + value.to_s end end @@ -116,6 +123,7 @@ class IntegerType < ValueType # @param value [Object] Casts the passed in object to an integer using to_i def cast(value) return nil if value.nil? + value.to_i end end @@ -128,6 +136,7 @@ def cast(value) return nil if value.nil? return true if value == true return false if value == false + raise TypeError, "#{value} must be either true or false" end end diff --git a/lib/nylas/version.rb b/lib/nylas/version.rb index 972a0aa8..f3c35278 100644 --- a/lib/nylas/version.rb +++ b/lib/nylas/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas - VERSION = "4.2.4".freeze + VERSION = "4.2.4" end diff --git a/lib/nylas/web_page.rb b/lib/nylas/web_page.rb index 024f9dd4..a002cf93 100644 --- a/lib/nylas/web_page.rb +++ b/lib/nylas/web_page.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Structure to represent the Web Page Schema # @see https://docs.nylas.com/reference#contactsid diff --git a/lib/nylas/webhook.rb b/lib/nylas/webhook.rb index 357e6a86..99c74273 100644 --- a/lib/nylas/webhook.rb +++ b/lib/nylas/webhook.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Nylas # Represents a webhook attached to your application. # @see https://docs.nylas.com/reference#webhooks diff --git a/nylas-streaming.gemspec b/nylas-streaming.gemspec index 07745544..b46db7b3 100644 --- a/nylas-streaming.gemspec +++ b/nylas-streaming.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "./gem_config" Gem::Specification.new do |gem| diff --git a/nylas.gemspec b/nylas.gemspec index 7b87900a..200e5249 100644 --- a/nylas.gemspec +++ b/nylas.gemspec @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "./gem_config" Gem::Specification.new do |gem| diff --git a/spec/nylas/account_spec.rb b/spec/nylas/account_spec.rb index 705c3221..8cdc85d6 100644 --- a/spec/nylas/account_spec.rb +++ b/spec/nylas/account_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Nylas::Account do it "is not filterable" do expect(described_class).not_to be_filterable @@ -53,7 +55,7 @@ it "can revoke all tokens" do api = instance_double("Nylas::API", execute: { success: true }, app_id: "app-987") account = described_class.from_json('{ "id": "acc-1234" }', api: api) - access_token = 'some_access_token' + access_token = "some_access_token" expect(account.revoke_all(keep_access_token: access_token)).to be_truthy diff --git a/spec/nylas/api_spec.rb b/spec/nylas/api_spec.rb index aa490c96..a98baf44 100644 --- a/spec/nylas/api_spec.rb +++ b/spec/nylas/api_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" # This spec is the only one that should have any webmock stuff going on, everything else should use the diff --git a/spec/nylas/collection_spec.rb b/spec/nylas/collection_spec.rb index 38b5b0c7..3a7e121f 100644 --- a/spec/nylas/collection_spec.rb +++ b/spec/nylas/collection_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Nylas::Collection do @@ -87,19 +89,19 @@ def example_instance_hash it "returns collection count" do collection = described_class.new(model: FullModel, api: api) allow(api).to receive(:execute) - .with(method: :get, path: "/collection", query: { limit: 100, offset: 0, view: "count"}, headers: {}) + .with(method: :get, path: "/collection", query: { limit: 100, offset: 0, view: "count" }, headers: {}) .and_return(count: 1) - expect(collection.count).to eql 1 + expect(collection.count).to be 1 end it "returns collection count filtered by `where`" do collection = described_class.new(model: FullModel, api: api) allow(api).to receive(:execute) - .with(method: :get, path: "/collection", query: { id: "1234", limit: 100, offset: 0, view: "count"}, headers: {}) + .with(method: :get, path: "/collection", query: { id: "1234", limit: 100, offset: 0, view: "count" }, headers: {}) .and_return(count: 1) - expect(collection.where(id: "1234").count).to eql 1 + expect(collection.where(id: "1234").count).to be 1 end end end diff --git a/spec/nylas/contact_spec.rb b/spec/nylas/contact_spec.rb index b4080e10..8475db6d 100644 --- a/spec/nylas/contact_spec.rb +++ b/spec/nylas/contact_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Nylas::Contact do @@ -114,7 +116,7 @@ postal_code: "12345+0987", state: "CA", country: "USA" }], web_pages: [{ type: "profile", url: "http://given.example.com" }], - groups: [{id: "di", object: "dnwi", account_id: "doiw", name: "nfowie", path: "fnien"}]) + groups: [{ id: "di", object: "dnwi", account_id: "doiw", name: "nfowie", path: "fnien" }]) end end describe "#to_json" do diff --git a/spec/nylas/current_account_spec.rb b/spec/nylas/current_account_spec.rb index 75bc7b6b..9b7f1e6d 100644 --- a/spec/nylas/current_account_spec.rb +++ b/spec/nylas/current_account_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Nylas::CurrentAccount do diff --git a/spec/nylas/deltas_collection_spec.rb b/spec/nylas/deltas_collection_spec.rb index 9d4ee565..dd396872 100644 --- a/spec/nylas/deltas_collection_spec.rb +++ b/spec/nylas/deltas_collection_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Nylas::DeltasCollection do diff --git a/spec/nylas/deltas_spec.rb b/spec/nylas/deltas_spec.rb index e4ee58a8..ce5cffdf 100644 --- a/spec/nylas/deltas_spec.rb +++ b/spec/nylas/deltas_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Nylas::Deltas do it "safely inflates an account.running event" do data = { "deltas": [{ "date": 1_514_335_663, "object": "account", "type": "account.running", diff --git a/spec/nylas/draft_spec.rb b/spec/nylas/draft_spec.rb index 08840c56..08415d73 100644 --- a/spec/nylas/draft_spec.rb +++ b/spec/nylas/draft_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Nylas::Draft do diff --git a/spec/nylas/folder_spec.rb b/spec/nylas/folder_spec.rb index f2a3bc45..30082c73 100644 --- a/spec/nylas/folder_spec.rb +++ b/spec/nylas/folder_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Nylas::Folder do it "is not filterable" do expect(described_class).not_to be_filterable diff --git a/spec/nylas/label_spec.rb b/spec/nylas/label_spec.rb index 293ab992..f8ededa6 100644 --- a/spec/nylas/label_spec.rb +++ b/spec/nylas/label_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Nylas::Label do it "is not filterable" do expect(described_class).not_to be_filterable diff --git a/spec/nylas/message_spec.rb b/spec/nylas/message_spec.rb index 01699a26..8828b45f 100644 --- a/spec/nylas/message_spec.rb +++ b/spec/nylas/message_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + describe Nylas::Message do describe ".from_json" do it "Deserializes all the attributes into Ruby objects" do diff --git a/spec/nylas/model_spec.rb b/spec/nylas/model_spec.rb index a3e686c9..0f4e5bb4 100644 --- a/spec/nylas/model_spec.rb +++ b/spec/nylas/model_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Nylas::Model do diff --git a/spec/nylas/native_authentication_spec.rb b/spec/nylas/native_authentication_spec.rb index 13acd660..547493f5 100644 --- a/spec/nylas/native_authentication_spec.rb +++ b/spec/nylas/native_authentication_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Nylas::NativeAuthentication do @@ -18,8 +20,8 @@ expect( api.authenticate( - name: 'fake', - email_address: 'fake@example.com', + name: "fake", + email_address: "fake@example.com", provider: :gmail, settings: {} ) @@ -42,8 +44,8 @@ expect( api.authenticate( - name: 'fake', - email_address: 'fake@example.com', + name: "fake", + email_address: "fake@example.com", provider: :gmail, settings: {}, scopes: ["email"] @@ -67,11 +69,11 @@ expect( api.authenticate( - name: 'fake', - email_address: 'fake@example.com', + name: "fake", + email_address: "fake@example.com", provider: :gmail, settings: {}, - scopes: ["email", "contacts"] + scopes: %w[email contacts] ) ).to eql("fake-token") end @@ -92,8 +94,8 @@ expect( api.authenticate( - name: 'fake', - email_address: 'fake@example.com', + name: "fake", + email_address: "fake@example.com", provider: :gmail, settings: {}, scopes: "calendar" diff --git a/spec/nylas/thread_spec.rb b/spec/nylas/thread_spec.rb index 572dda3e..5d83b684 100644 --- a/spec/nylas/thread_spec.rb +++ b/spec/nylas/thread_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "spec_helper" describe Nylas::Thread do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a836440b..a482011d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "simplecov" SimpleCov.start diff --git a/tasks/rspec.rake b/tasks/rspec.rake index b4601f28..1f1889a7 100644 --- a/tasks/rspec.rake +++ b/tasks/rspec.rake @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec)