codelocks 1.0.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.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +2 -0
- data/codelocks.gemspec +30 -0
- data/lib/codelocks.rb +50 -0
- data/lib/codelocks/net_code.rb +55 -0
- data/lib/codelocks/net_code/request.rb +34 -0
- data/lib/codelocks/net_code/response.rb +43 -0
- data/lib/codelocks/version.rb +3 -0
- data/spec/codelocks/net_code/request_spec.rb +44 -0
- data/spec/codelocks/net_code/response_spec.rb +59 -0
- data/spec/codelocks/net_code_spec.rb +64 -0
- data/spec/codelocks_spec.rb +55 -0
- data/spec/fixtures/vcr_cassettes/invalid_lock_id.yml +43 -0
- data/spec/fixtures/vcr_cassettes/valid_lock_id.yml +43 -0
- data/spec/spec_helper.rb +13 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 706157b5adb66d052b717f3a8dc0a7a619bce477
|
4
|
+
data.tar.gz: e6535ffecc98c8f01361ca1de1ad006fd79b3bbe
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 98cad81d6ff1cc09b75a2e5dcf67c123ecd8ed64fb74ffe282f1623437b07a236c577f0a2e830e3e511bb5fea3ad4389acaa13fbe39db6d3bbca4755262ea392
|
7
|
+
data.tar.gz: 296316b33e2a544692d37871c2c8acb15f7b985502b1afb11f2e4b7f392c8dd3f80bec5814d22365be153df6d1b6972d1c2e9693fcf68742d9765c8974dd4d2d
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Robert May
|
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,47 @@
|
|
1
|
+
# Codelocks
|
2
|
+
|
3
|
+
[](https://circleci.com/gh/kansohq/codelocks)
|
4
|
+
|
5
|
+
A simple gem to wrap the Codelocks NetCode API, for generating key codes to operate their physical locks.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'codelocks'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install codelocks
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Configure your API credentials, either by setting the following two environment variables:
|
26
|
+
|
27
|
+
```
|
28
|
+
CODELOCKS_API_KEY
|
29
|
+
CODELOCKS_PAIRING_ID
|
30
|
+
```
|
31
|
+
|
32
|
+
Or by setting them directly in Ruby:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
Codelocks.api_key = "blargh"
|
36
|
+
Codelocks.pairing_id = "argh"
|
37
|
+
```
|
38
|
+
|
39
|
+
API documentation with information on methods is [available on RubyDoc.info](http://www.rubydoc.info/github/kansohq/codelocks/master).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it ( https://github.com/[my-github-username]/codelocks/fork )
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/codelocks.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'codelocks/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "codelocks"
|
8
|
+
spec.version = Codelocks::VERSION
|
9
|
+
spec.authors = ["Robert May"]
|
10
|
+
spec.email = ["robert@kanso.io"]
|
11
|
+
spec.summary = %q{A simple API wrapper for the CodeLocks API}
|
12
|
+
spec.description = %q{A wrapper for the CodeLocks NetCode API used to generate lock codes.}
|
13
|
+
spec.homepage = "http://www.codelocks.co.uk"
|
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.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
24
|
+
spec.add_development_dependency "vcr", "~> 2.9"
|
25
|
+
spec.add_development_dependency "dotenv", "~> 2.0"
|
26
|
+
|
27
|
+
spec.add_dependency "faraday", "~> 0.8.11"
|
28
|
+
|
29
|
+
spec.required_ruby_version = "~> 2.2"
|
30
|
+
end
|
data/lib/codelocks.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require "faraday"
|
2
|
+
|
3
|
+
require "codelocks/version"
|
4
|
+
require "codelocks/net_code"
|
5
|
+
require "codelocks/net_code/request"
|
6
|
+
require "codelocks/net_code/response"
|
7
|
+
|
8
|
+
module Codelocks
|
9
|
+
class CodelocksError < StandardError; end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_writer :api_key, :pairing_id
|
13
|
+
|
14
|
+
# The base URI used for API request
|
15
|
+
#
|
16
|
+
# @return [String] the base URI
|
17
|
+
|
18
|
+
def base_uri
|
19
|
+
"https://api-2445581366752.apicast.io/api/v3"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Return the configured API key or raise an exception
|
23
|
+
#
|
24
|
+
# @return [String] the API key
|
25
|
+
|
26
|
+
def api_key
|
27
|
+
@api_key || ENV['CODELOCKS_API_KEY'] || (raise CodelocksError.new("No API key specified"))
|
28
|
+
end
|
29
|
+
|
30
|
+
# Return the configured pairing ID or raise an exception
|
31
|
+
#
|
32
|
+
# @return [String] the pairing ID
|
33
|
+
|
34
|
+
def pairing_id
|
35
|
+
@pairing_id || ENV['CODELOCKS_PAIRING_ID'] || (raise CodelocksError.new("No pairing ID specified"))
|
36
|
+
end
|
37
|
+
|
38
|
+
# Faraday connection object
|
39
|
+
#
|
40
|
+
# @return [Faraday]
|
41
|
+
|
42
|
+
def connection
|
43
|
+
@connection ||= Faraday.new(url: base_uri) do |faraday|
|
44
|
+
faraday.request :url_encoded
|
45
|
+
faraday.response :logger
|
46
|
+
faraday.adapter Faraday.default_adapter
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Codelocks
|
2
|
+
module NetCode
|
3
|
+
class << self
|
4
|
+
# Predefined method for generating a new NetCode
|
5
|
+
#
|
6
|
+
# @option [String] :lock_id The lock identifier
|
7
|
+
# @option [Time] :start_time (Time.now) The start datetime object
|
8
|
+
# @option [Integer] :duration The number of hours the generated code should be valid for from the start_time
|
9
|
+
#
|
10
|
+
# @return [Codelocks::NetCode::Response]
|
11
|
+
|
12
|
+
def generate_netcode(lock_id: nil, start_time: Time.now, duration: nil)
|
13
|
+
Request.create("netcode/ncgenerator/getnetcode", {
|
14
|
+
id: "N#{lock_id}",
|
15
|
+
sd: start_time.strftime("%d/%m/%Y"),
|
16
|
+
st: start_time.strftime("%H"),
|
17
|
+
du: convert_duration(duration)
|
18
|
+
})
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
# Convert a duration in hours to the NetCode duration option
|
24
|
+
#
|
25
|
+
# @param [Integer] duration number of hours duration
|
26
|
+
#
|
27
|
+
# @return [Integer]
|
28
|
+
|
29
|
+
def convert_duration(duration = 0)
|
30
|
+
case
|
31
|
+
when duration == 0
|
32
|
+
duration
|
33
|
+
when duration <= 12 # less than 13 hours
|
34
|
+
duration -1
|
35
|
+
when 13..24.include?(duration) # 1 day
|
36
|
+
12
|
37
|
+
when 25..48.include?(duration) # 2 days
|
38
|
+
13
|
39
|
+
when 49..72.include?(duration) # 3 days
|
40
|
+
14
|
41
|
+
when 73..96.include?(duration) # 4 days
|
42
|
+
15
|
43
|
+
when 97..120.include?(duration) # 5 days
|
44
|
+
16
|
45
|
+
when 121..144.include?(duration) # 6 days
|
46
|
+
17
|
47
|
+
when 145..168.include?(duration) # 7 days
|
48
|
+
18
|
49
|
+
when duration > 168 # more than 7 days, generates a URM code
|
50
|
+
19
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Codelocks
|
2
|
+
module NetCode
|
3
|
+
class Request
|
4
|
+
class << self
|
5
|
+
# Perform a request against the NetCode API
|
6
|
+
#
|
7
|
+
# @param [String] path the URI path to perform the request against
|
8
|
+
# @param [Hash] params
|
9
|
+
# @option params [String] :sd The start date in format dd/mm/yyyy
|
10
|
+
# @option params [String] :st The start time, 0 spaced: 00-23
|
11
|
+
# @option params [Integer] :duration The duration for the code to be valid for
|
12
|
+
#
|
13
|
+
# @return [Codelocks::NetCode::Response]
|
14
|
+
|
15
|
+
def create(path, params = {})
|
16
|
+
response = Codelocks.connection.get(path, default_params.merge(params))
|
17
|
+
Response.new(response)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
# The default params used in NetCode endpoint requests
|
22
|
+
#
|
23
|
+
# @return [Hash]
|
24
|
+
|
25
|
+
def default_params
|
26
|
+
{
|
27
|
+
user_key: Codelocks.api_key,
|
28
|
+
pid: Codelocks.pairing_id,
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module Codelocks
|
4
|
+
module NetCode
|
5
|
+
class Response
|
6
|
+
attr_reader :response
|
7
|
+
|
8
|
+
# Initialize the response object
|
9
|
+
#
|
10
|
+
# @param [Faraday::Response] faraday_response
|
11
|
+
|
12
|
+
def initialize(faraday_response)
|
13
|
+
@response = faraday_response
|
14
|
+
end
|
15
|
+
|
16
|
+
# Was the request successful?
|
17
|
+
#
|
18
|
+
# @return [Truthy]
|
19
|
+
|
20
|
+
def success?
|
21
|
+
response.success?
|
22
|
+
end
|
23
|
+
|
24
|
+
# Parse the response from the server if successful
|
25
|
+
#
|
26
|
+
# @return [Hash,Nil]
|
27
|
+
|
28
|
+
def body
|
29
|
+
if success?
|
30
|
+
@body ||= JSON.parse(response.body)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Simple method missing accessor for reading returned attributes
|
35
|
+
#
|
36
|
+
# @return [String] the raw returned string from the API
|
37
|
+
|
38
|
+
def method_missing(method_name, *opts, &block)
|
39
|
+
body[method_name.to_s]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Codelocks::NetCode::Request do
|
4
|
+
before do
|
5
|
+
Codelocks.api_key = "wibble"
|
6
|
+
Codelocks.pairing_id = "wobble"
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#create" do
|
10
|
+
let(:response) { double('faraday_response') }
|
11
|
+
let(:path) { "netcode/ncgenerator/getnetcode" }
|
12
|
+
let(:params) do
|
13
|
+
{
|
14
|
+
id: "lock"
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:default_params) do
|
19
|
+
{
|
20
|
+
api_key: "wibble",
|
21
|
+
pairing_id: "wobble"
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:all_params) { default_params.merge(params) }
|
26
|
+
|
27
|
+
before do
|
28
|
+
allow(Codelocks.connection).to receive(:get) { response }
|
29
|
+
allow(Codelocks::NetCode::Request).to receive(:default_params) { default_params }
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
it "performs a get request" do
|
34
|
+
expect(Codelocks.connection).to receive(:get).with(path, all_params)
|
35
|
+
Codelocks::NetCode::Request.create(path, params)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns a response object" do
|
39
|
+
expect(
|
40
|
+
Codelocks::NetCode::Request.create(path, params)
|
41
|
+
).to be_a(Codelocks::NetCode::Response)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Codelocks::NetCode::Response do
|
4
|
+
let(:response) { Codelocks::NetCode::Response.new(faraday_response) }
|
5
|
+
let(:faraday_response) { double('faraday_response', success?: true, body: '{"test": "thing"}') }
|
6
|
+
|
7
|
+
before do
|
8
|
+
Codelocks.api_key = "wibble"
|
9
|
+
Codelocks.pairing_id = "wobble"
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#initialize" do
|
13
|
+
it "sets the response instance variable" do
|
14
|
+
expect(response.response).to eq(faraday_response)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#success?" do
|
19
|
+
subject { response.success? }
|
20
|
+
|
21
|
+
context "is a success" do
|
22
|
+
before { allow(faraday_response).to receive(:success?) { true } }
|
23
|
+
|
24
|
+
it { is_expected.to be true }
|
25
|
+
end
|
26
|
+
|
27
|
+
context "is not a success" do
|
28
|
+
before { allow(faraday_response).to receive(:success?) { false } }
|
29
|
+
|
30
|
+
it { is_expected.to be false }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#body" do
|
35
|
+
subject { response.body }
|
36
|
+
|
37
|
+
context "success? is true" do
|
38
|
+
before { allow(faraday_response).to receive(:success?) { true } }
|
39
|
+
|
40
|
+
it { is_expected.to be_a(Hash) }
|
41
|
+
end
|
42
|
+
|
43
|
+
context "success? is false" do
|
44
|
+
before { allow(faraday_response).to receive(:success?) { false } }
|
45
|
+
|
46
|
+
it { is_expected.to be nil }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#method_missing" do
|
51
|
+
it "returns the value from the body hash" do
|
52
|
+
expect(response.test).to eq("thing")
|
53
|
+
end
|
54
|
+
|
55
|
+
it "returns nil for missing keys" do
|
56
|
+
expect(response.blargh).to be nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Codelocks::NetCode do
|
4
|
+
describe "#generate_netcode" do
|
5
|
+
let(:lock_id) { nil }
|
6
|
+
let(:start_time) { Time.now }
|
7
|
+
let(:duration) { 1 }
|
8
|
+
|
9
|
+
subject { Codelocks::NetCode.generate_netcode(lock_id: lock_id, start_time: start_time, duration: duration) }
|
10
|
+
|
11
|
+
before do
|
12
|
+
Codelocks.api_key = ENV['CODELOCKS_API_KEY'] || "wibble"
|
13
|
+
Codelocks.pairing_id = ENV['CODELOCKS_PAIRING_ID'] || "wobble"
|
14
|
+
end
|
15
|
+
|
16
|
+
context "valid lock ID" do
|
17
|
+
let(:lock_id) { ENV['CODELOCKS_LOCK_ID'] || "valid" }
|
18
|
+
|
19
|
+
around(:each) do |example|
|
20
|
+
VCR.use_cassette("valid_lock_id", erb: true, match_requests_on: [:method]) do
|
21
|
+
example.run
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it { is_expected.to be_a(Codelocks::NetCode::Response) }
|
26
|
+
|
27
|
+
it "is successful" do
|
28
|
+
expect(subject.success?).to be true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns a valid netcode" do
|
32
|
+
expect(subject.netcode).to be_a(String)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns a valid starttime" do
|
36
|
+
expect(subject.starttime).to be_a(String)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "doesn't return an error" do
|
40
|
+
expect(subject.error).to be nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "invalid lock ID" do
|
45
|
+
let(:lock_id) { "invalid" }
|
46
|
+
|
47
|
+
around(:each) do |example|
|
48
|
+
VCR.use_cassette("invalid_lock_id", erb: true, match_requests_on: [:method]) do
|
49
|
+
example.run
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it { is_expected.to be_a(Codelocks::NetCode::Response) }
|
54
|
+
|
55
|
+
it "returns an error" do
|
56
|
+
expect(subject.error).to be_a(String)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "returns an error message" do
|
60
|
+
expect(subject.message).to be_a(String)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Codelocks do
|
4
|
+
describe "#base_uri" do
|
5
|
+
subject { Codelocks.base_uri }
|
6
|
+
|
7
|
+
it { is_expected.to be_a(String) }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#api_key" do
|
11
|
+
subject { Codelocks.api_key }
|
12
|
+
|
13
|
+
before { allow(ENV).to receive(:[]) { nil } }
|
14
|
+
|
15
|
+
context "is present" do
|
16
|
+
before { Codelocks.api_key = "test" }
|
17
|
+
|
18
|
+
it { is_expected.to eq("test") }
|
19
|
+
end
|
20
|
+
|
21
|
+
context "is not present" do
|
22
|
+
before { Codelocks.api_key = nil }
|
23
|
+
|
24
|
+
it "raises an exception" do
|
25
|
+
expect { subject }.to raise_error(Codelocks::CodelocksError)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#pairing_id" do
|
31
|
+
subject { Codelocks.pairing_id }
|
32
|
+
|
33
|
+
before { allow(ENV).to receive(:[]) { nil } }
|
34
|
+
|
35
|
+
context "is present" do
|
36
|
+
before { Codelocks.pairing_id = "test" }
|
37
|
+
|
38
|
+
it { is_expected.to eq("test") }
|
39
|
+
end
|
40
|
+
|
41
|
+
context "is not present" do
|
42
|
+
before { Codelocks.pairing_id = nil }
|
43
|
+
|
44
|
+
it "raises an exception" do
|
45
|
+
expect { subject }.to raise_error(Codelocks::CodelocksError)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#connection" do
|
51
|
+
subject { Codelocks.connection }
|
52
|
+
|
53
|
+
it { is_expected.to be_a(Faraday::Connection) }
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api-2445581366752.apicast.io/api/v3/netcode/ncgenerator/getnetcode?user_key=<%= ENV['CODELOCKS_API_KEY'] || "wibble" %>&pid=<%= ENV['CODELOCKS_PAIRING_ID'] || "wobble" %>&id=Ninvalid&sd=20%2F10%2F2015&st=17&du=0
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.8.11
|
12
|
+
response:
|
13
|
+
status:
|
14
|
+
code: 200
|
15
|
+
message:
|
16
|
+
headers:
|
17
|
+
cache-control:
|
18
|
+
- no-store, no-cache, must-revalidate, post-check=0, pre-check=0
|
19
|
+
content-type:
|
20
|
+
- text/html; charset=UTF-8
|
21
|
+
date:
|
22
|
+
- Tue, 20 Oct 2015 16:08:07 GMT
|
23
|
+
expires:
|
24
|
+
- Thu, 19 Nov 1981 08:52:00 GMT
|
25
|
+
pragma:
|
26
|
+
- no-cache
|
27
|
+
server:
|
28
|
+
- openresty/1.5.11.1
|
29
|
+
set-cookie:
|
30
|
+
- cpt=6f3e912e9b229f18247850a374fb632aba7dcdcb; expires=Tue, 20-Oct-2015 18:08:20
|
31
|
+
GMT; path=/; HttpOnly
|
32
|
+
x-powered-by:
|
33
|
+
- ASP.NET, 3scale API Management - http://www.3scale.net
|
34
|
+
content-length:
|
35
|
+
- '76'
|
36
|
+
connection:
|
37
|
+
- Close
|
38
|
+
body:
|
39
|
+
encoding: UTF-8
|
40
|
+
string: '{"error":"Lock not found","message":"Please check the identifier provided."}'
|
41
|
+
http_version:
|
42
|
+
recorded_at: Tue, 20 Oct 2015 16:08:07 GMT
|
43
|
+
recorded_with: VCR 2.9.3
|
@@ -0,0 +1,43 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api-2445581366752.apicast.io/api/v3/netcode/ncgenerator/getnetcode?user_key=<%= ENV['CODELOCKS_API_KEY'] || "wibble" %>&pid=<%= ENV['CODELOCKS_PAIRING_ID'] || "wobble" %>&id=N<%= ENV['CODELOCKS_LOCK_ID'] || "valid" %>&sd=20%2F10%2F2015&st=17&du=0
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.8.11
|
12
|
+
response:
|
13
|
+
status:
|
14
|
+
code: 200
|
15
|
+
message:
|
16
|
+
headers:
|
17
|
+
cache-control:
|
18
|
+
- no-store, no-cache, must-revalidate, post-check=0, pre-check=0
|
19
|
+
content-type:
|
20
|
+
- application/json
|
21
|
+
date:
|
22
|
+
- Tue, 20 Oct 2015 16:08:05 GMT
|
23
|
+
expires:
|
24
|
+
- Thu, 19 Nov 1981 08:52:00 GMT
|
25
|
+
pragma:
|
26
|
+
- no-cache
|
27
|
+
server:
|
28
|
+
- openresty/1.5.11.1
|
29
|
+
set-cookie:
|
30
|
+
- cpt=30457e50b3e443bcd1407f77f7b39d71df699388; expires=Tue, 20-Oct-2015 18:08:19
|
31
|
+
GMT; path=/; HttpOnly
|
32
|
+
x-powered-by:
|
33
|
+
- ASP.NET, 3scale API Management - http://www.3scale.net
|
34
|
+
content-length:
|
35
|
+
- '53'
|
36
|
+
connection:
|
37
|
+
- Close
|
38
|
+
body:
|
39
|
+
encoding: UTF-8
|
40
|
+
string: '{"netcode":"000000","starttime":"2015\/10\/20\/17:0"}'
|
41
|
+
http_version:
|
42
|
+
recorded_at: Tue, 20 Oct 2015 16:08:05 GMT
|
43
|
+
recorded_with: VCR 2.9.3
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "dotenv"
|
2
|
+
Dotenv.load
|
3
|
+
|
4
|
+
require "codelocks"
|
5
|
+
require "vcr"
|
6
|
+
|
7
|
+
VCR.configure do |config|
|
8
|
+
config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
|
9
|
+
config.hook_into :faraday
|
10
|
+
config.filter_sensitive_data("<API_KEY>") { Codelocks.api_key }
|
11
|
+
config.filter_sensitive_data("<PAIRING_ID>") { Codelocks.pairing_id }
|
12
|
+
config.filter_sensitive_data("<LOCK_ID>") { ENV['CODELOCKS_LOCK_ID'] }
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codelocks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert May
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-21 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: vcr
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dotenv
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.8.11
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.8.11
|
97
|
+
description: A wrapper for the CodeLocks NetCode API used to generate lock codes.
|
98
|
+
email:
|
99
|
+
- robert@kanso.io
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- codelocks.gemspec
|
110
|
+
- lib/codelocks.rb
|
111
|
+
- lib/codelocks/net_code.rb
|
112
|
+
- lib/codelocks/net_code/request.rb
|
113
|
+
- lib/codelocks/net_code/response.rb
|
114
|
+
- lib/codelocks/version.rb
|
115
|
+
- spec/codelocks/net_code/request_spec.rb
|
116
|
+
- spec/codelocks/net_code/response_spec.rb
|
117
|
+
- spec/codelocks/net_code_spec.rb
|
118
|
+
- spec/codelocks_spec.rb
|
119
|
+
- spec/fixtures/vcr_cassettes/invalid_lock_id.yml
|
120
|
+
- spec/fixtures/vcr_cassettes/valid_lock_id.yml
|
121
|
+
- spec/spec_helper.rb
|
122
|
+
homepage: http://www.codelocks.co.uk
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - "~>"
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '2.2'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.4.5.1
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: A simple API wrapper for the CodeLocks API
|
146
|
+
test_files:
|
147
|
+
- spec/codelocks/net_code/request_spec.rb
|
148
|
+
- spec/codelocks/net_code/response_spec.rb
|
149
|
+
- spec/codelocks/net_code_spec.rb
|
150
|
+
- spec/codelocks_spec.rb
|
151
|
+
- spec/fixtures/vcr_cassettes/invalid_lock_id.yml
|
152
|
+
- spec/fixtures/vcr_cassettes/valid_lock_id.yml
|
153
|
+
- spec/spec_helper.rb
|
154
|
+
has_rdoc:
|