Class: Algorithmia::Algorithm
- Inherits:
-
Object
- Object
- Algorithmia::Algorithm
- Defined in:
- lib/algorithmia/algorithm.rb
Instance Method Summary collapse
-
#initialize(client, endpoint) ⇒ Algorithm
constructor
A new instance of Algorithm.
- #pipe(input) ⇒ Object
- #pipe_json(input) ⇒ Object
- #set(options_hash) ⇒ Object
Constructor Details
#initialize(client, endpoint) ⇒ Algorithm
Returns a new instance of Algorithm.
4 5 6 7 8 |
# File 'lib/algorithmia/algorithm.rb', line 4 def initialize(client, endpoint) @client = client @endpoint = '/v1/algo/' + endpoint @query = {} end |
Instance Method Details
#pipe(input) ⇒ Object
15 16 17 18 19 |
# File 'lib/algorithmia/algorithm.rb', line 15 def pipe(input) client_timeout = (@query[:timeout] || 300) + 10 response = Algorithmia::Requester.new(@client).post(@endpoint, input, query: @query, headers: {}, timeout: client_timeout) Algorithmia::Response.new(response.parsed_response, @query[:output]) end |
#pipe_json(input) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/algorithmia/algorithm.rb', line 21 def pipe_json(input) client_timeout = (@query[:timeout] || 300) + 10 headers = { 'Content-Type' => 'application/json' } response = Algorithmia::Requester.new(@client).post(@endpoint, input, query: @query, headers: headers, timeout: client_timeout) Algorithmia::Response.new(response.parsed_response, @query[:output]) end |
#set(options_hash) ⇒ Object
10 11 12 13 |
# File 'lib/algorithmia/algorithm.rb', line 10 def set() @query.update() self end |