Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3 Polish: Cleanup & documentation #420

Merged
merged 64 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
6b9c529
Clean up and upgrade gemspec
mrashed-dev May 31, 2023
13ca571
update webhook triggers
agtang96 May 31, 2023
4fb1fe7
protect http handlers from resources
agtang96 May 31, 2023
8ab3f27
rename api.rb to client.rb
mrashed-dev May 31, 2023
d0e93d7
remove unneeded gemfiles
mrashed-dev May 31, 2023
7ea8423
Skeleton cleanup (#419)
agtang96 May 31, 2023
8b635c0
Merge branch 'v3-skeleton' into v3-skeleton-polish
mrashed-dev May 31, 2023
83f22ab
protect base resource attributes
mrashed-dev May 31, 2023
0f573d6
Update README.md
mrashed-dev May 31, 2023
c5447b5
more cleanup
mrashed-dev May 31, 2023
5fc497a
update test
mrashed-dev May 31, 2023
c103888
change response
agtang96 May 31, 2023
adf88ba
Merge branch 'v3-skeleton' into v3-skeleton-polish
mrashed-dev May 31, 2023
1ab44f0
lint: make rubocop more bearable
agtang96 May 31, 2023
3976add
refactor: timeout
agtang96 May 31, 2023
d05aee2
Merge branch 'v3-skeleton' into v3-skeleton-polish
mrashed-dev Jun 1, 2023
ce1cec5
Add nylas config file
mrashed-dev Jun 1, 2023
0f33686
switch to named params for config
mrashed-dev Jun 1, 2023
14ccf37
stop tracking test.rb
mrashed-dev Jun 1, 2023
110e3ee
more cleanup
mrashed-dev Jun 1, 2023
c641977
Cleanup gem config
mrashed-dev Jun 1, 2023
8a1e39a
More readme updates
mrashed-dev Jun 1, 2023
d669022
Add yard comments to auth, application
mrashed-dev Jun 1, 2023
9bfb1db
Fix typo
mrashed-dev Jun 1, 2023
33c8d92
Add remaining yard comments
mrashed-dev Jun 1, 2023
4b72adb
upgrade dependencies
mrashed-dev Jun 1, 2023
899faf8
Add file for yard doc generation options
mrashed-dev Jun 1, 2023
bf437ae
cleanup
mrashed-dev Jun 1, 2023
2c02b23
Exclude more files
mrashed-dev Jun 2, 2023
4b1d43a
return true for deletes
mrashed-dev Jun 2, 2023
d68777f
Cleanup errors
mrashed-dev Jun 2, 2023
2954f19
parse v3 errors
mrashed-dev Jun 2, 2023
9e5c5c9
Move client_id and client_secret out of nylas init
mrashed-dev Jun 3, 2023
bcd7fb1
move mixin logic into api operations
mrashed-dev Jun 22, 2023
c96bf12
fix error with referencing DEFAULT_REGION_URL
mrashed-dev Jun 22, 2023
ffd0357
rename baseresource to resource
mrashed-dev Jun 22, 2023
816c5ee
rename Operations -> GrantsApiOperations
mrashed-dev Jun 22, 2023
fa6c8ad
cleanup
mrashed-dev Jun 22, 2023
70740f5
move v3 out of host
mrashed-dev Jun 22, 2023
2fac127
Introduce admin api operations
mrashed-dev Jun 22, 2023
54e8b99
add api operations for non-CRUD calls
mrashed-dev Jun 23, 2023
375182a
fix remaining ruby calls
mrashed-dev Jun 23, 2023
e06701b
set correct path
mrashed-dev Aug 8, 2023
76999ce
should be "applications"
mrashed-dev Aug 8, 2023
93190ed
update method name
mrashed-dev Aug 8, 2023
cabd22b
Refactor auth endpoints
mrashed-dev Aug 8, 2023
14c0350
fix delete operator
mrashed-dev Aug 8, 2023
97a830e
serialize payload before sending
mrashed-dev Aug 8, 2023
8c901f0
parse better errors
mrashed-dev Aug 8, 2023
3b48936
fix url builder
mrashed-dev Aug 8, 2023
52f8a33
fix building url
mrashed-dev Aug 8, 2023
d59cab6
use sym
mrashed-dev Aug 8, 2023
8738e9f
add missing v3
mrashed-dev Aug 8, 2023
eb4db68
further refactor auth
mrashed-dev Aug 8, 2023
73a8172
ad oauth error
mrashed-dev Aug 8, 2023
398b290
do not serialize payload before calling httpclient
mrashed-dev Aug 8, 2023
035bd54
make execute return the response from the server
mrashed-dev Aug 8, 2023
6b51c91
switch to using execute to get raw response
mrashed-dev Aug 8, 2023
826dd8e
End-of-day commit
emarsh1995 Aug 10, 2023
49de8a9
End-of-day commit
emarsh1995 Aug 11, 2023
7f048a4
End-of-day commit
emarsh1995 Aug 14, 2023
06f83df
Formatting updates
emarsh1995 Aug 15, 2023
a4041a1
Spec documentation
emarsh1995 Aug 15, 2023
67b3972
Merge pull request #424 from nylas/v3-docs-polish
emarsh1995 Aug 15, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .arcconfig

This file was deleted.

4 changes: 0 additions & 4 deletions .codeclimate.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ TAGS
*.swp
vendor/
out
test.rb
21 changes: 0 additions & 21 deletions .overcommit.yml

This file was deleted.

4 changes: 3 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ inherit_from: .rubocop_todo.yml

require: rubocop-rspec
AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 3.0
DisplayCopNames: true
DisplayStyleGuide: true
Exclude:
Expand All @@ -27,6 +27,7 @@ Metrics/ParameterLists:
- "lib/nylas/calendar_collection.rb"

Metrics/MethodLength:
Max: 20
Exclude:
- "lib/nylas/calendar_collection.rb"
- "lib/nylas/services/tunnel.rb"
Expand All @@ -36,6 +37,7 @@ Metrics/AbcSize:
- "lib/nylas/services/tunnel.rb"

Metrics/ModuleLength:
Max: 200
Exclude:
- "lib/nylas/model.rb"

Expand Down
6 changes: 6 additions & 0 deletions .yardopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
--no-private
--protected
--exclude lib/nylas/handler/api_operations.rb
--exclude lib/nylas/handler/http_client.rb
--exclude lib/nylas/resources/base_resource.rb
lib/**/*.rb
24 changes: 9 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ If you have a question that needs an answer, please reach out to support@nylas.c

## ⚙️ Install
### Prerequisites
- Ruby 2.3 or above.
- Ruby Frameworks: `rest-client`, `json`, `yajl-ruby`.

We support Rails 4.2 and above. A more detailed compatibility list can be found in our [list of Gemfiles](https://github.com/nylas/nylas-ruby/tree/master/gemfiles).
- Ruby 3.0 or above.
- Ruby Frameworks: `rest-client` and `yajl-ruby`.

### Install

Expand Down Expand Up @@ -93,26 +91,22 @@ To use this SDK, you first need to [sign up for a free Nylas developer account](

Then, follow our guide to [setup your first app and get your API access keys](https://docs.nylas.com/docs/get-your-developer-api-keys).

All of the functionality of the Nylas Communications Platform is available through the `API` object. To access data for an account that’s connected to Nylas, create a new API client object and pass the variables you gathered when you got your developer API keys. In the following example, replace `CLIENT_ID`, `CLIENT_SECRET`, and `ACCESS_TOKEN` with your values.
All of the functionality of the Nylas Communications Platform is available through the `API` object. To access data for an account that’s connected to Nylas, create a new API client object and pass the variables you gathered when you got your developer API keys. In the following example, replace `API_KEY` with your Nylas API Key, and optionally fill in the rest of the configuration.


```ruby
require 'nylas'

nylas = Nylas::API.new(
app_id: CLIENT_ID,
app_secret: CLIENT_SECRET,
access_token: ACCESS_TOKEN
api_key: API_KEY,
client_id: CLIENT_ID, # Optional
client_secret: CLIENT_SECRET, # Optional
host: DEFAULT_REGION_URL, # Optional
timeout: TIMEOUT # Optional
)
```

Now, you can use `nylas` to access full email, calendar, and contacts functionality. For example, here is how you would print the subject line for the most recent email message to the console.


```ruby
message = nylas.messages.first
puts(message.subject)
```
Now, you can use `nylas` to access full email, calendar, and contacts functionality.

To learn more about how to use the Nylas Ruby SDK, please refer to our [Ruby](https://docs.nylas.com/docs/quickstart-ruby) [SDK QuickStart Guide](https://docs.nylas.com/docs/quickstart-ruby).

Expand Down
42 changes: 16 additions & 26 deletions gem_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,45 @@

# Consistently apply nylas' standard gem data across gems
module GemConfig
def self.apply(gem, name)
gem.name = name
gem.files = Dir.glob("lib/{#{name}.rb,#{name}/**/*.rb}")
def self.apply(gem)
gem.description = %(Gem for interacting with the Nylas API.)
gem.files = Dir.glob("lib/{nylas.rb,nylas/**/*.rb}")
gem.license = "MIT"
gem.version = Nylas::VERSION
gem.platform = "ruby"
gem.required_ruby_version = ">= 3.0"
append_nylas_data(gem)
dev_dependencies.each do |dependency|
gem.add_development_dependency(*dependency)
end
end

def self.append_nylas_data(gem)
gem.metadata = metadata
gem.email = "support@nylas.com"
gem.authors = ["Nylas, Inc."]
dev_dependencies.each do |dependency|
gem.add_development_dependency(*dependency)
end
end

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",
"documentation_uri" => "http://www.rubydoc.info/gems/nylas",
"documentation_uri" => "https://developer.nylas.com/docs/sdks/ruby/",
"homepage_uri" => "https://www.nylas.com",
"source_code_uri" => "https://github.com/nylas/nylas-ruby",
"wiki_uri" => "https://github.com/nylas/nylas-ruby/wiki"
"github_repo" => "https://github.com/nylas/nylas-ruby"
}
end

def self.dev_dependencies
[["bundler", ">= 1.3.0"],
["yard", "~> 0.9.0"],
["awesome_print", "~> 1.0"],
["rubocop", "~> 1.24.1"],
["rubocop-rspec", "~> 2.7.0"],
["overcommit", "~> 0.41"]] + testing_and_debugging_dependencies
["yard", "~> 0.9.34"],
["rubocop", "~> 1.51"],
["rubocop-rspec", "~> 2.22"]] + testing_and_debugging_dependencies
end

def self.testing_and_debugging_dependencies
[["pry", "~> 0.14.1"],
["pry-nav", "~> 1.0.0"],
["pry-stack_explorer", "~> 0.4.9.3"],
["rspec", "~> 3.7"],
["rspec-json_matcher", "~> 0.1"],
["webmock", "~> 3.0"],
["faker", "~> 1.8"],
["informed", "~> 1.0"],
[["rspec", "~> 3.12"],
["rspec-json_matcher", "~> 0.2.0"],
["webmock", "~> 3.18", ">= 3.18.1"],
["simplecov", "~> 0.21.2"],
["simplecov-cobertura", "~> 2.1.0"]]
["simplecov-cobertura", "~> 2.1.0"],
["webrick", "~> 1.8", ">= 1.8.1"]]
end
end
5 changes: 0 additions & 5 deletions gemfiles/Gemfile.rails5

This file was deleted.

6 changes: 0 additions & 6 deletions gemfiles/Gemfile.rails6

This file was deleted.

5 changes: 0 additions & 5 deletions gemfiles/Gemfile.rest-client.1

This file was deleted.

5 changes: 0 additions & 5 deletions gemfiles/Gemfile.rest-client.2

This file was deleted.

4 changes: 0 additions & 4 deletions gemfiles/Gemfile.rubocop

This file was deleted.

28 changes: 16 additions & 12 deletions lib/nylas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,30 @@
# See https://github.com/sparklemotion/http-cookie/issues/27
# and https://github.com/sparklemotion/http-cookie/issues/6
#
# CookieJar uses unsafe class caching for dynamically loading cookie jars
# If 2 rest-client instances are instantiated at the same time, (in threads)
# non-deterministic behaviour can occur whereby the Hash cookie jar isn't
# properly loaded and cached.
# Forcing an instantiation of the jar onload will force the CookieJar to load
# before the system has a chance to spawn any threads.
# Note this should technically be fixed in rest-client itself however that
# library appears to be stagnant so we're forced to fix it here
# This object should get GC'd as it's not referenced by anything
# CookieJar uses unsafe class caching for dynamically loading cookie jars.
# If two rest-client instances are instantiated at the same time (in threads), non-deterministic
# behaviour can occur whereby the Hash cookie jar isn't properly loaded and cached.
# Forcing an instantiation of the jar onload will force the CookieJar to load before the system has
# a chance to spawn any threads.
# Note that this should technically be fixed in rest-client itself, however that library appears to
# be stagnant so we're forced to fix it here.
# This object should get GC'd as it's not referenced by anything.
HTTP::CookieJar.new

require "ostruct"
require "forwardable"

require_relative "nylas/version"
require_relative "nylas/errors"
require_relative "nylas/client"
require_relative "nylas/config"

require_relative "nylas/operations/http_client"
require_relative "nylas/operations/api_operations"
require_relative "nylas/handler/http_client"

require_relative "nylas/resources/base_resource"
require_relative "nylas/resources/applications"
require_relative "nylas/resources/auth"
require_relative "nylas/resources/calendars"
require_relative "nylas/resources/events"
require_relative "nylas/resources/grants"
require_relative "nylas/resources/redirect_uris"
require_relative "nylas/resources/webhooks"
41 changes: 0 additions & 41 deletions lib/nylas/api.rb

This file was deleted.

62 changes: 62 additions & 0 deletions lib/nylas/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# frozen_string_literal: true

require_relative "resources/calendars"
require_relative "resources/events"
require_relative "resources/auth"
require_relative "resources/webhooks"
require_relative "resources/applications"

module Nylas
# Methods to retrieve data from the Nylas API as Ruby objects.
class Client
attr_reader :api_key, :host, :timeout

# Initializes a client session.
#
# @param api_key [Hash, nil] API key to use for the client session.
# @param host [Hash] Client session's host.
# @param timeout [Hash, nil] Timeout value to use for the client session.
def initialize(api_key: nil,
host: Config::DEFAULT_REGION_URL,
timeout: nil)
@api_key = api_key
@host = host
@timeout = timeout
end

# The application resources for your Nylas application.
#
# @return [Nylas::Applications] Application resources for your Nylas application.
def applications
Applications.new(self)
end

# The calendar resources for your Nylas application.
#
# @return [Nylas::Calendars] Calendar resources for your Nylas application.
def calendars
Calendars.new(self)
end

# The event resources for your Nylas application.
#
# @return [Nylas::Events] Event resources for your Nylas application
def events
Events.new(self)
end

# The auth resources for your Nylas application.
#
# @return [Nylas::Auth] Auth resources for your Nylas application.
def auth
Auth.new(self)
end

# The webhook resources for your Nylas application.
#
# @return [Nylas::Webhooks] Webhook resources for your Nylas application.
def webhooks
Webhooks.new(self)
end
end
end
19 changes: 19 additions & 0 deletions lib/nylas/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module Nylas
# Configuration options for the Nylas Ruby SDK.
module Config
# The configuration options for supported regions.
REGION_CONFIG = {
us: {
nylas_api_url: "https://api.us.nylas.com"
},
eu: {
nylas_api_url: "https://api.eu.nylas.com"
}
}.freeze

# The default API endpoint for the Nylas API.
DEFAULT_REGION_URL = REGION_CONFIG[:us][:nylas_api_url]
end
end
Loading