usps-imis-api 0.6.8 → 0.6.10
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/Gemfile.lock +1 -1
- data/lib/usps/imis/mock.rb +23 -0
- data/lib/usps/imis/properties.rb +50 -0
- data/lib/usps/imis/version.rb +1 -1
- data/lib/usps/imis.rb +2 -1
- data/spec/lib/usps/imis/mock_spec.rb +28 -0
- data/spec/lib/usps/imis/{panel/properties_spec.rb → properties_spec.rb} +1 -1
- metadata +5 -3
- data/lib/usps/imis/panel/properties.rb +0 -52
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5103e3c7de24d79be7d86bfd21883d572d5cc88f6c58509973ab2bcce3d99202
|
|
4
|
+
data.tar.gz: 1e96b2dbf536e4205f2fb721ddba91cd2640af1893c30db3d911fea6824b6ea9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 53fa63489cda9a6dd09401605daf22329cad3a6f2f3313b068eb3ecd339d9ceff518134305601a2591451acdd03723f566096cb2bcc754c90da03d79d32de315
|
|
7
|
+
data.tar.gz: df0052735b664cc91e4d4b923b1c7ecffe065acc44d320624cc84e834607f557df7c3c39b04cc95410642de07df665da56700c9d543be3cb0f15e1644bf12f15
|
data/Gemfile.lock
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Usps
|
|
4
|
+
module Imis
|
|
5
|
+
# Mock data response for testing
|
|
6
|
+
#
|
|
7
|
+
class Mock
|
|
8
|
+
attr_reader :fields
|
|
9
|
+
|
|
10
|
+
def initialize(**fields)
|
|
11
|
+
@fields = fields.transform_keys(&:to_s)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def get_field(name) = fields[name]
|
|
15
|
+
|
|
16
|
+
def get
|
|
17
|
+
Usps::Imis::Properties.build do |props|
|
|
18
|
+
fields.each { |name, value| props.add(name, value) }
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Usps
|
|
4
|
+
module Imis
|
|
5
|
+
# Constructor for the Properties field
|
|
6
|
+
#
|
|
7
|
+
class Properties
|
|
8
|
+
# Build the data for a new Properties field
|
|
9
|
+
#
|
|
10
|
+
def self.build(&) = new.build(&)
|
|
11
|
+
|
|
12
|
+
# Build the data for the Properties field
|
|
13
|
+
#
|
|
14
|
+
def build
|
|
15
|
+
yield(self)
|
|
16
|
+
|
|
17
|
+
{
|
|
18
|
+
'Properties' => {
|
|
19
|
+
'$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts',
|
|
20
|
+
'$values' => @properties
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Add an individual property to the field
|
|
26
|
+
#
|
|
27
|
+
def add(name, value)
|
|
28
|
+
@properties ||= []
|
|
29
|
+
@properties << {
|
|
30
|
+
'$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
|
|
31
|
+
'Name' => name,
|
|
32
|
+
'Value' => wrap(value)
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def wrap(value)
|
|
39
|
+
case value
|
|
40
|
+
when String then value
|
|
41
|
+
when Time, DateTime then value.strftime('%Y-%m-%dT%H:%I:%S')
|
|
42
|
+
when Integer then { '$type' => 'System.Int32', '$value' => value }
|
|
43
|
+
when true, false then { '$type' => 'System.Boolean', '$value' => value }
|
|
44
|
+
else
|
|
45
|
+
raise Error::ApiError, "Unexpected property type: #{value.inspect}"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
data/lib/usps/imis/version.rb
CHANGED
data/lib/usps/imis.rb
CHANGED
|
@@ -22,8 +22,9 @@ require_relative 'imis/requests'
|
|
|
22
22
|
require_relative 'imis/business_object'
|
|
23
23
|
require_relative 'imis/api'
|
|
24
24
|
require_relative 'imis/mapper'
|
|
25
|
+
require_relative 'imis/properties'
|
|
26
|
+
require_relative 'imis/mock'
|
|
25
27
|
require_relative 'imis/panel/base_panel'
|
|
26
|
-
require_relative 'imis/panel/properties'
|
|
27
28
|
require_relative 'imis/panel/vsc'
|
|
28
29
|
require_relative 'imis/panel/education'
|
|
29
30
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
describe Usps::Imis::Mock do
|
|
6
|
+
let(:mock) { described_class.new(**fields) }
|
|
7
|
+
let(:fields) { { TotMMS: 2 } }
|
|
8
|
+
|
|
9
|
+
describe 'get' do
|
|
10
|
+
it 'returns the correct Properties data' do
|
|
11
|
+
expect(mock.get).to eq(
|
|
12
|
+
'Properties' => {
|
|
13
|
+
'$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts',
|
|
14
|
+
'$values' => [
|
|
15
|
+
{
|
|
16
|
+
'$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
|
|
17
|
+
'Name' => 'TotMMS',
|
|
18
|
+
'Value' => {
|
|
19
|
+
'$type' => 'System.Int32',
|
|
20
|
+
'$value' => 2
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: usps-imis-api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Julian Fiander
|
|
@@ -50,10 +50,11 @@ files:
|
|
|
50
50
|
- lib/usps/imis/error/mapper_error.rb
|
|
51
51
|
- lib/usps/imis/error/response_error.rb
|
|
52
52
|
- lib/usps/imis/mapper.rb
|
|
53
|
+
- lib/usps/imis/mock.rb
|
|
53
54
|
- lib/usps/imis/panel/base_panel.rb
|
|
54
55
|
- lib/usps/imis/panel/education.rb
|
|
55
|
-
- lib/usps/imis/panel/properties.rb
|
|
56
56
|
- lib/usps/imis/panel/vsc.rb
|
|
57
|
+
- lib/usps/imis/properties.rb
|
|
57
58
|
- lib/usps/imis/requests.rb
|
|
58
59
|
- lib/usps/imis/version.rb
|
|
59
60
|
- spec/lib/usps/imis/api_spec.rb
|
|
@@ -62,10 +63,11 @@ files:
|
|
|
62
63
|
- spec/lib/usps/imis/error/api_error_spec.rb
|
|
63
64
|
- spec/lib/usps/imis/error/response_error_spec.rb
|
|
64
65
|
- spec/lib/usps/imis/mapper_spec.rb
|
|
66
|
+
- spec/lib/usps/imis/mock_spec.rb
|
|
65
67
|
- spec/lib/usps/imis/panel/base_panel_spec.rb
|
|
66
68
|
- spec/lib/usps/imis/panel/education_spec.rb
|
|
67
|
-
- spec/lib/usps/imis/panel/properties_spec.rb
|
|
68
69
|
- spec/lib/usps/imis/panel/vsc_spec.rb
|
|
70
|
+
- spec/lib/usps/imis/properties_spec.rb
|
|
69
71
|
- spec/lib/usps/imis_spec.rb
|
|
70
72
|
- spec/spec_helper.rb
|
|
71
73
|
- usps-imis-api.gemspec
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Usps
|
|
4
|
-
module Imis
|
|
5
|
-
module Panel
|
|
6
|
-
# Constructor for the Properties field for Panel requests
|
|
7
|
-
#
|
|
8
|
-
class Properties
|
|
9
|
-
# Build the data for a new Properties field
|
|
10
|
-
#
|
|
11
|
-
def self.build(&) = new.build(&)
|
|
12
|
-
|
|
13
|
-
# Build the data for the Properties field
|
|
14
|
-
#
|
|
15
|
-
def build
|
|
16
|
-
yield(self)
|
|
17
|
-
|
|
18
|
-
{
|
|
19
|
-
'Properties' => {
|
|
20
|
-
'$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyDataCollection, Asi.Contracts',
|
|
21
|
-
'$values' => @properties
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# Add an individual property to the field
|
|
27
|
-
#
|
|
28
|
-
def add(name, value)
|
|
29
|
-
@properties ||= []
|
|
30
|
-
@properties << {
|
|
31
|
-
'$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
|
|
32
|
-
'Name' => name,
|
|
33
|
-
'Value' => wrap(value)
|
|
34
|
-
}
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
private
|
|
38
|
-
|
|
39
|
-
def wrap(value)
|
|
40
|
-
case value
|
|
41
|
-
when String then value
|
|
42
|
-
when Time, DateTime then value.strftime('%Y-%m-%dT%H:%I:%S')
|
|
43
|
-
when Integer then { '$type' => 'System.Int32', '$value' => value }
|
|
44
|
-
when true, false then { '$type' => 'System.Boolean', '$value' => value }
|
|
45
|
-
else
|
|
46
|
-
raise Error::ApiError, "Unexpected property type: #{value.inspect}"
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|