fizzy-api 0.0.1.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/.gitignore +128 -0
- data/.rubocop.yml +39 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +115 -0
- data/README.md +10 -0
- data/Rakefile +0 -0
- data/circle.yml +12 -0
- data/fizzy_api.gemspec +27 -0
- data/lib/fizzy/api/calculate_outcome.rb +28 -0
- data/lib/fizzy/api/errors/graph_not_found_error.rb +8 -0
- data/lib/fizzy/api/errors/outcome_not_available_error.rb +8 -0
- data/lib/fizzy/api/errors/too_few_measurements_error.rb +8 -0
- data/lib/fizzy/api/errors/unexpected_status_error.rb +8 -0
- data/lib/fizzy/api/errors.rb +4 -0
- data/lib/fizzy/api/models.rb +0 -0
- data/lib/fizzy/api/render_graph.rb +34 -0
- data/lib/fizzy/api/sessions/basic_auth_session.rb +87 -0
- data/lib/fizzy/api/sessions.rb +10 -0
- data/lib/fizzy/api/version.rb +5 -0
- data/lib/fizzy/api.rb +16 -0
- data/lib/fizzy-api.rb +1 -0
- data/rubocop-todo.yml +0 -0
- data/spec/factories/basic_auth_session.rb +5 -0
- data/spec/fizzy/api/calculate_outcome_spec.rb +51 -0
- data/spec/fizzy/api/render_graph_spec.rb +86 -0
- data/spec/fizzy/api/sessions/basic_auth_session_spec.rb +83 -0
- data/spec/fizzy/api/sessions_spec.rb +1 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/httparty_helpers.rb +5 -0
- metadata +43 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 624a2b9c0580b0d25778de852143f3fee0a68f37
|
|
4
|
+
data.tar.gz: ce9858bd4eb8eab70e8ea20989e0709a146a744d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1fa66d4c86515d7f2d5206031497354abfc1c5a58b448c63ef7f3d2837150cf5902dbeb43116fe0c16338c08cc27f26442d66069bef3de75d1e68dc9e9fa7cc1
|
|
7
|
+
data.tar.gz: fe8271087a9a8b3b1204230141792c1dd8a1e9be9e873415051aa41614fad06e6ec1d0af27d2a26d7d475c4ffb94989bbbb97bf2a0abd3b95eaf992de3a9364c
|
data/.gitignore
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
*.orig
|
|
2
|
+
*.bak
|
|
3
|
+
*.patch
|
|
4
|
+
*.csv
|
|
5
|
+
*~
|
|
6
|
+
.ruby-version
|
|
7
|
+
.rvmrc
|
|
8
|
+
.ruby*
|
|
9
|
+
.autotest
|
|
10
|
+
.bundle
|
|
11
|
+
.bundle/*
|
|
12
|
+
.DS_Store
|
|
13
|
+
.env
|
|
14
|
+
.idea
|
|
15
|
+
.loadpath
|
|
16
|
+
.powrc
|
|
17
|
+
.powenv
|
|
18
|
+
.project
|
|
19
|
+
.rspec
|
|
20
|
+
.sass-cache
|
|
21
|
+
.settings/*
|
|
22
|
+
.tmp_*
|
|
23
|
+
Guardfile.local
|
|
24
|
+
.~lock.*
|
|
25
|
+
app/assets/javascripts/i18n/*
|
|
26
|
+
aspec
|
|
27
|
+
config/database.yml
|
|
28
|
+
config/mongoid.yml
|
|
29
|
+
coverage
|
|
30
|
+
db/hl7-backup
|
|
31
|
+
db/questionnaires
|
|
32
|
+
db/seeds/*.example
|
|
33
|
+
doc/*/*.aux
|
|
34
|
+
doc/*/.*
|
|
35
|
+
doc/*/materiaal/*.psd
|
|
36
|
+
log/*.log
|
|
37
|
+
log/*.db
|
|
38
|
+
log/*.pid
|
|
39
|
+
nbproject
|
|
40
|
+
public/assets
|
|
41
|
+
scratch_directory
|
|
42
|
+
TAGS
|
|
43
|
+
tmp/**
|
|
44
|
+
script/switch_to_overrides
|
|
45
|
+
# Rails
|
|
46
|
+
.bundle
|
|
47
|
+
db/*.sqlite3
|
|
48
|
+
db/*.sqlite3-journal
|
|
49
|
+
*.log
|
|
50
|
+
tmp
|
|
51
|
+
tmp/**/*
|
|
52
|
+
|
|
53
|
+
# Documentation
|
|
54
|
+
doc/api
|
|
55
|
+
doc/app
|
|
56
|
+
.yardoc
|
|
57
|
+
.yardopts
|
|
58
|
+
coverage
|
|
59
|
+
|
|
60
|
+
# Public Uploads
|
|
61
|
+
public/system/*
|
|
62
|
+
public/themes/*
|
|
63
|
+
|
|
64
|
+
# Public Cache
|
|
65
|
+
public/javascripts/cache
|
|
66
|
+
public/stylesheets/cache
|
|
67
|
+
public/refinery/*
|
|
68
|
+
|
|
69
|
+
# Vendor Cache
|
|
70
|
+
vendor/cache
|
|
71
|
+
vendor/bundle
|
|
72
|
+
vendor/extensions/**/vendor/
|
|
73
|
+
vendor/extensions/**/bundle/
|
|
74
|
+
|
|
75
|
+
# Acts as Indexed
|
|
76
|
+
index/**/*
|
|
77
|
+
|
|
78
|
+
# Refinery Specific
|
|
79
|
+
*.tmproj
|
|
80
|
+
*.autobackupbyrefinery.*
|
|
81
|
+
refinerycms-*.gem
|
|
82
|
+
|
|
83
|
+
# Mac
|
|
84
|
+
.DS_Store
|
|
85
|
+
|
|
86
|
+
# Windows
|
|
87
|
+
Thumbs.db
|
|
88
|
+
|
|
89
|
+
# NetBeans
|
|
90
|
+
nbproject
|
|
91
|
+
|
|
92
|
+
# Eclipse
|
|
93
|
+
.project
|
|
94
|
+
|
|
95
|
+
# Redcar
|
|
96
|
+
.redcar
|
|
97
|
+
|
|
98
|
+
# Rubinius
|
|
99
|
+
*.rbc
|
|
100
|
+
|
|
101
|
+
# Vim
|
|
102
|
+
*.swp
|
|
103
|
+
*.swo
|
|
104
|
+
|
|
105
|
+
# RubyMine
|
|
106
|
+
.idea
|
|
107
|
+
|
|
108
|
+
# E-texteditor
|
|
109
|
+
.eprj
|
|
110
|
+
|
|
111
|
+
# Backup
|
|
112
|
+
*~
|
|
113
|
+
|
|
114
|
+
# Capybara Bug
|
|
115
|
+
capybara-*html
|
|
116
|
+
|
|
117
|
+
# sass
|
|
118
|
+
.sass-cache
|
|
119
|
+
.sass-cache/*
|
|
120
|
+
|
|
121
|
+
#rvm
|
|
122
|
+
.rvmrc
|
|
123
|
+
.rvmrc.*
|
|
124
|
+
|
|
125
|
+
# vendor/extensions dummy applications.
|
|
126
|
+
vendor/extensions/**/spec/dummy
|
|
127
|
+
|
|
128
|
+
*.gem
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
inherit_from: rubocop-todo.yml
|
|
2
|
+
|
|
3
|
+
AllCops:
|
|
4
|
+
Exclude:
|
|
5
|
+
- 'fizzy_api.gemspec'
|
|
6
|
+
- 'tmp/**/*'
|
|
7
|
+
- 'vendor/**/*'
|
|
8
|
+
- 'bin/*'
|
|
9
|
+
|
|
10
|
+
# Use UTF-8 as the source file encoding.
|
|
11
|
+
Encoding:
|
|
12
|
+
Enabled: false
|
|
13
|
+
|
|
14
|
+
# Limit lines to 80 characters.
|
|
15
|
+
LineLength:
|
|
16
|
+
Max: 120
|
|
17
|
+
|
|
18
|
+
# Avoid methods longer than 10 lines of code
|
|
19
|
+
MethodLength:
|
|
20
|
+
CountComments: false # count full line comments?
|
|
21
|
+
Max: 20
|
|
22
|
+
|
|
23
|
+
################################################################## DISABLED COPS
|
|
24
|
+
|
|
25
|
+
# These cops are disabled because we think they are a Bad Idea. If you add one
|
|
26
|
+
# here, make sure to add a comment describing what the cop does, and why this
|
|
27
|
+
# is a bad idea.
|
|
28
|
+
|
|
29
|
+
# Forces the argument names of the block given to #reduce to be `a, e`. Only
|
|
30
|
+
# applies on single-line blocks, but why would we want to force people to use
|
|
31
|
+
# less descriptive names?
|
|
32
|
+
Documentation:
|
|
33
|
+
Enabled: false
|
|
34
|
+
|
|
35
|
+
# Gems typically have one file named the-gem-name.rb which can be autorequired by bundler
|
|
36
|
+
Style/FileName:
|
|
37
|
+
Exclude:
|
|
38
|
+
- lib/fizzy-api.rb
|
|
39
|
+
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
fizzy-api (0.0.1.1)
|
|
5
|
+
active_interaction (~> 1.3)
|
|
6
|
+
httparty (~> 0.12)
|
|
7
|
+
virtus (~> 1.0)
|
|
8
|
+
|
|
9
|
+
GEM
|
|
10
|
+
remote: https://rubygems.org/
|
|
11
|
+
specs:
|
|
12
|
+
actionpack (4.1.8)
|
|
13
|
+
actionview (= 4.1.8)
|
|
14
|
+
activesupport (= 4.1.8)
|
|
15
|
+
rack (~> 1.5.2)
|
|
16
|
+
rack-test (~> 0.6.2)
|
|
17
|
+
actionview (4.1.8)
|
|
18
|
+
activesupport (= 4.1.8)
|
|
19
|
+
builder (~> 3.1)
|
|
20
|
+
erubis (~> 2.7.0)
|
|
21
|
+
active_interaction (1.3.0)
|
|
22
|
+
activemodel (>= 3.2, < 5)
|
|
23
|
+
activemodel (4.1.8)
|
|
24
|
+
activesupport (= 4.1.8)
|
|
25
|
+
builder (~> 3.1)
|
|
26
|
+
activesupport (4.1.8)
|
|
27
|
+
i18n (~> 0.6, >= 0.6.9)
|
|
28
|
+
json (~> 1.7, >= 1.7.7)
|
|
29
|
+
minitest (~> 5.1)
|
|
30
|
+
thread_safe (~> 0.1)
|
|
31
|
+
tzinfo (~> 1.1)
|
|
32
|
+
ast (2.0.0)
|
|
33
|
+
astrolabe (1.3.0)
|
|
34
|
+
parser (>= 2.2.0.pre.3, < 3.0)
|
|
35
|
+
axiom-types (0.1.1)
|
|
36
|
+
descendants_tracker (~> 0.0.4)
|
|
37
|
+
ice_nine (~> 0.11.0)
|
|
38
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
|
39
|
+
builder (3.2.2)
|
|
40
|
+
coercible (1.0.0)
|
|
41
|
+
descendants_tracker (~> 0.0.1)
|
|
42
|
+
descendants_tracker (0.0.4)
|
|
43
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
|
44
|
+
diff-lcs (1.2.5)
|
|
45
|
+
equalizer (0.0.9)
|
|
46
|
+
erubis (2.7.0)
|
|
47
|
+
factory_girl (4.5.0)
|
|
48
|
+
activesupport (>= 3.0.0)
|
|
49
|
+
factory_girl_rails (4.5.0)
|
|
50
|
+
factory_girl (~> 4.5.0)
|
|
51
|
+
railties (>= 3.0.0)
|
|
52
|
+
httparty (0.12.0)
|
|
53
|
+
json (~> 1.8)
|
|
54
|
+
multi_xml (>= 0.5.2)
|
|
55
|
+
i18n (0.6.11)
|
|
56
|
+
ice_nine (0.11.1)
|
|
57
|
+
json (1.8.1)
|
|
58
|
+
minitest (5.4.3)
|
|
59
|
+
multi_xml (0.5.5)
|
|
60
|
+
parser (2.2.0.pre.8)
|
|
61
|
+
ast (>= 1.1, < 3.0)
|
|
62
|
+
slop (~> 3.4, >= 3.4.5)
|
|
63
|
+
powerpack (0.0.9)
|
|
64
|
+
rack (1.5.2)
|
|
65
|
+
rack-test (0.6.2)
|
|
66
|
+
rack (>= 1.0)
|
|
67
|
+
railties (4.1.8)
|
|
68
|
+
actionpack (= 4.1.8)
|
|
69
|
+
activesupport (= 4.1.8)
|
|
70
|
+
rake (>= 0.8.7)
|
|
71
|
+
thor (>= 0.18.1, < 2.0)
|
|
72
|
+
rainbow (2.0.0)
|
|
73
|
+
rake (10.4.0)
|
|
74
|
+
rspec (3.1.0)
|
|
75
|
+
rspec-core (~> 3.1.0)
|
|
76
|
+
rspec-expectations (~> 3.1.0)
|
|
77
|
+
rspec-mocks (~> 3.1.0)
|
|
78
|
+
rspec-core (3.1.7)
|
|
79
|
+
rspec-support (~> 3.1.0)
|
|
80
|
+
rspec-expectations (3.1.2)
|
|
81
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
82
|
+
rspec-support (~> 3.1.0)
|
|
83
|
+
rspec-mocks (3.1.3)
|
|
84
|
+
rspec-support (~> 3.1.0)
|
|
85
|
+
rspec-support (3.1.2)
|
|
86
|
+
rubocop (0.27.1)
|
|
87
|
+
astrolabe (~> 1.3)
|
|
88
|
+
parser (>= 2.2.0.pre.7, < 3.0)
|
|
89
|
+
powerpack (~> 0.0.6)
|
|
90
|
+
rainbow (>= 1.99.1, < 3.0)
|
|
91
|
+
ruby-progressbar (~> 1.4)
|
|
92
|
+
ruby-progressbar (1.7.0)
|
|
93
|
+
slop (3.6.0)
|
|
94
|
+
thor (0.19.1)
|
|
95
|
+
thread_safe (0.3.4)
|
|
96
|
+
tzinfo (1.2.2)
|
|
97
|
+
thread_safe (~> 0.1)
|
|
98
|
+
virtus (1.0.3)
|
|
99
|
+
axiom-types (~> 0.1)
|
|
100
|
+
coercible (~> 1.0)
|
|
101
|
+
descendants_tracker (~> 0.0, >= 0.0.3)
|
|
102
|
+
equalizer (~> 0.0, >= 0.0.9)
|
|
103
|
+
|
|
104
|
+
PLATFORMS
|
|
105
|
+
ruby
|
|
106
|
+
|
|
107
|
+
DEPENDENCIES
|
|
108
|
+
active_interaction (~> 1.3.0)
|
|
109
|
+
bundler (~> 1.7)
|
|
110
|
+
factory_girl_rails
|
|
111
|
+
fizzy-api!
|
|
112
|
+
httparty (~> 0.12.0)
|
|
113
|
+
rake (~> 10.4)
|
|
114
|
+
rspec
|
|
115
|
+
rubocop
|
data/README.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
fizzy_api
|
|
2
|
+
=========
|
|
3
|
+
|
|
4
|
+
[](http://badge.fury.io/rb/fizzy-api) [](https://circleci.com/gh/roqua/fizzy_api)
|
|
5
|
+
|
|
6
|
+
Set the following ENV variables:
|
|
7
|
+
|
|
8
|
+
ENV['FIZZY_URL'] = 'http://fizzy.nl'
|
|
9
|
+
ENV['FIZZY_BASICAUTH_ID'] = 'basic_auth_id set in fizzy'
|
|
10
|
+
ENV['FIZZY_BASICAUTH_SECRET'] = 'secret set for fizzy clients'
|
data/Rakefile
ADDED
|
File without changes
|
data/circle.yml
ADDED
data/fizzy_api.gemspec
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require File.expand_path('../lib/fizzy/api/version', __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.name = 'fizzy-api'
|
|
6
|
+
gem.version = Fizzy::Api::VERSION
|
|
7
|
+
gem.summary = "%q{API wrapper gem around Fizzy's Graph API}"
|
|
8
|
+
gem.description = '%q{Provides authenticated access to fizzy utilities}'
|
|
9
|
+
gem.license = 'MIT'
|
|
10
|
+
gem.authors = ['Frank Blaauw', 'Ando Emerencia']
|
|
11
|
+
gem.email = ['f.j.blaauw@umcg.nl', 'ando.emerencia@gmail.com']
|
|
12
|
+
gem.homepage = 'http://github.com/roqua/fizzy_api'
|
|
13
|
+
|
|
14
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
17
|
+
gem.require_paths = ['lib']
|
|
18
|
+
|
|
19
|
+
gem.add_dependency 'httparty', '~> 0.12'
|
|
20
|
+
gem.add_dependency 'active_interaction', '~> 1.3'
|
|
21
|
+
gem.add_dependency 'virtus', '~> 1.0'
|
|
22
|
+
|
|
23
|
+
gem.add_development_dependency 'bundler', '~> 1.7'
|
|
24
|
+
gem.add_development_dependency 'rake', '~> 10.4'
|
|
25
|
+
gem.add_development_dependency 'rspec', '~> 3.1'
|
|
26
|
+
gem.add_development_dependency 'factory_girl_rails', '~> 4.5'
|
|
27
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Fizzy
|
|
2
|
+
module Api
|
|
3
|
+
class CalculateOutcome < ActiveInteraction::Base
|
|
4
|
+
string :dossier_id
|
|
5
|
+
string :protocol_subscription_id
|
|
6
|
+
|
|
7
|
+
def execute
|
|
8
|
+
response = Api.basic_auth_session.post("/dossier/#{dossier_id}"\
|
|
9
|
+
"/protocol_subscriptions/#{protocol_subscription_id}"\
|
|
10
|
+
'/calculate')
|
|
11
|
+
process_response(response)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def process_response(response)
|
|
17
|
+
case response.code
|
|
18
|
+
when 200
|
|
19
|
+
response
|
|
20
|
+
when 404
|
|
21
|
+
fail Errors::GraphNotFoundError, 'Participant not found, or graph not supported.'
|
|
22
|
+
else
|
|
23
|
+
fail Errors::UnexpectedStatusError, "Status code #{response.code} not expected."
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
File without changes
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Fizzy
|
|
2
|
+
module Api
|
|
3
|
+
class RenderGraph < ActiveInteraction::Base
|
|
4
|
+
string :dossier_id
|
|
5
|
+
string :protocol_subscription_id
|
|
6
|
+
string :path
|
|
7
|
+
hash :options, default: {}
|
|
8
|
+
|
|
9
|
+
def execute
|
|
10
|
+
response = Api.basic_auth_session.get("/dossier/#{dossier_id}"\
|
|
11
|
+
"/protocol_subscriptions/#{protocol_subscription_id}" \
|
|
12
|
+
"/render/#{path}", options)
|
|
13
|
+
process_response(response)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def process_response(response)
|
|
19
|
+
case response.code
|
|
20
|
+
when 200
|
|
21
|
+
response
|
|
22
|
+
when 202
|
|
23
|
+
fail Errors::OutcomeNotAvailableError, 'The results have not yet been calculated.'
|
|
24
|
+
when 204
|
|
25
|
+
fail Errors::TooFewMeasurementsError, 'Not enough measurements available.'
|
|
26
|
+
when 404
|
|
27
|
+
fail Errors::GraphNotFoundError, 'Graph not found.'
|
|
28
|
+
else
|
|
29
|
+
fail Errors::UnexpectedStatusError, "Status code #{response.code} not expected."
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
module Fizzy
|
|
2
|
+
module Api
|
|
3
|
+
module Sessions
|
|
4
|
+
class BasicAuthSession
|
|
5
|
+
attr_reader :fizzy_url
|
|
6
|
+
attr_reader :username
|
|
7
|
+
attr_reader :password
|
|
8
|
+
|
|
9
|
+
def initialize(fizzy_url: ENV['FIZZY_URL'],
|
|
10
|
+
username: ENV['FIZZY_BASICAUTH_ID'],
|
|
11
|
+
password: ENV['FIZZY_BASICAUTH_SECRET'])
|
|
12
|
+
@fizzy_url = fizzy_url
|
|
13
|
+
@username = username
|
|
14
|
+
@password = password
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def get(path, params = {})
|
|
18
|
+
perform_request_or_fail do
|
|
19
|
+
HTTParty.get(full_url_for(path),
|
|
20
|
+
query: params,
|
|
21
|
+
basic_auth: basic_auth)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def post(path, params = {})
|
|
26
|
+
perform_request_or_fail do
|
|
27
|
+
HTTParty.post(full_url_for(path),
|
|
28
|
+
headers: { 'Content-Type' => 'application/json' },
|
|
29
|
+
body: params.to_json,
|
|
30
|
+
basic_auth: basic_auth)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def patch(path, params = {})
|
|
35
|
+
perform_request_or_fail do
|
|
36
|
+
HTTParty.patch(full_url_for(path),
|
|
37
|
+
headers: { 'Content-Type' => 'application/json' },
|
|
38
|
+
body: params.to_json,
|
|
39
|
+
basic_auth: basic_auth)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def delete(path, params = {})
|
|
44
|
+
perform_request_or_fail do
|
|
45
|
+
HTTParty.delete(full_url_for(path),
|
|
46
|
+
query: params,
|
|
47
|
+
basic_auth: basic_auth)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def perform_request_or_fail(&_block)
|
|
54
|
+
response = yield
|
|
55
|
+
case response.code
|
|
56
|
+
when 401
|
|
57
|
+
access_denied(response)
|
|
58
|
+
when 500
|
|
59
|
+
fail response.parsed_response || "Received HTTP response code #{response.code}!"
|
|
60
|
+
else
|
|
61
|
+
response
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def access_denied(response)
|
|
66
|
+
if response.headers['WWW-Authenticate']
|
|
67
|
+
fail NoSession
|
|
68
|
+
else
|
|
69
|
+
fail Unauthorized
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def full_url_for(path)
|
|
74
|
+
fizzy_url + api_base + path
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def api_base
|
|
78
|
+
'/api/v1'
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def basic_auth
|
|
82
|
+
{ username: username, password: password }
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
data/lib/fizzy/api.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require 'active_interaction'
|
|
2
|
+
require 'fizzy/api/version'
|
|
3
|
+
require 'fizzy/api/sessions'
|
|
4
|
+
require 'fizzy/api/models'
|
|
5
|
+
require 'fizzy/api/errors'
|
|
6
|
+
|
|
7
|
+
require 'fizzy/api/calculate_outcome'
|
|
8
|
+
require 'fizzy/api/render_graph'
|
|
9
|
+
|
|
10
|
+
module Fizzy
|
|
11
|
+
module Api
|
|
12
|
+
# Raised when a request failed due to an expired/non-existing session.
|
|
13
|
+
class NoSession < StandardError; end
|
|
14
|
+
class Unauthorized < StandardError; end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/fizzy-api.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'fizzy/api'
|
data/rubocop-todo.yml
ADDED
|
File without changes
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
module Fizzy
|
|
3
|
+
module Api
|
|
4
|
+
describe CalculateOutcome do
|
|
5
|
+
let(:dossier_id) { '123' }
|
|
6
|
+
let(:protocol_subscription_id) { 'abc' }
|
|
7
|
+
let(:response) { httparty_response('') }
|
|
8
|
+
let(:session) { FactoryGirl.build :basic_auth_session }
|
|
9
|
+
|
|
10
|
+
before do
|
|
11
|
+
allow(Sessions::BasicAuthSession).to receive(:new).and_return session
|
|
12
|
+
allow(session).to receive(:post).and_return nil
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it 'should call the correct url' do
|
|
16
|
+
expect(session).to receive(:post)
|
|
17
|
+
.with("/dossier/#{dossier_id}/protocol_subscriptions/#{protocol_subscription_id}/calculate")
|
|
18
|
+
.and_return(response)
|
|
19
|
+
|
|
20
|
+
described_class.run! dossier_id: dossier_id,
|
|
21
|
+
protocol_subscription_id: protocol_subscription_id
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe 'error handling' do
|
|
25
|
+
it 'should notice a 404' do
|
|
26
|
+
allow(response).to receive(:code).and_return 404
|
|
27
|
+
expect(session).to receive(:post)
|
|
28
|
+
.with('/dossier/fake/protocol_subscriptions/fake/calculate')
|
|
29
|
+
.and_return(response)
|
|
30
|
+
outcome = lambda do
|
|
31
|
+
described_class.run! dossier_id: 'fake',
|
|
32
|
+
protocol_subscription_id: 'fake'
|
|
33
|
+
end
|
|
34
|
+
expect { outcome.call }.to raise_error(Errors::GraphNotFoundError)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'should fail a 500 with an UnexpectedStatusError' do
|
|
38
|
+
allow(response).to receive(:code).and_return 500
|
|
39
|
+
expect(session).to receive(:post)
|
|
40
|
+
.with('/dossier/fake/protocol_subscriptions/fake/calculate')
|
|
41
|
+
.and_return(response)
|
|
42
|
+
outcome = lambda do
|
|
43
|
+
described_class.run! dossier_id: 'fake',
|
|
44
|
+
protocol_subscription_id: 'fake'
|
|
45
|
+
end
|
|
46
|
+
expect { outcome.call }.to raise_error(Errors::UnexpectedStatusError)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
module Fizzy
|
|
3
|
+
module Api
|
|
4
|
+
describe RenderGraph do
|
|
5
|
+
let(:dossier_id) { '123' }
|
|
6
|
+
let(:protocol_subscription_id) { 'abc' }
|
|
7
|
+
let(:path) { 'welbevinden.svg' }
|
|
8
|
+
let(:options) { {} }
|
|
9
|
+
let(:response) { httparty_response('<svg>') }
|
|
10
|
+
let(:session) { FactoryGirl.build :basic_auth_session }
|
|
11
|
+
|
|
12
|
+
before do
|
|
13
|
+
allow(Sessions::BasicAuthSession).to receive(:new).and_return session
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'should call the correct url' do
|
|
17
|
+
expect(session).to receive(:get)
|
|
18
|
+
.with("/dossier/#{dossier_id}/protocol_subscriptions/#{protocol_subscription_id}/render/#{path}", options)
|
|
19
|
+
.and_return(response)
|
|
20
|
+
outcome = described_class.run! dossier_id: dossier_id,
|
|
21
|
+
protocol_subscription_id: protocol_subscription_id,
|
|
22
|
+
path: path,
|
|
23
|
+
options: options
|
|
24
|
+
expect(outcome).to eq '<svg>'
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
describe 'error handling' do
|
|
28
|
+
it 'should notice a 202' do
|
|
29
|
+
allow(response).to receive(:code).and_return 202
|
|
30
|
+
expect(session).to receive(:get)
|
|
31
|
+
.with("/dossier/#{dossier_id}/protocol_subscriptions/#{protocol_subscription_id}/render/#{path}", options)
|
|
32
|
+
.and_return(response)
|
|
33
|
+
outcome = lambda do
|
|
34
|
+
described_class.run! dossier_id: dossier_id,
|
|
35
|
+
protocol_subscription_id: protocol_subscription_id,
|
|
36
|
+
path: path,
|
|
37
|
+
options: options
|
|
38
|
+
end
|
|
39
|
+
expect { outcome.call }.to raise_error(Errors::OutcomeNotAvailableError)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'should notice a 204' do
|
|
43
|
+
allow(response).to receive(:code).and_return 204
|
|
44
|
+
expect(session).to receive(:get)
|
|
45
|
+
.with("/dossier/#{dossier_id}/protocol_subscriptions/#{protocol_subscription_id}/render/#{path}", options)
|
|
46
|
+
.and_return(response)
|
|
47
|
+
outcome = lambda do
|
|
48
|
+
described_class.run! dossier_id: dossier_id,
|
|
49
|
+
protocol_subscription_id: protocol_subscription_id,
|
|
50
|
+
path: path,
|
|
51
|
+
options: options
|
|
52
|
+
end
|
|
53
|
+
expect { outcome.call }.to raise_error(Errors::TooFewMeasurementsError)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'should notice a 404' do
|
|
57
|
+
allow(response).to receive(:code).and_return 404
|
|
58
|
+
expect(session).to receive(:get)
|
|
59
|
+
.with("/dossier/#{dossier_id}/protocol_subscriptions/#{protocol_subscription_id}/render/#{path}", options)
|
|
60
|
+
.and_return(response)
|
|
61
|
+
outcome = lambda do
|
|
62
|
+
described_class.run! dossier_id: dossier_id,
|
|
63
|
+
protocol_subscription_id: protocol_subscription_id,
|
|
64
|
+
path: path,
|
|
65
|
+
options: options
|
|
66
|
+
end
|
|
67
|
+
expect { outcome.call }.to raise_error(Errors::GraphNotFoundError)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it 'should fail a 500 with an UnexpectedStatusError' do
|
|
71
|
+
allow(response).to receive(:code).and_return 500
|
|
72
|
+
expect(session).to receive(:get)
|
|
73
|
+
.with("/dossier/#{dossier_id}/protocol_subscriptions/#{protocol_subscription_id}/render/#{path}", options)
|
|
74
|
+
.and_return(response)
|
|
75
|
+
outcome = lambda do
|
|
76
|
+
described_class.run! dossier_id: dossier_id,
|
|
77
|
+
protocol_subscription_id: protocol_subscription_id,
|
|
78
|
+
path: path,
|
|
79
|
+
options: options
|
|
80
|
+
end
|
|
81
|
+
expect { outcome.call }.to raise_error(Errors::UnexpectedStatusError)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
include Sessions
|
|
3
|
+
|
|
4
|
+
describe BasicAuthSession do
|
|
5
|
+
let(:session) { FactoryGirl.build :basic_auth_session }
|
|
6
|
+
let(:response) { double('response', code: 201, parsed_response: 'some_response') }
|
|
7
|
+
|
|
8
|
+
describe '#initialize' do
|
|
9
|
+
it 'sets the fizzy_url instance attribute' do
|
|
10
|
+
session = Fizzy::Api.basic_auth_session fizzy_url: 'some_fizzy_url'
|
|
11
|
+
expect(session.fizzy_url).to eq('some_fizzy_url')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'defaults the fizzy_url to the FIZZY_URL env variable' do
|
|
15
|
+
orginal_env_fizzy_url = ENV['FIZZY_URL']
|
|
16
|
+
ENV['FIZZY_URL'] = 'some_env_fizzy_url'
|
|
17
|
+
session = Fizzy::Api.basic_auth_session
|
|
18
|
+
ENV['FIZZY_URL'] = orginal_env_fizzy_url
|
|
19
|
+
expect(session.fizzy_url).to eq('some_env_fizzy_url')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'sets the username instance variable' do
|
|
23
|
+
session = Fizzy::Api.basic_auth_session username: 'some_username'
|
|
24
|
+
expect(session.username).to eq('some_username')
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'defaults the username to the FIZZY_BASICAUTH_ID env variable' do
|
|
28
|
+
orginal_env_fizzy_key = ENV['FIZZY_BASICAUTH_ID']
|
|
29
|
+
ENV['FIZZY_BASICAUTH_ID'] = 'some_env_fizzy_key'
|
|
30
|
+
session = Fizzy::Api.basic_auth_session
|
|
31
|
+
ENV['FIZZY_BASICAUTH_ID'] = orginal_env_fizzy_key
|
|
32
|
+
expect(session.username).to eq('some_env_fizzy_key')
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'sets the password instance variable' do
|
|
36
|
+
session = Fizzy::Api.basic_auth_session password: 'some_password'
|
|
37
|
+
expect(session.password).to eq('some_password')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'defaults the password to the FIZZY_BASICAUTH_SECRET env variable' do
|
|
41
|
+
orginal_env_fizzy_secret = ENV['FIZZY_BASICAUTH_SECRET']
|
|
42
|
+
ENV['FIZZY_BASICAUTH_SECRET'] = 'some_env_fizzy_secret'
|
|
43
|
+
session = Fizzy::Api.basic_auth_session
|
|
44
|
+
ENV['FIZZY_BASICAUTH_SECRET'] = orginal_env_fizzy_secret
|
|
45
|
+
expect(session.password).to eq('some_env_fizzy_secret')
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe '#get' do
|
|
50
|
+
it 'performs a get request' do
|
|
51
|
+
expect(HTTParty).to receive(:get).with('http://fizzy.dev/api/v1/some_path',
|
|
52
|
+
query: { some: 'param' },
|
|
53
|
+
basic_auth: { username: 'some_username', password: 'some_password' })
|
|
54
|
+
.and_return(response)
|
|
55
|
+
session.get '/some_path', some: 'param'
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'throws an error if the reponse is not within the 200 range' do
|
|
59
|
+
allow(response).to receive(:code).and_return(500)
|
|
60
|
+
allow(HTTParty).to receive(:get).and_return(response)
|
|
61
|
+
expect { session.get '/some_path' }.to raise_error(RuntimeError, 'some_response')
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'throws a NoSession error if the basic auth is incorrect' do
|
|
65
|
+
allow(response).to receive(:code).and_return(401)
|
|
66
|
+
allow(HTTParty).to receive(:get).and_return(response)
|
|
67
|
+
allow(response).to receive(:headers).and_return('WWW-Authenticate' => 'Basic realm="Application"')
|
|
68
|
+
expect { session.get '/some_path' }.to raise_error(Fizzy::Api::NoSession)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it 'throws a Unauthorized error on 401 without www-authenticate header' do
|
|
72
|
+
allow(response).to receive(:code).and_return(401)
|
|
73
|
+
allow(HTTParty).to receive(:get).and_return(response)
|
|
74
|
+
allow(response).to receive(:headers).and_return('foo' => 'bar')
|
|
75
|
+
expect { session.get '/some_path' }.to raise_error(Fizzy::Api::Unauthorized)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'returns the response' do
|
|
79
|
+
allow(HTTParty).to receive(:get).and_return(response)
|
|
80
|
+
expect(session.get '/some_path').to eq(response)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'spec_helper'
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'rspec'
|
|
2
|
+
require 'factory_girl_rails'
|
|
3
|
+
require 'fizzy-api'
|
|
4
|
+
require 'httparty'
|
|
5
|
+
include Fizzy::Api
|
|
6
|
+
include Fizzy::Api::Sessions
|
|
7
|
+
# include Fizzy::Api::Models
|
|
8
|
+
|
|
9
|
+
Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'support', '*.rb')].each { |f| require f }
|
|
10
|
+
Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'factories', '*.rb')].each { |f| require f }
|
|
11
|
+
|
|
12
|
+
RSpec.configure do |config|
|
|
13
|
+
config.filter_run :focus
|
|
14
|
+
config.run_all_when_everything_filtered = true
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# I18n.load_path << Dir[File.join(File.expand_path(File.dirname(__FILE__)), 'support', '*.yml')]
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fizzy-api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Frank Blaauw
|
|
@@ -109,15 +109,44 @@ dependencies:
|
|
|
109
109
|
- - "~>"
|
|
110
110
|
- !ruby/object:Gem::Version
|
|
111
111
|
version: '4.5'
|
|
112
|
-
description: Provides authenticated access to
|
|
112
|
+
description: "%q{Provides authenticated access to fizzy utilities}"
|
|
113
113
|
email:
|
|
114
114
|
- f.j.blaauw@umcg.nl
|
|
115
|
-
-
|
|
115
|
+
- ando.emerencia@gmail.com
|
|
116
116
|
executables: []
|
|
117
117
|
extensions: []
|
|
118
118
|
extra_rdoc_files: []
|
|
119
|
-
files:
|
|
120
|
-
|
|
119
|
+
files:
|
|
120
|
+
- ".gitignore"
|
|
121
|
+
- ".rubocop.yml"
|
|
122
|
+
- Gemfile
|
|
123
|
+
- Gemfile.lock
|
|
124
|
+
- README.md
|
|
125
|
+
- Rakefile
|
|
126
|
+
- circle.yml
|
|
127
|
+
- fizzy_api.gemspec
|
|
128
|
+
- lib/fizzy-api.rb
|
|
129
|
+
- lib/fizzy/api.rb
|
|
130
|
+
- lib/fizzy/api/calculate_outcome.rb
|
|
131
|
+
- lib/fizzy/api/errors.rb
|
|
132
|
+
- lib/fizzy/api/errors/graph_not_found_error.rb
|
|
133
|
+
- lib/fizzy/api/errors/outcome_not_available_error.rb
|
|
134
|
+
- lib/fizzy/api/errors/too_few_measurements_error.rb
|
|
135
|
+
- lib/fizzy/api/errors/unexpected_status_error.rb
|
|
136
|
+
- lib/fizzy/api/models.rb
|
|
137
|
+
- lib/fizzy/api/render_graph.rb
|
|
138
|
+
- lib/fizzy/api/sessions.rb
|
|
139
|
+
- lib/fizzy/api/sessions/basic_auth_session.rb
|
|
140
|
+
- lib/fizzy/api/version.rb
|
|
141
|
+
- rubocop-todo.yml
|
|
142
|
+
- spec/factories/basic_auth_session.rb
|
|
143
|
+
- spec/fizzy/api/calculate_outcome_spec.rb
|
|
144
|
+
- spec/fizzy/api/render_graph_spec.rb
|
|
145
|
+
- spec/fizzy/api/sessions/basic_auth_session_spec.rb
|
|
146
|
+
- spec/fizzy/api/sessions_spec.rb
|
|
147
|
+
- spec/spec_helper.rb
|
|
148
|
+
- spec/support/httparty_helpers.rb
|
|
149
|
+
homepage: http://github.com/roqua/fizzy_api
|
|
121
150
|
licenses:
|
|
122
151
|
- MIT
|
|
123
152
|
metadata: {}
|
|
@@ -140,5 +169,12 @@ rubyforge_project:
|
|
|
140
169
|
rubygems_version: 2.4.5
|
|
141
170
|
signing_key:
|
|
142
171
|
specification_version: 4
|
|
143
|
-
summary: API wrapper gem around Fizzy's Graph API
|
|
144
|
-
test_files:
|
|
172
|
+
summary: "%q{API wrapper gem around Fizzy's Graph API}"
|
|
173
|
+
test_files:
|
|
174
|
+
- spec/factories/basic_auth_session.rb
|
|
175
|
+
- spec/fizzy/api/calculate_outcome_spec.rb
|
|
176
|
+
- spec/fizzy/api/render_graph_spec.rb
|
|
177
|
+
- spec/fizzy/api/sessions/basic_auth_session_spec.rb
|
|
178
|
+
- spec/fizzy/api/sessions_spec.rb
|
|
179
|
+
- spec/spec_helper.rb
|
|
180
|
+
- spec/support/httparty_helpers.rb
|