usps-imis-api 0.11.38 → 0.11.40
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/usps/imis/api.rb +2 -2
- data/lib/usps/imis/blank_object.rb +4 -2
- data/lib/usps/imis/business_object.rb +12 -8
- data/lib/usps/imis/command_line/options_parser.rb +23 -2
- data/lib/usps/imis/properties.rb +15 -4
- data/lib/usps/imis/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '09b163c4f02496fa2205d3ed3056f2e0e7bf7306b63f2176390a498503ca32d3'
|
|
4
|
+
data.tar.gz: c5e9dd8def7221e9f63f71e277ebbdbd3d6b8f080d93af5a5494b50149b649cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2cf04565727807685ef016b823bdd798ac453ed9510d32b430c4b6e286b9f71d01ee6d2d08d15bcdfc3c55dc8168e42f224c9c2fddec2e9933c4e03ee34e03ed
|
|
7
|
+
data.tar.gz: b0a7eeb21ce375a205b1783f839eba1c02aa2040091319845729d33680e49cb43a373a256e3ac002037222516ef111bf8d08903181458c0e8a5fcc1180b30772
|
data/lib/usps/imis/api.rb
CHANGED
|
@@ -72,7 +72,7 @@ module Usps
|
|
|
72
72
|
#
|
|
73
73
|
# @param id [Integer, String] iMIS ID to select for future requests
|
|
74
74
|
#
|
|
75
|
-
# @return [Integer] iMIS ID
|
|
75
|
+
# @return [Integer, String] iMIS ID
|
|
76
76
|
#
|
|
77
77
|
def imis_id=(id)
|
|
78
78
|
raise Errors::LockedIdError if lock_imis_id
|
|
@@ -181,7 +181,7 @@ module Usps
|
|
|
181
181
|
#
|
|
182
182
|
# If no block is given, this returns the specified +BusinessObject+.
|
|
183
183
|
#
|
|
184
|
-
# @param business_object_name [String] Name of the business object
|
|
184
|
+
# @param business_object_name [String, Symbol] Name of the business object
|
|
185
185
|
# @param ordinal [Integer] Ordinal to build override ID param of the URL (e.g. used for Panels)
|
|
186
186
|
#
|
|
187
187
|
# @return [Usps::Imis::BusinessObject]
|
|
@@ -20,13 +20,15 @@ module Usps
|
|
|
20
20
|
|
|
21
21
|
# Build a blank object for the current iMIS ID
|
|
22
22
|
#
|
|
23
|
-
|
|
23
|
+
# @param hash [Hash] Hash version of props to set (block takes priority)
|
|
24
|
+
#
|
|
25
|
+
def build(hash = {}, &) = header.merge(Properties.build(parent.api.record_id.to_s, @ordinal&.to_s, hash, &))
|
|
24
26
|
|
|
25
27
|
private
|
|
26
28
|
|
|
27
29
|
def identity_type = 'System.Collections.ObjectModel.Collection`1[[System.String, mscorlib]], mscorlib'
|
|
28
30
|
|
|
29
|
-
def
|
|
31
|
+
def header
|
|
30
32
|
{
|
|
31
33
|
'$type' => 'Asi.Soa.Core.DataContracts.GenericEntityData, Asi.Contracts',
|
|
32
34
|
'EntityTypeName' => parent.business_object_name,
|
|
@@ -35,7 +35,7 @@ module Usps
|
|
|
35
35
|
#
|
|
36
36
|
def initialize(api, business_object_name, ordinal: nil)
|
|
37
37
|
@api = api
|
|
38
|
-
@business_object_name = business_object_name
|
|
38
|
+
@business_object_name = business_object_name.to_s
|
|
39
39
|
@ordinal = ordinal
|
|
40
40
|
@logger ||= Imis.logger('BusinessObject')
|
|
41
41
|
end
|
|
@@ -62,7 +62,7 @@ module Usps
|
|
|
62
62
|
#
|
|
63
63
|
# If +fields+ is provided, will return only those field values
|
|
64
64
|
#
|
|
65
|
-
# @param fields [String] Field names to return
|
|
65
|
+
# @param fields [Array<String, Symbol>] Field names to return
|
|
66
66
|
#
|
|
67
67
|
# @return [Usps::Imis::Data, Array<Usps::Imis::Data>] Response data from the API
|
|
68
68
|
#
|
|
@@ -71,23 +71,23 @@ module Usps
|
|
|
71
71
|
|
|
72
72
|
# Get a single named field from a business object for the current member
|
|
73
73
|
#
|
|
74
|
-
# @param field [String] Field name to return
|
|
74
|
+
# @param field [String, Symbol] Field name to return
|
|
75
75
|
#
|
|
76
76
|
# @return Response data field value from the API
|
|
77
77
|
#
|
|
78
|
-
def get_field(field) = raw_object[field]
|
|
78
|
+
def get_field(field) = raw_object[field.to_s]
|
|
79
79
|
alias fetch get_field
|
|
80
80
|
alias [] get_field
|
|
81
81
|
|
|
82
82
|
# Get named fields from a business object for the current member
|
|
83
83
|
#
|
|
84
|
-
# @param names [Array<String>] Field names to return
|
|
84
|
+
# @param names [Array<String, Symbol>] Field names to return
|
|
85
85
|
#
|
|
86
86
|
# @return [Array] Response data from the API
|
|
87
87
|
#
|
|
88
88
|
def get_fields(*fields)
|
|
89
89
|
values = raw_object
|
|
90
|
-
fields.map { values[it] }
|
|
90
|
+
fields.map { values[it.to_s] }
|
|
91
91
|
end
|
|
92
92
|
alias fetch_all get_fields
|
|
93
93
|
|
|
@@ -139,11 +139,13 @@ module Usps
|
|
|
139
139
|
|
|
140
140
|
# Build a blank object for the current iMIS ID
|
|
141
141
|
#
|
|
142
|
-
def blank_object(&) = BlankObject.new(self).build(&)
|
|
142
|
+
def blank_object(hash = {}, &) = BlankObject.new(self).build(hash, &)
|
|
143
143
|
|
|
144
144
|
# Create a business object for the current member, starting with a blank object and building properties
|
|
145
145
|
#
|
|
146
|
-
|
|
146
|
+
# @param hash [Hash] Hash version of props to set (block takes priority)
|
|
147
|
+
#
|
|
148
|
+
def post_from_blank(hash = {}, &) = post(blank_object(hash, &))
|
|
147
149
|
alias create_from_blank post_from_blank
|
|
148
150
|
|
|
149
151
|
# Ruby 3.5 instance variable filter
|
|
@@ -173,6 +175,8 @@ module Usps
|
|
|
173
175
|
def filter_fields(fields)
|
|
174
176
|
block_not_supported!
|
|
175
177
|
|
|
178
|
+
fields = fields.transform_keys(&:to_s)
|
|
179
|
+
|
|
176
180
|
existing = get
|
|
177
181
|
|
|
178
182
|
JSON.parse(JSON.dump(existing)).tap do |updated|
|
|
@@ -113,13 +113,29 @@ module Usps
|
|
|
113
113
|
@options = parse_options.compact
|
|
114
114
|
@arguments = ARGV # Not currently used
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
# Set the default behavior to --help instead of --version
|
|
117
|
+
#
|
|
118
|
+
# Passing any subcommands as arguments will cause this conditional to fail
|
|
119
|
+
#
|
|
120
|
+
# If this is disabled:
|
|
121
|
+
#
|
|
122
|
+
# - The default behavior is to print just the version label to the terminal
|
|
123
|
+
# - CommandLine::Performers#perform! *must* expect a `version:` pattern,
|
|
124
|
+
# and will return a quoted string of the version label
|
|
125
|
+
#
|
|
126
|
+
Optimist.educate if ARGV.empty? && defaults?
|
|
117
127
|
|
|
118
128
|
# :nocov:
|
|
119
129
|
@options[:data] = read_stdin if stdin?
|
|
120
130
|
# :nocov:
|
|
121
131
|
|
|
122
132
|
@options[:data] = JSON.parse(@options[:data]) if @options[:data]
|
|
133
|
+
|
|
134
|
+
# Support shorthand for setting `certificate` param on queries
|
|
135
|
+
return unless @options[:query] && @options[:certificate]
|
|
136
|
+
|
|
137
|
+
@options[:data] ||= {}
|
|
138
|
+
@options[:data]['certificate'] = @options.delete(:certificate)
|
|
123
139
|
end
|
|
124
140
|
|
|
125
141
|
private
|
|
@@ -143,7 +159,12 @@ module Usps
|
|
|
143
159
|
def read_stdin = $stdin.read.chomp
|
|
144
160
|
# :nocov:
|
|
145
161
|
|
|
146
|
-
def defaults?
|
|
162
|
+
def defaults?
|
|
163
|
+
options_with_defaults = OPTIONS.select { |_, data| data[1]&.key?(:default) }
|
|
164
|
+
|
|
165
|
+
options_with_defaults.all? { |option, data| data[1].nil? || options[option] == data[1][:default] } &&
|
|
166
|
+
options.except(*options_with_defaults.keys).values.none?
|
|
167
|
+
end
|
|
147
168
|
end
|
|
148
169
|
end
|
|
149
170
|
end
|
data/lib/usps/imis/properties.rb
CHANGED
|
@@ -9,14 +9,16 @@ module Usps
|
|
|
9
9
|
#
|
|
10
10
|
# @param id [String] iMIS ID to include in the properties before running the block
|
|
11
11
|
# @param ordinal [String] Ordinal to include in the properties before running the block
|
|
12
|
+
# @param hash [Hash] Hash version of props to set (block takes priority)
|
|
12
13
|
#
|
|
13
|
-
def self.build(id = nil, ordinal = nil, &) = new.build(id, ordinal, &)
|
|
14
|
+
def self.build(id = nil, ordinal = nil, hash = {}, &) = new.build(id, ordinal, hash, &)
|
|
14
15
|
|
|
15
16
|
# Wrap value in the API-internal type structure
|
|
16
17
|
#
|
|
17
18
|
def self.wrap(value)
|
|
18
19
|
case value
|
|
19
20
|
when String then value
|
|
21
|
+
when Symbol then value.to_s
|
|
20
22
|
when Time, DateTime then value.strftime('%Y-%m-%dT%H:%I:%S')
|
|
21
23
|
when Integer then { '$type' => 'System.Int32', '$value' => value }
|
|
22
24
|
when true, false then { '$type' => 'System.Boolean', '$value' => value }
|
|
@@ -29,14 +31,18 @@ module Usps
|
|
|
29
31
|
#
|
|
30
32
|
# @param id [String] iMIS ID to include in the properties before running the block
|
|
31
33
|
# @param ordinal [String] Ordinal to include in the properties before running the block
|
|
34
|
+
# @param hash [Hash] Hash version of props to set (block takes priority)
|
|
35
|
+
# @yield Block context to define additional properties with +add+
|
|
32
36
|
#
|
|
33
|
-
def build(id = nil, ordinal = nil)
|
|
37
|
+
def build(id = nil, ordinal = nil, hash = {})
|
|
34
38
|
@properties ||= []
|
|
35
39
|
|
|
36
40
|
add('ID', id) if id
|
|
37
41
|
add('Ordinal', ordinal) if ordinal
|
|
38
42
|
|
|
39
|
-
|
|
43
|
+
hash.each { |key, value| add(key, value) }
|
|
44
|
+
|
|
45
|
+
yield(self) if block_given?
|
|
40
46
|
|
|
41
47
|
{
|
|
42
48
|
'Properties' => {
|
|
@@ -48,10 +54,15 @@ module Usps
|
|
|
48
54
|
|
|
49
55
|
# Add an individual property to the field
|
|
50
56
|
#
|
|
57
|
+
# The last definition for a given property name will be used
|
|
58
|
+
#
|
|
51
59
|
def add(name, value)
|
|
60
|
+
existing = @properties.find { it['Name'] == name.to_s }
|
|
61
|
+
@properties.delete(existing) if existing
|
|
62
|
+
|
|
52
63
|
@properties << {
|
|
53
64
|
'$type' => 'Asi.Soa.Core.DataContracts.GenericPropertyData, Asi.Contracts',
|
|
54
|
-
'Name' => name,
|
|
65
|
+
'Name' => name.to_s,
|
|
55
66
|
'Value' => self.class.wrap(value)
|
|
56
67
|
}
|
|
57
68
|
end
|
data/lib/usps/imis/version.rb
CHANGED