quiz_api_client 0.1.0 → 0.1.1

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: 8e46fc44771fd9dd6ceeb5aaa6c4e331ac5f500b
4
- data.tar.gz: 1bf44fddb2e367f4a1271bafcccf3d256f66994d
3
+ metadata.gz: 00ad9fa5b40368f421f67c5a3d92d247fccb871b
4
+ data.tar.gz: 32cdb839ee80009fe55412dd35eac9c6ce55fd8e
5
5
  SHA512:
6
- metadata.gz: 6847f2213f8778d0ab0b6e5513f37cea73d6cbb1f4e7d9f27fce94b2053f437c5dfb1b214012d2b1383e592b5094a8575d6333006afdf1183b041d1a86a045e2
7
- data.tar.gz: b3e2e93799b2796c2b6ff639009c95adb8c00e2ee65f02d5f1a41813757291977eb6b73b805a079d3cde325a058bd3c4c7cb2c7a2deb2fff2548993fca3cc16c
6
+ metadata.gz: a0ac3d9c3d96b7f3287bc9ef95977a6628fd0c31385b87cd28da717a80fc92f3bec6d7ab8c272ca124fb78e5ce46f986b10f0ac97e684575fd38164513880599
7
+ data.tar.gz: a27958e16dd8769422fb44b60b3ad82bc3f7c32f973c66b8c64f89946a29d45fd8a165ee6a312c86c739fa42432a32a9200666b13b07d45556a44b2f5cbec422
data/README.md CHANGED
@@ -150,6 +150,10 @@ client.quiz_sessions_service.create(
150
150
 
151
151
  ## Development
152
152
 
153
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `rake console` for an interactive prompt that will allow you to experiment.
153
+ After checking out the repo, run `bin/setup` to install dependencies.
154
+
155
+ Then, run `rake spec` to run the tests.
156
+
157
+ You can also run `rake console` for an interactive prompt that will allow you to experiment.
154
158
 
155
159
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
@@ -7,38 +7,43 @@ 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
10
+ attr_reader :quiz_api_host, :quiz_api_secret_for_jwt, :protocol
11
11
 
12
- def initialize(quiz_api_host:, quiz_api_secret_for_jwt:)
12
+ def initialize(quiz_api_host:, quiz_api_secret_for_jwt:, protocol: 'https')
13
13
  @quiz_api_host = quiz_api_host
14
14
  @quiz_api_secret_for_jwt = quiz_api_secret_for_jwt
15
+ @protocol = protocol
15
16
  end
16
17
 
17
18
  def quiz_service
18
19
  @_quiz_service ||= Services::QuizService.new(
19
20
  quiz_api_host: quiz_api_host,
20
- quiz_api_secret_for_jwt: quiz_api_secret_for_jwt
21
+ quiz_api_secret_for_jwt: quiz_api_secret_for_jwt,
22
+ protocol: protocol
21
23
  )
22
24
  end
23
25
 
24
26
  def quizzes_service
25
27
  @_quizzes_service ||= Services::QuizzesService.new(
26
28
  quiz_api_host: quiz_api_host,
27
- quiz_api_secret_for_jwt: quiz_api_secret_for_jwt
29
+ quiz_api_secret_for_jwt: quiz_api_secret_for_jwt,
30
+ protocol: protocol
28
31
  )
29
32
  end
30
33
 
31
34
  def quiz_session_service
32
- @_quiz_service ||= Services::QuizSessionService.new(
35
+ @_quiz_session_service ||= Services::QuizSessionService.new(
33
36
  quiz_api_host: quiz_api_host,
34
- quiz_api_secret_for_jwt: quiz_api_secret_for_jwt
37
+ quiz_api_secret_for_jwt: quiz_api_secret_for_jwt,
38
+ protocol: protocol
35
39
  )
36
40
  end
37
41
 
38
42
  def quiz_sessions_service
39
43
  @_quiz_sessions_service ||= Services::QuizSessionsService.new(
40
44
  quiz_api_host: quiz_api_host,
41
- quiz_api_secret_for_jwt: quiz_api_secret_for_jwt
45
+ quiz_api_secret_for_jwt: quiz_api_secret_for_jwt,
46
+ protocol: protocol
42
47
  )
43
48
  end
44
49
  end
@@ -3,11 +3,12 @@ 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, :errors
6
+ attr_reader :quiz_api_host, :quiz_api_secret_for_jwt, :protocol, :errors
7
7
 
8
- def initialize(quiz_api_host:, quiz_api_secret_for_jwt:)
8
+ def initialize(quiz_api_host:, quiz_api_secret_for_jwt:, protocol: 'https')
9
9
  @quiz_api_host = quiz_api_host
10
10
  @quiz_api_secret_for_jwt = quiz_api_secret_for_jwt
11
+ @protocol = protocol
11
12
  @errors = []
12
13
  end
13
14
 
@@ -18,8 +19,10 @@ module QuizApiClient::Services
18
19
  generate_token(scope: scope, resource_id: resource_id)
19
20
  end
20
21
 
21
- def quiz_api_url
22
- "http://#{quiz_api_host}"
22
+ def quiz_api_uri
23
+ uri = URI::HTTP.build(host: quiz_api_host)
24
+ uri.scheme = protocol
25
+ uri.to_s
23
26
  end
24
27
 
25
28
  def generate_token(scope:, exp: nil, resource_id: nil)
@@ -28,14 +31,15 @@ module QuizApiClient::Services
28
31
 
29
32
  def jwt_service
30
33
  QuizApiClient::Services::JwtService.new(
31
- url: quiz_api_url,
32
- jwt_secret: quiz_api_secret_for_jwt
34
+ host: quiz_api_host,
35
+ jwt_secret: quiz_api_secret_for_jwt,
36
+ protocol: protocol
33
37
  )
34
38
  end
35
39
 
36
40
  def quiz_api_client(token:)
37
41
  QuizApiClient::HttpClient.new(
38
- uri: quiz_api_url,
42
+ uri: quiz_api_uri,
39
43
  jwt: token
40
44
  )
41
45
  end
@@ -3,16 +3,17 @@ require 'jwt'
3
3
  module QuizApiClient::Services
4
4
  HASHING_ALGORITHM = 'HS512'.freeze
5
5
  class JwtService
6
- attr_reader :url, :jwt_secret, :user_id
6
+ attr_reader :host, :jwt_secret, :protocol
7
7
 
8
- def initialize(jwt_secret:, url:)
9
- @url = url
8
+ def initialize(jwt_secret:, host:, protocol: 'https')
9
+ @host = host
10
10
  @jwt_secret = jwt_secret
11
+ @protocol = protocol
11
12
  end
12
13
 
13
14
  def grant_permission(scope:, exp: nil, resource_id: nil)
14
15
  payload = {
15
- host: url,
16
+ host: host,
16
17
  scope: scope,
17
18
  exp: exp || Time.now.utc.to_i + 60,
18
19
 
@@ -15,6 +15,7 @@ module QuizApiClient::Services
15
15
  def scope_update
16
16
  'quiz_session.update'
17
17
  end
18
+
18
19
  def scope_take
19
20
  'quiz_session.take'
20
21
  end
@@ -1,3 +1,3 @@
1
1
  module QuizApiClient
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  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.0
4
+ version: 0.1.1
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-10 00:00:00.000000000 Z
11
+ date: 2017-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty