cartowrap 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +55 -5
- data/Rakefile +4 -10
- data/lib/cartowrap/api.rb +19 -12
- data/lib/cartowrap/version.rb +1 -1
- data/spec/cases/api_spec.rb +34 -0
- data/spec/spec_helper.rb +2 -2
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7a1d35830b95c2bff443958669b6fa4a5954a0b
|
4
|
+
data.tar.gz: 4725acd39fcc184460cc49176f2f99c0db271fd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7aa60cc0ed1b3f3bf4bd8ac8e9d26b0442341c16e92ba90dd82d25af9c72354bd4ed62bd01425683efed6942a6eaf9befaa7e95ac58b4aeba72b63a1efab1c84
|
7
|
+
data.tar.gz: fe08cc252591656441c6351a9a45525ede23c3bff3295da63a6ee91b2a9a06c00d0be6e7ec1d753edf33fa58df557b3d5083510ae0abcc5c4bf743ef94c78abb
|
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Cartowrap
|
2
|
-
Short description and motivation.
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/Vizzuality/cartowrap.svg?branch=master)](https://travis-ci.org/Vizzuality/cartowrap)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/Vizzuality/cartowrap/badges/gpa.svg)](https://codeclimate.com/github/Vizzuality/cartowrap)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/Vizzuality/cartowrap/badges/coverage.svg)](https://codeclimate.com/github/Vizzuality/cartowrap/coverage)
|
6
|
+
|
7
|
+
This gem provides a simple wrapper for Cartodb SQL and Sync API. More features coming soon.
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
Add this line to your application's Gemfile:
|
@@ -13,7 +15,7 @@ gem 'cartowrap'
|
|
13
15
|
|
14
16
|
And then execute:
|
15
17
|
```bash
|
16
|
-
$ bundle
|
18
|
+
$ bundle install
|
17
19
|
```
|
18
20
|
|
19
21
|
Or install it yourself as:
|
@@ -21,8 +23,56 @@ Or install it yourself as:
|
|
21
23
|
$ gem install cartowrap
|
22
24
|
```
|
23
25
|
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'cartowrap'
|
30
|
+
api = Cartowrap::API.new(your_api_key, your_account)
|
31
|
+
api.send_query('select * from country_isos')
|
32
|
+
country_ison = JSON.parse(api.response)
|
33
|
+
```
|
34
|
+
|
35
|
+
### Usage with Rails
|
36
|
+
|
37
|
+
See also [Cartomodel](https://github.com/Vizzuality/cartomodel) for Activerecord integration
|
38
|
+
|
39
|
+
You can configure Cartowrap in an initializer
|
40
|
+
```ruby
|
41
|
+
#config/initializers/cartowrap.rb
|
42
|
+
require 'cartowrap'
|
43
|
+
Cartowrap.configure do |config|
|
44
|
+
config.account = your_cartodb_account
|
45
|
+
config.api_key = your_api_key
|
46
|
+
end
|
47
|
+
|
48
|
+
# Any other place in your code
|
49
|
+
api_call = Cartowrap::API.new
|
50
|
+
```
|
51
|
+
|
52
|
+
## Current methods
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
send_query(query)
|
56
|
+
get_synchronizations
|
57
|
+
get_synchronization(import_id)
|
58
|
+
check_synchronization(import_id)
|
59
|
+
force_synchronization(import_id)
|
60
|
+
create_synchronization(url, interval, sync_options={})
|
61
|
+
delete_synchronization(import_id)
|
62
|
+
```
|
63
|
+
|
64
|
+
## Config reference
|
65
|
+
|
66
|
+
If you want to use the gem in dry run mode (no calls actually made to the CartoDB API), set:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
Cartowrap.configure do |config|
|
70
|
+
config.dry_run = true
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
24
74
|
## Contributing
|
25
|
-
|
75
|
+
Feel free to contribute pull requests are welcome.
|
26
76
|
|
27
77
|
## License
|
28
78
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
@@ -4,14 +4,8 @@ rescue LoadError
|
|
4
4
|
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
5
|
end
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
rdoc.title = 'Cartowrap'
|
12
|
-
rdoc.options << '--line-numbers'
|
13
|
-
rdoc.rdoc_files.include('README.md')
|
14
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
7
|
+
task :default => [:spec]
|
8
|
+
desc 'run Rspec specs'
|
9
|
+
task :spec do
|
10
|
+
sh 'rspec'
|
15
11
|
end
|
16
|
-
|
17
|
-
Bundler::GemHelper.install_tasks
|
data/lib/cartowrap/api.rb
CHANGED
@@ -3,6 +3,7 @@ module Cartowrap
|
|
3
3
|
def initialize(api_key = nil, account = nil)
|
4
4
|
@api_key = api_key || Cartowrap.config.api_key
|
5
5
|
@account = account || Cartowrap.config.account
|
6
|
+
@dry_run = Cartowrap.config.dry_run || false
|
6
7
|
@credentials = {}
|
7
8
|
@credentials['api_key'] = @api_key
|
8
9
|
@credentials['account'] = @account
|
@@ -84,11 +85,13 @@ module Cartowrap
|
|
84
85
|
|
85
86
|
def validate_sync_options(sync_options)
|
86
87
|
valid_options = [:type_guessing, :quoted_fields_guessing, :content_guessing]
|
87
|
-
sync_options = sync_options.map{|o| ((valid_options.include? o[0]) && !!o[1] == o[1]) ? o : nil}.compact.to_h
|
88
|
+
sync_options = sync_options.map { |o| ((valid_options.include? o[0]) && !!o[1] == o[1]) ? o : nil }.compact.to_h
|
88
89
|
sync_options
|
89
90
|
end
|
90
91
|
|
91
92
|
def make_call(options)
|
93
|
+
return fake_response if @dry_run
|
94
|
+
|
92
95
|
result = Cartowrap.make_request(options, credentials)
|
93
96
|
unless check_errors(result.status.to_i, result.body)
|
94
97
|
MultiJson.load("[#{result.body.to_s}]")[0]
|
@@ -99,18 +102,22 @@ module Cartowrap
|
|
99
102
|
|
100
103
|
def check_errors(status, body)
|
101
104
|
case status
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
105
|
+
when 500
|
106
|
+
initialize_options
|
107
|
+
raise Cartowrap::ServerError.new(status, '')
|
108
|
+
when 401
|
109
|
+
initialize_options
|
110
|
+
raise Cartowrap::NoTokenError.new(status, body)
|
111
|
+
when 404
|
112
|
+
initialize_options
|
113
|
+
raise Cartowrap::NotFoundError.new(status, '')
|
114
|
+
else
|
115
|
+
return false
|
113
116
|
end
|
114
117
|
end
|
118
|
+
|
119
|
+
def fake_response
|
120
|
+
Cartowrap::HTTPService::Response.new(200, "", "")
|
121
|
+
end
|
115
122
|
end
|
116
123
|
end
|
data/lib/cartowrap/version.rb
CHANGED
data/spec/cases/api_spec.rb
CHANGED
@@ -32,3 +32,37 @@ describe "Cartowrap::API" do
|
|
32
32
|
@service.delete_synchronization("import_id")
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
describe "Cartowrap::API" do
|
39
|
+
before(:each) do
|
40
|
+
Cartowrap.config.dry_run = true
|
41
|
+
@service = Cartowrap::API.new()
|
42
|
+
end
|
43
|
+
it "dry runs query requests" do
|
44
|
+
expect(Cartowrap).to_not receive(:make_request)
|
45
|
+
@service.send_query('anything')
|
46
|
+
end
|
47
|
+
it "dry runs synchronizations requests" do
|
48
|
+
expect(Cartowrap).to_not receive(:make_request)
|
49
|
+
@service.get_synchronizations
|
50
|
+
end
|
51
|
+
it "dry runs checks for synchronization status" do
|
52
|
+
expect(Cartowrap).to_not receive(:make_request)
|
53
|
+
@service.check_synchronization("import_id")
|
54
|
+
end
|
55
|
+
it "dry runs synchronization forces" do
|
56
|
+
expect(Cartowrap).to_not receive(:make_request)
|
57
|
+
@service.force_synchronization("import_id")
|
58
|
+
end
|
59
|
+
it "dry runs synchronization creates" do
|
60
|
+
expect(Cartowrap).to_not receive(:make_request)
|
61
|
+
@service.create_synchronization("url", 900)
|
62
|
+
end
|
63
|
+
it "dry runs synchronization delete" do
|
64
|
+
expect(Cartowrap).to_not receive(:make_request)
|
65
|
+
@service.delete_synchronization("import_id")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cartowrap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vizzuality
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rspec-core
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,7 +67,7 @@ dependencies:
|
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: codeclimate-test-reporter
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|