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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 00ad9fa5b40368f421f67c5a3d92d247fccb871b
4
- data.tar.gz: 32cdb839ee80009fe55412dd35eac9c6ce55fd8e
3
+ metadata.gz: a7510dde6f3ff21858b72aa6fc3054583b210b9b
4
+ data.tar.gz: c5354fba783d3dc1399afae7462ac6d112568430
5
5
  SHA512:
6
- metadata.gz: a0ac3d9c3d96b7f3287bc9ef95977a6628fd0c31385b87cd28da717a80fc92f3bec6d7ab8c272ca124fb78e5ce46f986b10f0ac97e684575fd38164513880599
7
- data.tar.gz: a27958e16dd8769422fb44b60b3ad82bc3f7c32f973c66b8c64f89946a29d45fd8a165ee6a312c86c739fa42432a32a9200666b13b07d45556a44b2f5cbec422
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
- quiz_api_host: 'your-quiz-api-host-here.com',
34
- quiz_api_secret_for_jwt: 'the-api-secret normally stored on the quiz_api account'
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 :quiz_api_host, :quiz_api_secret_for_jwt, :protocol, :errors
7
-
8
- def initialize(quiz_api_host:, quiz_api_secret_for_jwt:, protocol: 'https')
9
- @quiz_api_host = quiz_api_host
10
- @quiz_api_secret_for_jwt = quiz_api_secret_for_jwt
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 quiz_api_uri
23
- uri = URI::HTTP.build(host: quiz_api_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
- host: quiz_api_host,
35
- jwt_secret: quiz_api_secret_for_jwt,
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 quiz_api_client(token:)
44
+ def client(token:)
41
45
  QuizApiClient::HttpClient.new(
42
- uri: quiz_api_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, :jwt_secret, :protocol
6
+ attr_reader :consumer_key, :host, :shared_secret, :protocol
7
7
 
8
- def initialize(jwt_secret:, host:, protocol: 'https')
8
+ def initialize(consumer_key: nil, shared_secret:, host:, protocol: 'https')
9
+ @consumer_key = consumer_key
9
10
  @host = host
10
- @jwt_secret = jwt_secret
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, jwt_secret, HASHING_ALGORITHM)
32
+ JWT.encode(payload, shared_secret, HASHING_ALGORITHM)
31
33
  end
32
34
  end
33
35
  end
@@ -23,7 +23,7 @@ module QuizApiClient::Services
23
23
  private
24
24
 
25
25
  def patch_to_quiz_api(params:, token:)
26
- quiz_api_client(token: token).patch(
26
+ client(token: token).patch(
27
27
  "/api/quiz_sessions/#{params[:id]}",
28
28
  quiz_session: params
29
29
  )
@@ -24,7 +24,7 @@ module QuizApiClient::Services
24
24
  private
25
25
 
26
26
  def post_to_quiz_api(params:, token:)
27
- quiz_api_client(token: token).post(
27
+ client(token: token).post(
28
28
  "/api/quizzes/#{params[:quiz_id]}/quiz_sessions",
29
29
  quiz_session: params
30
30
  )
@@ -27,14 +27,14 @@ module QuizApiClient::Services
27
27
  private
28
28
 
29
29
  def post_to_quiz_api(params:, token:)
30
- quiz_api_client(token: token).post(
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
- quiz_api_client(token: token).get(
37
+ client(token: token).get(
38
38
  '/api/quizzes',
39
39
  params
40
40
  )
@@ -1,3 +1,3 @@
1
1
  module QuizApiClient
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
@@ -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 :quiz_api_host, :quiz_api_secret_for_jwt, :protocol
10
+ attr_reader :consumer_key, :host, :shared_secret, :protocol
11
11
 
12
- def initialize(quiz_api_host:, quiz_api_secret_for_jwt:, protocol: 'https')
13
- @quiz_api_host = quiz_api_host
14
- @quiz_api_secret_for_jwt = quiz_api_secret_for_jwt
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
- quiz_api_host: quiz_api_host,
21
- quiz_api_secret_for_jwt: quiz_api_secret_for_jwt,
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
- quiz_api_host: quiz_api_host,
29
- quiz_api_secret_for_jwt: quiz_api_secret_for_jwt,
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
- quiz_api_host: quiz_api_host,
37
- quiz_api_secret_for_jwt: quiz_api_secret_for_jwt,
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
- quiz_api_host: quiz_api_host,
45
- quiz_api_secret_for_jwt: quiz_api_secret_for_jwt,
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.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-21 00:00:00.000000000 Z
11
+ date: 2017-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty