usps-imis-api 0.11.5 → 0.11.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
  SHA256:
3
- metadata.gz: b8e2923d6da2cf2d2fbfd60e2b29e6930efb66148bebd9746521454d64786106
4
- data.tar.gz: d4a8927801796b0a09a7ec2f1f1dd6c702e7785d6fb39d699d4f9f622e2be9d2
3
+ metadata.gz: ae10bc832e8ffa7cb4bc3bb14f5ea0b2d2daef3866cde32cdaea89bfcfe60376
4
+ data.tar.gz: 137943c3dce52c4c56bc32e2b2dcb6329e1bd568bb95c653084b299d701ed39e
5
5
  SHA512:
6
- metadata.gz: 1a69f233aca63d00f441fe6d044ba4206bce8aa309f3eb96ae05f07477585737a044a092dc7234f9d83c505fc14e1c8834dacadc4bfce5560efe4f42ee92ea5e
7
- data.tar.gz: d44e7298e69c825349194ff24338bcf74494b1e641dd6c3c4e2d05e68b530b959cbb435d84ecf39fb8da4b54b2097858c8c8479e5b3aad6491facdb51eca8b4c
6
+ metadata.gz: 9bfc02dddae6d07ee6fedfcc0a89101415d4af68cab2b90380f199957976dd4d128c2913373b38066a4da76d41fbc0a21bca6dab672032e3e6cd03ade2114547
7
+ data.tar.gz: f31225ef3c5f2b24a69220d165c42697f052427b27967525678846c8ddd0280a4177ef4f4b388e70a45c033a7e1dda7f6d16ead1d6c9ce786b552c96c6aefdbd
@@ -64,26 +64,26 @@ module Usps
64
64
 
65
65
  # rubocop:disable Metrics
66
66
  def perform!
67
- case options
68
- in mapper: true, data: then api.mapper.update(data)
69
- in map:, data: then api.mapper[map.to_sym] = data
70
- in map: then api.mapper[map.to_sym]
71
-
72
- in on:, delete: true then api.on(on).delete
73
- in on:, data:, post: true then api.on(on).post(data)
74
- in on:, data:, field: then api.on(on).put_field(field, data)
75
- in on:, data: then api.on(on).put_fields(data)
76
- in on:, fields: then api.on(on).get_fields(*fields)
77
- in on:, field: then api.on(on).get_field(field)
78
- in on: then api.on(on).get
79
-
80
- in panel:, ordinal:, delete: true then api.panels.public_send(panel).delete(ordinal)
81
- in panel:, data:, post: true then api.panels.public_send(panel).post(data)
82
- in panel:, ordinal:, data:, field: then api.panels.public_send(panel).put_field(ordinal, field, data)
83
- in panel:, ordinal:, data: then api.panels.public_send(panel).put_fields(ordinal, data)
84
- in panel:, ordinal:, fields: then api.panels.public_send(panel).get_fields(ordinal, *fields)
85
- in panel:, ordinal:, field: then api.panels.public_send(panel).get_field(ordinal, field)
86
- in panel:, ordinal: then api.panels.public_send(panel).get(ordinal)
67
+ case convert(options)
68
+ in mapper:, field:, data: then mapper.put_field(field.to_sym, data)
69
+ in mapper:, field: then mapper.fetch(field.to_sym)
70
+ in mapper:, data: then mapper.update(data)
71
+
72
+ in on:, delete: true then on.delete
73
+ in on:, post: true, data: then on.post(data)
74
+ in on:, data:, field: then on.put_field(field, data)
75
+ in on:, data: then on.put_fields(data)
76
+ in on:, fields: then on.get_fields(*fields)
77
+ in on:, field: then on.get_field(field)
78
+ in on: then on.get
79
+
80
+ in panel:, delete: true, ordinal: then panel.delete(ordinal)
81
+ in panel:, post: true, data: then panel.post(data)
82
+ in panel:, ordinal:, data:, field: then panel.put_field(ordinal, field, data)
83
+ in panel:, ordinal:, data: then panel.put_fields(ordinal, data)
84
+ in panel:, ordinal:, fields: then panel.get_fields(ordinal, *fields)
85
+ in panel:, ordinal:, field: then panel.get_field(ordinal, field)
86
+ in panel:, ordinal: then panel.get(ordinal)
87
87
 
88
88
  in query:, data: then api.query(query, data)
89
89
  in query: then api.query(query)
@@ -93,12 +93,34 @@ module Usps
93
93
  end
94
94
  # rubocop:enable Metrics
