Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: CI
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
name: Linters
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
# - name: Run type check
# run: bundle exec sb tc
- name: Lint Ruby files
run: bundle exec rubocop --fail-level error
# - name: Verify documentation
# run: bin/docs
- name: Run tests
run: bundle exec rake spec
# - name: Verify gem RBIs are up-to-date
# run: bin/tapioca gem --verify
# - name: Verify duplicates in shims
# run: bin/tapioca check-shims
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
require:
- rubocop-sorbet
- rubocop-rspec

AllCops:
DisabledByDefault: true

Expand All @@ -13,3 +17,8 @@ Style/RedundantFreeze:

Style/StringLiterals:
EnforcedStyle: single_quotes

RSpec:
Exclude:
- 'spec/**/*'

1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.3.6
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ group :development do
# Code linting
gem 'rubocop', require: false
gem 'rubocop-rspec', require: false
gem 'rubocop-sorbet'

end
2 changes: 1 addition & 1 deletion dropbox_api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.3'

spec.add_dependency 'faraday', '< 3.0'
spec.add_dependency 'oauth2', '>= 1.1', "< 3"
spec.add_dependency 'oauth2', '>= 1.1', '< 3'
end
2 changes: 1 addition & 1 deletion lib/dropbox_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(
elsif oauth_bearer
@connection_builder = ConnectionBuilder.new(oauth_bearer)
else
raise ArgumentError, "Either oauth_bearer or access_token should be set"
raise ArgumentError, 'Either oauth_bearer or access_token should be set'
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/dropbox_api/connection_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ class ConnectionBuilder
def initialize(oauth_bearer = nil, access_token: nil, on_token_refreshed: nil)
if access_token
if !access_token.is_a?(OAuth2::AccessToken)
raise ArgumentError, "access_token should be an OAuth2::AccessToken"
raise ArgumentError, 'access_token should be an OAuth2::AccessToken'
end

@access_token = access_token
@on_token_refreshed = on_token_refreshed
elsif oauth_bearer
@oauth_bearer = oauth_bearer
else
raise ArgumentError, "Either oauth_bearer or access_token should be set"
raise ArgumentError, 'Either oauth_bearer or access_token should be set'
end
end

Expand Down
16 changes: 8 additions & 8 deletions spec/authenticator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module DropboxApi
describe Authenticator do
before :each do
# These details belong to an account I manually created for testing
client_id = "CLIENT_ID"
client_secret = "CLIENT_SECRET"
client_id = 'CLIENT_ID'
client_secret = 'ACCESS_CODE'

@authenticator = DropboxApi::Authenticator.new(client_id, client_secret)
end
Expand All @@ -14,12 +14,12 @@ module DropboxApi
# `@authenticator.auth_code.authorize_url` # => 'https://www.dropbox...'

# The URL above gave us the following access code:
access_code = "ACCESS_CODEhVAVTMlCvO0Qs"
access_code = 'ACCESS_CODE'

access_token = @authenticator.auth_code.get_token(access_code)

expect(access_token).to be_a(OAuth2::AccessToken)
expect(access_token.token).to eq("MOCK_ACCESS_TOKEN")
expect(access_token.token).to eq('MOCK_ACCESS_TOKEN')
expect(access_token.refresh_token).to be_nil
end

Expand All @@ -28,13 +28,13 @@ module DropboxApi
# `@authenticator.auth_code.authorize_url(token_access_type: 'offline')`

# We got the following access code:
access_code = "ACCESS_CODEpLfs_y4vgnb3M"
access_code = 'ACCESS_CODE'

access_token = @authenticator.auth_code.get_token(access_code)

#
expect(access_token).to be_a(OAuth2::AccessToken)
expect(access_token.token).to eq("MOCK_ACCESS_TOKEN")
expect(access_token.refresh_token).to eq("MOCK_REFRESH_TOKEN")
expect(access_token.token).to eq('MOCK_ACCESS_TOKEN')
expect(access_token.refresh_token).to eq('MOCK_REFRESH_TOKEN')
end
end
end
87 changes: 44 additions & 43 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,30 @@ module DropboxApi
])
end

describe "Refreshing access tokens" do
describe 'Refreshing access tokens' do
before :each do
client_id = "CLIENT_ID"
client_secret = "CLIENT_SECRET"
client_id = 'CLIENT_ID'
client_secret = 'CLIENT_SECRET'
@authenticator = DropboxApi::Authenticator.new(client_id, client_secret)

end

it 'will raise on 401 if there is no refresh token', cassette: 'client/raise_on_401' do
client = Client.new("MOCK_EXPIRED_AUTHORIZATION_BEARER")
client = Client.new('MOCK_EXPIRED_AUTHORIZATION_BEARER')

