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
- #generate_connection(adapter = nil, options = nil) ⇒ Object
- #generate_parallel_connection ⇒ Object
- #make_the_call(http_verb, relative_path = '', data = {}, options = {}) ⇒ Object
Instance Attribute Details
#headers ⇒ Object
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, = nil) adapter ||= :net_http ||= {} url, timeout = ([:endpoint] || self.endpoint), ([:timeout] || self.timeout) ::Faraday.new(url: url) do |builder| builder.[:timeout] = timeout unless Helpers.blank?(timeout) builder.request :url_encoded builder.adapter adapter end end |
#generate_parallel_connection ⇒ Object
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 = {}, = {}) if Helpers.present?([:hydra]) operator_call = Operators::Typhoeus.new(self, http_verb, relative_path, data, ) else operator_call = Operators::Faraday.new(self, http_verb, relative_path, data, ) 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 |