truevault 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +41 -0
- data/LICENSE +20 -0
- data/README.md +34 -0
- data/Rakefile +21 -0
- data/examples/example_usage.rb +60 -0
- data/lib/truevault.rb +131 -0
- data/lib/truevault/version.rb +3 -0
- data/spec/fixtures/files/test.pdf +0 -0
- data/spec/fixtures/truevault_cassettes/create_blob.yml +35 -0
- data/spec/fixtures/truevault_cassettes/create_document.yml +35 -0
- data/spec/fixtures/truevault_cassettes/list_vaults.yml +36 -0
- data/spec/lib/truevault/client_spec.rb +119 -0
- data/spec/spec_helper.rb +34 -0
- data/truevault.gemspec +28 -0
- metadata +165 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4f15192223cd38d785722e97e269c43058e720c5
|
4
|
+
data.tar.gz: 584e4a7d42b8ebacc4b32d3c3f9ebd7b604d512c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3febc144e7a42cef8482f5d314e3b211d9ba6254c276bf86e5177e8e9b82df34e97fb6ada720e3600a1166fc205a203a69abe5f869c474a0c535eabeaa9402b0
|
7
|
+
data.tar.gz: c6ad31980f3622a88e7ce952c0a88e0b7e82f2eb525b368e64ce0f408e3ab00534bb39abdd934b91390fca173d6c26db941d116020cd1b6e71ce21c201916e05
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.DS_Store
|
6
|
+
coverage
|
7
|
+
InstalledFiles
|
8
|
+
lib/bundler/man
|
9
|
+
pkg
|
10
|
+
rdoc
|
11
|
+
spec/reports
|
12
|
+
test/tmp
|
13
|
+
test/version_tmp
|
14
|
+
tmp
|
15
|
+
|
16
|
+
# YARD artifacts
|
17
|
+
.yardoc
|
18
|
+
_yardoc
|
19
|
+
doc/
|
20
|
+
|
21
|
+
.ruby-gemset
|
22
|
+
.env
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
truevault (0.0.1)
|
5
|
+
httparty (~> 0.11)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.3.5)
|
11
|
+
ansi (1.4.3)
|
12
|
+
crack (0.4.1)
|
13
|
+
safe_yaml (~> 0.9.0)
|
14
|
+
dotenv (0.11.1)
|
15
|
+
dotenv-deployment (~> 0.0.2)
|
16
|
+
dotenv-deployment (0.0.2)
|
17
|
+
httparty (0.13.1)
|
18
|
+
json (~> 1.8)
|
19
|
+
multi_xml (>= 0.5.2)
|
20
|
+
json (1.8.1)
|
21
|
+
multi_xml (0.5.5)
|
22
|
+
rake (10.1.0)
|
23
|
+
safe_yaml (0.9.7)
|
24
|
+
turn (0.9.6)
|
25
|
+
ansi
|
26
|
+
vcr (2.5.0)
|
27
|
+
webmock (1.11.0)
|
28
|
+
addressable (>= 2.2.7)
|
29
|
+
crack (>= 0.3.2)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
bundler (~> 1.6)
|
36
|
+
dotenv
|
37
|
+
rake (~> 10.1)
|
38
|
+
truevault!
|
39
|
+
turn (~> 0.9)
|
40
|
+
vcr (~> 2.5)
|
41
|
+
webmock (= 1.11)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Mark Silverberg <mark@socialhealthinsights.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
truevault.rb
|
2
|
+
============
|
3
|
+
|
4
|
+
A super quick Ruby client for [TrueVault](http://truevault.com) ("handles HIPAA compliance so that you don’t have to") powered by [HTTParty](https://github.com/jnunemaker/httparty).
|
5
|
+
|
6
|
+
Developed by [@Skram](http://twitter.com/skram) of [Social Health Insights](http://socialhealthinsights.com).
|
7
|
+
|
8
|
+
How to use
|
9
|
+
----------
|
10
|
+
1. Clone this repository to your computer. Notice that all the code is in `lib/truevault.rb`
|
11
|
+
2. Set up the following environment variables: `TV_API_KEY` and `TV_ACCOUNT_ID`, `TV_A_VAULT_ID`.
|
12
|
+
```
|
13
|
+
cp .env.sample .env
|
14
|
+
```
|
15
|
+
3. Install required dependencies: `bundle install`
|
16
|
+
4. Run the example file: `bundle exec ruby example_usage.rb`
|
17
|
+
5. Profit and then contribute back to an open source project, please.
|
18
|
+
|
19
|
+
How to run tests
|
20
|
+
----------------
|
21
|
+
1. Follow steps 1 through 3 under 'How to use'
|
22
|
+
2. `bundle exec rake`
|
23
|
+
|
24
|
+
Resources
|
25
|
+
---------
|
26
|
+
* [TrueVault REST API Documentation](https://www.truevault.com/rest-api.html)
|
27
|
+
|
28
|
+
To do
|
29
|
+
-----
|
30
|
+
* Better error handling
|
31
|
+
* More tests
|
32
|
+
* Flush out README.md with details such as
|
33
|
+
* Dependency/platforms tested on
|
34
|
+
* Info on contributing
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "bundler"
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require 'rake/testtask'
|
4
|
+
|
5
|
+
Rake::TestTask.new do |t|
|
6
|
+
t.test_files = FileList['spec/lib/truevault/*_spec.rb']
|
7
|
+
t.verbose = true
|
8
|
+
end
|
9
|
+
|
10
|
+
task :console do
|
11
|
+
$LOAD_PATH << "./lib"
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
require "irb/completion"
|
15
|
+
require "truevault.rb"
|
16
|
+
|
17
|
+
ARGV.clear
|
18
|
+
IRB.start
|
19
|
+
end
|
20
|
+
|
21
|
+
task :default => :test
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require_relative '../lib/truevault.rb'
|
2
|
+
|
3
|
+
TV_API_KEY = ENV["TV_API_KEY"]
|
4
|
+
TV_A_VAULT_ID = ENV["TV_A_VAULT_ID"]
|
5
|
+
TV_ACCOUNT_ID = ENV["TV_ACCOUNT_ID"]
|
6
|
+
tv = TrueVault::Client.new(TV_API_KEY, TV_ACCOUNT_ID, 'v1')
|
7
|
+
|
8
|
+
puts "listing vaults:"
|
9
|
+
list_vaults = tv.list_vaults
|
10
|
+
puts " => #{list_vaults} \n\n\n"
|
11
|
+
|
12
|
+
puts "create a document:"
|
13
|
+
create_document = tv.create_document(TV_A_VAULT_ID, {"a" => "b"})
|
14
|
+
puts " => #{create_document} \n\n\n"
|
15
|
+
|
16
|
+
puts "get that document:"
|
17
|
+
get_document = tv.get_document(TV_A_VAULT_ID, create_document["document_id"])
|
18
|
+
puts " => #{get_document} \n\n\n"
|
19
|
+
|
20
|
+
puts "update that document:"
|
21
|
+
update_document = tv.update_document(TV_A_VAULT_ID, create_document["document_id"], {"x" => "y"})
|
22
|
+
puts " => #{update_document} \n\n\n"
|
23
|
+
|
24
|
+
puts "get that document, for a second time:"
|
25
|
+
get_document2 = tv.get_document(TV_A_VAULT_ID, create_document["document_id"])
|
26
|
+
puts " => #{get_document2} \n\n\n"
|
27
|
+
|
28
|
+
puts "delete that document:"
|
29
|
+
delete_document = tv.delete_document(TV_A_VAULT_ID, create_document["document_id"])
|
30
|
+
puts " => #{delete_document} \n\n\n"
|
31
|
+
|
32
|
+
puts "try to get the deleted document (hint: it shouldnt work):"
|
33
|
+
get_document3 = tv.get_document(TV_A_VAULT_ID, create_document["document_id"])
|
34
|
+
puts " => #{get_document3} \n\n\n"
|
35
|
+
|
36
|
+
|
37
|
+
file = File.new(File.expand_path(File.dirname(__FILE__))+'/../spec/fixtures/files/test.pdf', 'rb')
|
38
|
+
puts "create BLOB:"
|
39
|
+
create_blob = tv.create_blob(TV_A_VAULT_ID, file)
|
40
|
+
puts " => #{create_blob} \n\n\n"
|
41
|
+
|
42
|
+
puts "get that BLOB:"
|
43
|
+
get_blob = tv.get_blob(TV_A_VAULT_ID, create_blob["blob_id"])
|
44
|
+
puts " => #{get_blob} \n\n\n"
|
45
|
+
|
46
|
+
puts "update that BLOB:"
|
47
|
+
update_blob = tv.replace_blob(TV_A_VAULT_ID, create_blob["blob_id"], file)
|
48
|
+
puts " => #{update_blob} \n\n\n"
|
49
|
+
|
50
|
+
puts "get that BLOB (again):"
|
51
|
+
get_blob2 = tv.get_blob(TV_A_VAULT_ID, create_blob["blob_id"])
|
52
|
+
puts " => #{get_blob2} \n\n\n"
|
53
|
+
|
54
|
+
puts "delete that BLOB:"
|
55
|
+
delete_blob = tv.delete_blob(TV_A_VAULT_ID, create_blob["blob_id"])
|
56
|
+
puts " => #{delete_blob} \n\n\n"
|
57
|
+
|
58
|
+
puts "try to get the deleted BLOB (hint: it shouldnt work):"
|
59
|
+
get_blob3 = tv.get_blob(TV_A_VAULT_ID, create_blob["blob_id"])
|
60
|
+
puts " => #{get_blob3} \n\n\n"
|
data/lib/truevault.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'tempfile'
|
4
|
+
require 'httparty'
|
5
|
+
|
6
|
+
Bundler.require
|
7
|
+
|
8
|
+
module TrueVault
|
9
|
+
# Custom parser class for TrueVault API
|
10
|
+
class Parser < HTTParty::Parser
|
11
|
+
SupportedFormats.merge!({"application/octet-stream" => :octet_stream})
|
12
|
+
|
13
|
+
def parse
|
14
|
+
case format
|
15
|
+
when :html
|
16
|
+
body
|
17
|
+
when :json
|
18
|
+
JSON.parse(body)
|
19
|
+
when :octet_stream
|
20
|
+
# TODO find a better way of doing this
|
21
|
+
# The issue is that no matter what it gets frmo TV
|
22
|
+
# the ContentType is always octet_stream
|
23
|
+
begin
|
24
|
+
JSON.parse(Base64.decode64(body))
|
25
|
+
rescue JSON::ParserError
|
26
|
+
file = Tempfile.new('blob')
|
27
|
+
file.binmode
|
28
|
+
file.write(body)
|
29
|
+
file.rewind
|
30
|
+
file
|
31
|
+
end
|
32
|
+
else
|
33
|
+
body
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
class Client
|
40
|
+
include HTTParty
|
41
|
+
require 'json'
|
42
|
+
require 'base64'
|
43
|
+
|
44
|
+
# debug_output
|
45
|
+
base_uri 'https://api.truevault.com'
|
46
|
+
parser Parser
|
47
|
+
|
48
|
+
def default_options_to_merge_with
|
49
|
+
{:basic_auth => {:username => @api_key, :password => nil}}
|
50
|
+
end
|
51
|
+
|
52
|
+
def hash_to_base64_json(hash = {})
|
53
|
+
Base64.encode64(hash.to_json)
|
54
|
+
end
|
55
|
+
|
56
|
+
# api_key should be a valid TrueVault API key
|
57
|
+
# account_id should be a valid TrueVault account ID
|
58
|
+
# api_version should be a valid API version (ex 'v1')
|
59
|
+
def initialize(api_key, account_id, api_version = 'v1')
|
60
|
+
@api_key = api_key
|
61
|
+
@account_id = account_id
|
62
|
+
@api_ver = api_version
|
63
|
+
instance_variables.each do |variable|
|
64
|
+
raise ArgumentError, "#{variable} should not be nil or blank" if instance_variable_get(variable.to_sym).to_s == ""
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
####################################################
|
69
|
+
### JSON (structured text data store) API Methods
|
70
|
+
####################################################
|
71
|
+
|
72
|
+
# vault_id should be a valid vault ID
|
73
|
+
# document_id should be a valid document ID
|
74
|
+
# document_data should be a Ruby Hash. Method will convert it to JSON and base64 encode as required
|
75
|
+
def create_document(vault_id, document_data, options = {})
|
76
|
+
options.merge!(default_options_to_merge_with)
|
77
|
+
options[:body] = {:document => hash_to_base64_json(document_data)}
|
78
|
+
self.class.post("/#{@api_ver}/vaults/#{vault_id}/documents", options)
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_document(vault_id, document_id, options = {})
|
82
|
+
options.merge!(default_options_to_merge_with)
|
83
|
+
self.class.get("/#{@api_ver}/vaults/#{vault_id}/documents/#{document_id}", options)
|
84
|
+
end
|
85
|
+
|
86
|
+
def delete_document(vault_id, document_id, options = {})
|
87
|
+
options.merge!(default_options_to_merge_with)
|
88
|
+
self.class.delete("/#{@api_ver}/vaults/#{vault_id}/documents/#{document_id}", options)
|
89
|
+
end
|
90
|
+
|
91
|
+
def update_document(vault_id, document_id, document_data, options = {})
|
92
|
+
options.merge!(default_options_to_merge_with)
|
93
|
+
options[:body] = {:document => hash_to_base64_json(document_data)}
|
94
|
+
self.class.put("/#{@api_ver}/vaults/#{vault_id}/documents/#{document_id}", options)
|
95
|
+
end
|
96
|
+
|
97
|
+
def list_vaults(options = {})
|
98
|
+
options.merge!(default_options_to_merge_with)
|
99
|
+
self.class.get("/#{@api_ver}/accounts/#{@account_id}/vaults", options)
|
100
|
+
end
|
101
|
+
|
102
|
+
#####################################
|
103
|
+
### BLOB (binary file) API Methods
|
104
|
+
#####################################
|
105
|
+
|
106
|
+
def create_blob(vault_id, file, options = {:headers => {"Content-Type"=>"application/octet-stream"}})
|
107
|
+
options.merge!(default_options_to_merge_with)
|
108
|
+
options[:body] = file.read
|
109
|
+
self.class.post("/#{@api_ver}/vaults/#{vault_id}/blobs", options)
|
110
|
+
end
|
111
|
+
|
112
|
+
def replace_blob(vault_id, blob_id, file, options = {:headers => {"Content-Type"=>"application/octet-stream"}})
|
113
|
+
options.merge!(default_options_to_merge_with)
|
114
|
+
options[:body] = file.read
|
115
|
+
self.class.put("/#{@api_ver}/vaults/#{vault_id}/blobs/#{blob_id}", options)
|
116
|
+
end
|
117
|
+
|
118
|
+
def delete_blob(vault_id, blob_id, options = {})
|
119
|
+
options.merge!(default_options_to_merge_with)
|
120
|
+
self.class.delete("/#{@api_ver}/vaults/#{vault_id}/blobs/#{blob_id}", options)
|
121
|
+
end
|
122
|
+
|
123
|
+
def get_blob(vault_id, blob_id, options = {})
|
124
|
+
options.merge!(default_options_to_merge_with)
|
125
|
+
self.class.get("/#{@api_ver}/vaults/#{vault_id}/blobs/#{blob_id}", options)
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
end
|
Binary file
|
@@ -0,0 +1,35 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://REDACTED_ID:@api.truevault.com/v1/vaults/REDACTED_ID/blobs
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: body=
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Date:
|
16
|
+
- Thu, 10 Apr 2014 12:44:41 GMT
|
17
|
+
Content-Type:
|
18
|
+
- application/json
|
19
|
+
Content-Length:
|
20
|
+
- '130'
|
21
|
+
Connection:
|
22
|
+
- keep-alive
|
23
|
+
Server:
|
24
|
+
- gunicorn/18.0
|
25
|
+
Cache-Control:
|
26
|
+
- no-cache
|
27
|
+
Strict-Transport-Security:
|
28
|
+
- max-age=31536000
|
29
|
+
body:
|
30
|
+
encoding: US-ASCII
|
31
|
+
string: ! '{"blob_id": "REDACTED_ID", "result": "success", "transaction_id":
|
32
|
+
"REDACTED_ID"}'
|
33
|
+
http_version:
|
34
|
+
recorded_at: Thu, 10 Apr 2014 12:44:42 GMT
|
35
|
+
recorded_with: VCR 2.5.0
|
@@ -0,0 +1,35 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://REDACTED_ID:@api.truevault.com/v1/vaults/REDACTED_ID/documents
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: document=eyJhIjoiZG9jdW1lbnQifQ%3D%3D%0A
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Date:
|
16
|
+
- Sun, 29 Dec 2013 16:18:22 GMT
|
17
|
+
Content-Type:
|
18
|
+
- application/json
|
19
|
+
Content-Length:
|
20
|
+
- '134'
|
21
|
+
Connection:
|
22
|
+
- keep-alive
|
23
|
+
Server:
|
24
|
+
- gunicorn/18.0
|
25
|
+
Cache-Control:
|
26
|
+
- no-cache
|
27
|
+
Strict-Transport-Security:
|
28
|
+
- max-age=31536000
|
29
|
+
body:
|
30
|
+
encoding: UTF-8
|
31
|
+
string: '{"transaction_id": "REDACTED_ID", "result": "success", "document_id":
|
32
|
+
"REDACTED_ID"}'
|
33
|
+
http_version:
|
34
|
+
recorded_at: Sun, 29 Dec 2013 16:18:45 GMT
|
35
|
+
recorded_with: VCR 2.5.0
|
@@ -0,0 +1,36 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://REDACTED_ID:@api.truevault.com/v1/accounts/REDACTED_ID/vaults
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Date:
|
16
|
+
- Sun, 29 Dec 2013 16:18:23 GMT
|
17
|
+
Content-Type:
|
18
|
+
- application/json
|
19
|
+
Content-Length:
|
20
|
+
- '336'
|
21
|
+
Connection:
|
22
|
+
- keep-alive
|
23
|
+
Server:
|
24
|
+
- gunicorn/18.0
|
25
|
+
Cache-Control:
|
26
|
+
- no-cache
|
27
|
+
Strict-Transport-Security:
|
28
|
+
- max-age=31536000
|
29
|
+
body:
|
30
|
+
encoding: UTF-8
|
31
|
+
string: '{"vaults": [{"id": "REDACTED_ID", "name": "a vault", "account_id":
|
32
|
+
"REDACTED_ID"}, {"id": "REDACTED_ID", "name": "test_vault", "account_id":
|
33
|
+
"REDACTED_ID"}], "result": "success", "transaction_id": "REDACTED_ID"}'
|
34
|
+
http_version:
|
35
|
+
recorded_at: Sun, 29 Dec 2013 16:18:45 GMT
|
36
|
+
recorded_with: VCR 2.5.0
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe TrueVault::Client do
|
4
|
+
rs1 = random_string
|
5
|
+
rs2 = random_string
|
6
|
+
let(:fake_client){ TrueVault::Client.new(rs1,rs2)}
|
7
|
+
let(:real_client){ TrueVault::Client.new(ENV["TV_API_KEY"], ENV["TV_ACCOUNT_ID"], 'v1')}
|
8
|
+
|
9
|
+
it "parent class must include httparty methods" do
|
10
|
+
fake_client.class.must_include HTTParty
|
11
|
+
end
|
12
|
+
|
13
|
+
it "parent class must have the base url set to the TrueVault endpoint" do
|
14
|
+
fake_client.class.base_uri.must_equal 'https://api.truevault.com'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "must require one argument (API key) upon instantiation" do
|
18
|
+
-> {TrueVault::Client.new}.must_raise ArgumentError, "wrong number of arguments (0 for 2..3)"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "must store the first argument as the API key" do
|
22
|
+
fake_client.instance_variable_get("@api_key").must_equal rs1
|
23
|
+
end
|
24
|
+
|
25
|
+
methods = [:list_vaults, :create_document, :get_document, :update_document, :delete_document, :create_blob]
|
26
|
+
methods.each do |method|
|
27
|
+
it "must respond to method '#{method}'" do
|
28
|
+
fake_client.must_respond_to method
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "list vaults" do
|
33
|
+
let(:list_vaults){ real_client.list_vaults}
|
34
|
+
|
35
|
+
before do
|
36
|
+
VCR.insert_cassette 'list_vaults'
|
37
|
+
end
|
38
|
+
|
39
|
+
after do
|
40
|
+
VCR.eject_cassette
|
41
|
+
end
|
42
|
+
|
43
|
+
it "must parse the API response from JSON to a Ruby Hash" do
|
44
|
+
list_vaults.must_be_instance_of Hash
|
45
|
+
end
|
46
|
+
|
47
|
+
it "must have an array of vaults" do
|
48
|
+
list_vaults['vaults'].must_be_instance_of Array
|
49
|
+
end
|
50
|
+
|
51
|
+
it "must have been a successful API request" do
|
52
|
+
list_vaults['result'].must_equal "success"
|
53
|
+
end
|
54
|
+
|
55
|
+
it "must have a redacted transaction_id " do
|
56
|
+
list_vaults['transaction_id'].must_equal REDACTED_STRING
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
describe "create a document" do
|
62
|
+
let(:create_document){ real_client.create_document(ENV["TV_A_VAULT_ID"],{"a" => "document"})}
|
63
|
+
|
64
|
+
before do
|
65
|
+
VCR.insert_cassette 'create_document'
|
66
|
+
end
|
67
|
+
|
68
|
+
after do
|
69
|
+
VCR.eject_cassette
|
70
|
+
end
|
71
|
+
|
72
|
+
it "must parse the API response from JSON to a Ruby Hash" do
|
73
|
+
create_document.must_be_instance_of Hash
|
74
|
+
end
|
75
|
+
|
76
|
+
it "must have been a successful API request" do
|
77
|
+
create_document['result'].must_equal "success"
|
78
|
+
end
|
79
|
+
|
80
|
+
it "must have a redacted transaction_id" do
|
81
|
+
create_document['transaction_id'].must_equal REDACTED_STRING
|
82
|
+
end
|
83
|
+
|
84
|
+
it "must have a redacted document_id" do
|
85
|
+
create_document['document_id'].must_equal REDACTED_STRING
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "create a blob" do
|
90
|
+
let(:create_blob) do
|
91
|
+
file = File.new(File.expand_path(File.dirname(__FILE__))+'/../../fixtures/files/test.pdf', 'rb')
|
92
|
+
real_client.create_blob(ENV["TV_A_VAULT_ID"], file)
|
93
|
+
end
|
94
|
+
|
95
|
+
before do
|
96
|
+
VCR.insert_cassette 'create_blob'
|
97
|
+
end
|
98
|
+
|
99
|
+
after do
|
100
|
+
VCR.eject_cassette
|
101
|
+
end
|
102
|
+
|
103
|
+
it "must parse the API response from JSON to a Ruby Hash" do
|
104
|
+
create_blob.must_be_instance_of Hash
|
105
|
+
end
|
106
|
+
|
107
|
+
it "must have been a successful API request" do
|
108
|
+
create_blob['result'].must_equal "success"
|
109
|
+
end
|
110
|
+
|
111
|
+
it "must have a redacted transaction_id" do
|
112
|
+
create_blob['transaction_id'].must_equal REDACTED_STRING
|
113
|
+
end
|
114
|
+
|
115
|
+
it "must have a redacted document_id" do
|
116
|
+
create_blob['blob_id'].must_equal REDACTED_STRING
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#we need the actual library file
|
2
|
+
require_relative '../lib/truevault'
|
3
|
+
|
4
|
+
#dependencies
|
5
|
+
require 'minitest/autorun'
|
6
|
+
require 'webmock/minitest'
|
7
|
+
require 'dotenv'
|
8
|
+
require 'vcr'
|
9
|
+
require 'turn'
|
10
|
+
|
11
|
+
Dotenv.load
|
12
|
+
|
13
|
+
Turn.config do |c|
|
14
|
+
c.format = :pretty
|
15
|
+
c.natural = true
|
16
|
+
end
|
17
|
+
|
18
|
+
REDACTED_STRING = "REDACTED_ID"
|
19
|
+
|
20
|
+
VCR.configure do |c|
|
21
|
+
c.cassette_library_dir = 'spec/fixtures/truevault_cassettes'
|
22
|
+
c.hook_into :webmock
|
23
|
+
c.default_cassette_options = { :match_requests_on => [:method], :record => :new_episodes }
|
24
|
+
c.before_record do |interaction|
|
25
|
+
interaction.request.body.gsub!(/(\S{8}-\S{4}-\S{4}-\S{4}-\S{12})/, REDACTED_STRING)
|
26
|
+
interaction.request.uri.gsub!(/(\S{8}-\S{4}-\S{4}-\S{4}-\S{12})/, REDACTED_STRING)
|
27
|
+
interaction.response.body.gsub!(/(\S{8}-\S{4}-\S{4}-\S{4}-\S{12})/, REDACTED_STRING)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
def random_string(length = 10)
|
33
|
+
(0...length).map { (65 + rand(26)).chr }.join
|
34
|
+
end
|
data/truevault.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'truevault/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "truevault"
|
8
|
+
spec.version = TrueVault::VERSION
|
9
|
+
spec.authors = ["Mark Silverberg"]
|
10
|
+
spec.email = ["mark@socialhealthinsights.com"]
|
11
|
+
spec.summary = %q{Ruby client for True Vault API}
|
12
|
+
spec.description = %q{A super quick Ruby client for TrueVault ("handles HIPAA compliance so that you don’t have to") powered by HTTParty.}
|
13
|
+
spec.homepage = "https://github.com/marks/truevault.rb"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "httparty", "~> 0.11"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.1"
|
24
|
+
spec.add_development_dependency "webmock", "1.11"
|
25
|
+
spec.add_development_dependency "vcr", "~> 2.5"
|
26
|
+
spec.add_development_dependency "turn", "~> 0.9"
|
27
|
+
spec.add_development_dependency "dotenv"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: truevault
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Silverberg
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.11'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.11'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.11'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: vcr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.5'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: turn
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.9'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.9'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: dotenv
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: A super quick Ruby client for TrueVault ("handles HIPAA compliance so
|
112
|
+
that you don’t have to") powered by HTTParty.
|
113
|
+
email:
|
114
|
+
- mark@socialhealthinsights.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- Gemfile
|
121
|
+
- Gemfile.lock
|
122
|
+
- LICENSE
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- examples/example_usage.rb
|
126
|
+
- lib/truevault.rb
|
127
|
+
- lib/truevault/version.rb
|
128
|
+
- spec/fixtures/files/test.pdf
|
129
|
+
- spec/fixtures/truevault_cassettes/create_blob.yml
|
130
|
+
- spec/fixtures/truevault_cassettes/create_document.yml
|
131
|
+
- spec/fixtures/truevault_cassettes/list_vaults.yml
|
132
|
+
- spec/lib/truevault/client_spec.rb
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
- truevault.gemspec
|
135
|
+
homepage: https://github.com/marks/truevault.rb
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
metadata: {}
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
requirements: []
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 2.2.2
|
156
|
+
signing_key:
|
157
|
+
specification_version: 4
|
158
|
+
summary: Ruby client for True Vault API
|
159
|
+
test_files:
|
160
|
+
- spec/fixtures/files/test.pdf
|
161
|
+
- spec/fixtures/truevault_cassettes/create_blob.yml
|
162
|
+
- spec/fixtures/truevault_cassettes/create_document.yml
|
163
|
+
- spec/fixtures/truevault_cassettes/list_vaults.yml
|
164
|
+
- spec/lib/truevault/client_spec.rb
|
165
|
+
- spec/spec_helper.rb
|