95
95
 
96
+ def convert(options)
97
+ options.dup.tap do |converted|
98
+ case converted
99
+ in map: then converted.merge!(mapper: api.mapper, field: map)
100
+ in mapper: true then converted[:mapper] = api.mapper
101
+ in on: then converted[:on] = api.on(on)
102
+ in panel: then converted[:panel] = api.panels.public_send(panel)
103
+ else
104
+ # Nothing to convert
105
+ end
106
+
107
+ # Remove mapper flag when false
108
+ converted.delete(:mapper) unless converted[:mapper]
109
+ end
110
+ end
111
+
96
112
  def simplify(data)
97
113
  return data.to_a if data.is_a?(Query)
98
114
  return data if options[:raw]
99
- return data unless data.is_a?(Hash) # Includes Usps::Imis::Data
100
115
 
101
- data.properties(include_ids: options[:include_ids])
116
+ # Hash includes Usps::Imis::Data
117
+ if data.is_a?(Hash)
118
+ data.properties(include_ids: options[:include_ids])
119
+ elsif data.is_a?(Array) && data.all? { it.is_a?(Hash) }
120
+ data.map { it.properties(include_ids: options[:include_ids]) }
121
+ else
122
+ data
123
+ end
102
124
  end
103
125
 
104
126
  # :nocov:
@@ -13,25 +13,42 @@ module Usps
13
13
  panel: ['Panel name', { type: :string }],
14
14
  ordinal: ['Ordinal ID within a Panel', { type: :integer }],
15
15
  query: ['IQA Query or Business Object name to query', { type: :string, short: :Q }],
16
+ mapper: ['Interact with mapped fields', { short: :M }],
17
+ map: ["Shorthand for accessing a single mapped field\n Equivalent to #{'-Mf'.green}", { type: :string }],
16
18
  post: ["Send a #{'POST'.cyan} request", { short: :P }],
17
19
  delete: ["Send a #{'DELETE'.cyan} request", { short: :D }],
18
20
  field: ['Specific field to return or update', { type: :string }],
19
21
  fields: ['Specific field(s) to return', { type: :strings, short: :F }],
20
- map: ['Mapped field name to return or update', { type: :string }],
21
- mapper: ['Multiple mapped fields to update together', { short: :M }],
22
- data: ['JSON string input', { type: :string }],
22
+ data: ["JSON string input\n When present, sets the default HTTP verb to #{'PUT'.cyan}", { type: :string }],
23
23
  config: ['Path to the JSON config file to use', { type: :string, short: :C }],
24
24
  raw: ['Return raw JSON output, rather than simplified data', { short: :R }],
25
- include_ids: ['Include ID properties in returned data'],
26
- quiet: ['Suppress logging to STDERR'],
27
- log: ['Redirect logging to STDOUT'],
25
+ include_ids: ["Include #{'iMIS ID'.yellow} and #{'Ordinal'.yellow} properties in returned data, if present"],
26
+ quiet: ["Suppress logging to #{'STDERR'.red}"],
27
+ log: ["Redirect logging to #{'STDOUT'.red}"],
28
28
  log_level: ['Set the logging level', { type: :string, default: 'info', short: :L }]
29
29
  }.freeze
30
30
 
31
31
  CONFLICTING_OPTION_GROUPS = [
32
32
  %i[certificate id],
33
33
  %i[on panel query map],
34
- %i[field fields map query]
34
+ %i[field fields map query],
35
+ %i[raw include_ids],
36
+ %i[quiet log_level],
37
+ %i[quiet log],
38
+
39
+ %i[post delete],
40
+
41
+ %i[post mapper],
42
+ %i[post query],
43
+ %i[post map],
44
+
45
+ %i[delete mapper],
46
+ %i[delete query],
47
+ %i[delete map]
48
+ ].freeze
49
+
50
+ DEPENDENT_OPTION_PAIRS = [
51
+ %i[ordinal panel]
35
52
  ].freeze
36
53
 
37
54
  attr_reader :arguments, :options
@@ -103,6 +120,7 @@ module Usps
103
120
 
104
121
  OPTIONS.each { |option, data| opt(option, *data) }
105
122
  CONFLICTING_OPTION_GROUPS.each { |group| conflicts(*group) }
123
+ DEPENDENT_OPTION_PAIRS.each { |pair| depends(*pair) }
106
124
 
107
125
  educate_on_error
108
126
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.11.5'
5
+ VERSION = '0.11.7'
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.5
4
+ version: 0.11.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander