loginator 0.0.6 → 0.0.7
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/lib/loginator.rb +1 -0
- data/lib/loginator/jsonable_struct.rb +10 -5
- data/lib/loginator/transaction.rb +7 -0
- data/lib/loginator/version.rb +1 -1
- data/spec/integration/lib/loginator/transaction_spec.rb +23 -0
- data/spec/support/shared/lib/loginator/jsonable_struct_spec.rb +2 -2
- data/spec/support/shared/lib/loginator/struct_with_defaults_spec.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16cb733ff2fbe83f63150fd5abe6027c578a6054
|
4
|
+
data.tar.gz: c8ef72fffaae51fe5cd15476216440b23e1f8afa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d5773959c66a369cffe7dea5117d2b599e73b6131f3dfea049c815e74ac5c64278754efd132b17f75dbab839f06285a24e484cf607ed5998f1a28b9c860e847
|
7
|
+
data.tar.gz: ef38af19158edaec1a56c4bcbafee62303a81e0e2298d0eb288b30748a13cd4f8d74be5327f498c3c56cbc5caff4f1d62ecc457bc75b58d6fea641e36ae7b499
|
data/lib/loginator.rb
CHANGED
@@ -11,11 +11,16 @@ module Loginator
|
|
11
11
|
|
12
12
|
# class level mixins
|
13
13
|
module ClassMethods #:nodoc
|
14
|
-
def
|
15
|
-
|
16
|
-
fail(ArgumentError, format('Incorrect message type: %s',
|
17
|
-
fail(ArgumentError, format('Hash must contain keys: %s', members.join(', '))) unless valid_hash?(
|
18
|
-
new(*
|
14
|
+
def from_hash(hsh)
|
15
|
+
hsh_type = hsh.delete('type')
|
16
|
+
fail(ArgumentError, format('Incorrect message type: %s', hsh_type)) unless hsh_type == type
|
17
|
+
fail(ArgumentError, format('Hash must contain keys: %s', members.join(', '))) unless valid_hash?(hsh)
|
18
|
+
new(*hsh.values)
|
19
|
+
end
|
20
|
+
|
21
|
+
def from_json(json_str)
|
22
|
+
json = MultiJson.load(json_str)
|
23
|
+
from_hash(json)
|
19
24
|
end
|
20
25
|
|
21
26
|
def type
|
@@ -1,6 +1,13 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
1
3
|
module Loginator
|
2
4
|
# Methods for generating transactional metadata.
|
3
5
|
module Transaction
|
6
|
+
def self.from_json(json_str)
|
7
|
+
json = MultiJson.load(json_str)
|
8
|
+
Loginator.const_get(json['type'].capitalize).from_hash(json)
|
9
|
+
end
|
10
|
+
|
4
11
|
# Generate a UUID for this transaction.
|
5
12
|
def uuid
|
6
13
|
SecureRandom.uuid
|
data/lib/loginator/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'loginator/transaction'
|
2
|
+
|
3
|
+
RSpec.describe Loginator::Transaction do
|
4
|
+
subject { Loginator.const_get(type).new }
|
5
|
+
|
6
|
+
describe '.from_json' do
|
7
|
+
context 'when passed a request json body' do
|
8
|
+
let(:type) { 'Request' }
|
9
|
+
|
10
|
+
it 'returns a request' do
|
11
|
+
expect(Loginator::Transaction.from_json(subject.to_json)).to be_a_kind_of(Loginator::Request)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when passed a response json body' do
|
16
|
+
let(:type) { 'Response' }
|
17
|
+
|
18
|
+
it 'recognizes a response' do
|
19
|
+
expect(Loginator::Transaction.from_json(subject.to_json)).to be_a_kind_of(Loginator::Response)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
shared_examples_for 'jsonable_struct' do
|
2
2
|
describe '#to_json' do
|
3
3
|
it 'faithfully serializes' do
|
4
|
-
expect(subject.to_json).to eq(
|
4
|
+
expect(subject.to_json).to eq(subject.to_h.merge(type: described_class.type).to_json)
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
8
|
describe '.from_json' do
|
9
9
|
it 'faithfully deserializes' do
|
10
|
-
expect(described_class.from_json(
|
10
|
+
expect(described_class.from_json(subject.to_json)).to eq(subject)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -31,7 +31,7 @@ shared_examples_for 'struct_with_defaults' do
|
|
31
31
|
|
32
32
|
describe '.from_json' do
|
33
33
|
it 'faithfully deserializes' do
|
34
|
-
expect(described_class.from_json(
|
34
|
+
expect(described_class.from_json(subject.to_json)).to eq(subject)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loginator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Greg Poirier
|
@@ -279,6 +279,7 @@ files:
|
|
279
279
|
- spec/integration/lib/loginator/.gitignore
|
280
280
|
- spec/integration/lib/loginator/request_spec.rb
|
281
281
|
- spec/integration/lib/loginator/response_spec.rb
|
282
|
+
- spec/integration/lib/loginator/transaction_spec.rb
|
282
283
|
- spec/resources.rb
|
283
284
|
- spec/resources/.gitignore
|
284
285
|
- spec/spec_helper.rb
|
@@ -316,6 +317,7 @@ test_files:
|
|
316
317
|
- spec/integration/lib/loginator/.gitignore
|
317
318
|
- spec/integration/lib/loginator/request_spec.rb
|
318
319
|
- spec/integration/lib/loginator/response_spec.rb
|
320
|
+
- spec/integration/lib/loginator/transaction_spec.rb
|
319
321
|
- spec/resources.rb
|
320
322
|
- spec/resources/.gitignore
|
321
323
|
- spec/spec_helper.rb
|