usps-imis-api 0.11.7 → 0.11.9

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: ae10bc832e8ffa7cb4bc3bb14f5ea0b2d2daef3866cde32cdaea89bfcfe60376
4
- data.tar.gz: 137943c3dce52c4c56bc32e2b2dcb6329e1bd568bb95c653084b299d701ed39e
3
+ metadata.gz: 626c55f443b00f5c4bcf5fe4e266041157fc0bf961825f42a551e6473f8decc0
4
+ data.tar.gz: b7e430d604ff0f1ae3db77e8cad1a2cb41851fe0ed3e0d8c90c19782b0e5708d
5
5
  SHA512:
6
- metadata.gz: 9bfc02dddae6d07ee6fedfcc0a89101415d4af68cab2b90380f199957976dd4d128c2913373b38066a4da76d41fbc0a21bca6dab672032e3e6cd03ade2114547
7
- data.tar.gz: f31225ef3c5f2b24a69220d165c42697f052427b27967525678846c8ddd0280a4177ef4f4b388e70a45c033a7e1dda7f6d16ead1d6c9ce786b552c96c6aefdbd
6
+ metadata.gz: e8c1ec5ef4528680e87878225df3abda47e9892913d250eba1a8495ccde36a9801a78170a3bc211fad0714ac61d6696ba8d4cbe025888fa3a25a307d45a6e595
7
+ data.tar.gz: 98a8d1c2d38de72f9604b28070ca65144979d271ddacd077a2ce548ca7d8eef0a4fb15ad9d81acde7a63a0e1918ce7f8c354f4dbc6bb83d078a01a290aef9f48
@@ -66,7 +66,8 @@ module Usps
66
66
  def perform!
67
67
  case convert(options)
68
68
  in mapper:, field:, data: then mapper.put_field(field.to_sym, data)
69
- in mapper:, field: then mapper.fetch(field.to_sym)
69
+ in mapper:, fields: then mapper.get_fields(*fields)
70
+ in mapper:, field: then mapper.get_field(field.to_sym)
70
71
  in mapper:, data: then mapper.update(data)
71
72
 
72
73
  in on:, delete: true then on.delete
@@ -131,11 +132,13 @@ module Usps
131
132
  end
132
133
  # :nocov:
133
134
 
135
+ # Supports YAML or JSON config data
136
+ #
134
137
  def configure!
135
- json_config = JSON.parse(File.read(options[:config]))
138
+ config_data = YAML.safe_load_file(options[:config])
136
139
 
137
140
  Usps::Imis.configure do |config|
138
- json_config.each do |key, value|
141
+ config_data.each do |key, value|
139
142
  config.public_send("#{key}=", value)
140
143
  end
141
144
  end
@@ -20,7 +20,7 @@ module Usps
20
20
  field: ['Specific field to return or update', { type: :string }],
21
21
  fields: ['Specific field(s) to return', { type: :strings, short: :F }],
22
22
  data: ["JSON string input\n When present, sets the default HTTP verb to #{'PUT'.cyan}", { type: :string }],
23
- config: ['Path to the JSON config file to use', { type: :string, short: :C }],
23
+ config: ['Path to the JSON/YAML config file to use', { type: :string, short: :C }],
24
24
  raw: ['Return raw JSON output, rather than simplified data', { short: :R }],
25
25
  include_ids: ["Include #{'iMIS ID'.yellow} and #{'Ordinal'.yellow} properties in returned data, if present"],
26
26
  quiet: ["Suppress logging to #{'STDERR'.red}"],
@@ -73,25 +73,9 @@ module Usps
73
73
 
74
74
  #{'Configuration'.underline}
75
75
 
76
- API configuration can be specified in two ways:
76
+ For an explanation of how to provide API configuration, please refer to the wiki:
77
77
 
78
-
79
- With #{'--config'.green}/#{'-C'.green} given the path to a JSON file, e.g.:
80
-
81
- {
82
- "imis_id_query_name": "#{'$/IQA_QUERY_NAME'.yellow}",
83
- "environment": "#{'development'.yellow}",
84
- "username": "#{'USERNAME'.yellow}",
85
- "password": "#{'PASSWORD'.yellow}"
86
- }
87
-
88
-
89
- By setting the following environment variables:
90
-
91
- #{'IMIS_ID_QUERY_NAME'.yellow}
92
- #{'IMIS_ENVIRONMENT'.yellow}
93
- #{'IMIS_USERNAME'.yellow}
94
- #{'IMIS_PASSWORD'.yellow}
78
+ https://github.com/unitedstatespowersquadrons/imis-api-ruby/wiki/Usage#command-line-interface
95
79
 
