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



23
24
25
# File 'lib/smooth_operator/operator.rb', line 23

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

Instance Method Details

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



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

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



30
31
32
# File 'lib/smooth_operator/operator.rb', line 30

def generate_parallel_connection
  generate_connection(:typhoeus)
end

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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/smooth_operator/operator.rb', line 46

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

  remote_call = {}

  operator_call.make_the_call do |_remote_call|
    remote_call = _remote_call

    yield(remote_call) if block_given?
  end

  remote_call
end

#query_string(params) ⇒ Object



64
65
66
# File 'lib/smooth_operator/operator.rb', line 64

def query_string(params)
  params
end