Skip to content

Commit

Permalink
Rubocop auto-corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
singingwolfboy committed Mar 12, 2019
1 parent efdb925 commit 1cf2d3d
Show file tree
Hide file tree
Showing 74 changed files with 203 additions and 36 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

gemspec name: "nylas-streaming"
2 changes: 1 addition & 1 deletion bin/rspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion bin/rubocop
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion bin/yard
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion bin/yardoc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion bin/yri
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 7 additions & 5 deletions gem_config.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "./lib/nylas/version"

# Consistently apply nylas' standard gem data across gems
Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions lib/nylas-streaming.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "yajl"
require "em-http"
require "nylas"
Expand Down Expand Up @@ -72,6 +74,7 @@ def http_error_handler(client)

def parser
return @parser if @parser

@parser = Yajl::Parser.new(symbolize_keys: true)
@parser
end
Expand Down
2 changes: 2 additions & 0 deletions lib/nylas.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "json"
require "rest-client"

Expand Down
2 changes: 2 additions & 0 deletions lib/nylas/account.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 4 additions & 1 deletion lib/nylas/api.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Nylas
# Methods to retrieve data from the Nylas API as Ruby objects
class API
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/nylas/calendar.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Nylas
# Ruby bindings for the Nylas Calendar API
# @see https://docs.nylas.com/reference#calendars
Expand Down
9 changes: 9 additions & 0 deletions lib/nylas/collection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Nylas
# An enumerable for working with index and search endpoints
class Collection
Expand Down Expand Up @@ -27,11 +29,13 @@ def create(**attributes)
# @return [Collection<Model>]
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

Expand All @@ -40,6 +44,7 @@ def search(query)
# @return [Collection<String>]
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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -92,13 +99,15 @@ 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

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

Expand Down
3 changes: 3 additions & 0 deletions lib/nylas/constraints.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Nylas
# The constraints a particular GET request will include in their query params
class Constraints
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/nylas/contact.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/nylas/contact_group.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Nylas
# Structure to represent the Contact Group schema
# @see https://docs.nylas.com/reference#contactsid
Expand Down
2 changes: 2 additions & 0 deletions lib/nylas/current_account.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Nylas
# Ruby representation of the Nylas /account API
# @see https://docs.nylas.com/reference#account
Expand Down
3 changes: 3 additions & 0 deletions lib/nylas/delta.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions lib/nylas/deltas.rb
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
3 changes: 3 additions & 0 deletions lib/nylas/deltas_collection.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Nylas
# Special collection for delta objects
class DeltasCollection < Collection
Expand All @@ -24,6 +26,7 @@ def since(cursor)

def next_page(*)
return nil if empty?

where(cursor: cursor_end)
end

Expand Down
2 changes: 2 additions & 0 deletions lib/nylas/draft.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Nylas
# Ruby representatin of a Nylas Draft object
# @see https://docs.nylas.com/reference#drafts
Expand Down
2 changes: 2 additions & 0 deletions lib/nylas/email_address.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Nylas
# Structure to represent the Email Address Schema
# @see https://docs.nylas.com/reference#contactsid
Expand Down
2 changes: 2 additions & 0 deletions lib/nylas/errors.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Nylas
Error = Class.new(::StandardError)

Expand Down
2 changes: 2 additions & 0 deletions lib/nylas/event.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Nylas
# Structure to represent a the Event Schema.
# @see https://docs.nylas.com/reference#events
Expand Down
2 changes: 2 additions & 0 deletions lib/nylas/event_collection.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/nylas/file.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Nylas
# Structure to represent a the File Schema.
# @see https://docs.nylas.com/reference#events
Expand All @@ -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
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/nylas/folder.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Nylas
# Structure to represent the Folder Schema
# @see https://docs.nylas.com/reference#folders
Expand Down
18 changes: 10 additions & 8 deletions lib/nylas/http_client.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/nylas/im_address.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Nylas
# Structure to represent the IM Address Schema
# @see https://docs.nylas.com/reference#contactsid
Expand Down
2 changes: 2 additions & 0 deletions lib/nylas/label.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Nylas
# Structure to represent the Label Schema
# @see https://docs.nylas.com/reference#labels
Expand Down
Loading

0 comments on commit 1cf2d3d

Please sign in to comment.