usps-imis-api 0.11.39 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 490015ad8f86bea9afbc0eb9065a6b5e92432bc7c3bca8ec7faa2a6e61c2bd24
4
- data.tar.gz: 5376fcdd8ea7e4a3e31832ecc8b399b51949d39449f0be5a1d74ca24b8452b26
3
+ metadata.gz: '09b163c4f02496fa2205d3ed3056f2e0e7bf7306b63f2176390a498503ca32d3'
4
+ data.tar.gz: c5e9dd8def7221e9f63f71e277ebbdbd3d6b8f080d93af5a5494b50149b649cd
5
5
  SHA512:
6
- metadata.gz: 7cfc0becb2b9969998b472970bd07ca0ebdd8427d64bf74e17adf8aa7be59e11c1db21d77d853b567a8397f61f7fa816a7977f0c0873b7269d9ac755e4cf179c
7
- data.tar.gz: a26a68da79680d9b2f095d42caafee5b2a62bfd5ac9c01b278f367a7a996248dff7ff173f5498da46231e2e66cf7a8c8b26b45dc5471149e0e0e14a406bd1b54
6
+ metadata.gz: 2cf04565727807685ef016b823bdd798ac453ed9510d32b430c4b6e286b9f71d01ee6d2d08d15bcdfc3c55dc8168e42f224c9c2fddec2e9933c4e03ee34e03ed
7
+ data.tar.gz: b0a7eeb21ce375a205b1783f839eba1c02aa2040091319845729d33680e49cb43a373a256e3ac002037222516ef111bf8d08903181458c0e8a5fcc1180b30772
data/lib/usps/imis/api.rb CHANGED
@@ -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
- def build(&) = payload_header.merge(Properties.build(parent.api.record_id.to_s, @ordinal&.to_s, &))
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 payload_header
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
- def post_from_blank(&) = post(blank_object(&))
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|
@@ -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
- yield(self)
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.11.39'
5
+ VERSION = '0.11.40'
6
6
  end
7
7
  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.11.39
4
+ version: 0.11.40
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander