Class: GSolr::Connection::Streamly

Inherits:
Object
  • Object
show all
Includes:
Requestable
Defined in:
lib/gsolr/connection/streamly.rb

Instance Attribute Summary

Attributes included from Requestable

#opts, #uri

Instance Method Summary collapse

Methods included from Requestable

#initialize

Methods included from Utils

#build_param, #bytesize, #encode_utf8, #hash_to_query

Instance Method Details

#build_url(path, params = {}) ⇒ Object

accepts a path/string and optional hash of query params



70
71
72
73
74
75
# File 'lib/gsolr/connection/streamly.rb', line 70

def build_url(path, params={})
  full_path = @uri.path + path
  full_url  = "#{@uri.scheme}://#{@uri.host}"
  full_url += ":#{@uri.port}" if @uri.port
  full_url += super(full_path, params, @uri.query)
end

#connectionObject



12
13
14
# File 'lib/gsolr/connection/streamly.rb', line 12

def connection
  @connection ||= StreamlyFFI.connect
end

#create_http_context(response, url, path, params, data = nil, headers = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
67
# File 'lib/gsolr/connection/streamly.rb', line 58

def create_http_context(response, url, path, params, data=nil, headers={})
  return {
    :url          =>  url,
    :body         =>  response,
    :path         =>  path,
    :params       =>  params,
    :data         =>  data,
    :headers      =>  headers
  }
end

#escape(_string) ⇒ Object



16
17
18
# File 'lib/gsolr/connection/streamly.rb', line 16

def escape(_string)
  self.connection.escape(_string)
end

#get(path, params = {}) ⇒ Object



20
21
22
23
24
# File 'lib/gsolr/connection/streamly.rb', line 20

def get(path, params={})
  url       = self.build_url path, params
  response  = connection.get url
  create_http_context response, url, path, params
end

#post(path, data, params = {}, headers = {}) ⇒ Object



26
27
28
29
30
# File 'lib/gsolr/connection/streamly.rb', line 26

def post(path, data, params={}, headers={})
  url       = self.build_url path, params
  response  = connection.post url, data, headers
  create_http_context response, url, path, params, data, headers
end

#request(path, params = {}, *extra) ⇒ Object

send a request to the connection request ‘/select’, :q=>‘:

request ‘/update’, :wt=>:xml, ‘</commit>’

force a post where the post body is the param query request ‘/update’, “<optimize/>”, :method=>:post



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/gsolr/connection/streamly.rb', line 40

def request(path, params={}, *extra)
  opts = extra[-1].kind_of?(Hash) ? extra.pop : {}
  data = extra[0]
  # force a POST, use the query string as the POST body
  if opts[:method] == :post and data.to_s.empty?
    http_context = self.post(path, hash_to_query(params), {}, {'Content-Type' => 'application/x-www-form-urlencoded'})
  else
    if data
      # standard POST, using "data" as the POST body
      http_context = self.post(path, data, params, {"Content-Type" => 'text/xml; charset=utf-8'})
    else
      # standard GET
      http_context = self.get(path, params)
    end
  end
  return http_context
end