Class: Cleo::ElementServer

Inherits:
Base
  • Object
show all
Defined in:
lib/cleo/element_server.rb

Class Method Summary collapse

Methods inherited from Base

async?, auto_flush?, good_response_code?

Class Method Details

.execute_create(obj) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/cleo/element_server.rb', line 66

def self.execute_create(obj)
  obj = obj.to_cleo_result unless obj.is_a?(Cleo::Xml::Result)


  uri = URI.parse Cleo::Service.element_server_url + "_"
  request = Net::HTTP::Post.new(uri.path)

  request.body = obj.to_xml
  request.content_type = 'application/xml'

  response = Net::HTTP.new(uri.host, uri.port).start { |http| http.request request }

  return good_response_code?(response)
end

.execute_delete(obj_or_id) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cleo/element_server.rb', line 47

def self.execute_delete(obj_or_id)
  cleo_id = nil

  if obj_or_id.is_a?(Fixnum)
    cleo_id = obj_or_id
  elsif obj_or_id.respond_to?("cleo_id")
    cleo_id = obj_or_id.cleo_id
  elsif obj_or_id.is_a?(Cleo::Xml::Result)
    cleo_id = obj_or_id.id
  end

  uri = URI.parse Cleo::Service.element_server_url + "#{cleo_id}"
  request = Net::HTTP::Delete.new(uri.path)

  response = Net::HTTP.new(uri.host, uri.port).start { |http| http.request request }

  return good_response_code?(response)
end

.execute_update(obj) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/cleo/element_server.rb', line 34

def self.execute_update(obj)
  obj = obj.to_cleo_result unless obj.is_a?(Cleo::Xml::Result)

  uri = URI.parse Cleo::Service.element_server_url + "#{obj.id}"
  request = Net::HTTP::Put.new(uri.path)

  request.content_type = 'application/xml'
  request.body = obj.to_xml
  response = Net::HTTP.new(uri.host, uri.port).start { |http| http.request request }

  return good_response_code?(response)
end

.find(id) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/cleo/element_server.rb', line 17

def self.find(id)
  #query by element/id to get from cleo fast
  uri = URI.parse(Cleo::Service.element_server_url + "#{id}")
  response = Cleo.get(uri)

  return nil if response.body.blank?

  Cleo::Xml::Result.parse(response.body, :single => true)
end

.query(query_param) ⇒ Object



27
28
29
30
31
32
# File 'lib/cleo/element_server.rb', line 27

def self.query(query_param)
  uri = URI.parse(Cleo::Service.element_server_url + "search?query=#{CGI::escape query_param}")
  response = Cleo.get(uri)

  Cleo::Xml::Result.parse(response.body, :single => false)
end