Class: Mushy::HttpOperation
- Defined in:
- lib/mushy/fluxs/http_operation.rb
Overview
A HTTP Operation request.
Instance Attribute Summary
Attributes inherited from Flux
#config, #flow, #id, #masher, #parent_fluxs, #subscribed_to, #type
Class Method Summary collapse
Instance Method Summary collapse
- #operation ⇒ Object
-
#process(_event, config) ⇒ Object
rubocop:disable Metrics/MethodLength.
Methods inherited from Flux
#convert_this_to_an_array, #convert_to_symbolized_hash, #execute, #execute_single_event, #group_these_results, #guard, #ignore_these_results, inherited, #initialize, #join_these_results, #limit_these_results, #merge_these_results, #model_these_results, #outgoing_split_these_results, #shape_these, #sort_these_results, #standardize_these
Constructor Details
This class inherits a constructor from Mushy::Flux
Class Method Details
.details ⇒ Object
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 46 47 48 49 50 51 |
# File 'lib/mushy/fluxs/http_operation.rb', line 17 def self.details { name: operation.capitalize, title: "Make a #{operation.upcase} call", fluxGroup: { name: 'Web' }, description: "Makes a #{operation} call to a URL", config: { url: { description: 'The URL to visit.', type: 'text', value: 'https://www.google.com' }, headers: { description: 'Headers for the web request.', type: 'keyvalue', shrink: true, value: {} }, params: { description: 'Parameters for the URL.', type: 'keyvalue', shrink: true, value: {} }, body: { description: 'The body of the request.', type: 'text', shrink: true, value: '' }, }, examples: { } } end |
.operation ⇒ Object
9 10 11 |
# File 'lib/mushy/fluxs/http_operation.rb', line 9 def self.operation name.split('::').last.downcase end |
Instance Method Details
#operation ⇒ Object
13 14 15 |
# File 'lib/mushy/fluxs/http_operation.rb', line 13 def operation self.class.operation end |
#process(_event, config) ⇒ Object
rubocop:disable Metrics/MethodLength
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/mushy/fluxs/http_operation.rb', line 53 def process(_event, config) # rubocop:disable Metrics/MethodLength args = { params: config[:params], headers: config[:headers] } faraday = Faraday.new(**args) do |connection| connection.adapter Faraday.default_adapter end start = Process.clock_gettime(Process::CLOCK_MONOTONIC) response = faraday.send(operation.to_sym, config[:url]) do |request| request.body = config[:body] if config[:body].to_s != '' end time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start url = response.instance_variable_get(:@env).url.to_s { status: response.status, url: url, time: time, reason_phrase: response.reason_phrase, headers: response.headers, body: response.body } end |