agraph 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,6 +13,8 @@ The features that are exposed by this client are...
13
13
  * performing SparQL and Prolog queries
14
14
  * mapping of data type
15
15
 
16
+ {<img src="http://travis-ci.org/phifty/agraph.png" />}[http://travis-ci.org/phifty/agraph]
17
+
16
18
  == Installation
17
19
 
18
20
  There are no special dependencies. Just type
@@ -149,3 +151,8 @@ More examples can be found in the integration specs (spec/integration)
149
151
  Any contribution - especially bug reports - is welcome.
150
152
 
151
153
  Fork or send mail to b.phifty@gmail.com
154
+
155
+ == Support
156
+
157
+ Apart from contribution, support via
158
+ Flattr[http://flattr.com/thing/108992/Ruby-client-for-the-AllegroGraph-RDF-graph-database] is welcome.
@@ -30,6 +30,30 @@ module AllegroGraph
30
30
  @server.catalogs.include? self
31
31
  end
32
32
 
33
+ def create!
34
+ @server.request_http :put, self.path, :expected_status_code => 204
35
+ true
36
+ rescue ::Transport::UnexpectedStatusCodeError => error
37
+ return false if error.status_code == 400
38
+ raise error
39
+ end
40
+
41
+ def create_if_missing!
42
+ create! unless exists?
43
+ end
44
+
45
+ def delete!
46
+ @server.request_http :delete, self.path, :expected_status_code => 204
47
+ true
48
+ rescue ::Transport::UnexpectedStatusCodeError => error
49
+ return false if error.status_code == 400
50
+ raise error
51
+ end
52
+
53
+ def delete_if_exists!
54
+ delete! if exists?
55
+ end
56
+
33
57
  def repositories
34
58
  repositories = @server.request_json :get, self.path + "/repositories", :expected_status_code => 200
35
59
  repositories.map { |repository| Repository.new self, repository["id"] }
@@ -65,12 +65,12 @@ module AllegroGraph
65
65
  response.to_i
66
66
  end
67
67
 
68
- def transaction(&block)
69
- self.class.transaction self, &block
68
+ def transaction(options = { }, &block)
69
+ self.class.transaction self, options, &block
70
70
  end
71
71
 
72
- def self.transaction(repository, &block)
73
- session = Session.create repository
72
+ def self.transaction(repository, options = { }, &block)
73
+ session = Session.create repository, options
74
74
  begin
75
75
  session.instance_eval &block
76
76
  rescue Object => error
@@ -21,6 +21,18 @@ module AllegroGraph
21
21
 
22
22
  def ==(other)
23
23
  other.is_a?(self.class) && @host == other.host && @port == other.port
24
+ end
25
+
26
+ def url
27
+ "http://#{@host}:#{@port}"
28
+ end
29
+
30
+ def path
31
+ ""
32
+ end
33
+
34
+ def server
35
+ self
24
36
  end
25
37
 
26
38
  def request_http(http_method, path, options = { })
@@ -49,10 +61,6 @@ module AllegroGraph
49
61
  result
50
62
  end
51
63
 
52
- def url
53
- "http://#{@host}:#{@port}"
54
- end
55
-
56
64
  private
57
65
 
58
66
  def credentials
@@ -37,10 +37,20 @@ module AllegroGraph
37
37
  true
38
38
  end
39
39
 
40
- def self.create(repository)
41
- response = repository.request_http :post, repository.path + "/session", :expected_status_code => 200
40
+ def size
41
+ response = self.request_http :get, "/size", :type => :text, :expected_status_code => 200
42
+ response.to_i
43
+ end
44
+
45
+ def self.create(repository_or_server, options = { })
46
+ path = repository_or_server.path
47
+ raise ArgumentError, "The :store parameter is missing!" if path.empty? && !options.has_key?(:store)
48
+
49
+ response = repository_or_server.request_http :post,
50
+ path + "/session",
51
+ { :expected_status_code => 200, :parameters => build_parameters(options) }
42
52
  url = response.sub(/^"/, "").sub(/"$/, "")
43
- server = repository.server
53
+ server = repository_or_server.server
44
54
  new :url => url, :username => server.username, :password => server.password
45
55
  end
46
56
 
@@ -50,6 +60,20 @@ module AllegroGraph
50
60
  { :auth_type => :basic, :username => @username, :password => @password }
51
61
  end
52
62
 
63
+ def self.build_parameters(options)
64
+ parameters = { }
65
+
66
+ store = options[:store]
67
+ parameters[:store] = store.is_a?(Array) ? "<#{store.join('>+<')}>" : "<#{store}>" if store
68
+
69
+ # See http://www.franz.com/agraph/support/documentation/current/http-protocol.html#sessions
70
+ [ :autoCommit, :lifetime, :loadInitFile, :script ].each do |parameters_name|
71
+ parameters[parameters_name] = options[parameters_name] if options.has_key?(parameters_name)
72
+ end
73
+
74
+ parameters
75
+ end
76
+
53
77
  end
54
78
 
55
79
  end
@@ -10,6 +10,12 @@
10
10
  :response:
11
11
  :code: "204"
12
12
  :body: ""
13
+ -
14
+ :http_method: "get"
15
+ :url: "http://session:5555/size"
16
+ :response:
17
+ :code: "200"
18
+ :body: "6"
13
19
  -
14
20
  :http_method: "get"
15
21
  :url: "http://localhost:10035/version"
@@ -50,7 +56,19 @@
50
56
  :http_method: "put"
51
57
  :url: "http://localhost:10035/catalogs/not_existing"
52
58
  :response:
53
- :code: "201"
59
+ :code: "204"
60
+ :body: ""
61
+ -
62
+ :http_method: "delete"
63
+ :url: "http://localhost:10035/catalogs/test_catalog"
64
+ :response:
65
+ :code: "204"
66
+ :body: ""
67
+ -
68
+ :http_method: "delete"
69
+ :url: "http://localhost:10035/catalogs/not_existing"
70
+ :response:
71
+ :code: "400"
54
72
  :body: ""
55
73
  -
56
74
  :http_method: "get"
@@ -11,8 +11,8 @@ describe "server" do
11
11
 
12
12
  it "should return the server's version" do
13
13
  @server.version.should == {
14
- :version => "4.1.1",
15
- :date => "October 23, 2010 16:25:51 GMT-0700",
14
+ :version => "4.3.3",
15
+ :date => "September 30, 2011 11:55:21 GMT-0700",
16
16
  :revision => "internal reversion unknown"
17
17
  }
18
18
  end
@@ -71,6 +71,119 @@ describe AllegroGraph::Catalog do
71
71
 
72
72
  end
73
73
 
74
+ describe "create!" do
75
+
76
+ context "for a catalog that already exists" do
77
+
78
+ it "should return false" do
79
+ @catalog.create!.should be_false
80
+ end
81
+
82
+ end
83
+
84
+ context "for a catalog that not exists" do
85
+
86
+ before :each do
87
+ @catalog.name = "not_existing"
88
+ end
89
+
90
+ it "should return true" do
91
+ @catalog.create!.should be_true
92
+ end
93
+
94
+ end
95
+
96
+ end
97
+
98
+ describe "create_if_missing!" do
99
+
100
+ context "for a catalog that already exists" do
101
+
102
+ before :each do
103
+ @catalog.stub!(:exists?).and_return(true)
104
+ end
105
+
106
+ it "should do nothing" do
107
+ @catalog.should_not_receive(:create!)
108
+ @catalog.create_if_missing!
109
+ end
110
+
111
+ end
112
+
113
+ context "for a catalog that not exists" do
114
+
115
+ before :each do
116
+ @catalog.stub!(:exists?).and_return(false)
117
+ end
118
+
119
+ it "should call create!" do
120
+ @catalog.should_receive(:create!)
121
+ @catalog.create_if_missing!
122
+ end
123
+
124
+ end
125
+
126
+ end
127
+
128
+ describe "delete!" do
129
+
130
+ context "for a catalog that already exists" do
131
+
132
+ it "should return true" do
133
+ @catalog.delete!.should be_true
134
+ end
135
+
136
+ it "should return true even if a #{Transport::JSON::ParserError} is raised" do
137
+ @catalog.stub(:request).and_raise(Transport::JSON::ParserError)
138
+ @catalog.delete!.should be_true
139
+ end
140
+
141
+ end
142
+
143
+ context "for a catalog that not exists" do
144
+
145
+ before :each do
146
+ @catalog.name = "not_existing"
147
+ end
148
+
149
+ it "should return false" do
150
+ @catalog.delete!.should be_false
151
+ end
152
+
153
+ end
154
+
155
+ end
156
+
157
+ describe "delete_if_exists!" do
158
+
159
+ context "for a catalog that already exists" do
160
+
161
+ before :each do
162
+ @catalog.stub!(:exists?).and_return(true)
163
+ end
164
+
165
+ it "should call delete!" do
166
+ @catalog.should_receive(:delete!)
167
+ @catalog.delete_if_exists!
168
+ end
169
+
170
+ end
171
+
172
+ context "for a catalog that not exists" do
173
+
174
+ before :each do
175
+ @catalog.stub!(:exists?).and_return(false)
176
+ end
177
+
178
+ it "should do nothing" do
179
+ @catalog.should_not_receive(:delete!)
180
+ @catalog.delete_if_exists!
181
+ end
182
+
183
+ end
184
+
185
+ end
186
+
74
187
  describe "repositories" do
75
188
 
76
189
  before :each do
@@ -21,6 +21,14 @@ describe AllegroGraph::Server do
21
21
  end
22
22
 
23
23
  end
24
+
25
+ describe "server" do
26
+
27
+ it "should return the server itself" do
28
+ @server.server.should == @server
29
+ end
30
+
31
+ end
24
32
 
25
33
  describe "request_http" do
26
34
 
@@ -56,21 +56,53 @@ describe AllegroGraph::Session do
56
56
 
57
57
  end
58
58
 
59
+ describe "size" do
60
+
61
+ it "should return the number of statements" do
62
+ @session.size.should == 6
63
+ end
64
+
65
+ end
66
+
59
67
  describe "create" do
60
68
 
61
69
  before :each do
62
- @server = mock AllegroGraph::Server, :username => "test", :password => "test"
70
+ @server = mock AllegroGraph::Server,
71
+ :username => "test",
72
+ :password => "test",
73
+ :path => ""
74
+ @server.stub(:server).and_return(@server)
63
75
  @repository = mock AllegroGraph::Repository,
64
76
  :path => "/repositories/test_repository",
65
77
  :request_http => "http://session:5555",
66
78
  :server => @server
67
79
  end
68
80
 
69
- it "should request a session" do
81
+ it "should request a session on a store using the repository" do
70
82
  @repository.should_receive(:request_http).with(
71
- :post, "/repositories/test_repository/session", :expected_status_code => 200
83
+ :post, "/repositories/test_repository/session", { :expected_status_code => 200, :parameters => { :autoCommit => true } }
72
84
  ).and_return("http://session:5555")
73
- AllegroGraph::Session.create @repository
85
+ AllegroGraph::Session.create @repository, :autoCommit => true
86
+ end
87
+
88
+ it "should request a session on a store using the server" do
89
+ @server.should_receive(:request_http).with(
90
+ :post, "/session", { :expected_status_code => 200, :parameters => { :store => '<store_x>' } }
91
+ ).and_return("http://session:5555")
92
+ AllegroGraph::Session.create @server, :store => 'store_x'
93
+ end
94
+
95
+ it "should request a session on a federated store" do
96
+ @server.should_receive(:request_http).with(
97
+ :post, "/session", { :expected_status_code => 200, :parameters => { :store => '<store_x>+<store_y>' } }
98
+ ).and_return("http://session:5555")
99
+ AllegroGraph::Session.create @server, :store => ['store_x', 'store_y']
100
+ end
101
+
102
+ it "should raise an error if no store is supplied" do
103
+ lambda do
104
+ AllegroGraph::Session.create @server
105
+ end.should raise_error(ArgumentError)
74
106
  end
75
107
 
76
108
  it "should return a session" do
metadata CHANGED
@@ -1,149 +1,117 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: agraph
3
- version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 4
10
- version: 0.1.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
13
- - "Philipp Br\xC3\xBCll"
7
+ authors:
8
+ - Philipp Brüll
9
+ - Aymeric Brisse
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2010-12-15 00:00:00 +01:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2011-10-10 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: transport
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &22664080 !ruby/object:Gem::Requirement
25
18
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 23
30
- segments:
31
- - 1
32
- - 0
33
- - 0
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
34
22
  version: 1.0.0
35
23
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: rspec
39
24
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *22664080
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: &22662900 !ruby/object:Gem::Requirement
41
29
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 7
46
- segments:
47
- - 2
48
- version: "2"
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '2'
49
34
  type: :development
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: reek
53
35
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *22662900
37
+ - !ruby/object:Gem::Dependency
38
+ name: reek
39
+ requirement: &22661640 !ruby/object:Gem::Requirement
55
40
  none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 11
60
- segments:
61
- - 1
62
- - 2
63
- version: "1.2"
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '1.2'
64
45
  type: :development
65
- version_requirements: *id003
66
- description: The gem provides a client for the AllegroGraph 4.x RDF graph database. Features like searching geo-spatial data, type mapping and transactions are supported.
46
+ prerelease: false
47
+ version_requirements: *22661640
48
+ description: The gem provides a client for the AllegroGraph 4.x RDF graph database.
49
+ Features like searching geo-spatial data, type mapping and transactions are supported.
67
50
  email: b.phifty@gmail.com
68
51
  executables: []
69
-
70
52
  extensions: []
71
-
72
- extra_rdoc_files:
53
+ extra_rdoc_files:
73
54
  - README.rdoc
74
- files:
55
+ files:
75
56
  - README.rdoc
76
57
  - Rakefile
77
- - lib/allegro_graph.rb
78
- - lib/agraph.rb
79
- - lib/code_smells.reek
80
- - lib/allegro_graph/server.rb
81
- - lib/allegro_graph/catalog.rb
82
- - lib/allegro_graph/resource.rb
83
58
  - lib/allegro_graph/utility.rb
84
- - lib/allegro_graph/utility/parameter_mapper.rb
85
- - lib/allegro_graph/session.rb
86
- - lib/allegro_graph/proxy.rb
87
- - lib/allegro_graph/proxy/query.rb
88
59
  - lib/allegro_graph/proxy/mapping.rb
89
60
  - lib/allegro_graph/proxy/statements.rb
90
61
  - lib/allegro_graph/proxy/geometric.rb
62
+ - lib/allegro_graph/proxy/query.rb
63
+ - lib/allegro_graph/catalog.rb
64
+ - lib/allegro_graph/proxy.rb
65
+ - lib/allegro_graph/utility/parameter_mapper.rb
66
+ - lib/allegro_graph/resource.rb
67
+ - lib/allegro_graph/session.rb
91
68
  - lib/allegro_graph/repository.rb
92
- - spec/integration/mapping_spec.rb
93
- - spec/integration/query_spec.rb
94
- - spec/integration/repository_spec.rb
95
- - spec/integration/transactions_spec.rb
96
- - spec/integration/geo_spatial_spec.rb
97
- - spec/integration/statements_spec.rb
98
- - spec/integration/server_spec.rb
99
- - spec/lib/allegro_graph/catalog_spec.rb
100
- - spec/lib/allegro_graph/resource_spec.rb
101
- - spec/lib/allegro_graph/session_spec.rb
102
- - spec/lib/allegro_graph/utility/parameter_mapper_spec.rb
103
- - spec/lib/allegro_graph/repository_spec.rb
104
- - spec/lib/allegro_graph/proxy/mapping_spec.rb
69
+ - lib/allegro_graph/server.rb
70
+ - lib/agraph.rb
71
+ - lib/allegro_graph.rb
72
+ - lib/code_smells.reek
105
73
  - spec/lib/allegro_graph/proxy/query_spec.rb
106
- - spec/lib/allegro_graph/proxy/geometric_spec.rb
107
74
  - spec/lib/allegro_graph/proxy/statements_spec.rb
75
+ - spec/lib/allegro_graph/proxy/geometric_spec.rb
76
+ - spec/lib/allegro_graph/proxy/mapping_spec.rb
77
+ - spec/lib/allegro_graph/session_spec.rb
78
+ - spec/lib/allegro_graph/resource_spec.rb
79
+ - spec/lib/allegro_graph/utility/parameter_mapper_spec.rb
80
+ - spec/lib/allegro_graph/catalog_spec.rb
108
81
  - spec/lib/allegro_graph/server_spec.rb
109
- - spec/fake_transport_helper.rb
82
+ - spec/lib/allegro_graph/repository_spec.rb
110
83
  - spec/spec_helper.rb
84
+ - spec/fake_transport_helper.rb
111
85
  - spec/fake_transport.yml
112
- has_rdoc: true
113
- homepage: http://github.com/phifty/agraph
86
+ - spec/integration/query_spec.rb
87
+ - spec/integration/server_spec.rb
88
+ - spec/integration/repository_spec.rb
89
+ - spec/integration/statements_spec.rb
90
+ - spec/integration/transactions_spec.rb
91
+ - spec/integration/geo_spatial_spec.rb
92
+ - spec/integration/mapping_spec.rb
93
+ homepage: http://github.com/abrisse/agraph
114
94
  licenses: []
115
-
116
95
  post_install_message:
117
96
  rdoc_options: []
118
-
119
- require_paths:
97
+ require_paths:
120
98
  - lib
121
- required_ruby_version: !ruby/object:Gem::Requirement
99
+ required_ruby_version: !ruby/object:Gem::Requirement
122
100
  none: false
123
- requirements:
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- hash: 57
127
- segments:
128
- - 1
129
- - 8
130
- - 7
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
131
104
  version: 1.8.7
132
- required_rubygems_version: !ruby/object:Gem::Requirement
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
106
  none: false
134
- requirements:
135
- - - ">="
136
- - !ruby/object:Gem::Version
137
- hash: 3
138
- segments:
139
- - 0
140
- version: "0"
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
141
111
  requirements: []
142
-
143
112
  rubyforge_project: agraph
144
- rubygems_version: 1.3.7
113
+ rubygems_version: 1.8.10
145
114
  signing_key:
146
115
  specification_version: 3
147
116
  summary: Client for the AllegroGraph 4.x graph database.
148
117
  test_files: []
149
-