Module: SmoothOperator::Operator

Included in:
Base
Defined in:
lib/smooth_operator/operator.rb

Constant Summary collapse

HTTP_VERBS =
[:get, :post, :put, :patch, :delete]
OPTIONS =
[:endpoint, :endpoint_user, :endpoint_pass, :timeout]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#headersObject



21
22
23
# File 'lib/smooth_operator/operator.rb', line 21

def headers
  Helpers.get_instance_variable(self, :headers, {})
end

Instance Method Details

#generate_connection(adapter = nil, options = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/smooth_operator/operator.rb', line 32

def generate_connection(adapter = nil, options = nil)
  adapter ||= :net_http
  options ||= {}
  url, timeout = (options[:endpoint] || self.endpoint), (options[:timeout] || self.timeout)

  ::Faraday.new(url: url) do |builder|
    builder.options[:timeout] = timeout unless Helpers.blank?(timeout)
    builder.request :url_encoded
    builder.adapter adapter
  end
end

#generate_parallel_connectionObject



28
29
30
# File 'lib/smooth_operator/operator.rb', line 28

def generate_parallel_connection
  generate_connection(:typhoeus)
end

#make_the_call(http_verb, relative_path = '', data = {}, options = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/smooth_operator/operator.rb', line 44

def make_the_call(http_verb, relative_path = '', data = {}, options = {})
  if Helpers.present?(options[:hydra])
    operator_call = OperatorCall::Faraday.new(self, http_verb, relative_path, data, options)
  else
    operator_call = OperatorCall::Typhoeus.new(self, http_verb, relative_path, data, options)
  end

  operator_call.make_the_call
end