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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e096d117d2fc6ad0d615b29e0c99a28f74e58835
4
- data.tar.gz: faab9d2862bdf8a389628ed91978d63be0d25f2c
3
+ metadata.gz: 16cb733ff2fbe83f63150fd5abe6027c578a6054
4
+ data.tar.gz: c8ef72fffaae51fe5cd15476216440b23e1f8afa
5
5
  SHA512:
6
- metadata.gz: daec5f46f2cbc7096182e1316058c1356578bb28080f05a6b526e72dbecd071ed99ff7d4078259237be029b787f952cc40f1be94307f95f2192b3ed75cdd597c
7
- data.tar.gz: 271a9200bdf43ba6cfb1c06514f159df266d9474049fd4ac71d3ba6f0ba788de962ca344c274e64ed2102810c9fdf0f0606614da87432120433022c544c191a9
6
+ metadata.gz: 5d5773959c66a369cffe7dea5117d2b599e73b6131f3dfea049c815e74ac5c64278754efd132b17f75dbab839f06285a24e484cf607ed5998f1a28b9c860e847
7
+ data.tar.gz: ef38af19158edaec1a56c4bcbafee62303a81e0e2298d0eb288b30748a13cd4f8d74be5327f498c3c56cbc5caff4f1d62ecc457bc75b58d6fea641e36ae7b499
data/lib/loginator.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'loginator/version'
2
2
  require 'loginator/request'
3
3
  require 'loginator/response'
4
+ require 'loginator/transaction'
4
5
 
5
6
  # Loginator
6
7
  module Loginator
@@ -11,11 +11,16 @@ module Loginator
11
11
 
12
12
  # class level mixins
13
13
  module ClassMethods #:nodoc
14
- def from_json(json)
15
- json_type = json.delete('type')
16
- fail(ArgumentError, format('Incorrect message type: %s', json_type)) unless json_type == type
17
- fail(ArgumentError, format('Hash must contain keys: %s', members.join(', '))) unless valid_hash?(json)
18
- new(*json.values)
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
@@ -1,4 +1,4 @@
1
1
  # Increment when releasing.
2
2
  module Loginator
3
- VERSION = '0.0.6'
3
+ VERSION = '0.0.7'
4
4
  end
@@ -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(MultiJson.dump(subject.to_h.merge(type: described_class.type)))
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(MultiJson.load(subject.to_json))).to eq(subject)
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(MultiJson.load(subject.to_json))).to eq(subject)
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.6
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