codelocks 2.0.3 → 3.0.0.pre.beta
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/.env.test +3 -0
- data/.ruby-version +1 -1
- data/Gemfile +1 -1
- data/README.md +10 -0
- data/codelocks.gemspec +1 -1
- data/lib/codelocks.rb +3 -41
- data/lib/codelocks/client.rb +82 -0
- data/lib/codelocks/collection_proxy.rb +26 -0
- data/lib/codelocks/lock.rb +4 -6
- data/lib/codelocks/model.rb +29 -0
- data/lib/codelocks/net_code.rb +4 -4
- data/lib/codelocks/request.rb +4 -3
- data/lib/codelocks/version.rb +1 -1
- data/spec/codelocks/client_spec.rb +92 -0
- data/spec/codelocks/collection_proxy_spec.rb +32 -0
- data/spec/codelocks/lock_spec.rb +10 -8
- data/spec/codelocks/model_spec.rb +40 -0
- data/spec/codelocks/net_code_spec.rb +10 -8
- data/spec/codelocks/request_spec.rb +10 -8
- data/spec/codelocks/response_spec.rb +7 -5
- data/spec/codelocks_spec.rb +0 -64
- data/spec/spec_helper.rb +3 -3
- metadata +16 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d12d67e7bf9e7e0cb6597b6b551599635c426095
|
4
|
+
data.tar.gz: 0e7c79bf2018b276d820337d005f44ebfa4cc567
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63038db7974ae0fc0bc9137b98a2d4c056945d0ff825e48db06daaabaf44d6c4cb43ea2f8027bd69f17bcb75e8ef367b1f6e2d7354b1ec6467d5b73a8b4150ed
|
7
|
+
data.tar.gz: d0e3dcfca9d37e0c7df4741a9315cf7cb1563bd46ce0d275f01a5d67c41dd6a6203dd1fc99b02c144f7c38980ac4f2f319f4ec6cf05011106fb9034943c6ae5d
|
data/.env.test
ADDED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.4.1
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -45,6 +45,16 @@ Codelocks.access_key = "argh"
|
|
45
45
|
|
46
46
|
API documentation with information on methods is [available on RubyDoc.info](http://www.rubydoc.info/github/kansohq/codelocks/master).
|
47
47
|
|
48
|
+
## Tests
|
49
|
+
|
50
|
+
The test suite can be run locally using the following commands:
|
51
|
+
|
52
|
+
```
|
53
|
+
$ cp .env.test .env
|
54
|
+
$ dotenv
|
55
|
+
$ bundle exec rspec
|
56
|
+
```
|
57
|
+
|
48
58
|
## Contributing
|
49
59
|
|
50
60
|
1. Fork it ( https://github.com/[my-github-username]/codelocks/fork )
|
data/codelocks.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "codelocks"
|
8
8
|
spec.version = Codelocks::VERSION
|
9
9
|
spec.authors = ["Robert May"]
|
10
|
-
spec.email = ["
|
10
|
+
spec.email = ["rob@piratestudios.co.uk"]
|
11
11
|
spec.summary = %q{A simple API wrapper for the CodeLocks API}
|
12
12
|
spec.description = %q{A wrapper for the CodeLocks NetCode API used to generate lock codes.}
|
13
13
|
spec.homepage = "http://www.codelocks.co.uk"
|
data/lib/codelocks.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require "faraday"
|
2
2
|
|
3
3
|
require "codelocks/version"
|
4
|
+
require "codelocks/client"
|
5
|
+
require "codelocks/collection_proxy"
|
6
|
+
require "codelocks/model"
|
4
7
|
require "codelocks/request"
|
5
8
|
require "codelocks/response"
|
6
9
|
require "codelocks/lock"
|
@@ -8,45 +11,4 @@ require "codelocks/net_code"
|
|
8
11
|
|
9
12
|
module Codelocks
|
10
13
|
class CodelocksError < StandardError; end
|
11
|
-
|
12
|
-
class << self
|
13
|
-
attr_writer :base_uri, :api_key, :access_key
|
14
|
-
|
15
|
-
# The base URI used for API request
|
16
|
-
#
|
17
|
-
# @return [String] the base URI
|
18
|
-
|
19
|
-
def base_uri
|
20
|
-
@base_uri || ENV['CODELOCKS_BASE_URI'] || (raise CodelocksError.new("No base URI specified"))
|
21
|
-
end
|
22
|
-
|
23
|
-
# Return the configured API key or raise an exception
|
24
|
-
#
|
25
|
-
# @return [String] the API key
|
26
|
-
|
27
|
-
def api_key
|
28
|
-
@api_key || ENV['CODELOCKS_API_KEY'] || (raise CodelocksError.new("No API key specified"))
|
29
|
-
end
|
30
|
-
|
31
|
-
# Return the access key. This is tied to the K3 Connect App.
|
32
|
-
# This can be nil, as for certain models of locks you will provide a 6 digit ID instead.
|
33
|
-
#
|
34
|
-
# @return [String] the access key
|
35
|
-
|
36
|
-
def access_key
|
37
|
-
@access_key || ENV['CODELOCKS_ACCESS_KEY']
|
38
|
-
end
|
39
|
-
|
40
|
-
# Faraday connection object
|
41
|
-
#
|
42
|
-
# @return [Faraday]
|
43
|
-
|
44
|
-
def connection
|
45
|
-
@connection ||= Faraday.new(url: base_uri) do |faraday|
|
46
|
-
faraday.request :url_encoded
|
47
|
-
faraday.response :logger
|
48
|
-
faraday.adapter Faraday.default_adapter
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
14
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Codelocks
|
2
|
+
class Client
|
3
|
+
attr_writer :base_uri, :api_key, :access_key
|
4
|
+
|
5
|
+
# The base URI used for API request
|
6
|
+
#
|
7
|
+
# @return [String] the base URI
|
8
|
+
|
9
|
+
def base_uri
|
10
|
+
@base_uri || ENV['CODELOCKS_BASE_URI'] || (raise CodelocksError.new("No base URI specified"))
|
11
|
+
end
|
12
|
+
|
13
|
+
# Return the configured API key or raise an exception
|
14
|
+
#
|
15
|
+
# @return [String] the API key
|
16
|
+
|
17
|
+
def api_key
|
18
|
+
@api_key || ENV['CODELOCKS_API_KEY'] || (raise CodelocksError.new("No API key specified"))
|
19
|
+
end
|
20
|
+
|
21
|
+
# Return the access key. This is tied to the K3 Connect App.
|
22
|
+
# This can be nil, as for certain models of locks you will provide a 6 digit ID instead.
|
23
|
+
#
|
24
|
+
# @return [String] the access key
|
25
|
+
|
26
|
+
def access_key
|
27
|
+
@access_key || ENV['CODELOCKS_ACCESS_KEY']
|
28
|
+
end
|
29
|
+
|
30
|
+
# Faraday connection object
|
31
|
+
#
|
32
|
+
# @return [Faraday]
|
33
|
+
|
34
|
+
def connection
|
35
|
+
@connection ||= Faraday.new(url: base_uri) do |faraday|
|
36
|
+
faraday.request :url_encoded
|
37
|
+
faraday.response :logger
|
38
|
+
faraday.adapter Faraday.default_adapter
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# Set configuration variables on instantiation
|
43
|
+
#
|
44
|
+
# @return [Codelocks::Client]
|
45
|
+
|
46
|
+
def initialize(attributes = {})
|
47
|
+
attributes.each do |key, val|
|
48
|
+
setter = :"#{key}="
|
49
|
+
|
50
|
+
if respond_to?(setter)
|
51
|
+
send(setter, val)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
self
|
56
|
+
end
|
57
|
+
|
58
|
+
# Proxy for the requests model
|
59
|
+
#
|
60
|
+
# @return [CollectionProxy]
|
61
|
+
|
62
|
+
def requests
|
63
|
+
@request_collection ||= CollectionProxy.new(model: Request, client: self)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Proxy for the netcodes model
|
67
|
+
#
|
68
|
+
# @return [CollectionProxy]
|
69
|
+
|
70
|
+
def net_codes
|
71
|
+
@net_code_collection ||= CollectionProxy.new(model: NetCode, client: self)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Proxy for the locks model
|
75
|
+
#
|
76
|
+
# @return [CollectionProxy]
|
77
|
+
|
78
|
+
def locks
|
79
|
+
@lock_collection ||= CollectionProxy.new(model: Lock, client: self)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Codelocks
|
2
|
+
class CollectionProxy
|
3
|
+
extend Forwardable
|
4
|
+
|
5
|
+
# @return [Client]
|
6
|
+
attr_accessor :client
|
7
|
+
|
8
|
+
# @return [Lock, NetCode, Request]
|
9
|
+
attr_accessor :model
|
10
|
+
|
11
|
+
def_delegators :@model, :create, :all
|
12
|
+
|
13
|
+
# Set configuration variables on instantiation
|
14
|
+
#
|
15
|
+
# @return [Codelocks::CollectionProxy]
|
16
|
+
|
17
|
+
def initialize(client: nil, model: nil)
|
18
|
+
self.client = client
|
19
|
+
self.model = model
|
20
|
+
|
21
|
+
model.collection_proxy = self
|
22
|
+
|
23
|
+
self
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/codelocks/lock.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
module Codelocks
|
2
|
-
class Lock
|
2
|
+
class Lock < Model
|
3
3
|
class << self
|
4
4
|
# Fetch a list of locks. Requires the access key env var to be set
|
5
5
|
#
|
6
6
|
# @return [Codelocks::NetCode::Response]
|
7
7
|
|
8
8
|
def all
|
9
|
-
|
10
|
-
raise CodelocksError.new("An access key must be provided")
|
11
|
-
end
|
9
|
+
super
|
12
10
|
|
13
|
-
|
14
|
-
"accesskey":
|
11
|
+
client.requests.create("lock",
|
12
|
+
"accesskey": client.access_key
|
15
13
|
)
|
16
14
|
end
|
17
15
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Codelocks
|
2
|
+
class Model
|
3
|
+
extend Forwardable
|
4
|
+
|
5
|
+
# @return [Client]
|
6
|
+
|
7
|
+
def client
|
8
|
+
self.class.client
|
9
|
+
end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
extend Forwardable
|
13
|
+
|
14
|
+
# @return [CollectionProxy]
|
15
|
+
attr_accessor :collection_proxy
|
16
|
+
|
17
|
+
def_delegator :@collection_proxy, :client
|
18
|
+
|
19
|
+
def all
|
20
|
+
if !client.access_key
|
21
|
+
raise CodelocksError.new("An access key must be provided")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def create
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/codelocks/net_code.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Codelocks
|
2
|
-
class NetCode
|
2
|
+
class NetCode < Model
|
3
3
|
class << self
|
4
4
|
# Predefined method for generating a new NetCode
|
5
5
|
#
|
@@ -12,14 +12,14 @@ module Codelocks
|
|
12
12
|
#
|
13
13
|
# @return [Codelocks::NetCode::Response]
|
14
14
|
|
15
|
-
def
|
15
|
+
def create(opts = {})
|
16
16
|
netcode = new(opts)
|
17
17
|
|
18
18
|
if !netcode.identifier
|
19
19
|
raise CodelocksError.new("Either a lock identifier or an access key must be provided")
|
20
20
|
end
|
21
21
|
|
22
|
-
|
22
|
+
client.requests.create("netcode/#{netcode.lock_id}",
|
23
23
|
"id": netcode.lock_id,
|
24
24
|
"start": netcode.start_datetime,
|
25
25
|
"duration": netcode.duration_id,
|
@@ -52,7 +52,7 @@ module Codelocks
|
|
52
52
|
# @return [String]
|
53
53
|
|
54
54
|
def identifier
|
55
|
-
opts[:identifier] ||
|
55
|
+
opts[:identifier] || client.access_key
|
56
56
|
end
|
57
57
|
|
58
58
|
# String representing the start date in YYYY-MM-DD format
|
data/lib/codelocks/request.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Codelocks
|
2
|
-
class Request
|
2
|
+
class Request < Model
|
3
3
|
class << self
|
4
4
|
# Perform a request against the NetCode API
|
5
5
|
#
|
@@ -9,14 +9,15 @@ module Codelocks
|
|
9
9
|
# @return [Codelocks::NetCode::Response]
|
10
10
|
|
11
11
|
def create(path, params = {})
|
12
|
-
response =
|
13
|
-
req.headers['x-api-key'] =
|
12
|
+
response = client.connection.get(path, default_params.merge(params)) do |req|
|
13
|
+
req.headers['x-api-key'] = client.api_key
|
14
14
|
end
|
15
15
|
|
16
16
|
Response.new(response)
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
|
+
|
20
21
|
# The default params used in NetCode endpoint requests
|
21
22
|
#
|
22
23
|
# @return [Hash]
|
data/lib/codelocks/version.rb
CHANGED
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Codelocks::Client do
|
4
|
+
subject(:client) do
|
5
|
+
Codelocks::Client.new(
|
6
|
+
base_uri: ENV["CODELOCKS_BASE_URI"] || "wibble",
|
7
|
+
api_key: ENV["CODELOCKS_API_KEY"] || "wobble"
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#base_uri" do
|
12
|
+
subject { client.base_uri }
|
13
|
+
|
14
|
+
before { allow(ENV).to receive(:[]) { nil } }
|
15
|
+
|
16
|
+
context "is present" do
|
17
|
+
before { client.base_uri = "test" }
|
18
|
+
|
19
|
+
it { is_expected.to eq("test") }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "is not present" do
|
23
|
+
before { client.base_uri = nil }
|
24
|
+
|
25
|
+
it "raises an exception" do
|
26
|
+
expect { subject }.to raise_error(Codelocks::CodelocksError)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#api_key" do
|
32
|
+
subject { client.api_key }
|
33
|
+
|
34
|
+
before { allow(ENV).to receive(:[]) { nil } }
|
35
|
+
|
36
|
+
context "is present" do
|
37
|
+
before { client.api_key = "test" }
|
38
|
+
|
39
|
+
it { is_expected.to eq("test") }
|
40
|
+
end
|
41
|
+
|
42
|
+
context "is not present" do
|
43
|
+
before { client.api_key = nil }
|
44
|
+
|
45
|
+
it "raises an exception" do
|
46
|
+
expect { subject }.to raise_error(Codelocks::CodelocksError)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#access_key" do
|
52
|
+
subject { client.access_key }
|
53
|
+
|
54
|
+
before { allow(ENV).to receive(:[]) { nil } }
|
55
|
+
|
56
|
+
context "is present" do
|
57
|
+
before { client.access_key = "test" }
|
58
|
+
|
59
|
+
it { is_expected.to eq("test") }
|
60
|
+
end
|
61
|
+
|
62
|
+
context "is not present" do
|
63
|
+
before { client.access_key = nil }
|
64
|
+
|
65
|
+
it { is_expected.to eq(nil) }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#connection" do
|
70
|
+
subject { client.connection }
|
71
|
+
|
72
|
+
it { is_expected.to be_a(Faraday::Connection) }
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#requests" do
|
76
|
+
subject { client.requests }
|
77
|
+
|
78
|
+
it { is_expected.to be_a(Codelocks::CollectionProxy) }
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#net_codes" do
|
82
|
+
subject { client.net_codes }
|
83
|
+
|
84
|
+
it { is_expected.to be_a(Codelocks::CollectionProxy) }
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#locks" do
|
88
|
+
subject { client.locks }
|
89
|
+
|
90
|
+
it { is_expected.to be_a(Codelocks::CollectionProxy) }
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Codelocks::CollectionProxy do
|
4
|
+
subject(:proxy) { Codelocks::CollectionProxy.new(model: model, client: client) }
|
5
|
+
let(:client) { Codelocks::Client.new }
|
6
|
+
let(:model) { Codelocks::Model }
|
7
|
+
|
8
|
+
describe "attribute accessors" do
|
9
|
+
[:client, :model].each do |attr|
|
10
|
+
it { is_expected.to respond_to(attr) }
|
11
|
+
it { is_expected.to respond_to(:"#{attr}=") }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#initialize" do
|
16
|
+
subject { proxy.send(:initialize, client: client, model: model) }
|
17
|
+
|
18
|
+
after { subject }
|
19
|
+
|
20
|
+
it "sets the client" do
|
21
|
+
expect(proxy).to receive(:client=).with(client)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "sets the model" do
|
25
|
+
expect(proxy).to receive(:model=).with(model)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "sets itself as the model's proxy" do
|
29
|
+
expect(model).to receive(:collection_proxy=).with(proxy)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/codelocks/lock_spec.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Codelocks::Lock do
|
4
|
-
|
5
|
-
|
4
|
+
let(:client) do
|
5
|
+
Codelocks::Client.new(
|
6
|
+
base_uri: ENV["CODELOCKS_BASE_URI"] || "wibble",
|
7
|
+
api_key: ENV["CODELOCKS_API_KEY"] || "wobble"
|
8
|
+
)
|
9
|
+
end
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
Codelocks.api_key = ENV["CODELOCKS_API_KEY"] || "wobble"
|
10
|
-
end
|
11
|
+
describe ".all" do
|
12
|
+
subject { client.locks.all }
|
11
13
|
|
12
14
|
context "valid access key" do
|
13
15
|
before do
|
14
|
-
|
16
|
+
client.access_key = ENV["CODELOCKS_ACCESS_KEY"] || "wubble"
|
15
17
|
end
|
16
18
|
|
17
19
|
around(:each) do |example|
|
@@ -33,7 +35,7 @@ describe Codelocks::Lock do
|
|
33
35
|
|
34
36
|
context "invalid access key" do
|
35
37
|
before do
|
36
|
-
|
38
|
+
client.access_key = "abracadabra"
|
37
39
|
end
|
38
40
|
|
39
41
|
around(:each) do |example|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Codelocks::Model do
|
4
|
+
let(:client) { Codelocks::Client.new }
|
5
|
+
let(:proxy) { Codelocks::CollectionProxy.new(model: Codelocks::Model, client: client) }
|
6
|
+
|
7
|
+
before do
|
8
|
+
Codelocks::Model.collection_proxy = proxy
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "instance methods" do
|
12
|
+
subject(:model) { Codelocks::Model.new }
|
13
|
+
|
14
|
+
describe "#client" do
|
15
|
+
subject { model.client }
|
16
|
+
|
17
|
+
it { is_expected.to eq(client) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "class methods" do
|
22
|
+
subject { Codelocks::Model }
|
23
|
+
|
24
|
+
describe ".all" do
|
25
|
+
it { is_expected.to respond_to(:all) }
|
26
|
+
|
27
|
+
context "access key isn't set" do
|
28
|
+
before { allow(client).to receive(:access_key) { nil } }
|
29
|
+
|
30
|
+
it "raises an error" do
|
31
|
+
expect { subject.all }.to raise_error(Codelocks::CodelocksError)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe ".create" do
|
37
|
+
it { is_expected.to respond_to(:create) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,18 +1,20 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Codelocks::NetCode do
|
4
|
-
|
4
|
+
let(:client) do
|
5
|
+
Codelocks::Client.new(
|
6
|
+
base_uri: ENV["CODELOCKS_BASE_URI"] || "wibble",
|
7
|
+
api_key: ENV["CODELOCKS_API_KEY"] || "wobble",
|
8
|
+
access_key: ENV["CODELOCKS_ACCESS_KEY"] || "wubble"
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".create" do
|
5
13
|
let(:lock_id) { nil }
|
6
14
|
let(:start_time) { Time.now }
|
7
15
|
let(:duration) { 1 }
|
8
16
|
|
9
|
-
subject {
|
10
|
-
|
11
|
-
before do
|
12
|
-
Codelocks.base_uri = ENV["CODELOCKS_BASE_URI"] || "wibble"
|
13
|
-
Codelocks.api_key = ENV["CODELOCKS_API_KEY"] || "wobble"
|
14
|
-
Codelocks.access_key = ENV["CODELOCKS_ACCESS_KEY"] || "wubble"
|
15
|
-
end
|
17
|
+
subject { client.net_codes.create(lock_id: lock_id, start_time: start_time, duration: duration) }
|
16
18
|
|
17
19
|
context "valid lock ID" do
|
18
20
|
let(:lock_id) { ENV["CODELOCKS_LOCK_ID"] || "valid" }
|
@@ -1,9 +1,11 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Codelocks::Request do
|
4
|
-
|
5
|
-
Codelocks.
|
6
|
-
|
4
|
+
let(:client) do
|
5
|
+
Codelocks::Client.new(
|
6
|
+
base_uri: ENV["CODELOCKS_BASE_URI"] || "wibble",
|
7
|
+
api_key: ENV["CODELOCKS_API_KEY"] || "wobble"
|
8
|
+
)
|
7
9
|
end
|
8
10
|
|
9
11
|
describe "#create" do
|
@@ -21,19 +23,19 @@ describe Codelocks::Request do
|
|
21
23
|
let(:path) { "netcode/#{params[:id]}" }
|
22
24
|
|
23
25
|
before do
|
24
|
-
allow(
|
25
|
-
allow(
|
26
|
+
allow(client.connection).to receive(:get) { response }
|
27
|
+
allow(client.requests.model).to receive(:default_params) { default_params }
|
26
28
|
end
|
27
29
|
|
28
30
|
|
29
31
|
it "performs a get request" do
|
30
|
-
expect(
|
31
|
-
|
32
|
+
expect(client.connection).to receive(:get).with(path, all_params)
|
33
|
+
client.requests.create(path, params)
|
32
34
|
end
|
33
35
|
|
34
36
|
it "returns a response object" do
|
35
37
|
expect(
|
36
|
-
|
38
|
+
client.requests.create(path, params)
|
37
39
|
).to be_a(Codelocks::Response)
|
38
40
|
end
|
39
41
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Codelocks::Response do
|
4
|
+
let(:client) do
|
5
|
+
Codelocks::Client.new(
|
6
|
+
base_uri: ENV["CODELOCKS_BASE_URI"] || "wibble",
|
7
|
+
api_key: ENV["CODELOCKS_API_KEY"] || "wobble"
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
4
11
|
let(:response) { Codelocks::Response.new(faraday_response) }
|
5
12
|
let(:faraday_response) { double('faraday_response', success?: true, body: '{"test": "thing"}') }
|
6
13
|
|
7
|
-
before do
|
8
|
-
Codelocks.base_uri = "http://wobble.com/"
|
9
|
-
Codelocks.api_key = "wibble"
|
10
|
-
end
|
11
|
-
|
12
14
|
describe "#initialize" do
|
13
15
|
it "sets the response instance variable" do
|
14
16
|
expect(response.response).to eq(faraday_response)
|
data/spec/codelocks_spec.rb
CHANGED
@@ -1,68 +1,4 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Codelocks do
|
4
|
-
describe "#base_uri" do
|
5
|
-
subject { Codelocks.base_uri }
|
6
|
-
|
7
|
-
before { allow(ENV).to receive(:[]) { nil } }
|
8
|
-
|
9
|
-
context "is present" do
|
10
|
-
before { Codelocks.base_uri = "test" }
|
11
|
-
|
12
|
-
it { is_expected.to eq("test") }
|
13
|
-
end
|
14
|
-
|
15
|
-
context "is not present" do
|
16
|
-
before { Codelocks.base_uri = nil }
|
17
|
-
|
18
|
-
it "raises an exception" do
|
19
|
-
expect { subject }.to raise_error(Codelocks::CodelocksError)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe "#api_key" do
|
25
|
-
subject { Codelocks.api_key }
|
26
|
-
|
27
|
-
before { allow(ENV).to receive(:[]) { nil } }
|
28
|
-
|
29
|
-
context "is present" do
|
30
|
-
before { Codelocks.api_key = "test" }
|
31
|
-
|
32
|
-
it { is_expected.to eq("test") }
|
33
|
-
end
|
34
|
-
|
35
|
-
context "is not present" do
|
36
|
-
before { Codelocks.api_key = nil }
|
37
|
-
|
38
|
-
it "raises an exception" do
|
39
|
-
expect { subject }.to raise_error(Codelocks::CodelocksError)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "#access_key" do
|
45
|
-
subject { Codelocks.access_key }
|
46
|
-
|
47
|
-
before { allow(ENV).to receive(:[]) { nil } }
|
48
|
-
|
49
|
-
context "is present" do
|
50
|
-
before { Codelocks.access_key = "test" }
|
51
|
-
|
52
|
-
it { is_expected.to eq("test") }
|
53
|
-
end
|
54
|
-
|
55
|
-
context "is not present" do
|
56
|
-
before { Codelocks.access_key = nil }
|
57
|
-
|
58
|
-
it { is_expected.to eq(nil) }
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
|
63
|
-
describe "#connection" do
|
64
|
-
subject { Codelocks.connection }
|
65
|
-
|
66
|
-
it { is_expected.to be_a(Faraday::Connection) }
|
67
|
-
end
|
68
4
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -8,8 +8,8 @@ require "pry"
|
|
8
8
|
VCR.configure do |config|
|
9
9
|
config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
|
10
10
|
config.hook_into :faraday
|
11
|
-
config.filter_sensitive_data("<BASE_URI>") {
|
12
|
-
config.filter_sensitive_data("<API_KEY>") {
|
13
|
-
config.filter_sensitive_data("<ACCESS_KEY>") {
|
11
|
+
config.filter_sensitive_data("<BASE_URI>") { ENV['CODELOCKS_BASE_URI'] }
|
12
|
+
config.filter_sensitive_data("<API_KEY>") { ENV['CODELOCKS_API_KEY'] }
|
13
|
+
config.filter_sensitive_data("<ACCESS_KEY>") { ENV['CODELOCKS_ACCESS_KEY'] }
|
14
14
|
config.filter_sensitive_data("LOCK_ID") { ENV['CODELOCKS_LOCK_ID'] }
|
15
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codelocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0.pre.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert May
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,11 +110,12 @@ dependencies:
|
|
110
110
|
version: '0.9'
|
111
111
|
description: A wrapper for the CodeLocks NetCode API used to generate lock codes.
|
112
112
|
email:
|
113
|
-
-
|
113
|
+
- rob@piratestudios.co.uk
|
114
114
|
executables: []
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
+
- ".env.test"
|
118
119
|
- ".gitignore"
|
119
120
|
- ".ruby-version"
|
120
121
|
- Gemfile
|
@@ -123,12 +124,18 @@ files:
|
|
123
124
|
- Rakefile
|
124
125
|
- codelocks.gemspec
|
125
126
|
- lib/codelocks.rb
|
127
|
+
- lib/codelocks/client.rb
|
128
|
+
- lib/codelocks/collection_proxy.rb
|
126
129
|
- lib/codelocks/lock.rb
|
130
|
+
- lib/codelocks/model.rb
|
127
131
|
- lib/codelocks/net_code.rb
|
128
132
|
- lib/codelocks/request.rb
|
129
133
|
- lib/codelocks/response.rb
|
130
134
|
- lib/codelocks/version.rb
|
135
|
+
- spec/codelocks/client_spec.rb
|
136
|
+
- spec/codelocks/collection_proxy_spec.rb
|
131
137
|
- spec/codelocks/lock_spec.rb
|
138
|
+
- spec/codelocks/model_spec.rb
|
132
139
|
- spec/codelocks/net_code_spec.rb
|
133
140
|
- spec/codelocks/request_spec.rb
|
134
141
|
- spec/codelocks/response_spec.rb
|
@@ -153,17 +160,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
160
|
version: '2.2'
|
154
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
162
|
requirements:
|
156
|
-
- - "
|
163
|
+
- - ">"
|
157
164
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
165
|
+
version: 1.3.1
|
159
166
|
requirements: []
|
160
167
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.
|
168
|
+
rubygems_version: 2.6.13
|
162
169
|
signing_key:
|
163
170
|
specification_version: 4
|
164
171
|
summary: A simple API wrapper for the CodeLocks API
|
165
172
|
test_files:
|
173
|
+
- spec/codelocks/client_spec.rb
|
174
|
+
- spec/codelocks/collection_proxy_spec.rb
|
166
175
|
- spec/codelocks/lock_spec.rb
|
176
|
+
- spec/codelocks/model_spec.rb
|
167
177
|
- spec/codelocks/net_code_spec.rb
|
168
178
|
- spec/codelocks/request_spec.rb
|
169
179
|
- spec/codelocks/response_spec.rb
|
@@ -173,4 +183,3 @@ test_files:
|
|
173
183
|
- spec/fixtures/vcr_cassettes/valid_access_key.yml
|
174
184
|
- spec/fixtures/vcr_cassettes/valid_lock_id.yml
|
175
185
|
- spec/spec_helper.rb
|
176
|
-
has_rdoc:
|