Class: EVSS::PCIU::RequestBody
- Inherits:
-
Object
- Object
- EVSS::PCIU::RequestBody
- Defined in:
- lib/evss/pciu/request_body.rb
Instance Attribute Summary collapse
-
#date_attr ⇒ Object
readonly
Returns the value of attribute date_attr.
-
#pciu_key ⇒ Object
readonly
Returns the value of attribute pciu_key.
-
#request_attrs ⇒ Object
readonly
Returns the value of attribute request_attrs.
Instance Method Summary collapse
- #convert_to_json ⇒ Object private
-
#initialize(request_attrs, pciu_key:, date_attr: 'effective_date') ⇒ RequestBody
constructor
A new instance of RequestBody.
- #remove_empty_attrs ⇒ Object private
-
#set ⇒ String
Adjusts the passed request attributes to be formatted for an EVSS POST or PUT request body.
- #set_effective_date ⇒ Object private
Constructor Details
#initialize(request_attrs, pciu_key:, date_attr: 'effective_date') ⇒ RequestBody
Returns a new instance of RequestBody.
8 9 10 11 12 |
# File 'lib/evss/pciu/request_body.rb', line 8 def initialize(request_attrs, pciu_key:, date_attr: 'effective_date') @request_attrs = request_attrs @pciu_key = pciu_key @date_attr = date_attr end |
Instance Attribute Details
#date_attr ⇒ Object (readonly)
Returns the value of attribute date_attr.
6 7 8 |
# File 'lib/evss/pciu/request_body.rb', line 6 def date_attr @date_attr end |
#pciu_key ⇒ Object (readonly)
Returns the value of attribute pciu_key.
6 7 8 |
# File 'lib/evss/pciu/request_body.rb', line 6 def pciu_key @pciu_key end |
#request_attrs ⇒ Object (readonly)
Returns the value of attribute request_attrs.
6 7 8 |
# File 'lib/evss/pciu/request_body.rb', line 6 def request_attrs @request_attrs end |
Instance Method Details
#convert_to_json ⇒ Object (private)
44 45 46 47 48 49 50 |
# File 'lib/evss/pciu/request_body.rb', line 44 def convert_to_json { pciu_key => request_attrs.as_json.transform_keys { |k| k.camelize(:lower) } }.to_json end |
#remove_empty_attrs ⇒ Object (private)
40 41 42 |
# File 'lib/evss/pciu/request_body.rb', line 40 def remove_empty_attrs @request_attrs = request_attrs.as_json.delete_if { |_k, v| v.blank? } end |
#set ⇒ String
Adjusts the passed request attributes to be formatted for an EVSS POST or PUT request body.
28 29 30 31 32 |
# File 'lib/evss/pciu/request_body.rb', line 28 def set set_effective_date remove_empty_attrs convert_to_json end |
#set_effective_date ⇒ Object (private)
36 37 38 |
# File 'lib/evss/pciu/request_body.rb', line 36 def set_effective_date request_attrs.tap { |instance| instance[date_attr] = DateTime.now.utc } end |