bht_survey 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4f67171e515407f84b9a99933a7f5834bf96045c
4
+ data.tar.gz: c5478b894db9b23b70623c9ea02dee49db9f43ba
5
+ SHA512:
6
+ metadata.gz: 18371fb560679c708f54a6c3676efd1da2251cf54583481c16d8c045c6db49d93fed8f07495dca56afc8078307f5d15f0e4abf9a8371351d78b015ecdae04c00
7
+ data.tar.gz: 478cd75e6a62d86fb185b7a8aa0169e7cd1012d4864e6b1e25853e311ad2ff2134a6ab1e4b55fcdee7a755623a998f46a651df5ddd2795027c4954400950832f
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.5
5
+ before_install: gem install bundler -v 1.14.4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ #source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bht_survey.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 jfinucane
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # BhtSurvey
2
+
3
+ This is a simple wrapper for Faraday access to the Qualtric Interface Service. It generates the workspace key separately from individual API calls.
4
+
5
+
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'bht_survey'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install bht_survey
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jfinucane/bht_survey.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,30 @@
1
+ module BhtSurvey
2
+
3
+ class QualtricsSurveysController < ApplicationController
4
+ include QualtricsInterface
5
+ before_action :set_workspace
6
+ EXCLUDELIST = ['IPAddress', 'Location', 'StartDate', 'ResponseID', 'ResponseSet',
7
+ 'LocationAccuracy', 'LocationLatitude', 'LocationLongitude', 'RecipientLastName', 'RecipientFirstName',
8
+ 'Status', 'Finished', 'RecipientEmail']
9
+ def index
10
+ participant_id = params["participant_id"]
11
+ survey_name = params["survey_name"]
12
+ result = get_participant_link participant_id, survey_name
13
+ unique_link = result['unique_link']
14
+ puts 'Unique',unique_link
15
+ render json: {unique_link: unique_link}.to_json, status: 200
16
+ end
17
+
18
+ def results
19
+ puts '-----------------seriously'
20
+ participant_id = params["participant_id"]
21
+ survey_name = params["survey_name"]
22
+ result = get_results participant_id, survey_name
23
+ display_answers = result['answers'].except(*EXCLUDELIST)
24
+ render json: display_answers.to_json, status: 200
25
+ end
26
+ end
27
+ end
28
+
29
+
30
+
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bht_survey/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bht_survey"
8
+ spec.version = BhtSurvey::VERSION
9
+ spec.authors = ["jfinucane"]
10
+ spec.email = ["jimway@gmail.com"]
11
+
12
+ spec.summary = %q{Shim for Faraday access to the APIs of Qualtrics Interface Service}
13
+ spec.description = %q{Requires a hash with three key values
14
+ @workspace = {
15
+ 'qualtrics_id' => ENV['qualtrics_id'],
16
+ 'qualtrics_library' => ENV['qualtrics_library_id'],
17
+ 'study_workspace_name' => 'Shuti-Example'
18
+ }
19
+ }
20
+ spec.homepage = "https://github.com/jfinucane/bht_survey.git"
21
+ spec.license = "MIT"
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
24
+ f.match(%r{^(test|spec|features)/})
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.14"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.2"
33
+ spec.add_dependency "rails", "~> 5.0"
34
+
35
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bht_survey"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ Rails.application.routes.draw do
2
+ get 'qualtrics_surveys' => 'bht_survey/qualtrics_surveys#index'
3
+ get 'qualtrics_surveys/results' => 'bht_survey/qualtrics_surveys#results'
4
+ end
@@ -0,0 +1,8 @@
1
+ require "bht_survey/version"
2
+ require 'bht_survey/engine'
3
+ require 'bht_survey/qualtrics_interface'
4
+ module BhtSurvey
5
+ STUFF=9
6
+ end
7
+
8
+
@@ -0,0 +1,4 @@
1
+ require 'rails/engine' #Pat from https://github.com/pat/combustion/issues/70
2
+ module BhtSurvey
3
+ class Engine < Rails::Engine; end
4
+ end
@@ -0,0 +1,49 @@
1
+ module QualtricsInterface
2
+ def get_api method_url, api_conditions
3
+ connect_to_api = Faraday.new(url: API_URL) do |faraday|
4
+ faraday.response :logger do | logger |
5
+ logger.filter(/(api_key=)(\w+)/,'\1[REMOVED]') #TODO remove the qualtics key
6
+ end
7
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
8
+ end
9
+
10
+ local_response = connect_to_api.get method_url, api_conditions
11
+ result = JSON.parse(local_response.body)
12
+ result
13
+ end
14
+
15
+ # Initialization parameters are used to provide credentials in RICE
16
+ # The Account table is used for saving credentials for multiple survey developers.
17
+
18
+ def get_workspace_key
19
+ puts "----------------- #{@workspace}"
20
+ api_params = {
21
+ qualtrics_id: @workspace['qualtrics_id'],
22
+ qualtrics_library: @workspace['qualtrics_library'],
23
+ study_workspace_name: @workspace['study_workspace_name']
24
+ }
25
+ puts ">>>>>>>>>>>>>>>>>>> #{api_params.inspect}"
26
+ result = get_api 'api/v1/study_workspace', api_params
27
+ session[:workspace_key] = result['response']['workspace_key']
28
+ end
29
+
30
+ def get_participant_states participant_id
31
+ api_params = {workspace_key: get_workspace_key, participant_id: participant_id}
32
+ result = get_api 'api/v1/participant_states', api_params
33
+ result['response']
34
+ end
35
+
36
+ def get_participant_link participant_id, survey_name
37
+ api_params = {workspace_key: get_workspace_key, participant_id: participant_id, assessment_name: survey_name}
38
+ result = get_api 'api/v1/participant_link', api_params
39
+ result['response']
40
+ end
41
+
42
+ def get_results participant_id, survey_name
43
+ api_params = {workspace_key: get_workspace_key, participant_id: participant_id, assessment_name: survey_name}
44
+ result = get_api 'api/v1/survey_results', api_params
45
+ result['response']
46
+ end
47
+
48
+ end
49
+
@@ -0,0 +1,3 @@
1
+ module BhtSurvey
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bht_survey
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - jfinucane
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description: "Requires a hash with three key values \n @workspace = {\n 'qualtrics_id'
70
+ => ENV['qualtrics_id'],\n 'qualtrics_library' => ENV['qualtrics_library_id'],\n
71
+ \ 'study_workspace_name' => 'Shuti-Example'\n }\n "
72
+ email:
73
+ - jimway@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - app/controllers/bht_survey/qualtrics_surveys_controller.rb
86
+ - bht_survey.gemspec
87
+ - bin/console
88
+ - bin/setup
89
+ - config/routes.rb
90
+ - lib/bht_survey.rb
91
+ - lib/bht_survey/engine.rb
92
+ - lib/bht_survey/qualtrics_interface.rb
93
+ - lib/bht_survey/version.rb
94
+ homepage: https://github.com/jfinucane/bht_survey.git
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.8
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Shim for Faraday access to the APIs of Qualtrics Interface Service
118
+ test_files: []