Skip to content
Open
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
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby 2.7.5
ruby 3.4.4
137 changes: 64 additions & 73 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,102 +2,92 @@ PATH
remote: .
specs:
oneroster (2.3.23)
base64
dry-inflector (~> 1.0.0)
faraday
faraday_middleware
oauth
simple_oauth
faraday (~> 2.13, < 3.0)
faraday-oauth (~> 0.1.1)
oauth (~> 1.1)
ostruct
simple_oauth (~> 0.3.1)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
builder (3.2.3)
coderay (1.1.2)
diff-lcs (1.3)
ast (2.4.3)
base64 (0.3.0)
coderay (1.1.3)
diff-lcs (1.6.2)
docile (1.4.1)
dry-inflector (1.0.0)
faraday (1.10.4)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
faraday-excon (~> 1.1)
faraday-httpclient (~> 1.0)
faraday-multipart (~> 1.0)
faraday-net_http (~> 1.0)
faraday-net_http_persistent (~> 1.0)
faraday-patron (~> 1.0)
faraday-rack (~> 1.0)
faraday-retry (~> 1.0)
ruby2_keywords (>= 0.0.4)
faraday-em_http (1.0.0)
faraday-em_synchrony (1.0.0)
faraday-excon (1.1.0)
faraday-httpclient (1.0.1)
faraday-multipart (1.1.0)
multipart-post (~> 2.0)
faraday-net_http (1.0.2)
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday-retry (1.0.3)
faraday_middleware (1.2.1)
faraday (~> 1.0)
faraday (2.13.1)
faraday-net_http (>= 2.0, < 3.5)
json
logger
faraday-net_http (3.4.1)
net-http (>= 0.5.0)
faraday-oauth (0.1.1)
faraday (~> 2.0)
simple_oauth (~> 0.3)
hashie (5.0.0)
json (2.9.1)
language_server-protocol (3.17.0.4)
metaclass (0.0.4)
method_source (0.8.2)
mocha (1.8.0)
metaclass (~> 0.0.1)
multipart-post (2.4.1)
json (2.12.2)
language_server-protocol (3.17.0.5)
lint_roller (1.1.0)
logger (1.7.0)
method_source (1.1.0)
mocha (2.7.1)
ruby2_keywords (>= 0.0.5)
net-http (0.6.0)
uri
oauth (1.1.0)
oauth-tty (~> 1.0, >= 1.0.1)
snaky_hash (~> 2.0)
version_gem (~> 1.1)
oauth-tty (1.0.5)
version_gem (~> 1.1, >= 1.1.1)
parallel (1.26.3)
parser (3.3.7.0)
ostruct (0.6.1)
parallel (1.27.0)
parser (3.3.8.0)
ast (~> 2.4.1)
racc
pry (0.10.4)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
pry-nav (0.2.4)
pry (>= 0.9.10, < 0.11.0)
prism (1.4.0)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
pry-nav (1.0.0)
pry (>= 0.9.10, < 0.15)
racc (1.8.1)
rainbow (3.1.1)
rake (10.5.0)
regexp_parser (2.10.0)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.2)
rspec (3.13.1)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.4)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rspec_junit_formatter (0.2.2)
builder (< 4)
rspec-support (~> 3.13.0)
rspec-support (3.13.4)
rspec_junit_formatter (0.6.0)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.71.0)
rubocop (1.76.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.36.2, < 2.0)
rubocop-ast (>= 1.45.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.38.0)
parser (>= 3.3.1.0)
rubocop-ast (1.45.1)
parser (>= 3.3.7.2)
prism (~> 1.4)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
simple_oauth (0.3.1)
Expand All @@ -107,20 +97,21 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
slop (3.6.0)
snaky_hash (2.0.1)
hashie
version_gem (~> 1.1, >= 1.1.1)
snaky_hash (2.0.3)
hashie (>= 0.1.0, < 6)
version_gem (>= 1.1.8, < 3)
unicode-display_width (3.1.4)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)
version_gem (1.1.6)
uri (1.0.3)
version_gem (1.1.8)

PLATFORMS
arm64-darwin-24
ruby

DEPENDENCIES
bundler (~> 2.1.4)
bundler (~> 2.6.9)
mocha
oneroster!
pry
Expand All @@ -132,4 +123,4 @@ DEPENDENCIES
simplecov (~> 0.22)

BUNDLED WITH
2.1.4
2.6.9
1 change: 0 additions & 1 deletion lib/one_roster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

require 'dry/inflector'
require 'faraday'
require 'faraday_middleware'
require 'oauth'
require 'simple_oauth'

Expand Down
13 changes: 8 additions & 5 deletions lib/one_roster/connection.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true
require 'faraday/oauth'

module OneRoster
class Connection
Expand Down Expand Up @@ -31,7 +32,8 @@ def execute(path, method = :get, params = nil, body = nil, content_type = nil)
end

def set_auth_headers(token, cookie)
connection.authorization :Bearer, token
# connection.authorization :Bearer, token
connection.headers['Authorization'] = "Bearer #{token}"
@cookie = cookie
end

