Class: Algorithmia::Algorithm
- Inherits:
-
Object
- Object
- Algorithmia::Algorithm
- Defined in:
- lib/algorithmia/algorithm.rb
Instance Method Summary collapse
- #enable_stdout ⇒ Object
-
#initialize(client, endpoint) ⇒ Algorithm
constructor
A new instance of Algorithm.
- #pipe(input) ⇒ Object
- #pipe_json(input) ⇒ Object
- #set_options(options_hash) ⇒ Object
- #set_timeout(timeout) ⇒ Object
Constructor Details
#initialize(client, endpoint) ⇒ Algorithm
Returns a new instance of Algorithm.
4 5 6 7 8 9 10 11 12 |
# File 'lib/algorithmia/algorithm.rb', line 4 def initialize(client, endpoint) @client = client @endpoint = '/v1/algo/' + endpoint @query = { timeout: 300, stdout: false, output: 'default' } end |
Instance Method Details
#enable_stdout ⇒ Object
22 23 24 |
# File 'lib/algorithmia/algorithm.rb', line 22 def enable_stdout @query_options[:stdout] = true end |
#pipe(input) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/algorithmia/algorithm.rb', line 26 def pipe(input) content_type = case when input.kind_of?(String) && input.encoding == Encoding::ASCII_8BIT 'application/octet-stream' when input.kind_of?(String) 'text/plain' else 'application/json' end headers = { 'Content-Type' => content_type } response = Algorithmia::Requester.new(@client).post(@endpoint, input, query: @query, headers: headers) Algorithmia::Response.new(response.parsed_response) end |
#pipe_json(input) ⇒ Object
44 45 46 47 |
# File 'lib/algorithmia/algorithm.rb', line 44 def pipe_json(input) response = Algorithmia::Requester.new(@client).post(@endpoint, input, query: @query, headers: {}) Algorithmia::Response.new(response.parsed_response) end |
#set_options(options_hash) ⇒ Object
14 15 16 |
# File 'lib/algorithmia/algorithm.rb', line 14 def () @query_options.update() end |
#set_timeout(timeout) ⇒ Object
18 19 20 |
# File 'lib/algorithmia/algorithm.rb', line 18 def set_timeout(timeout) @query_options[:timeout] = timeout.to_i end |