Class: Algorithmia::Algorithm

Inherits:
Object
  • Object
show all
Defined in:
lib/algorithmia/algorithm.rb

Instance Method Summary collapse

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(options_hash)
  @query.update(options_hash)
  self
end