noids_client 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +15 -0
- data/README.md +84 -0
- data/Rakefile +1 -0
- data/lib/noids_client.rb +7 -0
- data/lib/noids_client/connection.rb +37 -0
- data/lib/noids_client/pool.rb +51 -0
- data/lib/noids_client/version.rb +3 -0
- data/noids_client.gemspec +30 -0
- data/spec/cassettes/integration-1.yml +283 -0
- data/spec/lib/integration_spec.rb +23 -0
- data/spec/lib/pool_spec.rb +16 -0
- data/spec/spec_helper.rb +14 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f84c41e5fda4436621de5c0dadb9939753f4a804
|
4
|
+
data.tar.gz: e43be3ae32af0efebd19f9086717ae313d95067c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9b2bb7f767b7568e7acabeadce6f245e435a9ddc568ad1791c007a74fcb9ccf4c5e7f0a155c4e7784f681edc6f6588a4dfec990c7a4591cf832f169c53539f23
|
7
|
+
data.tar.gz: 0babfde7d9a137eefa87b2b1c44f62022ac9a2dacbce3e91aa1e683e9de454c9fc4260b8b0600d351555365784dcef84db625b59ae43060bab8c284c6b640cf6
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
##########################################################################
|
2
|
+
# Copyright 2014 University of Notre Dame
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
NoidsClient
|
2
|
+
===========
|
3
|
+
|
4
|
+
NoidsClient provides a wrapper around the [noids server](https://github.com/dbrower/noids) REST API.
|
5
|
+
This is the thinnest wrapper possible. Don't expect any sophisticated behavior.
|
6
|
+
|
7
|
+
# Usage
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require 'noids_client'
|
11
|
+
|
12
|
+
noids = NoidsClient::Connection.new("localhost:13001")
|
13
|
+
noids.pool_list # = ["sdfg"]
|
14
|
+
noids.server_version # = "1.0.1"
|
15
|
+
mypool = noids.new_pool("mypool", ".zdddk")
|
16
|
+
mypool.mint # = ["0000"]
|
17
|
+
p = noids.get_pool("sdfg") # load a pool which has already been created
|
18
|
+
p.name # = "sdfg"
|
19
|
+
p.closed? # = false
|
20
|
+
p.last_mint_date # = #<DateTime: 2014-06-16T14:27:19-04:00 ((2456825j,66439s,22553001n),-14400s,2299161j)>
|
21
|
+
p.template # = ".zeeek+24457"
|
22
|
+
p.ids_used # = 24457
|
23
|
+
p.max_ids # = Float::INFINITY
|
24
|
+
p.mint # = ["102bm"]
|
25
|
+
p.mint(50) # = ["102cr", "102dw", ..., "1042q"]
|
26
|
+
p.close # closes the pool to new minting
|
27
|
+
p.closed? # = true
|
28
|
+
p.open # opens the pool to new minting (provided there are more ids available for minting)
|
29
|
+
p.advance_past('zzzs')
|
30
|
+
p.update # reloads ids_used and last_mint_date from the server
|
31
|
+
```
|
32
|
+
|
33
|
+
# Notes
|
34
|
+
|
35
|
+
* `mint` will only take an argument between 1 and 1000, inclusive. Other values will cause an exception.
|
36
|
+
This limitation is imposed by the server.
|
37
|
+
* In the case of connection issues, exceptions are raised.
|
38
|
+
|
39
|
+
# Setting up a noids server
|
40
|
+
|
41
|
+
A noids server is not provided by this repository.
|
42
|
+
However, for testing or experimentation it is convinent to set up a noids server, which is not difficult.
|
43
|
+
|
44
|
+
## On a Mac with homebrew
|
45
|
+
|
46
|
+
First install a golang environment.
|
47
|
+
|
48
|
+
brew install go
|
49
|
+
mkdir ~/gocode
|
50
|
+
export GOPATH=~/gocode
|
51
|
+
export PATH=$GOPATH/bin:$PATH
|
52
|
+
|
53
|
+
Install the noids server:
|
54
|
+
|
55
|
+
go get https://github.com/dbrower/noids
|
56
|
+
|
57
|
+
Start it, and have it keep pools in memory.
|
58
|
+
|
59
|
+
noids
|
60
|
+
|
61
|
+
These pools will be lost when the server is restarted.
|
62
|
+
To save the pools to disk use
|
63
|
+
|
64
|
+
noids -storage directory/to/use
|
65
|
+
|
66
|
+
There are other options, including saving the pools to a database.
|
67
|
+
See the documentation on the [noids server](https://github.com/dbrower/noids) page.
|
68
|
+
|
69
|
+
You can test the server using `curl`.
|
70
|
+
Note that the default port for the server to listen on is 13001.
|
71
|
+
These commands will create a pool named 'test' which will generate ids using the template `.sddd`.
|
72
|
+
Then 50 ids are minted, and the pool is advanced past the id `432`, so that `432` will never be minted by this pool.
|
73
|
+
|
74
|
+
curl 'http://localhost:13001/pools' -F 'name=test' -F 'template=.sddd'
|
75
|
+
curl 'http://localhost:13001/pools/test/mint' -F 'n=50'
|
76
|
+
curl 'http://localhost:13001/pools/test/advancePast' -F 'id=432'
|
77
|
+
|
78
|
+
|
79
|
+
## On Linux
|
80
|
+
|
81
|
+
Install a golang envrionment. This should be done using your package management system.
|
82
|
+
e.g. `yum install golang`.
|
83
|
+
Then follow the remaining steps above.
|
84
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/noids_client.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#
|
2
|
+
# Connection remembers how to contact a given noids server
|
3
|
+
#
|
4
|
+
module NoidsClient
|
5
|
+
class Connection
|
6
|
+
|
7
|
+
attr_reader :server_version
|
8
|
+
|
9
|
+
def initialize(url)
|
10
|
+
@noids = ::RestClient::Resource.new(url)
|
11
|
+
update
|
12
|
+
end
|
13
|
+
|
14
|
+
def new_pool(name, template)
|
15
|
+
@noids['pools'].post '', params: {name: name, template: template}
|
16
|
+
get_pool(name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_pool(name)
|
20
|
+
Pool.new(@noids["pools/#{name}"])
|
21
|
+
end
|
22
|
+
|
23
|
+
def pool_list
|
24
|
+
JSON.parse(@noids['pools'].get)
|
25
|
+
end
|
26
|
+
|
27
|
+
def update
|
28
|
+
parse_stats(@noids['stats'].get)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def parse_stats(json_string)
|
33
|
+
stats = JSON.parse(json_string)
|
34
|
+
@server_version = stats['Version']
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module NoidsClient
|
4
|
+
class Pool
|
5
|
+
|
6
|
+
attr_reader :name, :template, :ids_used, :max_ids, :last_mint_date
|
7
|
+
|
8
|
+
def initialize(rest_resource)
|
9
|
+
@noid_pool = rest_resource
|
10
|
+
update
|
11
|
+
end
|
12
|
+
|
13
|
+
def update
|
14
|
+
decode_json(@noid_pool.get)
|
15
|
+
end
|
16
|
+
|
17
|
+
def open
|
18
|
+
decode_json(@noid_pool['open'].put '')
|
19
|
+
end
|
20
|
+
|
21
|
+
def close
|
22
|
+
decode_json(@noid_pool['close'].put '')
|
23
|
+
end
|
24
|
+
|
25
|
+
def closed?
|
26
|
+
@is_closed
|
27
|
+
end
|
28
|
+
|
29
|
+
def mint(this_many_ids=1)
|
30
|
+
JSON.parse(@noid_pool['mint'].post '', params: {n: this_many_ids})
|
31
|
+
end
|
32
|
+
|
33
|
+
def advance_past(this_id)
|
34
|
+
decode_json(@noid_pool['advancePast'].post '', params: {id: this_id})
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def decode_json(json_string)
|
39
|
+
info = JSON.parse(json_string)
|
40
|
+
@name = info['Name']
|
41
|
+
@template = info['Template']
|
42
|
+
@ids_used = info['Used']
|
43
|
+
@max_ids = info['Max']
|
44
|
+
if @max_ids == -1
|
45
|
+
@max_ids = Float::INFINITY
|
46
|
+
end
|
47
|
+
@is_closed = info['Closed']
|
48
|
+
@last_mint_date = DateTime.rfc3339(info['LastMint'])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'noids_client/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'noids_client'
|
8
|
+
spec.version = NoidsClient::VERSION
|
9
|
+
spec.summary = 'Ruby client for a NOIDS server'
|
10
|
+
spec.description = %q{Provides an idiomatic interface to the REST API of a noids server (see https://github.com/dbrower/noids)}
|
11
|
+
spec.authors = ['Don Brower']
|
12
|
+
spec.email = ['dbrower@nd.edu']
|
13
|
+
spec.license = 'APACHE2'
|
14
|
+
spec.homepage = 'https://github.com/ndlib/noids_client'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'rest-client', '~> 1.6'
|
22
|
+
spec.add_dependency 'json', '~> 1.8'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.3'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
27
|
+
spec.add_development_dependency 'vcr', '~> 2.8'
|
28
|
+
spec.add_development_dependency 'webmock', '~> 1.17'
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,283 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: http://localhost:13001/stats
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- '*/*; q=0.5, application/xml'
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip, deflate
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Date:
|
22
|
+
- Tue, 17 Jun 2014 20:47:07 GMT
|
23
|
+
Content-Length:
|
24
|
+
- '20'
|
25
|
+
Content-Type:
|
26
|
+
- text/plain; charset=utf-8
|
27
|
+
body:
|
28
|
+
encoding: UTF-8
|
29
|
+
string: |
|
30
|
+
{"Version":"1.0.1"}
|
31
|
+
http_version:
|
32
|
+
recorded_at: Tue, 17 Jun 2014 20:47:07 GMT
|
33
|
+
- request:
|
34
|
+
method: get
|
35
|
+
uri: http://localhost:13001/pools
|
36
|
+
body:
|
37
|
+
encoding: US-ASCII
|
38
|
+
string: ''
|
39
|
+
headers:
|
40
|
+
Accept:
|
41
|
+
- '*/*; q=0.5, application/xml'
|
42
|
+
Accept-Encoding:
|
43
|
+
- gzip, deflate
|
44
|
+
User-Agent:
|
45
|
+
- Ruby
|
46
|
+
response:
|
47
|
+
status:
|
48
|
+
code: 200
|
49
|
+
message: OK
|
50
|
+
headers:
|
51
|
+
Date:
|
52
|
+
- Tue, 17 Jun 2014 20:47:07 GMT
|
53
|
+
Content-Length:
|
54
|
+
- '3'
|
55
|
+
Content-Type:
|
56
|
+
- text/plain; charset=utf-8
|
57
|
+
body:
|
58
|
+
encoding: UTF-8
|
59
|
+
string: |
|
60
|
+
[]
|
61
|
+
http_version:
|
62
|
+
recorded_at: Tue, 17 Jun 2014 20:47:07 GMT
|
63
|
+
- request:
|
64
|
+
method: get
|
65
|
+
uri: http://localhost:13001/pools
|
66
|
+
body:
|
67
|
+
encoding: US-ASCII
|
68
|
+
string: ''
|
69
|
+
headers:
|
70
|
+
Accept:
|
71
|
+
- '*/*; q=0.5, application/xml'
|
72
|
+
Accept-Encoding:
|
73
|
+
- gzip, deflate
|
74
|
+
User-Agent:
|
75
|
+
- Ruby
|
76
|
+
response:
|
77
|
+
status:
|
78
|
+
code: 200
|
79
|
+
message: OK
|
80
|
+
headers:
|
81
|
+
Date:
|
82
|
+
- Tue, 17 Jun 2014 20:47:07 GMT
|
83
|
+
Content-Length:
|
84
|
+
- '3'
|
85
|
+
Content-Type:
|
86
|
+
- text/plain; charset=utf-8
|
87
|
+
body:
|
88
|
+
encoding: UTF-8
|
89
|
+
string: |
|
90
|
+
[]
|
91
|
+
http_version:
|
92
|
+
recorded_at: Tue, 17 Jun 2014 20:47:07 GMT
|
93
|
+
- request:
|
94
|
+
method: post
|
95
|
+
uri: http://localhost:13001/pools?name=abcd&template=.sddd
|
96
|
+
body:
|
97
|
+
encoding: ASCII-8BIT
|
98
|
+
string: ''
|
99
|
+
headers:
|
100
|
+
Accept:
|
101
|
+
- '*/*; q=0.5, application/xml'
|
102
|
+
Accept-Encoding:
|
103
|
+
- gzip, deflate
|
104
|
+
Content-Length:
|
105
|
+
- '0'
|
106
|
+
User-Agent:
|
107
|
+
- Ruby
|
108
|
+
response:
|
109
|
+
status:
|
110
|
+
code: 201
|
111
|
+
message: Created
|
112
|
+
headers:
|
113
|
+
Date:
|
114
|
+
- Tue, 17 Jun 2014 20:47:07 GMT
|
115
|
+
Content-Length:
|
116
|
+
- '121'
|
117
|
+
Content-Type:
|
118
|
+
- text/plain; charset=utf-8
|
119
|
+
body:
|
120
|
+
encoding: UTF-8
|
121
|
+
string: |
|
122
|
+
{"Name":"abcd","Template":".sddd+0","Used":0,"Max":1000,"Closed":false,"LastMint":"2014-06-17T16:47:07.397416664-04:00"}
|
123
|
+
http_version:
|
124
|
+
recorded_at: Tue, 17 Jun 2014 20:47:07 GMT
|
125
|
+
- request:
|
126
|
+
method: get
|
127
|
+
uri: http://localhost:13001/pools/abcd
|
128
|
+
body:
|
129
|
+
encoding: US-ASCII
|
130
|
+
string: ''
|
131
|
+
headers:
|
132
|
+
Accept:
|
133
|
+
- '*/*; q=0.5, application/xml'
|
134
|
+
Accept-Encoding:
|
135
|
+
- gzip, deflate
|
136
|
+
User-Agent:
|
137
|
+
- Ruby
|
138
|
+
response:
|
139
|
+
status:
|
140
|
+
code: 200
|
141
|
+
message: OK
|
142
|
+
headers:
|
143
|
+
Date:
|
144
|
+
- Tue, 17 Jun 2014 20:47:07 GMT
|
145
|
+
Content-Length:
|
146
|
+
- '121'
|
147
|
+
Content-Type:
|
148
|
+
- text/plain; charset=utf-8
|
149
|
+
body:
|
150
|
+
encoding: UTF-8
|
151
|
+
string: |
|
152
|
+
{"Name":"abcd","Template":".sddd+0","Used":0,"Max":1000,"Closed":false,"LastMint":"2014-06-17T16:47:07.397416664-04:00"}
|
153
|
+
http_version:
|
154
|
+
recorded_at: Tue, 17 Jun 2014 20:47:07 GMT
|
155
|
+
- request:
|
156
|
+
method: post
|
157
|
+
uri: http://localhost:13001/pools/abcd/advancePast?id=100
|
158
|
+
body:
|
159
|
+
encoding: ASCII-8BIT
|
160
|
+
string: ''
|
161
|
+
headers:
|
162
|
+
Accept:
|
163
|
+
- '*/*; q=0.5, application/xml'
|
164
|
+
Accept-Encoding:
|
165
|
+
- gzip, deflate
|
166
|
+
Content-Length:
|
167
|
+
- '0'
|
168
|
+
User-Agent:
|
169
|
+
- Ruby
|
170
|
+
response:
|
171
|
+
status:
|
172
|
+
code: 200
|
173
|
+
message: OK
|
174
|
+
headers:
|
175
|
+
Date:
|
176
|
+
- Tue, 17 Jun 2014 20:47:07 GMT
|
177
|
+
Content-Length:
|
178
|
+
- '125'
|
179
|
+
Content-Type:
|
180
|
+
- text/plain; charset=utf-8
|
181
|
+
body:
|
182
|
+
encoding: UTF-8
|
183
|
+
string: |
|
184
|
+
{"Name":"abcd","Template":".sddd+101","Used":101,"Max":1000,"Closed":false,"LastMint":"2014-06-17T16:47:07.407251383-04:00"}
|
185
|
+
http_version:
|
186
|
+
recorded_at: Tue, 17 Jun 2014 20:47:07 GMT
|
187
|
+
- request:
|
188
|
+
method: post
|
189
|
+
uri: http://localhost:13001/pools/abcd/mint?n=2
|
190
|
+
body:
|
191
|
+
encoding: ASCII-8BIT
|
192
|
+
string: ''
|
193
|
+
headers:
|
194
|
+
Accept:
|
195
|
+
- '*/*; q=0.5, application/xml'
|
196
|
+
Accept-Encoding:
|
197
|
+
- gzip, deflate
|
198
|
+
Content-Length:
|
199
|
+
- '0'
|
200
|
+
User-Agent:
|
201
|
+
- Ruby
|
202
|
+
response:
|
203
|
+
status:
|
204
|
+
code: 200
|
205
|
+
message: OK
|
206
|
+
headers:
|
207
|
+
Date:
|
208
|
+
- Tue, 17 Jun 2014 20:47:07 GMT
|
209
|
+
Content-Length:
|
210
|
+
- '14'
|
211
|
+
Content-Type:
|
212
|
+
- text/plain; charset=utf-8
|
213
|
+
body:
|
214
|
+
encoding: UTF-8
|
215
|
+
string: |
|
216
|
+
["101","102"]
|
217
|
+
http_version:
|
218
|
+
recorded_at: Tue, 17 Jun 2014 20:47:07 GMT
|
219
|
+
- request:
|
220
|
+
method: put
|
221
|
+
uri: http://localhost:13001/pools/abcd/close
|
222
|
+
body:
|
223
|
+
encoding: ASCII-8BIT
|
224
|
+
string: ''
|
225
|
+
headers:
|
226
|
+
Accept:
|
227
|
+
- '*/*; q=0.5, application/xml'
|
228
|
+
Accept-Encoding:
|
229
|
+
- gzip, deflate
|
230
|
+
Content-Length:
|
231
|
+
- '0'
|
232
|
+
User-Agent:
|
233
|
+
- Ruby
|
234
|
+
response:
|
235
|
+
status:
|
236
|
+
code: 200
|
237
|
+
message: OK
|
238
|
+
headers:
|
239
|
+
Date:
|
240
|
+
- Tue, 17 Jun 2014 20:47:07 GMT
|
241
|
+
Content-Length:
|
242
|
+
- '124'
|
243
|
+
Content-Type:
|
244
|
+
- text/plain; charset=utf-8
|
245
|
+
body:
|
246
|
+
encoding: UTF-8
|
247
|
+
string: |
|
248
|
+
{"Name":"abcd","Template":".sddd+103","Used":103,"Max":1000,"Closed":true,"LastMint":"2014-06-17T16:47:07.413350405-04:00"}
|
249
|
+
http_version:
|
250
|
+
recorded_at: Tue, 17 Jun 2014 20:47:07 GMT
|
251
|
+
- request:
|
252
|
+
method: post
|
253
|
+
uri: http://localhost:13001/pools/abcd/mint?n=1
|
254
|
+
body:
|
255
|
+
encoding: ASCII-8BIT
|
256
|
+
string: ''
|
257
|
+
headers:
|
258
|
+
Accept:
|
259
|
+
- '*/*; q=0.5, application/xml'
|
260
|
+
Accept-Encoding:
|
261
|
+
- gzip, deflate
|
262
|
+
Content-Length:
|
263
|
+
- '0'
|
264
|
+
User-Agent:
|
265
|
+
- Ruby
|
266
|
+
response:
|
267
|
+
status:
|
268
|
+
code: 400
|
269
|
+
message: Bad Request
|
270
|
+
headers:
|
271
|
+
Content-Type:
|
272
|
+
- text/plain; charset=utf-8
|
273
|
+
Date:
|
274
|
+
- Tue, 17 Jun 2014 20:47:07 GMT
|
275
|
+
Content-Length:
|
276
|
+
- '15'
|
277
|
+
body:
|
278
|
+
encoding: UTF-8
|
279
|
+
string: |
|
280
|
+
Pool is closed
|
281
|
+
http_version:
|
282
|
+
recorded_at: Tue, 17 Jun 2014 20:47:07 GMT
|
283
|
+
recorded_with: VCR 2.8.0
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Integration" do
|
4
|
+
it "handles a normal situation correctly" do
|
5
|
+
VCR.use_cassette('integration-1') do
|
6
|
+
c = NoidsClient::Connection.new('http://localhost:13001')
|
7
|
+
expect(c.pool_list).to be_a(Array)
|
8
|
+
expect(c.pool_list).to be_empty
|
9
|
+
p = c.new_pool("abcd", ".sddd")
|
10
|
+
expect(p.name).to eq("abcd")
|
11
|
+
expect(p.template).to eq(".sddd+0")
|
12
|
+
expect(p.closed?).to be_falsy
|
13
|
+
expect(p.ids_used).to eq(0)
|
14
|
+
expect(p.max_ids).to eq(1000)
|
15
|
+
p.advance_past("100")
|
16
|
+
expect(p.ids_used).to eq(101)
|
17
|
+
expect(p.mint(2)).to eq(["101", "102"])
|
18
|
+
p.close
|
19
|
+
expect(p.closed?).to be_truthy
|
20
|
+
expect {p.mint}.to raise_error
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NoidsClient::Pool do
|
4
|
+
it "decodes json" do
|
5
|
+
response = %q{{"Name":"abc","Template":".zeee+0","Used":0,"Max":-1,"Closed":false,"LastMint":"2014-06-16T14:27:19.022553001-04:00"}}
|
6
|
+
rest_resource = double("rest_resource", get: response)
|
7
|
+
pool = NoidsClient::Pool.new(rest_resource)
|
8
|
+
expect(pool.name).to eq("abc")
|
9
|
+
expect(pool.template).to eq(".zeee+0")
|
10
|
+
expect(pool.ids_used).to eq(0)
|
11
|
+
expect(pool.max_ids).to eq(Float::INFINITY)
|
12
|
+
expect(pool.closed?).to be_falsey
|
13
|
+
expect(pool.last_mint_date).to be_a(DateTime)
|
14
|
+
expect(pool.last_mint_date.day).to eq(16)
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'vcr'
|
4
|
+
|
5
|
+
require 'noids_client'
|
6
|
+
|
7
|
+
VCR.configure do |c|
|
8
|
+
c.cassette_library_dir = 'spec/cassettes'
|
9
|
+
c.hook_into :webmock
|
10
|
+
c.configure_rspec_metadata!
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: noids_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Don Brower
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.17'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.17'
|
111
|
+
description: Provides an idiomatic interface to the REST API of a noids server (see
|
112
|
+
https://github.com/dbrower/noids)
|
113
|
+
email:
|
114
|
+
- dbrower@nd.edu
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- lib/noids_client.rb
|
124
|
+
- lib/noids_client/connection.rb
|
125
|
+
- lib/noids_client/pool.rb
|
126
|
+
- lib/noids_client/version.rb
|
127
|
+
- noids_client.gemspec
|
128
|
+
- spec/cassettes/integration-1.yml
|
129
|
+
- spec/lib/integration_spec.rb
|
130
|
+
- spec/lib/pool_spec.rb
|
131
|
+
- spec/spec_helper.rb
|
132
|
+
homepage: https://github.com/ndlib/noids_client
|
133
|
+
licenses:
|
134
|
+
- APACHE2
|
135
|
+
metadata: {}
|
136
|
+
post_install_message:
|
137
|
+
rdoc_options: []
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
requirements: []
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 2.1.11
|
153
|
+
signing_key:
|
154
|
+
specification_version: 4
|
155
|
+
summary: Ruby client for a NOIDS server
|
156
|
+
test_files:
|
157
|
+
- spec/cassettes/integration-1.yml
|
158
|
+
- spec/lib/integration_spec.rb
|
159
|
+
- spec/lib/pool_spec.rb
|
160
|
+
- spec/spec_helper.rb
|
161
|
+
has_rdoc:
|