Class: JxClient::OperationBase
- Inherits:
-
Object
- Object
- JxClient::OperationBase
- Defined in:
- lib/jx_client/operation_base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#sent_options ⇒ Object
readonly
Returns the value of attribute sent_options.
Instance Method Summary collapse
-
#call ⇒ Object
call operation.
-
#initialize(operation_name:, client:, default_options: {}, operation_default_options: {}, message_id_generate: false, timestamp_generate: false) ⇒ OperationBase
constructor
A new instance of OperationBase.
-
#locals(options) ⇒ Hash
Locals for savon call.
-
#merge_options(options) ⇒ Object
merge options, default options and operation specific default options.
-
#new_message_id ⇒ String
New message id.
- #new_timestamp ⇒ Object
- #options(options) ⇒ self
-
#sent_locals ⇒ Hash
Sent locals for savon call.
-
#with_generated(options) ⇒ Hash
Options with :message_id.
-
#wrap_response(response) ⇒ Object
wraps response.
Constructor Details
#initialize(operation_name:, client:, default_options: {}, operation_default_options: {}, message_id_generate: false, timestamp_generate: false) ⇒ OperationBase
Returns a new instance of OperationBase.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jx_client/operation_base.rb', line 13 def initialize( operation_name:, client:, default_options: {}, operation_default_options: {}, message_id_generate: false, timestamp_generate: false ) @operation_name = operation_name @client = client @default_options = @operation_default_options = @message_id_generate = == true ? -> { SecureRandom.uuid } : @timestamp_generate = == true ? -> { Time.now.utc.iso8601 } : end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
5 6 7 |
# File 'lib/jx_client/operation_base.rb', line 5 def response @response end |
#sent_options ⇒ Object (readonly)
Returns the value of attribute sent_options.
5 6 7 |
# File 'lib/jx_client/operation_base.rb', line 5 def @sent_options end |
Instance Method Details
#call ⇒ Object
call operation
42 43 44 45 |
# File 'lib/jx_client/operation_base.rb', line 42 def call @response = wrap_response(@client.call(@operation_name, sent_locals)) self end |
#locals(options) ⇒ Hash
Returns locals for savon call.
54 55 56 |
# File 'lib/jx_client/operation_base.rb', line 54 def locals() raise NotImplementedError end |
#merge_options(options) ⇒ Object
merge options, default options and operation specific default options
48 49 50 |
# File 'lib/jx_client/operation_base.rb', line 48 def () with_generated(@default_options.merge(@operation_default_options, )) end |
#new_message_id ⇒ String
Returns new message id.
67 68 69 70 |
# File 'lib/jx_client/operation_base.rb', line 67 def raise "message_id must be included because message ID generation is disabled." unless @message_id_generate @message_id_generate.call end |
#new_timestamp ⇒ Object
72 73 74 75 |
# File 'lib/jx_client/operation_base.rb', line 72 def raise "timestamp must be included because timestamp generation is disabled." unless @timestamp_generate @timestamp_generate.call end |
#options(options) ⇒ self
36 37 38 39 |
# File 'lib/jx_client/operation_base.rb', line 36 def () @sent_options = () self end |
#sent_locals ⇒ Hash
Returns sent locals for savon call.
30 31 32 |
# File 'lib/jx_client/operation_base.rb', line 30 def sent_locals locals(@sent_options) end |
#with_generated(options) ⇒ Hash
Returns options with :message_id.
60 61 62 63 64 |
# File 'lib/jx_client/operation_base.rb', line 60 def with_generated() [:message_id] ||= [:timestamp] ||= end |
#wrap_response(response) ⇒ Object
wraps response
78 79 80 |
# File 'lib/jx_client/operation_base.rb', line 78 def wrap_response(response) response end |