quiz_api_client 2.5.2 → 2.7.0

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
- SHA1:
3
- metadata.gz: b4180659165856ded9b3764ed9e934de07a3d776
4
- data.tar.gz: 88023493343bbf8acecf384db4d30d056f78ac80
2
+ SHA256:
3
+ metadata.gz: c62d6c7422e6e7955a1d2ff49b5129adfae616cd48e20586226f8793361cf5d6
4
+ data.tar.gz: 3109b9e79d25dad954ff33ce31be7a6fab7cb78b10ad11865267ff55e52efd11
5
5
  SHA512:
6
- metadata.gz: aa0eaa98585b415c124008c862696ebad0c185f0f5d425a1c874bcf62575882e527b67e58fb0303bb127567b17278c4de990700535be814cf299888a501746d5
7
- data.tar.gz: e1039a2b1ec7403999120785011e87c9205ee9972bfdfdee204e0c5809a37b30dc711b6511edc92d47de9659c087a4f8fcf4bbcc486151ac246184d3d16e93ad
6
+ metadata.gz: e8d52fbd491cae973d46862f1ea33efc844c12eacf6308c7a5eff9d711a65a9a09769f0f19eec2844696789862ce68bb0859a2ae5cb8b04dbc56401593539407
7
+ data.tar.gz: 8c989448eab56f161e2a4dfacf6d68f12f7ad4244410e43478374f5cff60942b397312d4b11527e4a6546cc42c8632c93d43575e92db6f6788bd31bec0b451b8
data/README.md CHANGED
@@ -185,21 +185,19 @@ When you add or modify a service, be sure to add or modify contract tests!
185
185
  ## Contract Tests
186
186
 
