Class: Opener::Webservice::InputExtractor
- Inherits:
-
Object
- Object
- Opener::Webservice::InputExtractor
- Defined in:
- lib/opener/webservice/input_extractor.rb
Overview
Extracts the KAF/text input to use from a set of input parameters.
Instance Attribute Summary collapse
- #http ⇒ HTTPClient readonly
Instance Method Summary collapse
- #extract(options) ⇒ String
-
#initialize ⇒ InputExtractor
constructor
A new instance of InputExtractor.
Constructor Details
#initialize ⇒ InputExtractor
Returns a new instance of InputExtractor.
12 13 14 |
# File 'lib/opener/webservice/input_extractor.rb', line 12 def initialize @http = HTTPClient.new end |
Instance Attribute Details
#http ⇒ HTTPClient (readonly)
9 10 11 12 13 14 15 16 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 |
# File 'lib/opener/webservice/input_extractor.rb', line 9 class InputExtractor attr_reader :http def initialize @http = HTTPClient.new end ## # @param [Hash] options # # @option options [String] input_url A URL to download input from. # @option options [String] input The direct input to process. # # @return [String] # # @raise [RuntimeError] Raised when the input could not be downloaded. # def extract() if ['input_url'] resp = http.get(['input_url'], :follow_redirect => true) unless resp.ok? raise "Failed to download input from #{options['input_url']}" end input = resp.body else input = ['input'] end return input end end |
Instance Method Details
#extract(options) ⇒ String
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/opener/webservice/input_extractor.rb', line 26 def extract() if ['input_url'] resp = http.get(['input_url'], :follow_redirect => true) unless resp.ok? raise "Failed to download input from #{options['input_url']}" end input = resp.body else input = ['input'] end return input end |