96
80
 
97
81
  #{'Options'.underline}
@@ -38,13 +38,36 @@ module Usps
38
38
  #
39
39
  # @return Value of the field
40
40
  #
41
- def fetch(field_key)
41
+ def get_field(field_key)
42
42
  missing_mapping!(field_key) unless FIELD_MAPPING.key?(field_key.to_sym)
43
43
 
44
44
  business_object_name, field = FIELD_MAPPING[field_key]
45
45
  api.on(business_object_name)[field]
46
46
  end
47
- alias [] fetch
47
+ alias fetch get_field
48
+ alias [] get_field
49
+
50
+ # Get specific fields by arbitrary field names
51
+ #
52
+ # @param names [Array<String>] Internal name of the fields
53
+ #
54
+ # @return [Array] Values of the field
55
+ #
56
+ def get_fields(*fields)
57
+ business_objects = {}
58
+
59
+ fields.map do |field_key|
60
+ business_object_name, field = FIELD_MAPPING[field_key.to_sym]
61
+
62
+ business_objects[business_object_name] ||= []
63
+ business_objects[business_object_name] << field
64
+ end
65
+
66
+ business_objects.flat_map do |business_object_name, fields|
67
+ api.on(business_object_name).get_fields(*fields)
68
+ end
69
+ end
70
+ alias fetch_all get_fields
48
71
 
49
72
  # Update a member's data for a specific field by arbitrary field name
50
73
  #
@@ -52,7 +52,6 @@ module Usps
52
52
  @api = api
53
53
  @query_name = query_name
54
54
  @query_params = query_params
55
- @query_params.merge!(QueryName: query_name) if iqa?
56
55
  @page_size = page_size
57
56
  @offset = offset
58
57
  @count = 0
@@ -137,10 +136,16 @@ module Usps
137
136
  def iqa? = query_name.match?(/^\$/)
138
137
  def query_type = iqa? ? :IQA : :'Business Object'
139
138
  def path_params = query_params.merge({ Offset: offset, Limit: page_size }.compact)
140
- def endpoint = iqa? ? IQA_PATH : "#{Imis::BusinessObject::API_PATH}/#{query_name}"
141
- def path = "#{endpoint}?#{path_params.to_query}"
142
139
  def uri = URI(File.join(Imis.configuration.hostname, path))
143
140
 
141
+ def path
142
+ if iqa?
143
+ "#{IQA_PATH}?#{path_params.merge(QueryName: query_name).to_query}"
144
+ else
145
+ "#{Imis::BusinessObject::API_PATH}/#{query_name}?#{path_params.to_query}"
146
+ end
147
+ end
148
+
144
149
  def logger = Imis.logger("#{query_type} Query")
145
150
  end
146
151
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.11.7'
5
+ VERSION = '0.11.9'
6
6
  end
7
7
  end
data/lib/usps/imis.rb CHANGED
@@ -4,6 +4,7 @@
4
4
  # Core dependencies
5
5
  require 'net/https'
6
6
  require 'json'
7
+ require 'yaml'
7
8
  require 'time'
8
9
  require 'cgi'
9
10
 
@@ -15,6 +16,8 @@ require 'logger'
15
16
  require 'active_support/isolated_execution_state' # Fix costant loading issue with TaggedLogging
16
17
  require 'active_support/tagged_logging'
17
18
 
19
+ require 'dotenv/load'
20
+
18
21
  # Internal requires
19
22
  require_relative 'imis/config'
20
23
  require_relative 'imis/error'
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.7
4
+ version: 0.11.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
@@ -23,6 +23,20 @@ dependencies:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
25
  version: '8.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: dotenv
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 3.1.4
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 3.1.4
26
40
  - !ruby/object:Gem::Dependency
27
41
  name: colorize
28
42
  requirement: !ruby/object:Gem::Requirement