portcullis 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58ce27aaa7f1ad15e8bfa5a215dd5b0c65a690c0
4
+ data.tar.gz: 6c0a6b7174cf8e84658b452259e6598cabfb9e39
5
+ SHA512:
6
+ metadata.gz: 7a81950a718ffdde9af63e38da889a6a3ff43aa37803dd44da601afa86635803194ea72347d1240ee9ccdb71c8328128aa4ef3f4f3041214d2d17ee9e234a861
7
+ data.tar.gz: 825385862aaee128dfc978cb8779c46187f10b6c1138d9cab7badf83218e733b27533a47bbe00f4ec31f466d9994263523b8498658d90f530b6d231aa901d373
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ Copyright 2017 Elliot Speck
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,30 @@
1
+ # Portcullis
2
+
3
+ A gem for interaction with https://portcullis.io/. This gem has no external dependencies.
4
+
5
+ ## Usage
6
+
7
+ ### Create a Token
8
+
9
+ ```ruby
10
+ user_id = 123456
11
+ client = Portcullis::APIClient.new("/path/to/config.yml")
12
+ client.create_token(user_id)
13
+ ```
14
+
15
+ ### Verify a Token
16
+
17
+ ```ruby
18
+ user_id = 123456
19
+ token = "013579"
20
+ client = Portcullis::APIClient.new("/path/to/config.yml")
21
+ client.verify_token(user_id, token)
22
+ ```
23
+
24
+ ### Destroy a Token
25
+
26
+ ```ruby
27
+ user_id = 123456
28
+ client = Portcullis::APIClient.new("/path/to/config.yml")
29
+ client.destroy_token(user_id)
30
+ ```
@@ -0,0 +1,46 @@
1
+ require 'json'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'yaml'
5
+
6
+ module Portcullis
7
+ class APIClient
8
+ def initialize(config_file_path)
9
+ @config = YAML::load_file(config_file_path)
10
+ end
11
+
12
+ def post(path, content)
13
+ uri = URI("https://portcullis.io/api/#{path}")
14
+ req = Net::HTTP::Post.new(uri)
15
+ req["X-PORTCULLIS-GATEWAY"] = @config["gateway"]
16
+ req["X-PORTCULLIS-API-KEY"] = @config["api_key"]
17
+ req.set_form_data(content)
18
+
19
+ res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) do |http|
20
+ http.request(req)
21
+ end
22
+
23
+ response = JSON.parse(res.body)
24
+
25
+ return response["success"], response
26
+ end
27
+
28
+ def create_token(user_id)
29
+ success, response = post("tokens/create", {"uid": user_id})
30
+ end
31
+
32
+ def destroy_token(user_id)
33
+ success, response = post("tokens/destroy", {"uid": user_id})
34
+ unless success
35
+ return response
36
+ end
37
+ end
38
+
39
+ def verify_token(user_id, token)
40
+ success, response = post("tokens/verify", {"uid": user_id, "token": token})
41
+ unless success
42
+ return response
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Portcullis
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: portcullis
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Elliot Speck
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem for interaction with https://portcullis.io/
14
+ email: rubygems@elliot.pro
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - LICENSE
20
+ - README.md
21
+ - lib/portcullis.rb
22
+ - lib/portcullis/version.rb
23
+ homepage: https://github.com/aeyris/portcullis-ruby
24
+ licenses:
25
+ - BSD-2-Clause
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.6.8
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: A gem for interaction with https://portcullis.io/
47
+ test_files: []