Class: Setsuzoku::Service::WebService::ApiStrategy

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Includes:
ApiStrategy
Defined in:
lib/setsuzoku/service/web_service/api_strategy.rb

Defined Under Namespace

Modules: InterfaceMethods

Instance Attribute Summary

Attributes included from ApiStrategy

#current_action, #service

Attributes included from HasConfigContext

#config_context

Instance Method Summary collapse

Methods included from ApiStrategy

#call_external_api, #final, #initialize

Methods included from HasConfigContext

#get_from_context

Instance Method Details

#api_headersHash

Specific API headers an API strategy must have when making requests.

Returns:

  • (Hash)

    the additional required headers for a request.



52
53
54
# File 'lib/setsuzoku/service/web_service/api_strategy.rb', line 52

def api_headers
  {}
end

#parse_response(response:, **options) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/setsuzoku/service/web_service/api_strategy.rb', line 81

def parse_response(response:, **options)
  case options[:response_type]
  when :json
    resp = JSON.parse(response.body)
    resp.is_a?(Hash) ? resp.deep_symbolize_keys : resp
  when :xml
    convert_xml_to_hash(response.body)
  when :html
    response.body
  when :txt, :png, :jpg, :gif
    # for now just return the file
    response.body
    # for now just put in tmp
    # tmp_dir = "#{Dir.tmpdir}/setsuzoku/#{self.plugin.class.system_name.underscore}/#{self.plugin.name.underscore}"
    # file_name = "#{self.plugin.class.system_name.underscore}_#{self.plugin.name.underscore}_#{Time.now.strftime("%Y_%m_%d_%T")}"
    # t = Tempfile.new([file_name, ".#{options[:response_type]}"], encoding: 'ascii-8bit')
    # t.write(response.body)
    # t.rewind
    # t
  else
    resp = JSON.parse(response.body)
    resp.is_a?(Hash) ? resp.deep_symbolize_keys : resp
  end
end

#perform_external_call(request:, action_details:, **options) ⇒ Object



71
# File 'lib/setsuzoku/service/web_service/api_strategy.rb', line 71

def perform_external_call(request:, action_details:, **options); end