Expand Down Expand Up @@ -89,21 +91,22 @@ def oauth_connection
connection.request :oauth,
consumer_key: @client.app_id,
consumer_secret: @client.app_secret
connection.response :logger, @client.logger if @client.logger
connection.response :json, content_type: /\bjson$/
connection.response :logger, @client.logger if @client.logger
connection.adapter Faraday.default_adapter
end
end

def oauth2_connection
connection = Faraday.new(@client.api_url) do |connection|
Faraday.new(@client.api_url) do |connection|
connection.request :json
connection.request :authorization, :basic,
@client.app_id, @client.app_secret

connection.response :logger, @client.logger if @client.logger
connection.response :json, content_type: /\bjson$/
connection.adapter Faraday.default_adapter
end
connection.basic_auth(@client.app_id, @client.app_secret)
connection
end

def log_to_sentry(payload)
Expand Down
16 changes: 12 additions & 4 deletions lib/types/student.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@ class Student < Base
attr_reader :uid,
:first_name,
:last_name,
:provider
:username,
:provider,
:email,
:grades,
:tenant_id

def initialize(attributes = {}, client: nil)
@uid = attributes['sourcedId']
@first_name = attributes['givenName']
@last_name = attributes['familyName']
@api_username = attributes['username']
@status = attributes['status']
@email = attributes['email']
@username = username(client)
@provider = 'oneroster'
@grades = attributes['grades']
@tenant_id = attributes.dig("orgs", 0, "sourcedId")
end

def username(client = nil)
Expand All @@ -31,8 +36,11 @@ def to_h
first_name: @first_name,
last_name: @last_name,
username: @username,
provider: @provider
}
provider: @provider,
email: @email,
grades: @grades,
tenant_id: @tenant_id
}
end

private
Expand Down
6 changes: 4 additions & 2 deletions lib/types/teacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class Teacher < Base
:first_name,
:last_name,
:provider,
:role
:role,
:api_username

def initialize(attributes = {}, *, client: nil)
@uid = attributes['sourcedId']
Expand All @@ -33,7 +34,8 @@ def to_h
first_name: @first_name,
last_name: @last_name,
username: @username,
provider: @provider
provider: @provider,
api_username: @api_username,
}
end

Expand Down
13 changes: 8 additions & 5 deletions one_roster.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_runtime_dependency 'faraday'
spec.add_runtime_dependency 'faraday_middleware'
spec.add_runtime_dependency 'base64'
spec.add_runtime_dependency 'ostruct'
spec.add_runtime_dependency 'faraday', '~> 2.13', '< 3.0'
spec.add_runtime_dependency 'dry-inflector', '~> 1.0.0'
spec.add_runtime_dependency 'simple_oauth'
spec.add_runtime_dependency 'oauth'
spec.add_runtime_dependency 'simple_oauth', '~> 0.3.1'
spec.add_runtime_dependency 'oauth', '~> 1.1'
spec.add_runtime_dependency 'faraday-oauth', '~> 0.1.1'

spec.add_development_dependency 'bundler', '~> 2.1.4'

spec.add_development_dependency 'bundler', '~> 2.6.9'
spec.add_development_dependency 'mocha'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'pry-nav'
Expand Down
8 changes: 7 additions & 1 deletion spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@
expect(first_student.first_name).to eq(student_1['givenName'])
expect(first_student.last_name).to eq(student_1['familyName'])
expect(first_student.username).to eq(student_1['sourcedId'])
expect(first_student.email).to eq(student_1['email'])
expect(first_student.provider).to eq('oneroster')

expect(second_student).to be_a(OneRoster::Types::Student)
expect(second_student.uid).to eq(student_3['sourcedId'])
expect(second_student.first_name).to eq(student_3['givenName'])
expect(second_student.last_name).to eq(student_3['familyName'])
expect(second_student.email).to eq(student_3['email'])
expect(second_student.username).to eq(student_3['email'])
expect(second_student.provider).to eq('oneroster')
end
Expand Down Expand Up @@ -664,6 +666,7 @@
email: teacher_1['email'],
first_name: teacher_1['givenName'],
last_name: teacher_1['familyName'],
api_username: teacher_1['username'],
username: nil,
provider: 'oneroster'
)
Expand All @@ -690,7 +693,10 @@
first_name: student_1['givenName'],
last_name: student_1['familyName'],
username: student_1['sourcedId'],
provider: 'oneroster'
provider: 'oneroster',
email: student_1['email'],
grades: student_1['grades'],
tenant_id: nil
)
end
end
Expand Down
9 changes: 4 additions & 5 deletions spec/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
conn = connection.connection
expect(conn).to be_a(Faraday::Connection)
expect(conn.headers).to eq('User-Agent' => "Faraday v#{Faraday::VERSION}")
expect(conn.builder.handlers).to eq(
[
FaradayMiddleware::OAuth, Faraday::Response::Logger,
FaradayMiddleware::ParseJson
]
expect(conn.builder.handlers).to include(
Faraday::OAuth::Middleware,
Faraday::Response::Json,
Faraday::Response::Logger
)
end

Expand Down