strongmind-schoology-client 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae95f00744a8364f799342056301ff99f387a757117fce80f3d0819530fc20c0
4
- data.tar.gz: a5a88caa7e2dbbb42f4d54662e38ff42b75b22a665d8ad2ba110a4c5135dbd21
3
+ metadata.gz: 1b4adaea90620c1414be5f78d31cba6f521114b6692f1b5917b93eda23857169
4
+ data.tar.gz: 624f6830f28c28ea5261be09495440cb2bdfa527e5d69c5e67f9c1ac8afd820d
5
5
  SHA512:
6
- metadata.gz: 33a8aa9d22200d827dc09189f705b2ff1c9f721e3733de1b9283e8264bc664a48697a5ae428e5d9f64f0c09b2ce82f11aaf7a13bcf94d3af27c1f72f025f21e6
7
- data.tar.gz: 7b3a45d2eb4531ef612056ff3bfa433df05e114c5580444a371d280e52dfbb63950e852311ffa02f4918cd4ff63f047252c313b33f068a8704fcb1b0404d949e
6
+ metadata.gz: a2ca0fcdf5eb50bc8826cc2e041de18aae11501eb3c8df2bfcbaa09a46f03265d67d73f73f24c01bca6b784aa61a0606b9ca3b57e0727244c1dff034118dccfb
7
+ data.tar.gz: b334eade9ffe19115844aee89b0b6374bf5a730308ba58f03823018a3227109165ce128207cc1a7a3c9d7bffd109f13c1545e4b704f7559eed6e8e6212f918d8
data/Gemfile CHANGED
@@ -11,6 +11,5 @@ gem "rspec", "~> 3.0"
11
11
 
12
12
  gem "rubocop", "~> 1.21"
13
13
 
14
- gem 'faraday'
15
- gem 'faraday_middleware'
16
- gem 'oauth'
14
+ gem 'faraday', '>= 2.0'
15
+ gem 'simple_oauth'
data/Gemfile.lock CHANGED
@@ -1,9 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- strongmind-schoology-client (0.1.2)
5
- faraday (~> 1.1)
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 (1.10.3)
87
- faraday-em_http (~> 1.0)
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-em_http (1.0.0)
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.20.0)
94
+ loofah (2.21.2)
118
95
  crass (~> 1.0.2)
119
- nokogiri (>= 1.5.9)
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.3-x86_64-darwin)
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
- snaky_hash (2.0.1)
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
- require 'faraday_middleware'
4
- require 'simple_oauth'
3
+
5
4
 
6
5
  module SchoologyClient
7
6
  class Client
8
- attr_reader :adapter, :oauth_consumer_key, :oauth_consumer_secret, :url, :stubs
9
-
10
- def initialize(adapter: Faraday.default_adapter, stubs: nil)
11
- @adapter = adapter
12
- @oauth_consumer_key = SchoologyClient.configuration.oauth_consumer_key
13
- @oauth_consumer_secret = SchoologyClient.configuration.oauth_consumer_secret
14
- @url = SchoologyClient.configuration.url
15
-
16
- #used for specs
17
- @stubs = stubs
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
- # setup faraday connection using 2-legged oauth 1.0
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
@@ -12,6 +12,10 @@ module SchoologyClient
12
12
  handle_response @client.connection.post(url, body, headers)
13
13
  end
14
14
 
15
+ def put_request(url, body:, headers: {})
16
+ handle_response @client.connection.put(url, body, headers)
17
+ end
18
+
15
19
  def handle_response(response)
16
20
  case response.status
17
21
  when 400
@@ -6,6 +6,10 @@ module SchoologyClient
6
6
  def create(**attributes)
7
7
  GroupResource.new post_request("groups", body: attributes.to_json).body
8
8
  end
9
+
10
+ def update(id, **attributes)
11
+ GroupResource.new put_request("groups/#{id}", body: attributes.to_json).body
12
+ end
9
13
  end
10
14
  end
11
15
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SchoologyClient
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
5
5
  end
@@ -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.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Strongmind
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-05-08 00:00:00.000000000 Z
11
+ date: 2023-06-21 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: '1.1'
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: '1.2'
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