Class: AllegroGraph::Proxy::Statements

Inherits:
Object
  • Object
show all
Defined in:
lib/allegro_graph/proxy/statements.rb

Overview

The Statement class acts as proxy to functions that add, remove or find statements in the AllegroGraph data store.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ Statements

Returns a new instance of Statements.



12
13
14
# File 'lib/allegro_graph/proxy/statements.rb', line 12

def initialize(resource)
  @resource = resource
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



10
11
12
# File 'lib/allegro_graph/proxy/statements.rb', line 10

def resource
  @resource
end

Instance Method Details

#create(subject, predicate, object, context = nil) ⇒ Object



20
21
22
23
24
25
# File 'lib/allegro_graph/proxy/statements.rb', line 20

def create(subject, predicate, object, context = nil)
  statement = [ subject, predicate, object ]
  statement << context if context
  @resource.request_json :post, self.path + "/statements", :body => [ statement ], :expected_status_code => 204
  true
end

#delete(options = { }) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/allegro_graph/proxy/statements.rb', line 27

def delete(options = { })
  parameters = { }

  { :subject => :subj, :predicate => :pred, :object => :obj, :context => :context }.each do |option_key, parameter_key|
    value = options[option_key]
    parameters.merge! parameter_key => value if value
  end

  @resource.request_http :delete, self.path + "/statements", :parameters => parameters, :expected_status_code => 200
end

#find(options = { }) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/allegro_graph/proxy/statements.rb', line 38

def find(options = { })
  parameters = { }

  { :subject => :subj, :predicate => :pred, :object => :obj, :context => :context }.each do |option_key, parameter_key|
    value = options[option_key]
    parameters.merge! value.is_a?(Array) ?
                        { :"#{parameter_key}" => value[0], :"#{parameter_key}End" => value[1] } :
                        { parameter_key => value } if value
  end

  [ :offset, :limit, :infer ].each do |key|
    parameters.merge! key => options[key] if options.has_key?(key)
  end

  parameters = nil if parameters.empty?

  @resource.request_json :get, self.path + "/statements", :parameters => parameters, :expected_status_code => 200
end

#find_inside_box(parameters = { }) ⇒ Object



57
58
59
60
# File 'lib/allegro_graph/proxy/statements.rb', line 57

def find_inside_box(parameters = { })
  parameters = Utility::ParameterMapper.map parameters, :find_inside_box
  @resource.request_json :get, self.path + "/geo/box", :parameters => parameters, :expected_status_code => 200
end

#find_inside_circle(parameters = { }) ⇒ Object



62
63
64
65
# File 'lib/allegro_graph/proxy/statements.rb', line 62

def find_inside_circle(parameters = { })
  parameters = Utility::ParameterMapper.map parameters, :find_inside_circle
  @resource.request_json :get, self.path + "/geo/circle", :parameters => parameters, :expected_status_code => 200
end

#find_inside_haversine(parameters = { }) ⇒ Object



67
68
69
70
# File 'lib/allegro_graph/proxy/statements.rb', line 67

def find_inside_haversine(parameters = { })
  parameters = Utility::ParameterMapper.map parameters, :find_inside_haversine
  @resource.request_json :get, self.path + "/geo/haversine", :parameters => parameters, :expected_status_code => 200
end

#find_inside_polygon(parameters = { }) ⇒ Object



72
73
74
75
# File 'lib/allegro_graph/proxy/statements.rb', line 72

def find_inside_polygon(parameters = { })
  parameters = Utility::ParameterMapper.map parameters, :find_inside_polygon
  @resource.request_json :get, self.path + "/geo/polygon", :parameters => parameters, :expected_status_code => 200
end

#pathObject



16
17
18
# File 'lib/allegro_graph/proxy/statements.rb', line 16

def path
  @resource.path
end