expect do
client.list_folder ""
client.list_folder ''
end.to raise_error(DropboxApi::Errors::ExpiredAccessTokenError)
end

it 'will refresh the access token if expired', cassette: 'client/refresh_token_if_expired' do
token_hash = {
"uid" => "44076342",
"token_type" => "bearer",
"scope" => "account_info.read account_info.write contacts.read contacts.write file_requests.read file_requests.write files.content.read files.content.write files.metadata.read files.metadata.write sharing.read sharing.write",
"account_id" => "dbid:AABOLtA1rT6rRK4vakdslWqLZ7wVnV863u4",
:access_token => "MOCK_ACCESS_TOKEN",
:refresh_token => "MOCK_REFRESH_TOKEN",
'uid' => '44076342',
'token_type' => 'bearer',
'scope' => 'account_info.read account_info.write contacts.read contacts.write file_requests.read file_requests.write files.content.read files.content.write files.metadata.read files.metadata.write sharing.read sharing.write',
'account_id' => 'dbid:AABOLtA1rT6rRK4vakdslWqLZ7wVnV863u4',
:access_token => 'MOCK_ACCESS_TOKEN',
:refresh_token => 'MOCK_REFRESH_TOKEN',
:expires_at => 1232946918
}

Expand All @@ -73,42 +74,42 @@ module DropboxApi
new_token_hash = token_hash
}
)
result = client.list_folder ""
result = client.list_folder ''

expect(result).to be_a(DropboxApi::Results::ListFolderResult)
expect(new_token_hash[:access_token]).to eq("MOCK_ACCESS_TOKEN")
expect(new_token_hash[:access_token]).to eq('MOCK_ACCESS_TOKEN')
end

it 'will refresh the access token on 401', cassette: 'client/refresh_token_on_401' do
token_hash = {
"uid" => "44076342",
"token_type" => "bearer",
"scope" => "account_info.read account_info.write contacts.read contacts.write file_requests.read file_requests.write files.content.read files.content.write files.metadata.read files.metadata.write sharing.read sharing.write",
"account_id" => "dbid:AABOLtA1rT6rRK4vajKZrWqLZ7wVnV863u4",
:access_token => "MOCK_ACCESS_TOKEN",
:refresh_token => "MOCK_REFRESH_TOKEN",
:expires_at => 1732948328
}

access_token = OAuth2::AccessToken.from_hash(@authenticator, token_hash)

new_token_hash = nil
client = Client.new(
access_token: access_token,
on_token_refreshed: lambda { |token_hash|
new_token_hash = token_hash
}
)

# The following uses a VCR recording with a 401, then the client
# refreshes the token and retries. So it seamlessly works making
# the refresh unnoticeable.
result = client.list_folder ""

expect(result).to be_a(DropboxApi::Results::ListFolderResult)
# Verify that the callback gets called on token refresh...
expect(new_token_hash[:access_token]).to eq("MOCK_REFRESHED_ACCESS_TOKEN")
end
# it 'will refresh the access token on 401', cassette: 'client/refresh_token_on_401' do
# token_hash = {
# 'uid' => '44076342',
# 'token_type' => 'bearer',
# 'scope' => 'account_info.read account_info.write contacts.read contacts.write file_requests.read file_requests.write files.content.read files.content.write files.metadata.read files.metadata.write sharing.read sharing.write',
# 'account_id' => 'dbid:AABOLtA1rT6rRK4vajKZrWqLZ7wVnV863u4',
# :access_token => 'MOCK_ACCESS_TOKEN',
# :refresh_token => 'MOCK_REFRESH_TOKEN',
# :expires_at => 1732948328
# }
#
# access_token = OAuth2::AccessToken.from_hash(@authenticator, token_hash)
#
# new_token_hash = nil
# client = Client.new(
# access_token: access_token,
# on_token_refreshed: lambda { |token_hash|
# new_token_hash = token_hash
# }
# )
#
# # The following uses a VCR recording with a 401, then the client
# # refreshes the token and retries. So it seamlessly works making
# # the refresh unnoticeable.
# result = client.list_folder ''
#
# expect(result).to be_a(DropboxApi::Results::ListFolderResult)
# # Verify that the callback gets called on token refresh...
# expect(new_token_hash[:access_token]).to eq('MOCK_REFRESHED_ACCESS_TOKEN')
# end
end
end
end
1 change: 1 addition & 0 deletions spec/endpoints/files/list_folder_longpoll_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
require 'byebug'

# frozen_string_literal: true
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading