quiz_api_client 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/quiz_api_client/services/base_api_service.rb +15 -11
- data/lib/quiz_api_client/services/jwt_service.rb +6 -4
- data/lib/quiz_api_client/services/quiz_session_service.rb +1 -1
- data/lib/quiz_api_client/services/quiz_sessions_service.rb +1 -1
- data/lib/quiz_api_client/services/quizzes_service.rb +2 -2
- data/lib/quiz_api_client/version.rb +1 -1
- data/lib/quiz_api_client.rb +17 -12
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7510dde6f3ff21858b72aa6fc3054583b210b9b
|
4
|
+
data.tar.gz: c5354fba783d3dc1399afae7462ac6d112568430
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3868dd59280ee8c59b3517d12ba5fd31e88c77ae9649736ef5d4b6c1083e133c6a1e40269143279e0a44d1f0c2588b824f462c3b32cf72345c198fd0423456b8
|
7
|
+
data.tar.gz: a453ef98e547383558b24f78f57992f5ecae5f62660e980821b6aad22cca4ffe86e33f56ced23676c7f28550c7843127553e7151438e2c4877383543bd9b5279
|
data/README.md
CHANGED
@@ -30,8 +30,10 @@ To instantiate a client, you'll need the secret and the host.
|
|
30
30
|
|
31
31
|
```ruby
|
32
32
|
client = QuizApiClient::Client.new(
|
33
|
-
|
34
|
-
|
33
|
+
consumer_key: 'the consumer key normally stored in the quiz_api signed_auth_consumers table',
|
34
|
+
host: 'your-quiz-api-host-here.com',
|
35
|
+
shared_secret: 'the-api-secret normally stored on the quiz_api account',
|
36
|
+
protocol: 'http' # Set this to what you need, ideally it's an environment variable
|
35
37
|
)
|
36
38
|
```
|
37
39
|
|
@@ -3,11 +3,14 @@ require 'quiz_api_client/services/jwt_service'
|
|
3
3
|
|
4
4
|
module QuizApiClient::Services
|
5
5
|
class BaseApiService
|
6
|
-
attr_reader :
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
attr_reader :consumer_key, :host, :shared_secret,
|
7
|
+
:protocol, :errors
|
8
|
+
|
9
|
+
def initialize(consumer_key:, host:,
|
10
|
+
shared_secret:, protocol: 'https')
|
11
|
+
@consumer_key = consumer_key
|
12
|
+
@host = host
|
13
|
+
@shared_secret = shared_secret
|
11
14
|
@protocol = protocol
|
12
15
|
@errors = []
|
13
16
|
end
|
@@ -19,8 +22,8 @@ module QuizApiClient::Services
|
|
19
22
|
generate_token(scope: scope, resource_id: resource_id)
|
20
23
|
end
|
21
24
|
|
22
|
-
def
|
23
|
-
uri = URI::HTTP.build(host:
|
25
|
+
def uri
|
26
|
+
uri = URI::HTTP.build(host: host)
|
24
27
|
uri.scheme = protocol
|
25
28
|
uri.to_s
|
26
29
|
end
|
@@ -31,15 +34,16 @@ module QuizApiClient::Services
|
|
31
34
|
|
32
35
|
def jwt_service
|
33
36
|
QuizApiClient::Services::JwtService.new(
|
34
|
-
|
35
|
-
|
37
|
+
consumer_key: consumer_key,
|
38
|
+
host: host,
|
39
|
+
shared_secret: shared_secret,
|
36
40
|
protocol: protocol
|
37
41
|
)
|
38
42
|
end
|
39
43
|
|
40
|
-
def
|
44
|
+
def client(token:)
|
41
45
|
QuizApiClient::HttpClient.new(
|
42
|
-
uri:
|
46
|
+
uri: uri,
|
43
47
|
jwt: token
|
44
48
|
)
|
45
49
|
end
|
@@ -3,17 +3,19 @@ require 'jwt'
|
|
3
3
|
module QuizApiClient::Services
|
4
4
|
HASHING_ALGORITHM = 'HS512'.freeze
|
5
5
|
class JwtService
|
6
|
-
attr_reader :host, :
|
6
|
+
attr_reader :consumer_key, :host, :shared_secret, :protocol
|
7
7
|
|
8
|
-
def initialize(
|
8
|
+
def initialize(consumer_key: nil, shared_secret:, host:, protocol: 'https')
|
9
|
+
@consumer_key = consumer_key
|
9
10
|
@host = host
|
10
|
-
@
|
11
|
+
@shared_secret = shared_secret
|
11
12
|
@protocol = protocol
|
12
13
|
end
|
13
14
|
|
14
15
|
def grant_permission(scope:, exp: nil, resource_id: nil)
|
15
16
|
payload = {
|
16
17
|
host: host,
|
18
|
+
consumer_key: consumer_key,
|
17
19
|
scope: scope,
|
18
20
|
exp: exp || Time.now.utc.to_i + 60,
|
19
21
|
|
@@ -27,7 +29,7 @@ module QuizApiClient::Services
|
|
27
29
|
}
|
28
30
|
payload[:resource_id] = resource_id if resource_id
|
29
31
|
|
30
|
-
JWT.encode(payload,
|
32
|
+
JWT.encode(payload, shared_secret, HASHING_ALGORITHM)
|
31
33
|
end
|
32
34
|
end
|
33
35
|
end
|
@@ -27,14 +27,14 @@ module QuizApiClient::Services
|
|
27
27
|
private
|
28
28
|
|
29
29
|
def post_to_quiz_api(params:, token:)
|
30
|
-
|
30
|
+
client(token: token).post(
|
31
31
|
'/api/quizzes',
|
32
32
|
quiz: params
|
33
33
|
)
|
34
34
|
end
|
35
35
|
|
36
36
|
def get_from_quiz_api(params:, token:)
|
37
|
-
|
37
|
+
client(token: token).get(
|
38
38
|
'/api/quizzes',
|
39
39
|
params
|
40
40
|
)
|
data/lib/quiz_api_client.rb
CHANGED
@@ -7,42 +7,47 @@ require 'quiz_api_client/services/quiz_sessions_service'
|
|
7
7
|
|
8
8
|
module QuizApiClient
|
9
9
|
class Client
|
10
|
-
attr_reader :
|
10
|
+
attr_reader :consumer_key, :host, :shared_secret, :protocol
|
11
11
|
|
12
|
-
def initialize(
|
13
|
-
@
|
14
|
-
@
|
12
|
+
def initialize(consumer_key:, host:, shared_secret:, protocol: 'https')
|
13
|
+
@consumer_key = consumer_key
|
14
|
+
@host = host
|
15
|
+
@shared_secret = shared_secret
|
15
16
|
@protocol = protocol
|
16
17
|
end
|
17
18
|
|
18
19
|
def quiz_service
|
19
20
|
@_quiz_service ||= Services::QuizService.new(
|
20
|
-
|
21
|
-
|
21
|
+
consumer_key: consumer_key,
|
22
|
+
host: host,
|
23
|
+
shared_secret: shared_secret,
|
22
24
|
protocol: protocol
|
23
25
|
)
|
24
26
|
end
|
25
27
|
|
26
28
|
def quizzes_service
|
27
29
|
@_quizzes_service ||= Services::QuizzesService.new(
|
28
|
-
|
29
|
-
|
30
|
+
consumer_key: consumer_key,
|
31
|
+
host: host,
|
32
|
+
shared_secret: shared_secret,
|
30
33
|
protocol: protocol
|
31
34
|
)
|
32
35
|
end
|
33
36
|
|
34
37
|
def quiz_session_service
|
35
38
|
@_quiz_session_service ||= Services::QuizSessionService.new(
|
36
|
-
|
37
|
-
|
39
|
+
consumer_key: consumer_key,
|
40
|
+
host: host,
|
41
|
+
shared_secret: shared_secret,
|
38
42
|
protocol: protocol
|
39
43
|
)
|
40
44
|
end
|
41
45
|
|
42
46
|
def quiz_sessions_service
|
43
47
|
@_quiz_sessions_service ||= Services::QuizSessionsService.new(
|
44
|
-
|
45
|
-
|
48
|
+
consumer_key: consumer_key,
|
49
|
+
host: host,
|
50
|
+
shared_secret: shared_secret,
|
46
51
|
protocol: protocol
|
47
52
|
)
|
48
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quiz_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|