citysdk 0.1.2.5 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +33 -0
- data/Gemfile.lock +27 -21
- data/README.md +55 -33
- data/bin/csdk +1220 -0
- data/citysdk.gemspec +6 -5
- data/examples/simple_api.rb +68 -0
- data/lib/citysdk/api.rb +105 -105
- data/lib/citysdk/file_reader.rb +195 -120
- data/lib/citysdk/importer.rb +36 -113
- data/lib/citysdk/util.rb +26 -4
- data/lib/citysdk.rb +1 -1
- data/spec/api_spec.rb +41 -34
- data/spec/import_spec.rb +40 -75
- metadata +40 -24
- data/b.sh +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 969313e0796217d8f9e3ec407c477a01b8a83e26
|
4
|
+
data.tar.gz: 4d06bd0a1e14fefdd92699b80733d35b7747f2aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da86200998e771230aecbcb3027af48ce77d23190898dfb9a1b9a57865e15221833c5b16d4cb038a2e10af2f9ca9e4235b9ceba61bcf7f44385ad6f6a5652a6d
|
7
|
+
data.tar.gz: fe3e3978db2a0f0eab25d9ee109873fcc56a81fa865a8cd1f203b46878aa05dbd7cf194a7184bf4c6cdc5e364176a9258c0682db339dac0244b50d573e78a344
|
data/.gitignore
CHANGED
@@ -1 +1,34 @@
|
|
1
1
|
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/lib/bundler/man/
|
26
|
+
|
27
|
+
# for a library or gem, you might want to ignore these files since the code is
|
28
|
+
# intended to run in multiple environments; otherwise, check them in:
|
29
|
+
# Gemfile.lock
|
30
|
+
# .ruby-version
|
31
|
+
# .ruby-gemset
|
32
|
+
|
33
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
34
|
+
.rvmrc
|
data/Gemfile.lock
CHANGED
@@ -1,32 +1,38 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
citysdk (
|
5
|
-
charlock_holmes (
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
citysdk (1.0)
|
5
|
+
charlock_holmes (~> 0.6)
|
6
|
+
curses (~> 1.0)
|
7
|
+
dbf (~> 2.0)
|
8
|
+
faraday (~> 0.8)
|
9
|
+
georuby (~> 2.0)
|
9
10
|
|
10
11
|
GEM
|
11
12
|
remote: https://rubygems.org/
|
12
13
|
specs:
|
13
|
-
charlock_holmes (0.
|
14
|
-
|
14
|
+
charlock_holmes (0.7.3)
|
15
|
+
curses (1.0.1)
|
16
|
+
dbf (2.0.7)
|
15
17
|
fastercsv (~> 1.5.4)
|
16
|
-
diff-lcs (1.2.
|
17
|
-
faraday (0.
|
18
|
-
multipart-post (
|
18
|
+
diff-lcs (1.2.5)
|
19
|
+
faraday (0.9.0)
|
20
|
+
multipart-post (>= 1.2, < 3)
|
19
21
|
fastercsv (1.5.5)
|
20
|
-
georuby (2.
|
21
|
-
multipart-post (
|
22
|
-
rspec (
|
23
|
-
rspec-core (~>
|
24
|
-
rspec-expectations (~>
|
25
|
-
rspec-mocks (~>
|
26
|
-
rspec-core (
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
georuby (2.2.1)
|
23
|
+
multipart-post (2.0.0)
|
24
|
+
rspec (3.0.0)
|
25
|
+
rspec-core (~> 3.0.0)
|
26
|
+
rspec-expectations (~> 3.0.0)
|
27
|
+
rspec-mocks (~> 3.0.0)
|
28
|
+
rspec-core (3.0.2)
|
29
|
+
rspec-support (~> 3.0.0)
|
30
|
+
rspec-expectations (3.0.2)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.0.0)
|
33
|
+
rspec-mocks (3.0.2)
|
34
|
+
rspec-support (~> 3.0.0)
|
35
|
+
rspec-support (3.0.2)
|
30
36
|
|
31
37
|
PLATFORMS
|
32
38
|
ruby
|
@@ -36,4 +42,4 @@ DEPENDENCIES
|
|
36
42
|
citysdk!
|
37
43
|
faraday
|
38
44
|
georuby
|
39
|
-
rspec
|
45
|
+
rspec (~> 3.0)
|
data/README.md
CHANGED
@@ -1,47 +1,69 @@
|
|
1
|
-
#
|
1
|
+
# CitySDK GEM
|
2
2
|
|
3
|
-
The CitySDK gem encapulates the
|
4
|
-
The CitySDK API is part of an (open)data distribution platform developed in the EU CitySDK program by [Waag Society](http://waag.org).
|
5
|
-
Find the platform itself on [github](https://github.com/waagsociety/citysdk),
|
3
|
+
The CitySDK gem encapulates the CitySDK LD-API, and offers high-level file import functionalities.
|
4
|
+
The CitySDK LD-API is part of an (open)data distribution platform developed in the EU CitySDK program by [Waag Society](http://waag.org).
|
5
|
+
Find the platform itself on [github](https://github.com/waagsociety/citysdk-ld), background is [here](http://dev.citysdk.waag.org).
|
6
|
+
|
7
|
+
In order to best get an overview of the way to use the GEM to import files into the CitySDK LD-API, have a look at the 'admr' importer for the top-level administrative regions in the Netherlands.
|
8
|
+
The data consists of three ESRI shape files; the importer is well commented, explaining most of the possibilities of the GEM.
|
9
|
+
Please download the importer [here](https://github.com/waagsociety/citysdk-amsterdam/tree/master/importers/admr)
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
To install it just install the gem:
|
14
|
+
|
15
|
+
gem install citysdk
|
16
|
+
|
17
|
+
If you're using Bundler, add the gem to Gemfile.
|
18
|
+
|
19
|
+
gem 'citysdk'
|
20
|
+
|
21
|
+
Then run `bundle install`.
|
6
22
|
|
7
23
|
|
8
24
|
## Usage
|
25
|
+
The GEM can be used on two different levels, either simply as a wrapper around the API, or as a means to read, convert and import various types of data files.
|
26
|
+
The gem exposes it's functionality through three different objects:
|
27
|
+
|
28
|
+
- CitySDK::API
|
29
|
+
- CitySDK::FileReader
|
30
|
+
- CitySDK::Importer
|
31
|
+
|
32
|
+
The FileReader can be used stand-alone to read, edit and save data files, the Importer builds on the FileReader and API objects.
|
33
|
+
|
34
|
+
The FileReader has support for CSV, Shape and (Geo)Json files. XML is currently not supported; we recommend [OpenRefine](https://github.com/OpenRefine/OpenRefine/wiki/Downloads) to convert these to either CSV or JSON.
|
35
|
+
|
36
|
+
|
37
|
+
### CitySDK::API Usage
|
38
|
+
|
9
39
|
|
10
|
-
|
11
|
-
|
12
|
-
|
40
|
+
CALL | Description
|
41
|
+
|:-------------------------------------|:-------------------------------------------------------
|
42
|
+
`@api = CitySDK::API.new('<endpoint IP>')` | Establish a link to the particular endpoint
|
43
|
+
`@api.authenticate('<name>','<password>')` | For reading this is not necessary, for writing and deleting you need to authenticate. The authentication times out if not used (is reset by writing to the API). This call takes an optional block for immediate automatic release when the block has been called.
|
44
|
+
`@api.get path` | Simply issue a 'GET' against the API; the results are returned as a ruby Hash.
|
45
|
+
`@api.put path,data` | PUT a resource; see [Documentation](https://github.com/waagsociety/citysdk-ld/wiki/Objects)
|
46
|
+
`@api.post path,data` | POST a resource; see [Documentation](https://github.com/waagsociety/citysdk-ld/wiki/Objects)
|
47
|
+
`@api.patch path,data` | PATCH a resource; see [Documentation](https://github.com/waagsociety/citysdk-ld/wiki/Objects)
|
48
|
+
`@api.delete path` | Issue a DELETE to the API; path points to the resource to delete. Requires authentication.
|
49
|
+
`@api.release` | This call will flush any buffered object that were scheduled to be created or updated. See also batch_size, below.
|
50
|
+
`@api.set_layer(layername)` | Set the the layer for subsequent 'create_object' calls. User must be authenticate for this layer in order to sucesfully create objects.
|
51
|
+
`@api.create_object(objhash)` | Adds an object to the database. See also batch_size, below.
|
52
|
+
`@api.layers` | Shortcut for `get '/layers'`
|
53
|
+
`@api.owners` | Shortcut for `get '/owners'`
|
54
|
+
`@api.objects(layer=nil)` | Shortcut for `get '/objects'`. When a layer name is supplied, returns only objects from with data on this layer, and the layerdata itself.
|
55
|
+
`@api.next` | When more results are available, returns the next page.
|
56
|
+
`@api.format = <format>` | Specify the output format. Currently supported are (Geo)JSON and (Geo)JSON-LD.
|
57
|
+
`@api.page_size = <page_size>` | Specify the number of features returned; default is 25.
|
58
|
+
`@api.batch_size = <n>` | When adding objects thorugh 'create_object', they are buffered until '<n>' objects are available, then a single call is issuesd to the API.
|
59
|
+
`@api.last_result` | Returns a Hash with the last HTTP status and the headers returned from the last call.
|
13
60
|
|
14
|
-
api = CitySDK::API.new('api.citysdk.waag.org')
|
15
61
|
|
16
|
-
# simple GET
|
17
|
-
# GET requests do not need authentication
|
18
|
-
first10layers = api.get('/layers')
|
19
|
-
puts "Number of layers: #{first10layers[:record_count]}"
|
20
|
-
puts "First layer: #{JSON.pretty_generate(first10layers[:results][0])}"
|
21
|
-
|
22
62
|
|
23
|
-
# authenticate for write actions.
|
24
|
-
exit if not api.authenticate(<email>,<passw>)
|
25
63
|
|
26
|
-
# make a layer
|
27
|
-
# when you own the 'my' top level layer domain:
|
28
|
-
@api.put('/layers',{:data => {
|
29
|
-
:name => 'my.layer',
|
30
|
-
:description => 'for testing',
|
31
|
-
:organization => 'me',
|
32
|
-
:category => 'civic.test'
|
33
|
-
}})
|
34
64
|
|
35
|
-
# add data to this layer
|
36
|
-
# attach to the node representing the city of Rotterdam
|
37
|
-
api.put('/admr.nl.rotterdam/my.layer', {:data => {:key1=>'value1', :key2=>10}})
|
38
65
|
|
39
66
|
|
40
|
-
...
|
41
|
-
|
42
|
-
# don't forget to release! this will also send 'unfilled' batches to the backend.
|
43
|
-
api.release
|
44
|
-
|
45
67
|
|
46
68
|
## Contributing
|
47
69
|
|
@@ -49,4 +71,4 @@ Find the platform itself on [github](https://github.com/waagsociety/citysdk), pl
|
|
49
71
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
72
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
73
|
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
-
5. Create new Pull Request
|
74
|
+
5. Create new Pull Request
|