quiz_api_client 2.3.1 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/lib/quiz_api_client/http_client.rb +38 -2
- data/lib/quiz_api_client/json_formatter.rb +18 -0
- data/lib/quiz_api_client/services/base_api_service.rb +4 -2
- data/lib/quiz_api_client/services/jwt_service.rb +2 -1
- data/lib/quiz_api_client/version.rb +1 -1
- data/lib/quiz_api_client.rb +7 -4
- data/quiz_api_client.gemspec +29 -3
- metadata +29 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f109a4af811b6581467d20b04bc580c1f2a3c209
|
4
|
+
data.tar.gz: 73ffe5b91db4ffa77db9de146b29c8162aaef2db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 355d7520d371d4cf3a19cb42def9ff1eee21e70eefe6e001b2e0558d6a26dfca1abd9a48d9c184f33ff2bf4ec0d338497729acfa749d73736c490106018509ed
|
7
|
+
data.tar.gz: f99bbc820678763fd8caee43d27ea3ee78f6bb02591c3a0bc833889d754421b088a7b218615ea9940b97bc7dbf94cf2073105772fcf1c8dcfe4bcd3ff5fafdda
|
data/Gemfile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
1
3
|
module QuizApiClient
|
2
4
|
class HttpClient
|
3
5
|
include HTTParty
|
@@ -6,9 +8,11 @@ module QuizApiClient
|
|
6
8
|
|
7
9
|
attr_reader :jwt, :uri
|
8
10
|
|
9
|
-
def initialize(uri:, jwt:)
|
11
|
+
def initialize(uri:, jwt:, consumer_request_id: nil, logging: true, log_level: :info)
|
10
12
|
@uri = uri
|
11
13
|
@jwt = jwt
|
14
|
+
@consumer_request_id = consumer_request_id
|
15
|
+
initialize_logger(log_level) if logging
|
12
16
|
end
|
13
17
|
|
14
18
|
def get(path, all: false, query: {})
|
@@ -34,6 +38,33 @@ module QuizApiClient
|
|
34
38
|
|
35
39
|
private
|
36
40
|
|
41
|
+
def initialize_logger(log_level)
|
42
|
+
HTTParty::Logger.add_formatter('quiz_api_client_json_formatter', QuizApiClient::JSONFormatter)
|
43
|
+
@logger = ::Logger.new(STDOUT,
|
44
|
+
formatter: proc {|_,_,_,msg| msg.merge({consumer_request_id: @consumer_request_id}).to_json },
|
45
|
+
level: unfriendly_logger_level(log_level)
|
46
|
+
)
|
47
|
+
@logger_config = { logger: @logger,
|
48
|
+
log_level: log_level,
|
49
|
+
log_format: :quiz_api_client_json_formatter
|
50
|
+
}
|
51
|
+
end
|
52
|
+
|
53
|
+
def unfriendly_logger_level(level)
|
54
|
+
case level
|
55
|
+
when :fatal
|
56
|
+
::Logger::FATAL
|
57
|
+
when :error
|
58
|
+
::Logger::ERROR
|
59
|
+
when :warn
|
60
|
+
::Logger::WARN
|
61
|
+
when :info
|
62
|
+
::Logger::INFO
|
63
|
+
when :debug
|
64
|
+
::Logger::DEBUG
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
37
68
|
def make_request(method, path, request_options = {})
|
38
69
|
self.class.send(
|
39
70
|
method,
|
@@ -57,7 +88,7 @@ module QuizApiClient
|
|
57
88
|
end
|
58
89
|
|
59
90
|
def default_request_data
|
60
|
-
{
|
91
|
+
initial_hash = {
|
61
92
|
headers: {
|
62
93
|
'Authorization' => jwt,
|
63
94
|
'AuthType' => 'Signature',
|
@@ -65,6 +96,11 @@ module QuizApiClient
|
|
65
96
|
'Content-Type' => 'application/json'
|
66
97
|
}
|
67
98
|
}
|
99
|
+
|
100
|
+
initial_hash[:headers]['X-Consumer-Request-Id'] = @consumer_request_id if @consumer_request_id
|
101
|
+
|
102
|
+
initial_hash.merge!(@logger_config) if @logger_config
|
103
|
+
initial_hash
|
68
104
|
end
|
69
105
|
|
70
106
|
def next_page(response)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module QuizApiClient
|
2
|
+
class JSONFormatter
|
3
|
+
def initialize(logger, level)
|
4
|
+
@logger = logger
|
5
|
+
@level = level.to_sym
|
6
|
+
end
|
7
|
+
|
8
|
+
def format(request, response)
|
9
|
+
@logger.send(@level, {
|
10
|
+
client_request_id: response.headers.dig('x-request-id', 0),
|
11
|
+
request_url: request.last_uri,
|
12
|
+
response_code: response.code
|
13
|
+
})
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
@@ -4,12 +4,13 @@ module QuizApiClient::Services
|
|
4
4
|
:protocol, :errors
|
5
5
|
|
6
6
|
def initialize(consumer_key:, host:,
|
7
|
-
shared_secret:, protocol: 'https')
|
7
|
+
shared_secret:, protocol: 'https', consumer_request_id: nil)
|
8
8
|
@consumer_key = consumer_key
|
9
9
|
@host = host
|
10
10
|
@shared_secret = shared_secret
|
11
11
|
@protocol = protocol
|
12
12
|
@errors = []
|
13
|
+
@consumer_request_id = consumer_request_id
|
13
14
|
end
|
14
15
|
|
15
16
|
private
|
@@ -21,7 +22,8 @@ module QuizApiClient::Services
|
|
21
22
|
def client(token:)
|
22
23
|
QuizApiClient::HttpClient.new(
|
23
24
|
uri: uri,
|
24
|
-
jwt: token
|
25
|
+
jwt: token,
|
26
|
+
consumer_request_id: @consumer_request_id
|
25
27
|
)
|
26
28
|
end
|
27
29
|
end
|
@@ -4,11 +4,12 @@ module QuizApiClient::Services
|
|
4
4
|
|
5
5
|
attr_reader :consumer_key, :host, :shared_secret, :protocol
|
6
6
|
|
7
|
-
def initialize(consumer_key: nil, shared_secret:, host:, protocol: 'https')
|
7
|
+
def initialize(consumer_key: nil, consumer_request_id: nil, shared_secret:, host:, protocol: 'https')
|
8
8
|
@consumer_key = consumer_key
|
9
9
|
@host = host
|
10
10
|
@shared_secret = shared_secret
|
11
11
|
@protocol = protocol
|
12
|
+
@consumer_request_id = consumer_request_id
|
12
13
|
end
|
13
14
|
|
14
15
|
def grant_permission(scope:, exp: nil, uuid: nil, **additional_fields)
|
data/lib/quiz_api_client.rb
CHANGED
@@ -3,13 +3,14 @@ require 'jwt'
|
|
3
3
|
|
4
4
|
module QuizApiClient
|
5
5
|
class Client
|
6
|
-
attr_reader :consumer_key, :host, :
|
6
|
+
attr_reader :consumer_key, :consumer_request_id, :host, :protocol, :shared_secret
|
7
7
|
|
8
|
-
def initialize(consumer_key:, host:, shared_secret:, protocol: 'https')
|
8
|
+
def initialize(consumer_key:, host:, shared_secret:, protocol: 'https', consumer_request_id: nil)
|
9
9
|
@consumer_key = consumer_key
|
10
10
|
@host = host
|
11
11
|
@shared_secret = shared_secret
|
12
12
|
@protocol = protocol
|
13
|
+
@consumer_request_id = consumer_request_id
|
13
14
|
end
|
14
15
|
|
15
16
|
def jwt_service
|
@@ -69,9 +70,10 @@ module QuizApiClient
|
|
69
70
|
def service_params
|
70
71
|
{
|
71
72
|
consumer_key: consumer_key,
|
73
|
+
consumer_request_id: consumer_request_id,
|
72
74
|
host: host,
|
73
|
-
|
74
|
-
|
75
|
+
protocol: protocol,
|
76
|
+
shared_secret: shared_secret
|
75
77
|
}
|
76
78
|
end
|
77
79
|
end
|
@@ -80,6 +82,7 @@ end
|
|
80
82
|
require 'quiz_api_client/version'
|
81
83
|
|
82
84
|
require 'quiz_api_client/http_client'
|
85
|
+
require 'quiz_api_client/json_formatter'
|
83
86
|
require 'quiz_api_client/services/jwt_service'
|
84
87
|
require 'quiz_api_client/services/base_api_service'
|
85
88
|
|
data/quiz_api_client.gemspec
CHANGED
@@ -6,8 +6,34 @@ require 'quiz_api_client/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'quiz_api_client'
|
8
8
|
spec.version = QuizApiClient::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
|
9
|
+
spec.authors = [
|
10
|
+
'Chris Wang',
|
11
|
+
'Augusto Callejas',
|
12
|
+
'Bryan Petty',
|
13
|
+
'Christian Prescott',
|
14
|
+
'Han Yan',
|
15
|
+
'Jayce Higgins',
|
16
|
+
'Marc Alan Phillips',
|
17
|
+
'Michael Brewer-Davis',
|
18
|
+
'Michael Hargiss',
|
19
|
+
'Omar Khan',
|
20
|
+
'Robin Kuss',
|
21
|
+
'Ryan Taylor'
|
22
|
+
]
|
23
|
+
spec.email = [
|
24
|
+
'acallejas@instructure.com',
|
25
|
+
'bpetty@instructure.com',
|
26
|
+
'cprescott@instructure.com',
|
27
|
+
'hyan@instructure.com',
|
28
|
+
'jhiggins@instructure.com',
|
29
|
+
'mphillips@instructure.com',
|
30
|
+
'mbd@instructure.com',
|
31
|
+
'mhargiss@instructure.com',
|
32
|
+
'okhan@instructure.com',
|
33
|
+
'rkuss@instructure.com',
|
34
|
+
'rtaylor@instructure.com',
|
35
|
+
'cwang@instructure.com'
|
36
|
+
]
|
11
37
|
spec.summary = 'Ruby client for quiz_api'
|
12
38
|
|
13
39
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
@@ -16,7 +42,7 @@ Gem::Specification.new do |spec|
|
|
16
42
|
spec.require_paths = ['lib']
|
17
43
|
|
18
44
|
spec.add_dependency 'httparty', '0.14.0'
|
19
|
-
spec.add_dependency 'jwt'
|
45
|
+
spec.add_dependency 'jwt', '~> 1.5'
|
20
46
|
spec.add_dependency 'link_header'
|
21
47
|
|
22
48
|
spec.add_development_dependency 'bundler', '~> 1.12'
|
metadata
CHANGED
@@ -1,14 +1,25 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quiz_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wang
|
8
|
+
- Augusto Callejas
|
9
|
+
- Bryan Petty
|
10
|
+
- Christian Prescott
|
11
|
+
- Han Yan
|
12
|
+
- Jayce Higgins
|
13
|
+
- Marc Alan Phillips
|
14
|
+
- Michael Brewer-Davis
|
15
|
+
- Michael Hargiss
|
16
|
+
- Omar Khan
|
17
|
+
- Robin Kuss
|
18
|
+
- Ryan Taylor
|
8
19
|
autorequire:
|
9
20
|
bindir: exe
|
10
21
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
22
|
+
date: 2017-09-28 00:00:00.000000000 Z
|
12
23
|
dependencies:
|
13
24
|
- !ruby/object:Gem::Dependency
|
14
25
|
name: httparty
|
@@ -28,16 +39,16 @@ dependencies:
|
|
28
39
|
name: jwt
|
29
40
|
requirement: !ruby/object:Gem::Requirement
|
30
41
|
requirements:
|
31
|
-
- - "
|
42
|
+
- - "~>"
|
32
43
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
44
|
+
version: '1.5'
|
34
45
|
type: :runtime
|
35
46
|
prerelease: false
|
36
47
|
version_requirements: !ruby/object:Gem::Requirement
|
37
48
|
requirements:
|
38
|
-
- - "
|
49
|
+
- - "~>"
|
39
50
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
51
|
+
version: '1.5'
|
41
52
|
- !ruby/object:Gem::Dependency
|
42
53
|
name: link_header
|
43
54
|
requirement: !ruby/object:Gem::Requirement
|
@@ -138,6 +149,17 @@ dependencies:
|
|
138
149
|
version: '3.0'
|
139
150
|
description:
|
140
151
|
email:
|
152
|
+
- acallejas@instructure.com
|
153
|
+
- bpetty@instructure.com
|
154
|
+
- cprescott@instructure.com
|
155
|
+
- hyan@instructure.com
|
156
|
+
- jhiggins@instructure.com
|
157
|
+
- mphillips@instructure.com
|
158
|
+
- mbd@instructure.com
|
159
|
+
- mhargiss@instructure.com
|
160
|
+
- okhan@instructure.com
|
161
|
+
- rkuss@instructure.com
|
162
|
+
- rtaylor@instructure.com
|
141
163
|
- cwang@instructure.com
|
142
164
|
executables: []
|
143
165
|
extensions: []
|
@@ -161,6 +183,7 @@ files:
|
|
161
183
|
- docker-compose.yml
|
162
184
|
- lib/quiz_api_client.rb
|
163
185
|
- lib/quiz_api_client/http_client.rb
|
186
|
+
- lib/quiz_api_client/json_formatter.rb
|
164
187
|
- lib/quiz_api_client/services/base_api_service.rb
|
165
188
|
- lib/quiz_api_client/services/item_analyses_service.rb
|
166
189
|
- lib/quiz_api_client/services/jwt_service.rb
|