/
client_index.rb
34 lines (30 loc) · 957 Bytes
/
client_index.rb
1
2
3
4
5
6
7
8
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
module Picky
class Client
# TODO Rename?
#
# Parameters:
# * index_name: An index that exists in the Picky server.
# * data: A hash in the form of { :id => 1234, :attr1 => 'attr1', :attr2 => 'attr2', ... }.
#
def replace index_name, data
send_off Net::HTTP::Post.new(self.path), index_name, data
end
# TODO Rename?
#
# Parameters:
# * index_name: An index that exists in the Picky server.
# * data: A hash in the form of { :id => 1234 }.
#
def remove index_name, data
send_off Net::HTTP::Delete.new(self.path), index_name, data
end
# Sends a request to the Picky server.
#
# Note: Data is JSON encoded.
#
def send_off request, index_name, data
request.form_data = { :index => index_name, :data => ActiveSupport::JSON.encode(data) }
Net::HTTP.new(self.host, self.port).start { |http| http.request request }
end
end
end