strongmind-schoology-client 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -3
- data/Gemfile.lock +13 -46
- data/lib/schoology_client/client.rb +19 -24
- data/lib/schoology_client/oauth.rb +85 -0
- data/lib/schoology_client/version.rb +1 -1
- data/lib/schoology_client.rb +4 -1
- metadata +7 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d0ab2bf3b584a58dd5ff1910327b299578cfdca8652626b96875ae8739e8069
|
4
|
+
data.tar.gz: 023bfd2f65938daac6e6a499cbaa779f1a4207665b9a3f2ab02138279d0cf9df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82126ddbfac4653562ee968be3e3e20edeef457b75f29b9542354e771a989404c1b201ccb4959769916e7dfa139573f746192b5a2ec07cbbfeb19fa9931ae74a
|
7
|
+
data.tar.gz: 1727d3db2822510fd11b1b5648605156ee4003d1d42efa599ef9ff1a590dbd68d848280e8ac37115b2372a70c4247c627d33bc5ab161e9806cd66ef321c4baed
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
strongmind-schoology-client (0.1.
|
5
|
-
faraday (
|
6
|
-
faraday_middleware (~> 1.2)
|
4
|
+
strongmind-schoology-client (0.1.3)
|
5
|
+
faraday (>= 2.0)
|
7
6
|
rails (~> 7.0)
|
8
7
|
railties (~> 7.0)
|
9
8
|
simple_oauth (~> 0.3.1)
|
@@ -83,40 +82,18 @@ GEM
|
|
83
82
|
date (3.3.3)
|
84
83
|
diff-lcs (1.5.0)
|
85
84
|
erubi (1.12.0)
|
86
|
-
faraday (
|
87
|
-
faraday-
|
88
|
-
faraday-em_synchrony (~> 1.0)
|
89
|
-
faraday-excon (~> 1.1)
|
90
|
-
faraday-httpclient (~> 1.0)
|
91
|
-
faraday-multipart (~> 1.0)
|
92
|
-
faraday-net_http (~> 1.0)
|
93
|
-
faraday-net_http_persistent (~> 1.0)
|
94
|
-
faraday-patron (~> 1.0)
|
95
|
-
faraday-rack (~> 1.0)
|
96
|
-
faraday-retry (~> 1.0)
|
85
|
+
faraday (2.7.4)
|
86
|
+
faraday-net_http (>= 2.0, < 3.1)
|
97
87
|
ruby2_keywords (>= 0.0.4)
|
98
|
-
faraday-
|
99
|
-
faraday-em_synchrony (1.0.0)
|
100
|
-
faraday-excon (1.1.0)
|
101
|
-
faraday-httpclient (1.0.1)
|
102
|
-
faraday-multipart (1.0.4)
|
103
|
-
multipart-post (~> 2)
|
104
|
-
faraday-net_http (1.0.1)
|
105
|
-
faraday-net_http_persistent (1.2.0)
|
106
|
-
faraday-patron (1.0.0)
|
107
|
-
faraday-rack (1.0.0)
|
108
|
-
faraday-retry (1.0.3)
|
109
|
-
faraday_middleware (1.2.0)
|
110
|
-
faraday (~> 1.0)
|
88
|
+
faraday-net_http (3.0.2)
|
111
89
|
globalid (1.1.0)
|
112
90
|
activesupport (>= 5.0)
|
113
|
-
hashie (5.0.0)
|
114
91
|
i18n (1.13.0)
|
115
92
|
concurrent-ruby (~> 1.0)
|
116
93
|
json (2.6.3)
|
117
|
-
loofah (2.
|
94
|
+
loofah (2.21.2)
|
118
95
|
crass (~> 1.0.2)
|
119
|
-
nokogiri (>= 1.
|
96
|
+
nokogiri (>= 1.12.0)
|
120
97
|
mail (2.8.1)
|
121
98
|
mini_mime (>= 0.1.1)
|
122
99
|
net-imap
|
@@ -126,7 +103,6 @@ GEM
|
|
126
103
|
method_source (1.0.0)
|
127
104
|
mini_mime (1.1.2)
|
128
105
|
minitest (5.18.0)
|
129
|
-
multipart-post (2.3.0)
|
130
106
|
net-imap (0.3.4)
|
131
107
|
date
|
132
108
|
net-protocol
|
@@ -137,14 +113,10 @@ GEM
|
|
137
113
|
net-smtp (0.3.3)
|
138
114
|
net-protocol
|
139
115
|
nio4r (2.5.9)
|
140
|
-
nokogiri (1.14.
|
116
|
+
nokogiri (1.14.4-arm64-darwin)
|
117
|
+
racc (~> 1.4)
|
118
|
+
nokogiri (1.14.4-x86_64-darwin)
|
141
119
|
racc (~> 1.4)
|
142
|
-
oauth (1.1.0)
|
143
|
-
oauth-tty (~> 1.0, >= 1.0.1)
|
144
|
-
snaky_hash (~> 2.0)
|
145
|
-
version_gem (~> 1.1)
|
146
|
-
oauth-tty (1.0.5)
|
147
|
-
version_gem (~> 1.1, >= 1.1.1)
|
148
120
|
parallel (1.23.0)
|
149
121
|
parser (3.2.2.1)
|
150
122
|
ast (~> 2.4.1)
|
@@ -210,15 +182,11 @@ GEM
|
|
210
182
|
ruby-progressbar (1.13.0)
|
211
183
|
ruby2_keywords (0.0.5)
|
212
184
|
simple_oauth (0.3.1)
|
213
|
-
|
214
|
-
hashie
|
215
|
-
version_gem (~> 1.1, >= 1.1.1)
|
216
|
-
thor (1.2.1)
|
185
|
+
thor (1.2.2)
|
217
186
|
timeout (0.3.2)
|
218
187
|
tzinfo (2.0.6)
|
219
188
|
concurrent-ruby (~> 1.0)
|
220
189
|
unicode-display_width (2.4.2)
|
221
|
-
version_gem (1.1.2)
|
222
190
|
websocket-driver (0.7.5)
|
223
191
|
websocket-extensions (>= 0.1.0)
|
224
192
|
websocket-extensions (0.1.5)
|
@@ -230,12 +198,11 @@ PLATFORMS
|
|
230
198
|
x86_64-darwin-21
|
231
199
|
|
232
200
|
DEPENDENCIES
|
233
|
-
faraday
|
234
|
-
faraday_middleware
|
235
|
-
oauth
|
201
|
+
faraday (>= 2.0)
|
236
202
|
rake (~> 13.0)
|
237
203
|
rspec (~> 3.0)
|
238
204
|
rubocop (~> 1.21)
|
205
|
+
simple_oauth
|
239
206
|
strongmind-schoology-client!
|
240
207
|
|
241
208
|
BUNDLED WITH
|
@@ -1,20 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'faraday'
|
3
|
-
|
4
|
-
require 'simple_oauth'
|
3
|
+
|
5
4
|
|
6
5
|
module SchoologyClient
|
7
6
|
class Client
|
8
|
-
attr_reader :
|
9
|
-
|
10
|
-
def initialize(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
7
|
+
attr_reader :oauth_consumer_key, :oauth_consumer_secret, :url
|
8
|
+
|
9
|
+
def initialize(conn = nil)
|
10
|
+
if conn.nil?
|
11
|
+
# setup faraday connection using 2-legged oauth 1.0
|
12
|
+
@connection = Faraday.new(url: SchoologyClient.configuration.url) do |faraday|
|
13
|
+
faraday.request :json
|
14
|
+
faraday.request :oauth, {
|
15
|
+
consumer_key: SchoologyClient.configuration.oauth_consumer_key,
|
16
|
+
consumer_secret: SchoologyClient.configuration.oauth_consumer_secret
|
17
|
+
}
|
18
|
+
|
19
|
+
faraday.response :json
|
20
|
+
end
|
21
|
+
else
|
22
|
+
@connection = conn
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
26
|
def group
|
@@ -22,18 +28,7 @@ module SchoologyClient
|
|
22
28
|
end
|
23
29
|
|
24
30
|
def connection
|
25
|
-
|
26
|
-
connection = Faraday.new(url: @url) do |faraday|
|
27
|
-
faraday.request :json
|
28
|
-
faraday.request :oauth, {
|
29
|
-
consumer_key: @oauth_consumer_key,
|
30
|
-
consumer_secret: @oauth_consumer_secret
|
31
|
-
}
|
32
|
-
|
33
|
-
faraday.response :json
|
34
|
-
faraday.adapter @adapter, @stubs
|
35
|
-
end
|
36
|
-
connection
|
31
|
+
@connection
|
37
32
|
end
|
38
33
|
|
39
34
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'simple_oauth'
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module SchoologyClient
|
6
|
+
# Public: Uses the simple_oauth library to sign requests according the
|
7
|
+
# OAuth protocol.
|
8
|
+
#
|
9
|
+
# The options for this middleware are forwarded to SimpleOAuth::Header:
|
10
|
+
# :consumer_key, :consumer_secret, :token, :token_secret. All these
|
11
|
+
# parameters are optional.
|
12
|
+
#
|
13
|
+
# The signature is added to the "Authorization" HTTP request header. If the
|
14
|
+
# value for this header already exists, it is not overriden.
|
15
|
+
#
|
16
|
+
# If no Content-Type header is specified, this middleware assumes that
|
17
|
+
# request body parameters should be included while signing the request.
|
18
|
+
# Otherwise, it only includes them if the Content-Type is
|
19
|
+
# "application/x-www-form-urlencoded", as per OAuth 1.0.
|
20
|
+
#
|
21
|
+
# For better performance while signing requests, this middleware should be
|
22
|
+
# positioned before UrlEncoded middleware on the stack, but after any other
|
23
|
+
# body-encoding middleware (such as EncodeJson).
|
24
|
+
class OAuth < Faraday::Middleware
|
25
|
+
AUTH_HEADER = 'Authorization'
|
26
|
+
CONTENT_TYPE = 'Content-Type'
|
27
|
+
TYPE_URLENCODED = 'application/x-www-form-urlencoded'
|
28
|
+
|
29
|
+
extend Forwardable
|
30
|
+
def_delegator :'Faraday::Utils', :parse_nested_query
|
31
|
+
|
32
|
+
def initialize(app, options)
|
33
|
+
super(app)
|
34
|
+
@options = options
|
35
|
+
end
|
36
|
+
|
37
|
+
def call(env)
|
38
|
+
env[:request_headers][AUTH_HEADER] ||= oauth_header(env).to_s if sign_request?(env)
|
39
|
+
@app.call(env)
|
40
|
+
end
|
41
|
+
|
42
|
+
def oauth_header(env)
|
43
|
+
SimpleOAuth::Header.new env[:method],
|
44
|
+
env[:url].to_s,
|
45
|
+
signature_params(body_params(env)),
|
46
|
+
oauth_options(env)
|
47
|
+
end
|
48
|
+
|
49
|
+
def sign_request?(env)
|
50
|
+
!!env[:request].fetch(:oauth, true)
|
51
|
+
end
|
52
|
+
|
53
|
+
def oauth_options(env)
|
54
|
+
if (extra = env[:request][:oauth]) && extra.is_a?(Hash) && !extra.empty?
|
55
|
+
@options.merge extra
|
56
|
+
else
|
57
|
+
@options
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def body_params(env)
|
62
|
+
if include_body_params?(env)
|
63
|
+
if env[:body].respond_to?(:to_str)
|
64
|
+
parse_nested_query env[:body]
|
65
|
+
else
|
66
|
+
env[:body]
|
67
|
+
end
|
68
|
+
end || {}
|
69
|
+
end
|
70
|
+
|
71
|
+
def include_body_params?(env)
|
72
|
+
# see RFC 5849, section 3.4.1.3.1 for details
|
73
|
+
!(type = env[:request_headers][CONTENT_TYPE]) || (type == TYPE_URLENCODED)
|
74
|
+
end
|
75
|
+
|
76
|
+
def signature_params(params)
|
77
|
+
if params.empty?
|
78
|
+
params
|
79
|
+
else
|
80
|
+
params.reject { |_k, v| v.respond_to?(:content_type) }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
data/lib/schoology_client.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "faraday"
|
4
|
-
require "faraday_middleware"
|
5
4
|
require "rails"
|
6
5
|
require_relative "schoology_client/version"
|
7
6
|
|
@@ -23,6 +22,10 @@ module SchoologyClient
|
|
23
22
|
# Classes used to return a nicer object wrapping the response data
|
24
23
|
autoload :Group, "schoology/objects/group"
|
25
24
|
|
25
|
+
|
26
|
+
autoload :OAuth, 'schoology_client/oauth'
|
27
|
+
Faraday::Request.register_middleware oauth: -> { OAuth }
|
28
|
+
|
26
29
|
def self.configuration
|
27
30
|
@configuration ||= SchoologyClient::Configuration.new
|
28
31
|
end
|
metadata
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strongmind-schoology-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Strongmind
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.1'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: faraday_middleware
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.2'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
24
|
+
- - ">="
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
26
|
+
version: '2.0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: simple_oauth
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,6 +88,7 @@ files:
|
|
102
88
|
- lib/schoology_client/error.rb
|
103
89
|
- lib/schoology_client/generators/schoology_client/install_generator.rb
|
104
90
|
- lib/schoology_client/generators/templates/schoology_client_initializer.rb
|
91
|
+
- lib/schoology_client/oauth.rb
|
105
92
|
- lib/schoology_client/object.rb
|
106
93
|
- lib/schoology_client/objects/group.rb
|
107
94
|
- lib/schoology_client/resource.rb
|