187
187
  We use [Pact](https://docs.pact.io/) for our contract testing. To generate
188
- a Pact file, run `bin/contracts`.
189
-
190
- The `bin/contracts` script will generate the Pact file and place it in the
191
- pacts/ directory. It will also attempt to publish the Pact file to a local
192
- Pact Broker.
188
+ a Pact file, run `bin/contracts-generate`. The script will generate the Pact
189
+ file and place it in the pacts/ directory. It will also attempt to publish the
190
+ Pact file to a local Pact Broker.
193
191
 
194
192
  ### Development Workflow:
195
193
 
196
194
  1. In the quiz_api repo, spin up the Quiz API service with `bin/dev-setup`
197
195
  2. In the quiz_pact_broker repo, spin up a Pact Broker with `bin/dev-setup`
198
196
  3. In the quiz_api repo, write Pact provider states in the
199
- spec/service_consumers/quiz_api_client_ruby/ directory as needed
197
+ spec/service_consumers/api/quiz_api_client_ruby/ directory as needed
200
198
  4. In this repo's spec/contracts/ directory, write or modify a contract test
201
- 5. In this repo, run `bin/contracts` to generate a Pact file and publish it to
202
- the Pact Broker
199
+ 5. In this repo, run `bin/contracts-generate` to generate a Pact file and
200
+ publish it to the Pact Broker
203
201
  6. In the quiz_api repo, run `bin/contracts` to pull the new Pact file from
204
202
  the Pact Broker and run the updated contract tests against the Quiz API service
205
203
 
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'pact_broker/client/tasks'
3
3
  require 'rspec/core/rake_task'
4
+ require_relative './spec/contracts/pact_config'
4
5
 
5
6
  RSpec::Core::RakeTask.new(:spec)
6
7
 
@@ -20,32 +21,28 @@ task :console do
20
21
  end
21
22
 
22
23
  # see https://github.com/pact-foundation/pact_broker-client/blob/master/README.md
23
- PactBroker::Client::PublicationTask.new(:local) do |task|
24
- require 'quiz_api_client'
25
-
26
- task.consumer_version = QuizApiClient::VERSION
27
- task.pattern = 'pacts/*.json'
28
-
29
- task.pact_broker_base_url = 'http://pact-broker.docker'
30
- task.pact_broker_basic_auth = { username: 'pact', password: 'broker' }
24
+ namespace :broker do
25
+ PactBroker::Client::PublicationTask.new(:local) do |task|
26
+ prepare_pact_files_for_publishing(task)
27
+ end
31
28
 
32
- # tag the pact with the git branch name
33
- task.tag = `git rev-parse --abbrev-ref HEAD`.strip
34
- puts "Pact file tagged with: #{task.tag}"
35
- end
29
+ PactBroker::Client::PublicationTask.new(:jenkins_post_merge) do |task|
30
+ prepare_pact_files_for_publishing(task)
31
+ end
36
32
 
37
- PactBroker::Client::PublicationTask.new(:jenkins_post_merge) do |task|
38
- require 'quiz_api_client'
33
+ def prepare_pact_files_for_publishing(task)
34
+ task.pattern = 'pacts/*.json'
39
35
 
40
- task.consumer_version = QuizApiClient::VERSION
41
- task.pattern = 'pacts/*.json'
36
+ task.pact_broker_base_url = PactConfig.broker_host
37
+ task.pact_broker_basic_auth = {
38
+ username: PactConfig.broker_username,
39
+ password: PactConfig.broker_password
40
+ }
42
41
 
43
- task.pact_broker_base_url = ENV.fetch('PACT_BROKER_BASE_URL')
44
- task.pact_broker_basic_auth = {
45
- username: ENV.fetch('PACT_BROKER_BASIC_AUTH_USERNAME'),
46
- password: ENV.fetch('PACT_BROKER_BASIC_AUTH_PASSWORD')
47
- }
42
+ task.consumer_version = PactConfig.consumer_version
43
+ puts "Consumer version: #{task.consumer_version}"
48
44
 
49
- task.tag = 'master'
50
- puts "Pact file tagged with: #{task.tag}"
45
+ task.tag = PactConfig.consumer_tag
46
+ puts "Pact file tagged with: #{task.tag}"
47
+ end
51
48
  end
@@ -12,10 +12,16 @@ function print_results() {
12
12
 
13
13
  docker cp contracts:/usr/src/app/log . &> /dev/null
14
14
  docker cp contracts:/usr/src/app/pacts . &> /dev/null
15
+ docker rm -f contracts &> /dev/null
15
16
 
16
17
  docker-compose rm -fv contracts-testrunner &> /dev/null
17
18
  }
18
19
  trap print_results INT TERM EXIT
19
20
  set -e
20
21
 
21
- docker-compose run --name contracts contracts-testrunner bash -c "bundle && bundle exec rspec spec/contracts && bundle exec rake pact:publish:local"
22
+ rm -rf pacts
23
+ sha="$(git rev-parse --short HEAD)"
24
+
25
+
26
+ docker-compose run --name contracts -e SHA="${sha}" contracts-testrunner bash -c \
27
+ "bundle && bundle exec rspec spec/contracts && bundle exec rake broker:pact:publish:local"
data/bin/setup CHANGED
@@ -15,23 +15,51 @@ function print_results() {
15
15
  trap print_results INT TERM EXIT
16
16
  set -e
17
17
 
18
+ OSNAME=$(uname | tr "[:upper:]" "[:lower:]")
19
+
20
+ function generate_docker_override_os () {
21
+ sed -E "s/#(.*# ${OSNAME}$)/\1/"
22
+ }
23
+
24
+ function generate_docker_override_filesystem () {
25
+ if [ -z "${IGNORE_FILESYSTEM_OVERRIDE}" ]; then
26
+ sed -E "s/#(.*# ${OSNAME}:fs)/\1/"
27
+ else
28
+ cat
29
+ fi
30
+ }
31
+
32
+ function generate_docker_override() {
33
+ if [ -e docker-compose.override.yml ]; then
34
+ echo "We found an existing docker-compose.override.yml"
35
+ echo ""
36
+ echo "You'll want to merge that file with the version controlled
37
+ docker-compose.dev.override.yml file to make sure you've got
38
+ the most recent changes"
39
+ echo ""
40
+ else
41
+ echo "we are building the development example override file to docker-compose.override.yml for you"
42
+ generate_docker_override_os < docker-compose.dev.override.yml | \
43
+ generate_docker_override_filesystem > docker-compose.override.yml
44
+ fi
45
+ }
46
+
47
+ function os_linux_specific_setup() {
48
+ mkdir -p log pacts
49
+ }
50
+
51
+ os_specific_setup() {
52
+ echo Configuring for "${OSNAME}"
53
+ case ${OSNAME} in
54
+ linux)
55
+ os_linux_specific_setup
56
+ ;;
57
+ esac
58
+ }
59
+
60
+ os_specific_setup
61
+ generate_docker_override
62
+
18
63
  echo ""
19
64
  echo "Preparing environment for native development..."
20
65
  bundle install
21
-
22
- echo ""
23
- echo "Preparing environment for dockerized development (if you choose to use it)..."
24
-
25
- override_file='docker-compose.override.yml'
26
- dev_override_file='docker-compose.dev.override.yml'
27
- if [ -f ${override_file} ] && ! cmp ${override_file} ${dev_override_file} --silent; then
28
- echo "We found an existing ${override_file}"
29
- echo ""
30
- echo "You'll want to merge that file with the version controlled
31
- docker-compose.dev.override.yml file to make sure you've got
32
- the most recent changes."
33
- echo ""
34
- else
35
- echo "We are copying the development example override file to docker-compose.override.yml for you."
36
- cp ${dev_override_file} ${override_file}
37
- fi
data/build.sh CHANGED
@@ -6,11 +6,16 @@ function publish_pact_file_to_pact_broker()
6
6
  {
7
7
  echo "Publishing pact file to Pact Broker..."
8
8
 
9
+ sha="$(git rev-parse --short HEAD)"
10
+
9
11
  docker-compose run --rm \
10
- -e PACT_BROKER_BASE_URL=${PACT_BROKER_BASE_URL} \
11
- -e PACT_BROKER_BASIC_AUTH_USERNAME=${PACT_BROKER_BASIC_AUTH_USERNAME} \
12
- -e PACT_BROKER_BASIC_AUTH_PASSWORD=${PACT_BROKER_BASIC_AUTH_PASSWORD} \
13
- contracts-testrunner bundle exec rake pact:publish:jenkins_post_merge
12
+ -e JENKINS_URL="${JENKINS_URL}" \
13
+ -e PACT_BROKER_HOST="${PACT_BROKER_HOST}" \
14
+ -e PACT_BROKER_USERNAME="${PACT_BROKER_USERNAME}" \
15
+ -e PACT_BROKER_PASSWORD="${PACT_BROKER_PASSWORD}" \
16
+ -e PACT_CONSUMER_TAG="${PACT_CONSUMER_TAG}" \
17
+ -e SHA="${sha}" \
18
+ contracts-testrunner bundle exec rake broker:pact:publish:jenkins_post_merge
14
19
  }
15
20
 
16
21
  function cleanup() {
@@ -7,9 +7,13 @@ services:
7
7
  - bundler-config:/home/docker/.rvm/gems/ruby-2.4.0
8
8
 
9
9
  contracts-testrunner:
10
+ #external_links: # linux
11
+ # - dory_dinghy_http_proxy:pact-broker.docker # linux
10
12
  volumes:
11
13
  - .:/usr/src/app
14
+ #- api-logs:/usr/src/app/log # linux:fs
12
15
  - bundler-config:/home/docker/.rvm/gems/ruby-2.4.0
13
16
 
14
17
  volumes:
15
18
  bundler-config: {}
19
+ api-logs: {}
@@ -34,6 +34,10 @@ module QuizApiClient
34
34
  @_quiz_sessions_service ||= Services::QuizSessionsService.new(service_params)
35
35
  end
36
36
 
37
+ def quiz_clone_job_service
38
+ @_quiz_clone_job_service ||= Services::QuizCloneJobService.new(service_params)
39
+ end
40
+
37
41
  def quiz_clone_jobs_service
38
42
  @_quiz_clone_jobs_service ||= Services::QuizCloneJobsService.new(service_params)
39
43
  end
@@ -78,6 +82,10 @@ module QuizApiClient
78
82
  @_interaction_types_service ||= QuizApiClient::Services::InteractionTypesService.new(service_params)
79
83
  end
80
84
 
85
+ def shared_banks
86
+ @_shared_banks ||= QuizApiClient::Services::SharedBanks.new(service_params)
87
+ end
88
+
81
89
  private
82
90
 
83
91
  def service_params
@@ -111,6 +119,8 @@ require 'quiz_api_client/services/quiz_sessions_service'
111
119
  require 'quiz_api_client/services/quiz_service'
112
120
  require 'quiz_api_client/services/quizzes_service'
113
121
  require 'quiz_api_client/services/quiz_session_result_service'
122
+ require 'quiz_api_client/services/quiz_clone_job_service'
114
123
  require 'quiz_api_client/services/quiz_clone_jobs_service'
115
124
  require 'quiz_api_client/services/session_items_service'
116
125
  require 'quiz_api_client/services/session_item_results_service'
126
+ require 'quiz_api_client/services/shared_banks'
@@ -90,6 +90,7 @@ module QuizApiClient
90
90
 
91
91
  until request_url.nil?
92
92
  resp = make_request(method, request_url, request_options)
93
+ raise RequestFailed, "#{url} responded #{resp.body} (#{resp.code})" unless resp.code == 200
93
94
  entities.concat(resp.parsed_response)
94
95
  request_url, request_options = next_page(resp, url, options)
95
96
  end
@@ -8,8 +8,10 @@ module QuizApiClient::Services
8
8
  private
9
9
 
10
10
  def post_to_quiz_api(params:, token:)
11
+ quiz_id = params.delete(:quiz_id)
11
12
  client(token: token).post(
12
- "/api/quizzes/#{params[:quiz_id]}/items",
13
+ "/api/quizzes/#{quiz_id}/items",
14
+ quiz_id: quiz_id,
13
15
  item: params
14
16
  )
15
17
  end
@@ -0,0 +1,16 @@
1
+ module QuizApiClient::Services
2
+ class QuizCloneJobService < BaseApiService
3
+ def show(params:, token: nil)
4
+ raise 'Quiz Clone Job Id Required' unless params && params[:id]
5
+ get_from_quiz_api(params: params, token: token)
6
+ end
7
+
8
+ private
9
+
10
+ def get_from_quiz_api(params:, token:)
11
+ client(token: token).get(
12
+ "/api/quiz_clone_jobs/#{params.fetch(:id)}"
13
+ )
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,29 @@
1
+ module QuizApiClient::Services
2
+ class SharedBanks < BaseApiService
3
+ def list(params:, token: nil, all: false)
4
+ raise 'Bank Id Required' unless params && params[:bank_id]
5
+ client(token: token).get(
6
+ "/api/banks/#{params[:bank_id]}/shared_banks",
7
+ all: all
8
+ )
9
+ end
10
+
11
+ def create(params:, token: nil)
12
+ raise 'Bank Id Required' unless params && params[:bank_id]
13
+ client(token: token).post(
14
+ "/api/banks/#{params[:bank_id]}/shared_banks",
15
+ params
16
+ )
17
+ end
18
+
19
+ def update(params:, token: nil)
20
+ raise 'Bank Id Required' unless params && params[:bank_id]
21
+ raise 'Shared Bank Id Required' unless params && params[:shared_bank_id]
22
+ shared_bank_id = params.delete(:shared_bank_id)
23
+ client(token: token).put(
24
+ "/api/banks/#{params[:bank_id]}/shared_banks/#{shared_bank_id}",
25
+ params
26
+ )
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module QuizApiClient
2
- VERSION = '2.5.2'.freeze
2
+ VERSION = '2.7.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quiz_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.2
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wang
@@ -19,7 +19,7 @@ authors:
19
19
  autorequire:
20
20
  bindir: exe
21
21
  cert_chain: []
22
- date: 2018-03-13 00:00:00.000000000 Z
22
+ date: 2018-10-15 00:00:00.000000000 Z
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
25
25
  name: httparty
@@ -210,7 +210,7 @@ files:
210
210
  - README.md
211
211
  - Rakefile
212
212
  - bin/console
213
- - bin/contracts
213
+ - bin/contracts-generate
214
214
  - bin/setup
215
215
  - build.sh
216
216
  - docker-compose.dev.override.yml
@@ -225,6 +225,7 @@ files:
225
225
  - lib/quiz_api_client/services/jwt_service.rb
226
226
  - lib/quiz_api_client/services/qti_imports_service.rb
227
227
  - lib/quiz_api_client/services/quiz_analyses_service.rb
228
+ - lib/quiz_api_client/services/quiz_clone_job_service.rb
228
229
  - lib/quiz_api_client/services/quiz_clone_jobs_service.rb
229
230
  - lib/quiz_api_client/services/quiz_entries_service.rb
230
231
  - lib/quiz_api_client/services/quiz_service.rb
@@ -235,6 +236,7 @@ files:
235
236
  - lib/quiz_api_client/services/quizzes_service.rb
236
237
  - lib/quiz_api_client/services/session_item_results_service.rb
237
238
  - lib/quiz_api_client/services/session_items_service.rb
239
+ - lib/quiz_api_client/services/shared_banks.rb
238
240
  - lib/quiz_api_client/version.rb
239
241
  - quiz_api_client.gemspec
240
242
  homepage:
@@ -256,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
258
  version: '0'
257
259
  requirements: []
258
260
  rubyforge_project:
259
- rubygems_version: 2.6.14
261
+ rubygems_version: 2.7.6
260
262
  signing_key:
261
263
  specification_version: 4
262
264
  summary: Ruby client for quiz_api