Module: CloudSearch
- Defined in:
- lib/cloudsearchable/cloud_search.rb
Constant Summary collapse
- API_VERSION =
"2011-02-01"
Class Method Summary collapse
- .client ⇒ Object
- .client=(client) ⇒ Object
-
.post_sdf(endpoint, sdf) ⇒ Object
Send an SDF document to CloudSearch via http post request.
- .post_sdf_list(endpoint, sdf_list) ⇒ Object
Class Method Details
.client ⇒ Object
7 8 9 |
# File 'lib/cloudsearchable/cloud_search.rb', line 7 def self.client @client ||= Aws::CloudSearch::Client.new end |
.client=(client) ⇒ Object
11 12 13 |
# File 'lib/cloudsearchable/cloud_search.rb', line 11 def self.client=(client) @client = client end |
.post_sdf(endpoint, sdf) ⇒ Object
Send an SDF document to CloudSearch via http post request. Returns parsed JSON response, or raises an exception
19 20 21 |
# File 'lib/cloudsearchable/cloud_search.rb', line 19 def self.post_sdf endpoint, sdf self.post_sdf_list endpoint, [sdf] end |
.post_sdf_list(endpoint, sdf_list) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cloudsearchable/cloud_search.rb', line 23 def self.post_sdf_list endpoint, sdf_list uri = URI.parse("http://#{endpoint}/#{API_VERSION}/documents/batch") req = Net::HTTP::Post.new(uri.path) req.body = JSON.generate sdf_list req["Content-Type"] = "application/json" response = Net::HTTP.start(uri.host, uri.port){|http| http.request(req)} if response.is_a? Net::HTTPSuccess JSON.parse response.body else # Raise an exception based on the response see http://ruby-doc.org/stdlib-1.9.2/libdoc/net/http/rdoc/Net/HTTP.html response.error! end end |