usps-imis-api 0.6.12 → 0.6.13

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: 03dbc937f5336d48ede502436a3ddcee7d77f8f357d18d807ac4119b52acf7e8
4
- data.tar.gz: 9052ead6d9fb967e5faadb730d7000f32d0e97e83545e60fdef7e9a0b3deda18
3
+ metadata.gz: ce718cab17b65f021cb739faa943d2437f2f4e83f051ad50c37a9ae0cfe48131
4
+ data.tar.gz: 34cece880ed383d43536f915b1c9480fe557587a61d69c9ed32c061932bbfd3a
5
5
  SHA512:
6
- metadata.gz: 33d7ced678ecc240e405b73fe5ba6c006fedece86612f76018296166c53e8226996b27617fb1a7212f885c4a5107c9c03186ad922106ccc79714e6a522127fd9
7
- data.tar.gz: 78b04d51fde868adf81b86231083bdafdb6f08a7f6e7664ba3406b65557be09bb875cc9f1c37846a353872f784cdc872506b27415150ad1b5f79363b5baf29aa
6
+ metadata.gz: a05b5e0bc67ac874b306e688decd19d61c28d4a734165817395f2194a5ac2e166c5e75bcfc900488036f83941c81b4fd0c840810a261813d8b2ae343d5597608
7
+ data.tar.gz: aa402f52a26d2eb0d44928d9461707bc671d6ebf4f3e85325407762d2529b09668b02c2970f58528ad125d1e36c87718439817307f676b0858d764ac358cc7df
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- usps-imis-api (0.6.12)
4
+ usps-imis-api (0.6.13)
5
5
  activesupport (~> 8.0)
6
6
 
7
7
  GEM
data/lib/usps/imis/api.rb CHANGED
@@ -135,10 +135,10 @@ module Usps
135
135
  # An instance of +BusinessObject+, using this instance as its parent +Api+
136
136
  #
137
137
  # @param business_object_name [String] Name of the business object
138
- # @param url_id [String] Override the ID param of the URL (e.g. used for Panels)
138
+ # @param ordinal [Integer] Ordinal to build override ID param of the URL (e.g. used for Panels)
139
139
  #
140
- def business_object(business_object_name, url_id: nil)
141
- BusinessObject.new(self, business_object_name, url_id:)
140
+ def business_object(business_object_name, ordinal: nil)
141
+ BusinessObject.new(self, business_object_name, ordinal:)
142
142
  end
143
143
 
144
144
  # Run requests as DSL, with specific +BusinessObject+ only maintained for this scope
@@ -146,15 +146,13 @@ module Usps
146
146
  # If no block is given, this returns the specified +BusinessObject+.
147
147
  #
148
148
  # @param business_object_name [String] Name of the business object
149
- # @param url_id [String] Override the ID param of the URL (e.g. used for Panels)
149
+ # @param ordinal [Integer] Ordinal to build override ID param of the URL (e.g. used for Panels)
150
150
  #
151
- def on(business_object_name, url_id: nil, &)
152
- object = business_object(business_object_name, url_id:)
151
+ def on(business_object_name, ordinal: nil, &)
152
+ object = business_object(business_object_name, ordinal:)
153
153
  return object unless block_given?
154
154
 
155
- result = nil
156
- object.tap { |obj| result = obj.instance_eval(&) }
157
- result
155
+ object.instance_eval(&)
158
156
  end
159
157
 
160
158
  # An instance of +Mapper+, using this instance as its parent +Api+
@@ -18,16 +18,16 @@ module Usps
18
18
  #
19
19
  attr_reader :business_object_name
20
20
 
21
- # Override ID param of the URL (e.g. used for Panels)
21
+ # Ordinal to build override ID param of the URL (e.g. used for Panels)
22
22
  #
23
- attr_reader :url_id
23
+ attr_reader :ordinal
24
24
 
25
25
  # A new instance of +BusinessObject+
26
26
  #
27
- def initialize(api, business_object_name, url_id: nil)
27
+ def initialize(api, business_object_name, ordinal: nil)
28
28
  @api = api
29
29
  @business_object_name = business_object_name
30
- @url_id = url_id
30
+ @ordinal = ordinal
31
31
  end
32
32
 
33
33
  # Get a business object for the current member
@@ -84,7 +84,7 @@ module Usps
84
84
  # @return [Hash] Response data from the API
85
85
  #
86
86
  def post(body)
87
- request = Net::HTTP::Post.new(uri)
87
+ request = Net::HTTP::Post.new(uri(id: ''))
88
88
  request.body = JSON.dump(body)
89
89
  result = submit(uri, authorize(request))
90
90
  JSON.parse(result.body)
@@ -107,12 +107,20 @@ module Usps
107
107
 
108
108
  # Construct a business object API endpoint address
109
109
  #
110
- def uri
111
- id_for_url = url_id ? CGI.escape(url_id) : api.imis_id
112
- full_path = "#{API_PATH}/#{business_object_name}/#{id_for_url}"
110
+ def uri(id: nil)
111
+ full_path = "#{API_PATH}/#{business_object_name}/#{id_for_uri(id)}"
113
112
  URI(File.join(Imis.configuration.hostname, full_path))
114
113
  end
115
114
 
115
+ # Select the correct ID to use in the URI
116
+ #
117
+ def id_for_uri(id = nil)
118
+ return CGI.escape(id) unless id.nil?
119
+ return CGI.escape("~#{api.imis_id}|#{ordinal}") if ordinal
120
+
121
+ api.imis_id
122
+ end
123
+
116
124
  # Manually assemble the matching data structure, with fields in the correct order
117
125
  #
118
126
  def filter_fields(fields)
@@ -20,7 +20,7 @@ module Usps
20
20
  # @param ordinal [Integer] The ordinal identifier for the desired object
21
21
  #
22
22
  def get(ordinal)
23
- api.business_object(business_object, url_id: "~#{api.imis_id}|#{ordinal}").get
23
+ api.on(business_object, ordinal:).get
24
24
  end
25
25
 
26
26
  # Create a new object in the Panel
@@ -28,7 +28,7 @@ module Usps
28
28
  # @param data [Hash] The record data for the desired object
29
29
  #
30
30
  def create(data)
31
- api.business_object(business_object, url_id: '').post(payload(data))
31
+ api.on(business_object).post(payload(data))
32
32
  end
33
33
 
34
34
  # Update an existing object in the Panel
@@ -37,9 +37,7 @@ module Usps
37
37
  # +ordinal+ identifier
38
38
  #
39
39
  def update(data)
40
- api
41
- .business_object(business_object, url_id: "~#{api.imis_id}|#{data[:ordinal]}")
42
- .put(payload(data))
40
+ api.on(business_object, ordinal: data[:ordinal]).put(payload(data))
43
41
  end
44
42
 
45
43
  # Remove a specific object from the Panel
@@ -47,7 +45,7 @@ module Usps
47
45
  # @param ordinal [Integer] The ordinal identifier for the desired object
48
46
  #
49
47
  def destroy(ordinal)
50
- api.business_object(business_object, url_id: "~#{api.imis_id}|#{ordinal}").delete
48
+ api.on(business_object, ordinal:).delete
51
49
  end
52
50
 
53
51
  private
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Usps
4
4
  module Imis
5
- VERSION = '0.6.12'
5
+ VERSION = '0.6.13'
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.6.12
4
+ version: 0.6.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander