riak_json 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4829b641aa58acf10a0b5f6b8bb465a2dda3ae7
4
- data.tar.gz: bfe725495387a621908a165cac547cfc282bd0e2
3
+ metadata.gz: d41e9a70c0803cf7d5ff1c6b4002866fe6650b22
4
+ data.tar.gz: 907d211669ba6c4e9f20d83a60d72c0e5ce24170
5
5
  SHA512:
6
- metadata.gz: 82ff9f6dc5beba9b516ec396c0ab1fb12604f3ad922d45d09db5c426016654c692b14197f7411748ef27e542570460905ed8fe34400ae4672c7fc5044a0f32b0
7
- data.tar.gz: c17cd830fc7dc717b138f0621016afecfbc8e2eebeb22956163f1be4b79b9797c4cf24e8a259f1782b0b6da5026b77553de045a2a5517253817ba809cb2fddc7
6
+ metadata.gz: 3152be4a674d854a099b61887d021abf7f657663de4040500dbfdd48b90a20da5d11ade833042a2f107d1f8bcab54978298b381145f474ef9a0cbc8ee0dc09a9
7
+ data.tar.gz: 3643ab72d5f7b865e7c8405904e5387425f07f89fc4ecc0d683239f339b4c1d7e752c0e69ace4d4004c7e602d0e01fb47b871911d2267e17fa80ddb49df19c40
data/README.md CHANGED
@@ -1,11 +1,19 @@
1
1
  # Riak Json Ruby Client
2
2
 
