Class: Curbala::Action
- Inherits:
-
Object
- Object
- Curbala::Action
- Defined in:
- lib/curbala/action.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#args_hash ⇒ Object
Returns the value of attribute args_hash.
-
#config ⇒ Object
Returns the value of attribute config.
-
#curl ⇒ Object
Returns the value of attribute curl.
-
#exception ⇒ Object
Returns the value of attribute exception.
-
#http_status ⇒ Object
Returns the value of attribute http_status.
-
#message ⇒ Object
Returns the value of attribute message.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#raw_response_string ⇒ Object
Returns the value of attribute raw_response_string.
-
#response ⇒ Object
Returns the value of attribute response.
-
#success ⇒ Object
Returns the value of attribute success.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #hash_from_json_response ⇒ Object
-
#hash_from_xml_response ⇒ Object
response utilities:.
-
#initialize(service_url_segment, input_config, input_args_hash, logger, simulated_status = 200, simulated_response = "simulated response") ⇒ Action
constructor
A new instance of Action.
- #xml_payload(xml) ⇒ Object
-
#xml_payload_from_args_hash(root) ⇒ Object
APIs have different formatting/hygiene needs…
-
#xml_request ⇒ Object
request utilities:.
Constructor Details
#initialize(service_url_segment, input_config, input_args_hash, logger, simulated_status = 200, simulated_response = "simulated response") ⇒ Action
Returns a new instance of Action.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/curbala/action.rb', line 8 def initialize(service_url_segment, input_config, input_args_hash, logger, simulated_status=200, simulated_response="simulated response") begin @payload, @args_hash, @config = '', input_args_hash, input_config @url = "#{@config['url']}#{service_url_segment}#{action_url_segment}" @config['simulate'] == true ? inject_status_and_response(simulated_status, simulated_response) : invoke_curl_action rescue Exception => @exception @success = false @message = "Service Not Available: #{@exception.}" # : BACKTRACE: #{@exception.backtrace[0..500]}" logger.debug "Exception occurred: #{@exception.}: BACKTRACE: #{@exception.backtrace}" @raw_response_string ||= 'exception occurred in action processing' @response ||= @raw_response_string @http_status ||= -1 end self ensure logger.debug '' logger.debug("#{self.class.name}: #{url}") logger.debug("config: #{config.inspect}") logger.debug("args_hash: #{args_hash.inspect}") logger.debug("payload: #{payload.inspect}") unless payload.nil? || payload.empty? logger.debug("http status: #{http_status}, success: #{success}, message: #{}") logger.debug("raw response string:") logger.debug(raw_response_string.strip) logger.debug("unpacked response: #{response.class.name}") logger.debug(response.inspect) logger.debug '' end |
Instance Attribute Details
#args_hash ⇒ Object
Returns the value of attribute args_hash.
6 7 8 |
# File 'lib/curbala/action.rb', line 6 def args_hash @args_hash end |
#config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/curbala/action.rb', line 6 def config @config end |
#curl ⇒ Object
Returns the value of attribute curl.
6 7 8 |
# File 'lib/curbala/action.rb', line 6 def curl @curl end |
#exception ⇒ Object
Returns the value of attribute exception.
6 7 8 |
# File 'lib/curbala/action.rb', line 6 def exception @exception end |
#http_status ⇒ Object
Returns the value of attribute http_status.
6 7 8 |
# File 'lib/curbala/action.rb', line 6 def http_status @http_status end |
#message ⇒ Object
Returns the value of attribute message.
6 7 8 |
# File 'lib/curbala/action.rb', line 6 def @message end |
#payload ⇒ Object
Returns the value of attribute payload.
6 7 8 |
# File 'lib/curbala/action.rb', line 6 def payload @payload end |
#raw_response_string ⇒ Object
Returns the value of attribute raw_response_string.
6 7 8 |
# File 'lib/curbala/action.rb', line 6 def raw_response_string @raw_response_string end |
#response ⇒ Object
Returns the value of attribute response.
6 7 8 |
# File 'lib/curbala/action.rb', line 6 def response @response end |
#success ⇒ Object
Returns the value of attribute success.
6 7 8 |
# File 'lib/curbala/action.rb', line 6 def success @success end |
#url ⇒ Object
Returns the value of attribute url.
6 7 8 |
# File 'lib/curbala/action.rb', line 6 def url @url end |
Instance Method Details
#hash_from_json_response ⇒ Object
71 72 73 |
# File 'lib/curbala/action.rb', line 71 def hash_from_json_response @response = (ActiveSupport::JSON.decode(@raw_response_string) rescue {}) end |
#hash_from_xml_response ⇒ Object
response utilities:
66 67 68 69 |
# File 'lib/curbala/action.rb', line 66 def hash_from_xml_response @response = Hash.from_xml(@raw_response_string) @response ||= {} end |
#xml_payload(xml) ⇒ Object
55 56 57 58 |
# File 'lib/curbala/action.rb', line 55 def xml_payload(xml) xml_request @payload = xml end |
#xml_payload_from_args_hash(root) ⇒ Object
APIs have different formatting/hygiene needs…
60 61 62 63 |
# File 'lib/curbala/action.rb', line 60 def xml_payload_from_args_hash(root) # APIs have different formatting/hygiene needs... xml_request @payload = @args_hash.to_xml(:root => root, :indent => 0) # .gsub(/(>[ \t\r\n]+<\/)/,"><\/").gsub(/[ \t\r\n]+^/,'') end |
#xml_request ⇒ Object
request utilities:
50 51 52 53 |
# File 'lib/curbala/action.rb', line 50 def xml_request @curl.headers['Accept'] = 'application/xml' @curl.headers['Content-Type'] = 'application/xml' end |