context_hub_vault 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5e9bf7e3e774555283cd7af06fbf1d120a1911e2
4
+ data.tar.gz: 9fd1418ff2396bd735a5ecd92a6ddd4e28aed0ea
5
+ SHA512:
6
+ metadata.gz: 6e137fcc8ae38a610bfed751383c42a68f9e9304e0a580965eeef51449910457556cb270213b03dcc163fc1b9f663c77051eb8f0d6205379838951bc983f5a28
7
+ data.tar.gz: 24f6b6cd4ec4364f13afb3f466eda1ca4bd89c1aa3bf299243c56823fb798a7aa5aa76bf3fb35b88dfc3d5f7d64660e7cf5aa1e7d8430c13e15d00a859849ef4
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in context_hub_vault.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Robert Boone
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # ContextHubVault
2
+
3
+ [![Code Climate](https://codeclimate.com/github/chaione/context_hub_vault.png)](https://codeclimate.com/github/chaione/context_hub_vault/badges)
4
+
5
+ Ruby client for the ContextHUB vault
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'context_hub_vault'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install context_hub_vault
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ client = ContextHubVault::Client.new(host: 'http://localhost:3000', app_id: '1', auth_token: ENV['AUTH_TOKEN'])
25
+ c.create('music', name: 'Miles Davis', style: 'jazz')
26
+ c.create('music', name: 'Monk', style: 'jazz')
27
+ jazz_musicians = c.search(style: 'jazz')
28
+ ```
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it ( http://github.com/<my-github-username>/context_hub_vault/fork )
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ task :console do
9
+ require 'pry'
10
+ require 'context_hub_vault'
11
+ ARGV.clear
12
+ Pry.start
13
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'context_hub_vault/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'context_hub_vault'
8
+ spec.version = ContextHubVault::VERSION
9
+ spec.authors = ['Robert Boone']
10
+ spec.email = ['robert@chaione.com']
11
+ spec.description = %q{Ruby client for the ContextHUB Vault }
12
+ spec.summary = spec.description
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.5'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'pry'
25
+
26
+ spec.add_dependency 'httparty', '~> 0.10'
27
+ end
@@ -0,0 +1,25 @@
1
+ require 'context_hub_vault/version'
2
+ require 'context_hub_vault/client'
3
+
4
+ module ContextHubVault
5
+ class << self
6
+ attr_accessor :host, :version, :auth_token, :app_id
7
+
8
+ # config/initializers/context_hub_vault.rb (for instance)
9
+ #
10
+ # ContextHubVault.configure do |config|
11
+ # config.host = 'example.com'
12
+ # config.auth_token = 'qwertyasdfqwerty'
13
+ # config.version = 42
14
+ # config.app_id = 50
15
+ # end
16
+ #
17
+ # elsewhere
18
+ #
19
+ # client = ContextHubVault::Client.new
20
+ def configure
21
+ yield self
22
+ true
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,86 @@
1
+ require 'httparty'
2
+
3
+ module ContextHubVault
4
+ class Client
5
+ include HTTParty
6
+ format :json
7
+
8
+ def initialize(host: ContextHubVault.host, auth_token: ContextHubVault.auth_token, version: ContextHubVault.version, app_id: ContextHubVault.app_id)
9
+ if http_prefix(host)
10
+ self.class.base_uri "#{host}/api"
11
+ else
12
+ self.class.base_uri "https://#{host}/api"
13
+ end
14
+ self.class.headers('Authorization' => %Q[Token token="#{auth_token}"]) if auth_token
15
+ self.class.headers('Accept' => "application/vnd.carbon.vault.v#{version}") if version
16
+ self.class.headers('HTTP_CARBON_APP_ID' => app_id) if app_id
17
+ end
18
+
19
+ # Find a vault by it's vault_id
20
+ #
21
+ # @param id [String] vault_id
22
+ # @return [Hash] The full vault data structure that matches the vault_id
23
+ def find_by_id(id)
24
+ search('vault_info.vault_id' => id).first
25
+ end
26
+
27
+ # Search the vault for items that match your query params
28
+ #
29
+ # @param query [Hash] search by keyword
30
+ # @param query [String] javascript language search
31
+ # @return [Array] An array of the matching search results
32
+ def search(query = {})
33
+ get '/vaults', body: { query: query }
34
+ end
35
+
36
+ # Create new vault data
37
+ #
38
+ # @param container [String] The name of the vault container
39
+ # @param data [Hash] A hash of key/value pairs to store in the vault
40
+ # @return [Hash] The newly created vault
41
+ def create(container, data = {})
42
+ fail 'Must include the container' unless container
43
+
44
+ data.merge! container: container
45
+ post '/vaults', body: data
46
+ end
47
+
48
+ # Update vault data
49
+ #
50
+ # @param id [String] vault_id
51
+ # @param data [Hash] Data to update the vault with
52
+ # @return [Hash] The updated vault data structure
53
+ def update(id, data = {})
54
+ patch "/vaults/#{id}", body: data
55
+ end
56
+
57
+ # Delete a vault by vault_id
58
+ #
59
+ # @param id [String] vault_id
60
+ def destroy(id, data = {})
61
+ delete "/vaults/#{id}"
62
+ end
63
+
64
+ private
65
+
66
+ def http_prefix(host)
67
+ host.downcase.start_with?('http://', 'https://')
68
+ end
69
+
70
+ def post(path, options = {})
71
+ self.class.post path, options
72
+ end
73
+
74
+ def get(path, options = {})
75
+ self.class.get path, options
76
+ end
77
+
78
+ def patch(path, options = {})
79
+ self.class.patch path, options
80
+ end
81
+
82
+ def delete(path, options = {})
83
+ self.class.delete path, options
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,3 @@
1
+ module ContextHubVault
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe ContextHubVault::Client do
4
+ context 'initialization' do
5
+ let(:host) { 'example.com' }
6
+ let(:auth_token) { nil }
7
+ let(:version) { nil }
8
+ let(:app_id) { nil }
9
+ let!(:client) { ContextHubVault::Client.new(host: host, auth_token: auth_token, version: version, app_id: app_id) }
10
+
11
+ context 'defaults' do
12
+ it 'should default to ssl when given a hostname' do
13
+ client.class.base_uri.should == 'https://example.com/api'
14
+ end
15
+
16
+ it 'should not have the authorization header set' do
17
+ client.class.headers.should_not have_key('Authorization')
18
+ end
19
+
20
+ it 'should not have the version header set' do
21
+ client.class.headers.should_not have_key('Accept')
22
+ end
23
+ end
24
+
25
+ context 'custom' do
26
+ let(:host) { 'http://example.com:5000' }
27
+ let(:auth_token) { 'abcdef' }
28
+ let(:version) { 42 }
29
+
30
+ it 'should use http if explicitly defined' do
31
+ client.class.base_uri.should == 'http://example.com:5000/api'
32
+ end
33
+
34
+ it 'should set the authorization header if given an auth token' do
35
+ client.class.headers['Authorization'].should eq 'Token token="abcdef"'
36
+ end
37
+
38
+ it 'should set the version header if given a version' do
39
+ client.class.headers['Accept'].should eq 'application/vnd.carbon.vault.v42'
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe ContextHubVault do
4
+ it 'should have a version number' do
5
+ ContextHubVault::VERSION.should_not be_nil
6
+ end
7
+
8
+ it 'should be able to set its attributes via a configuration block' do
9
+ ContextHubVault.configure do |config|
10
+ config.host = 'example.com'
11
+ config.auth_token = 'qwertyasdfqwerty'
12
+ config.version = 42
13
+ config.app_id = 50
14
+ end
15
+
16
+ expect(ContextHubVault.host).to eq('example.com')
17
+ expect(ContextHubVault.app_id).to eq(50)
18
+ expect(ContextHubVault.auth_token).to eq('qwertyasdfqwerty')
19
+ expect(ContextHubVault.version).to eq(42)
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'context_hub_vault'
3
+ require 'pry'
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: context_hub_vault
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Robert Boone
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-18 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ description: 'Ruby client for the ContextHUB Vault '
84
+ email:
85
+ - robert@chaione.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .travis.yml
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - context_hub_vault.gemspec
98
+ - lib/context_hub_vault.rb
99
+ - lib/context_hub_vault/client.rb
100
+ - lib/context_hub_vault/version.rb
101
+ - spec/context_hub_vault/client_spec.rb
102
+ - spec/context_hub_vault_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: ''
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.1
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Ruby client for the ContextHUB Vault
128
+ test_files:
129
+ - spec/context_hub_vault/client_spec.rb
130
+ - spec/context_hub_vault_spec.rb
131
+ - spec/spec_helper.rb