3
3
  A Ruby client for [Riak Json](https://github.com/basho-labs/riak_json/).
4
- For ActiveModel integration for RiakJson, see [riak_json-active_model](https://github.com/dmitrizagidulin/rj-activemodel) gem.
4
+ For ActiveModel and Rails integration for RiakJson, see the [riagent](https://github.com/dmitrizagidulin/riagent) gem.
5
+
6
+ For a sample Rails 4 application using RiakJson, see [Riak Threaded Forum](https://github.com/dmitrizagidulin/riak-threaded-forum)
7
+
8
+ See also [](RELEASE_NOTES.md) for a version/feature log.
5
9
 
6
10
  ## Installation
7
- Since this gem is not released to the public yet, build it locally:
11
+ To install from Ruby Gems:
12
+ ```
13
+ gem install riak_json
14
+ ```
8
15
 
16
+ To build locally, from source:
9
17
  ```bash
10
18
  git clone git@github.com:basho/riak_json_ruby_client.git
11
19
  cd riak_json_ruby_client
@@ -17,25 +25,36 @@ Use bundler to install dev dependencies:
17
25
  ```
18
26
  bundle install
19
27
  ```
20
- To run both unit and integration tests:
21
- ```
22
- bundle exec rake test
23
- ```
24
- Note: By default, integration tests assume that Riak is listening on ```127.0.0.1:8098```
25
- (the result of ```make rel```).
26
28
 
27
- To specify alternate host and port, use the ```RIAK_HOST``` and ```RIAK_PORT``` env variables:
28
- ```
29
- RIAK_HOST=127.0.0.1 RIAK_PORT=10018 bundle exec rake
30
- ```
31
- To run just the unit tests:
29
+ To run just the unit tests (no db connection necessary):
32
30
  ```
33
31
  bundle exec rake unittest
34
32
  ```
33
+
34
+ To run both unit and integration tests:
35
+
36
+ 1. Make sure Riak with RiakJson is up and running. Note: By default, integration tests assume that Riak
37
+ is listening on ```127.0.0.1:8098``` (the result of ```make rel```).
38
+ To specify alternate host and port, use the ```RIAK_HOST``` and ```RIAK_PORT``` env variables:
39
+ ```
40
+ RIAK_HOST=127.0.0.1 RIAK_PORT=10018 bundle exec rake
41
+ ```
42
+
43
+ 2. Seed the db (required for several of the integration tests)
44
+ ```
45
+ rake db:seed
46
+ ```
47
+
48
+ 3. Run the tests:
49
+ ```
50
+ bundle exec rake test
51
+ ```
52
+
35
53
  To run just the integration tests:
36
54
  ```
37
55
  bundle exec rake itest
38
56
  ```
57
+
39
58
  ## Usage
40
59
  ### Loading the Client Config File
41
60
  ```ruby
@@ -64,12 +83,14 @@ collection = client.collection("cities")
64
83
  # - text (spaces allowed)
65
84
  # - multi_string (an array of strings, no spaces)
66
85
  # - integer
86
+ # - geo (Solr 'location'/LatLonType type field)
67
87
  schema = RiakJson::CollectionSchema.new
68
88
  schema.add_text_field(name='city', required=true)
69
89
  schema.add_string_field('state', true)
70
90
  schema.add_multi_string_field('zip_codes') # required: false
71
91
  schema.add_integer_field('population', false)
72
92
  schema.add_string_field('country', true)
93
+ schema.add_geo_field('coordinates')
73
94
 
74
95
  # Store the schema
75
96
  collection.set_schema(schema)
@@ -96,6 +117,10 @@ schema_result = collection.get_schema()
96
117
  # :type => "integer",
97
118
  # :require => false
98
119
  # }, {
120
+ # :name => "coordinates",
121
+ # :type => "geo",
122
+ # :require => false
123
+ # }, {
99
124
  # :name => "country",
100
125
  # :type => "string",
101
126
  # :require => true
@@ -107,6 +132,15 @@ schema_result = collection.get_schema()
107
132
  collection.delete_schema
108
133
  ```
109
134
 
135
+ ### List All RiakJson Collections
136
+ This returns an array of ```RiakJson::Collection``` instances.
137
+ Unlike the Riak 'List Buckets' call, this does not iterate through all of the keys, but gets the
138
+ custom RJ collection types from the ring metadata.
139
+
140
+ ```ruby
141
+ client.collections()
142
+ ```
143
+
110
144
  ### Reading and Writing Documents
111
145
  ```ruby
112
146
  # You can insert a document with no key
data/Rakefile CHANGED
@@ -37,4 +37,11 @@ end
37
37
  Rake::TestTask.new :unittest do |t|
38
38
  t.libs << 'lib' << 'test'
39
39
  t.pattern = 'test/unit/*_test.rb'
40
+ end
41
+
42
+ namespace :db do
43
+ task :seed do
44
+ seed_file = File.join('test', 'seeds', 'seeds.rb')
45
+ load(seed_file) if File.exist?(seed_file)
46
+ end
40
47
  end
@@ -61,6 +61,22 @@ module RiakJson
61
61
  self.collection_cache[name] ||= RiakJson::Collection.new(name, self)
62
62
  end
63
63
 
64
+ # List all of the RiakJson collections on the riak cluster
65
+ # This is different from a Riak 'list buckets' command.
66
+ # Instead of iterating over all the keys on the cluster, 'list collections'
67
+ # only lists the custom RJ bucket types on the cluster (from the ring metadata)
68
+ # Raw JSON that's returned by RJ:
69
+ #
70
+ # <code>{"collections":[{"name":"collection1"},{"name":"collection2"}]}</code>
71
+ #
72
+ # This is then mapped to a list of RiakJsonCollection instances.
73
+ # @return [Array] List of +RiakJson::Collection+ instances that exist in the cluster.
74
+ def collections
75
+ result = self.transport.send_request("#{self.base_collection_url}", :get)
76
+ collection_list = JSON.parse(result)['collections']
77
+ collection_list.map { |ea| self.collection(ea['name'])}
78
+ end
79
+
64
80
  def delete_json_object(collection_name, key)
65
81
  self.transport.send_request("#{self.base_collection_url}/#{collection_name}/#{key}", :delete)
66
82
  end
@@ -34,6 +34,10 @@ module RiakJson
34
34
  self.fields << { name: field_name.to_s, type: field_type.to_s, require: required }
35
35
  end
36
36
 
37
+ def add_geo_field(field_name, required=false)
38
+ self.add_field(:geo, field_name, required)
39
+ end
40
+
37
41
  def add_integer_field(field_name, required=false)
38
42
  self.add_field(:integer, field_name, required)
39
43
  end
@@ -55,7 +59,7 @@ module RiakJson
55
59
  end
56
60
 
57
61
  def self.valid_field_types
58
- [:text, :string, :multi_string, :integer]
62
+ [:text, :string, :multi_string, :integer, :geo]
59
63
  end
60
64
  end
61
65
  end
@@ -19,5 +19,5 @@
19
19
  ## -------------------------------------------------------------------
20
20
 
21
21
  module RiakJson
22
- VERSION = "0.0.2"
22
+ VERSION = "0.0.3"
23
23
  end
@@ -48,4 +48,10 @@ describe "RiakJson Ruby Client" do
48
48
  lambda { rj_test_client.get_schema(collection_name) }.must_raise RestClient::ResourceNotFound # 404
49
49
  end
50
50
  end
51
+
52
+ it "can list all collections in the cluster" do
53
+ result = rj_test_client.collections()
54
+ result.wont_be_empty
55
+ result.first.must_be_kind_of RiakJson::Collection
56
+ end
51
57
  end
@@ -168,14 +168,9 @@ describe "a RiakJson Collection" do
168
168
 
169
169
  it "can delete (unset) a schema for a collection" do
170
170
  client = rj_test_client
171
+ # schema created via 'rake db:seed' (See test/seeds/seed.rb)
171
172
  collection = client.collection('cities-delete-schema')
172
173
 
173
- # Ensure a collection has an existing schema
174
- schema = RiakJson::CollectionSchema.new
175
- schema.add_text_field(name='city', required=true)
176
- response = collection.set_schema(schema)
177
- response.code.must_equal 204
178
-
179
174
  # Delete the schema
180
175
  response = collection.delete_schema
181
176
  response.code.must_equal 204
@@ -0,0 +1,32 @@
1
+ ## -------------------------------------------------------------------
2
+ ##
3
+ ## Copyright (c) "2013" Basho Technologies, Inc.
4
+ ##
5
+ ## This file is provided to you under the Apache License,
6
+ ## Version 2.0 (the "License"); you may not use this file
7
+ ## except in compliance with the License. You may obtain
8
+ ## a copy of the License at
9
+ ##
10
+ ## http://www.apache.org/licenses/LICENSE-2.0
11
+ ##
12
+ ## Unless required by applicable law or agreed to in writing,
13
+ ## software distributed under the License is distributed on an
14
+ ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
+ ## KIND, either express or implied. See the License for the
16
+ ## specific language governing permissions and limitations
17
+ ## under the License.
18
+ ##
19
+ ## -------------------------------------------------------------------
20
+
21
+ require 'riak_json'
22
+
23
+ # Create a client pointed to test instance
24
+ host = ENV['RIAK_HOST'] ? ENV['RIAK_HOST'] : RiakJson::RIAK_TEST_HOST
25
+ port = ENV['RIAK_PORT'] ? ENV['RIAK_PORT'] : RiakJson::RIAK_TEST_PORT
26
+ client = RiakJson::Client.new(host, port)
27
+
28
+ # Ensure a collection has an existing schema for the Delete Schema test
29
+ collection = client.collection('cities-delete-schema')
30
+ schema = RiakJson::CollectionSchema.new
31
+ schema.add_text_field(name='city', required=true)
32
+ collection.set_schema(schema)
@@ -80,7 +80,7 @@ describe "a RiakJson Collection Schema" do
80
80
  schema.fields[0][:type].must_equal 'multi_string'
81
81
  schema.fields[0][:require].must_equal true
82
82
  end
83
-
83
+
84
84
  it "can add an integer field to the schema definition" do
85
85
  # schema = [{
86
86
  # :name => "population",
@@ -95,6 +95,20 @@ describe "a RiakJson Collection Schema" do
95
95
  schema.fields[0][:require].must_equal false
96
96
  end
97
97
 
98
+ it "can add a geo type field to the schema definition" do
99
+ # schema = [{
100
+ # :name => "coordinates",
101
+ # :type => "geo",
102
+ # :require => false
103
+ # }]
104
+ schema = RiakJson::CollectionSchema.new
105
+ schema.add_geo_field(name='coordinates', required=false)
106
+ schema.fields.count.must_equal 1
107
+ schema.fields[0][:name].must_equal 'coordinates'
108
+ schema.fields[0][:type].must_equal 'geo'
109
+ schema.fields[0][:require].must_equal false
110
+ end
111
+
98
112
  it "builds a json object representation" do
99
113
  schema = RiakJson::CollectionSchema.new
100
114
  schema.add_text_field(name='city', required=true)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riak_json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitri Zagidulin
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-19 00:00:00.000000000 Z
12
+ date: 2014-02-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -165,6 +165,7 @@ files:
165
165
  - test/helper.rb
166
166
  - test/integration/client_integration_test.rb
167
167
  - test/integration/collection_integration_test.rb
168
+ - test/seeds/seeds.rb
168
169
  - test/unit/client_test.rb
169
170
  - test/unit/client_transport_test.rb
170
171
  - test/unit/collection_schema_test.rb
@@ -201,6 +202,7 @@ test_files:
201
202
  - test/helper.rb
202
203
  - test/integration/client_integration_test.rb
203
204
  - test/integration/collection_integration_test.rb
205
+ - test/seeds/seeds.rb
204
206
  - test/unit/client_test.rb
205
207
  - test/unit/client_transport_test.rb
206
208
  - test/unit/collection_schema_test.rb