strongmind-schoology-client 0.1.2 → 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 +15 -47
- data/lib/schoology_client/client.rb +19 -39
- data/lib/schoology_client/generators/{schoology_api → schoology_client}/install_generator.rb +4 -4
- data/lib/schoology_client/oauth.rb +85 -0
- data/lib/schoology_client/resources/group.rb +1 -2
- data/lib/schoology_client/version.rb +1 -1
- data/lib/schoology_client.rb +5 -4
- metadata +12 -26
- data/lib/templates/rails/initializer/schoology-client.rb.tt +0 -0
- /data/lib/{templates → schoology_client/generators/templates}/schoology_client_initializer.rb +0 -0
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,12 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
strongmind-schoology-client (0.1.
|
5
|
-
faraday (
|
6
|
-
faraday_middleware (~> 1.2)
|
7
|
-
oauth (~> 1.1)
|
4
|
+
strongmind-schoology-client (0.1.3)
|
5
|
+
faraday (>= 2.0)
|
8
6
|
rails (~> 7.0)
|
9
7
|
railties (~> 7.0)
|
8
|
+
simple_oauth (~> 0.3.1)
|
10
9
|
|
11
10
|
GEM
|
12
11
|
remote: https://rubygems.org/
|
@@ -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)
|
@@ -209,15 +181,12 @@ GEM
|
|
209
181
|
parser (>= 3.2.1.0)
|
210
182
|
ruby-progressbar (1.13.0)
|
211
183
|
ruby2_keywords (0.0.5)
|
212
|
-
|
213
|
-
|
214
|
-
version_gem (~> 1.1, >= 1.1.1)
|
215
|
-
thor (1.2.1)
|
184
|
+
simple_oauth (0.3.1)
|
185
|
+
thor (1.2.2)
|
216
186
|
timeout (0.3.2)
|
217
187
|
tzinfo (2.0.6)
|
218
188
|
concurrent-ruby (~> 1.0)
|
219
189
|
unicode-display_width (2.4.2)
|
220
|
-
version_gem (1.1.2)
|
221
190
|
websocket-driver (0.7.5)
|
222
191
|
websocket-extensions (>= 0.1.0)
|
223
192
|
websocket-extensions (0.1.5)
|
@@ -229,12 +198,11 @@ PLATFORMS
|
|
229
198
|
x86_64-darwin-21
|
230
199
|
|
231
200
|
DEPENDENCIES
|
232
|
-
faraday
|
233
|
-
faraday_middleware
|
234
|
-
oauth
|
201
|
+
faraday (>= 2.0)
|
235
202
|
rake (~> 13.0)
|
236
203
|
rspec (~> 3.0)
|
237
204
|
rubocop (~> 1.21)
|
205
|
+
simple_oauth
|
238
206
|
strongmind-schoology-client!
|
239
207
|
|
240
208
|
BUNDLED WITH
|
@@ -1,20 +1,26 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'faraday'
|
3
|
-
|
4
|
-
require '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,33 +28,7 @@ module SchoologyClient
|
|
22
28
|
end
|
23
29
|
|
24
30
|
def connection
|
25
|
-
|
26
|
-
# Set up the OAuth 1.0 consumer
|
27
|
-
consumer = OAuth::Consumer.new(
|
28
|
-
@oauth_consumer_key,
|
29
|
-
@oauth_consumer_secret,
|
30
|
-
site: @url,
|
31
|
-
scheme: :header,
|
32
|
-
signature_method: 'PLAINTEXT',
|
33
|
-
realm: 'Schoology API'
|
34
|
-
)
|
35
|
-
|
36
|
-
# Set up the Faraday connection
|
37
|
-
connection = Faraday.new("#{@url}") do |conn|
|
38
|
-
conn.request :url_encoded
|
39
|
-
conn.request :json
|
40
|
-
|
41
|
-
conn.response :dates
|
42
|
-
conn.response :json, content_type: "application/json"
|
43
|
-
|
44
|
-
if @stubs
|
45
|
-
conn.adapter adapter, @stubs
|
46
|
-
else
|
47
|
-
conn.adapter adapter
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
return connection
|
31
|
+
@connection
|
52
32
|
end
|
53
33
|
|
54
34
|
end
|
data/lib/schoology_client/generators/{schoology_api → schoology_client}/install_generator.rb
RENAMED
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'rails/
|
4
|
-
require 'schoology_client'
|
3
|
+
require 'rails/generators/base'
|
5
4
|
|
6
|
-
module
|
5
|
+
module SchoologyClient
|
7
6
|
module Generators
|
7
|
+
|
8
8
|
class InstallGenerator < Rails::Generators::Base
|
9
9
|
source_root File.expand_path("../../templates", __FILE__)
|
10
10
|
|
11
|
-
desc "Generate
|
11
|
+
desc "Generate Strongmind Schoology Client initializer file for Rails applications"
|
12
12
|
|
13
13
|
def copy_initializer
|
14
14
|
template "schoology_api.rb", "config/initializers/schoology_api.rb"
|
@@ -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
|
@@ -4,8 +4,7 @@ require 'json'
|
|
4
4
|
module SchoologyClient
|
5
5
|
class GroupResource < Resource
|
6
6
|
def create(**attributes)
|
7
|
-
|
8
|
-
return GroupResource.new(response_body)
|
7
|
+
GroupResource.new post_request("groups", body: attributes.to_json).body
|
9
8
|
end
|
10
9
|
end
|
11
10
|
end
|
data/lib/schoology_client.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "faraday"
|
4
|
-
require "
|
5
|
-
require "rails/all"
|
4
|
+
require "rails"
|
6
5
|
require_relative "schoology_client/version"
|
7
6
|
|
8
|
-
|
9
7
|
module SchoologyClient
|
10
8
|
|
11
9
|
class << self
|
@@ -17,7 +15,6 @@ module SchoologyClient
|
|
17
15
|
autoload :Object, "schoology_client/object"
|
18
16
|
autoload :Resource, "schoology_client/resource"
|
19
17
|
autoload :Error, "schoology_client/error"
|
20
|
-
autoload :Railtie, "schoology_client/railtie"
|
21
18
|
|
22
19
|
# High-level categories of Schoology API calls
|
23
20
|
autoload :GroupResource, "schoology_client/resources/group"
|
@@ -25,6 +22,10 @@ module SchoologyClient
|
|
25
22
|
# Classes used to return a nicer object wrapping the response data
|
26
23
|
autoload :Group, "schoology/objects/group"
|
27
24
|
|
25
|
+
|
26
|
+
autoload :OAuth, 'schoology_client/oauth'
|
27
|
+
Faraday::Request.register_middleware oauth: -> { OAuth }
|
28
|
+
|
28
29
|
def self.configuration
|
29
30
|
@configuration ||= SchoologyClient::Configuration.new
|
30
31
|
end
|
metadata
CHANGED
@@ -1,57 +1,43 @@
|
|
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
|
-
name:
|
28
|
+
name: simple_oauth
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
33
|
+
version: 0.3.1
|
48
34
|
type: :runtime
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
40
|
+
version: 0.3.1
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rails
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +86,14 @@ files:
|
|
100
86
|
- lib/schoology_client/client.rb
|
101
87
|
- lib/schoology_client/configuration.rb
|
102
88
|
- lib/schoology_client/error.rb
|
103
|
-
- lib/schoology_client/generators/
|
89
|
+
- lib/schoology_client/generators/schoology_client/install_generator.rb
|
90
|
+
- lib/schoology_client/generators/templates/schoology_client_initializer.rb
|
91
|
+
- lib/schoology_client/oauth.rb
|
104
92
|
- lib/schoology_client/object.rb
|
105
93
|
- lib/schoology_client/objects/group.rb
|
106
94
|
- lib/schoology_client/resource.rb
|
107
95
|
- lib/schoology_client/resources/group.rb
|
108
96
|
- lib/schoology_client/version.rb
|
109
|
-
- lib/templates/rails/initializer/schoology-client.rb.tt
|
110
|
-
- lib/templates/schoology_client_initializer.rb
|
111
97
|
- sig/schoology.rbs
|
112
98
|
homepage: https://github.com/Strongmind/schoology-client
|
113
99
|
licenses: []
|
File without changes
|
/data/lib/{templates → schoology_client/generators/templates}/schoology_client_initializer.rb
RENAMED
File without changes
|