cartowrap 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +17 -0
- data/lib/cartowrap/api.rb +116 -0
- data/lib/cartowrap/config/spring.rb +1 -0
- data/lib/cartowrap/errors.rb +78 -0
- data/lib/cartowrap/http_service/endpoint.rb +52 -0
- data/lib/cartowrap/http_service/response.rb +15 -0
- data/lib/cartowrap/http_service.rb +25 -0
- data/lib/cartowrap/version.rb +3 -0
- data/lib/cartowrap.rb +23 -0
- data/lib/tasks/cartowrap_tasks.rake +4 -0
- data/spec/cases/api_spec.rb +34 -0
- data/spec/cases/error_spec.rb +116 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/test_app/log/development.log +0 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aec8b6861e9df5308c3a92d3837eb2a2f1327726
|
4
|
+
data.tar.gz: c1393f7b197d66c13f0ea7d6082368032f1f1491
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cae94667afb8b4893d9bfc2f0cad8e8acb56c40121c3e7eaaa1b429f816d9acbecf3a8493ec4acad6011f58f11a4b14721215adbd2ed6d304831af4be3b61912
|
7
|
+
data.tar.gz: a414751fa85250d00a249f93ee724447a2e34e4df521489dd552762443088daf79ddcf81122a77098b86460653de1e7cc46a0499e8e3fd189af0581802afa925
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Miguel Mendoza
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Cartowrap
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'cartowrap'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install cartowrap
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Cartowrap'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
Bundler::GemHelper.install_tasks
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module Cartowrap
|
2
|
+
class API
|
3
|
+
def initialize(api_key = nil, account = nil)
|
4
|
+
@api_key = api_key || Cartowrap.config.api_key
|
5
|
+
@account = account || Cartowrap.config.account
|
6
|
+
@credentials = {}
|
7
|
+
@credentials['api_key'] = @api_key
|
8
|
+
@credentials['account'] = @account
|
9
|
+
@options = OpenStruct.new
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :api_key, :account, :credentials, :options, :response
|
13
|
+
|
14
|
+
def send_query(query)
|
15
|
+
options.endpoint = "sql"
|
16
|
+
options.query_string = true
|
17
|
+
options.q = query
|
18
|
+
result = make_call(options)
|
19
|
+
result
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_synchronizations
|
23
|
+
options.endpoint = "import"
|
24
|
+
options.query_string = false
|
25
|
+
result = make_call(options)
|
26
|
+
result
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_synchronization(import_id)
|
30
|
+
options.endpoint = "import"
|
31
|
+
options.import_id = import_id
|
32
|
+
options.query_string = false
|
33
|
+
options.http_method = 'get'
|
34
|
+
result = make_call(options)
|
35
|
+
result
|
36
|
+
end
|
37
|
+
|
38
|
+
def check_synchronization(import_id)
|
39
|
+
options.endpoint = "import"
|
40
|
+
options.query_string = false
|
41
|
+
options.http_method = 'get'
|
42
|
+
options.resource_id = "#{import_id}/sync_now"
|
43
|
+
result = make_call(options)
|
44
|
+
result
|
45
|
+
end
|
46
|
+
|
47
|
+
def force_synchronization(import_id)
|
48
|
+
options.endpoint = "import"
|
49
|
+
options.query_string = false
|
50
|
+
options.http_method = 'put'
|
51
|
+
options.resource_id = "#{import_id}/sync_now"
|
52
|
+
result = make_call(options)
|
53
|
+
result
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_synchronization(url, interval, sync_options={})
|
57
|
+
validate_sync_options(sync_options) if sync_options
|
58
|
+
options.endpoint = "import"
|
59
|
+
options.type_guessing = sync_options[:type_guessing]
|
60
|
+
options.quoted_fields_guessing = sync_options[:quoted_fields_guessing]
|
61
|
+
options.content_guessing = sync_options[:content_guessing]
|
62
|
+
options.query_string = false
|
63
|
+
options.url = url
|
64
|
+
options.interval = interval
|
65
|
+
options.http_method = 'post'
|
66
|
+
result = make_call(options)
|
67
|
+
result
|
68
|
+
end
|
69
|
+
|
70
|
+
def delete_synchronization(import_id)
|
71
|
+
options.endpoint = "import"
|
72
|
+
options.resource_id = import_id
|
73
|
+
options.query_string = false
|
74
|
+
options.http_method = 'delete'
|
75
|
+
result = make_call(options)
|
76
|
+
result
|
77
|
+
end
|
78
|
+
|
79
|
+
def initialize_options
|
80
|
+
@options = OpenStruct.new
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def validate_sync_options(sync_options)
|
86
|
+
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
|
89
|
+
end
|
90
|
+
|
91
|
+
def make_call(options)
|
92
|
+
result = Cartowrap.make_request(options, credentials)
|
93
|
+
unless check_errors(result.status.to_i, result.body)
|
94
|
+
MultiJson.load("[#{result.body.to_s}]")[0]
|
95
|
+
end
|
96
|
+
initialize_options
|
97
|
+
@response = result.body
|
98
|
+
end
|
99
|
+
|
100
|
+
def check_errors(status, body)
|
101
|
+
case status
|
102
|
+
when 500
|
103
|
+
initialize_options
|
104
|
+
raise Cartowrap::ServerError.new(status, '')
|
105
|
+
when 401
|
106
|
+
initialize_options
|
107
|
+
raise Cartowrap::NoTokenError.new(status, body)
|
108
|
+
when 404
|
109
|
+
initialize_options
|
110
|
+
raise Cartowrap::NotFoundError.new(status, '')
|
111
|
+
else
|
112
|
+
return false
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Spring.applicaiton_root = 'spec/test_app'
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Cartowrap
|
2
|
+
|
3
|
+
class CartowrapError < StandardError; end
|
4
|
+
|
5
|
+
class AppSecretNotDefinedError < ::Cartowrap::CartowrapError; end
|
6
|
+
|
7
|
+
|
8
|
+
class APIError < ::Cartowrap::CartowrapError
|
9
|
+
attr_accessor :cdb_error_type, :cdb_error_code, :cdb_error_subcode, :cdb_error_message,
|
10
|
+
:cdb_error_user_msg, :cdb_error_user_title, :http_status, :response_body
|
11
|
+
|
12
|
+
|
13
|
+
def initialize(http_status, response_body, error_info = nil)
|
14
|
+
if response_body
|
15
|
+
self.response_body = response_body.strip
|
16
|
+
else
|
17
|
+
self.response_body = ''
|
18
|
+
end
|
19
|
+
self.http_status = http_status
|
20
|
+
|
21
|
+
if error_info && error_info.is_a?(String)
|
22
|
+
message = error_info
|
23
|
+
else
|
24
|
+
unless error_info
|
25
|
+
begin
|
26
|
+
error_info = MultiJson.load(response_body)['error'] if response_body
|
27
|
+
rescue
|
28
|
+
end
|
29
|
+
error_info ||= {}
|
30
|
+
end
|
31
|
+
|
32
|
+
self.cdb_error_type = error_info["type"]
|
33
|
+
self.cdb_error_code = error_info["code"]
|
34
|
+
self.cdb_error_subcode = error_info["error_subcode"]
|
35
|
+
self.cdb_error_message = error_info["message"]
|
36
|
+
self.cdb_error_user_msg = error_info["error_user_msg"]
|
37
|
+
self.cdb_error_user_title = error_info["error_user_title"]
|
38
|
+
|
39
|
+
error_array = []
|
40
|
+
%w(type code error_subcode message error_user_title error_user_msg).each do |key|
|
41
|
+
error_array << "#{key}: #{error_info[key]}" if error_info[key]
|
42
|
+
end
|
43
|
+
|
44
|
+
if error_array.empty?
|
45
|
+
message = self.response_body
|
46
|
+
else
|
47
|
+
message = error_array.join(', ')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
message += " [HTTP #{http_status}]" if http_status
|
51
|
+
|
52
|
+
super(message)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Cartodb returned an invalid response body
|
57
|
+
class BadCartodbResponse < APIError; end
|
58
|
+
|
59
|
+
# Cartodb responded with an error while attempting to request an access token
|
60
|
+
class OAuthTokenRequestError < APIError; end
|
61
|
+
|
62
|
+
# Any error with a 5xx HTTP status code
|
63
|
+
class ServerError < APIError; end
|
64
|
+
|
65
|
+
# Any error with a 4xx HTTP status code
|
66
|
+
class ClientError < APIError; end
|
67
|
+
|
68
|
+
# All API authentication failures.
|
69
|
+
class AuthenticationError < ClientError; end
|
70
|
+
|
71
|
+
# not found
|
72
|
+
class NotFoundError < APIError; end
|
73
|
+
|
74
|
+
# not found
|
75
|
+
class NoTokenError < APIError; end
|
76
|
+
|
77
|
+
|
78
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Cartowrap
|
2
|
+
module HTTPService
|
3
|
+
class Endpoint
|
4
|
+
|
5
|
+
attr_reader :options, :credentials
|
6
|
+
|
7
|
+
def initialize(options, credentials = {})
|
8
|
+
@options = options
|
9
|
+
@credentials = credentials
|
10
|
+
end
|
11
|
+
|
12
|
+
def get
|
13
|
+
p options.to_json
|
14
|
+
endpoint = "#{endpoint_uri}#{endpoint_querystring}"
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def endpoint_uri
|
20
|
+
query = options.q if options.q
|
21
|
+
resource = options.resource_id if options.resource_id
|
22
|
+
string = ""
|
23
|
+
api = options.endpoint
|
24
|
+
case api
|
25
|
+
when "sql"
|
26
|
+
string += "/api/v2/sql/?q=#{query}"
|
27
|
+
when "import"
|
28
|
+
string += "/api/v1/synchronizations/"
|
29
|
+
string += "?#{options.query}" if options.query_string && options.query
|
30
|
+
else
|
31
|
+
end
|
32
|
+
string += resource if resource
|
33
|
+
string
|
34
|
+
end
|
35
|
+
|
36
|
+
def endpoint_querystring
|
37
|
+
p options.query_string
|
38
|
+
api_key = credentials["api_key"]
|
39
|
+
string = ''
|
40
|
+
if options.query_string == false
|
41
|
+
string += "?api_key=#{api_key}"
|
42
|
+
else
|
43
|
+
string += "&api_key=#{api_key}"
|
44
|
+
end
|
45
|
+
string
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
Endpoint = HTTPService::Endpoint
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Cartowrap
|
2
|
+
module HTTPService
|
3
|
+
class Response
|
4
|
+
attr_reader :status, :body, :headers
|
5
|
+
|
6
|
+
# Creates a new Response object, which standardizes the response received by Facebook for use within Koala.
|
7
|
+
def initialize(status, body, headers)
|
8
|
+
@status = status
|
9
|
+
@body = body
|
10
|
+
@headers = headers
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
Response = HTTPService::Response
|
15
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'cartowrap/http_service/response'
|
3
|
+
require 'cartowrap/http_service/endpoint'
|
4
|
+
module Cartowrap
|
5
|
+
module HTTPService
|
6
|
+
class << self
|
7
|
+
end
|
8
|
+
def self.make_request(options, credentials={})
|
9
|
+
http_method = options.http_method&.to_sym || :get
|
10
|
+
account = credentials["account"]
|
11
|
+
endpoint = Endpoint.new(options, credentials).get
|
12
|
+
con = Faraday.new(:url => "https://#{account}.cartodb.com") do |faraday|
|
13
|
+
faraday.request :multipart
|
14
|
+
faraday.response :logger
|
15
|
+
faraday.adapter Faraday.default_adapter
|
16
|
+
end
|
17
|
+
response = con.send(http_method) do |req|
|
18
|
+
req.url "#{endpoint}"
|
19
|
+
req.headers['Content-Type'] = 'application/json' if options.http_method == 'post' || options.http_method == 'put'
|
20
|
+
req.body = options.marshal_dump.to_json if options.http_method == 'post' || options.http_method == 'put'
|
21
|
+
end
|
22
|
+
Cartowrap::HTTPService::Response.new(response.status.to_i, response.body, response.headers)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/cartowrap.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
require 'cartowrap/api'
|
3
|
+
require 'cartowrap/http_service'
|
4
|
+
require 'cartowrap/errors'
|
5
|
+
require 'ostruct'
|
6
|
+
module Cartowrap
|
7
|
+
class << self
|
8
|
+
attr_accessor :http_service, :config
|
9
|
+
def configure
|
10
|
+
yield config
|
11
|
+
end
|
12
|
+
def config
|
13
|
+
@config ||= OpenStruct.new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
def self.http_service=(service)
|
17
|
+
@http_service = service
|
18
|
+
end
|
19
|
+
def self.make_request(options, credentials = {})
|
20
|
+
http_service.make_request(options, credentials)
|
21
|
+
end
|
22
|
+
self.http_service = HTTPService
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe "Cartowrap::API" do
|
3
|
+
before(:each) do
|
4
|
+
@service = Cartowrap::API.new()
|
5
|
+
end
|
6
|
+
it "makes query requests" do
|
7
|
+
expect(Cartowrap).to receive(:make_request).and_return(Cartowrap::HTTPService::Response.new(200, "", ""))
|
8
|
+
@service.send_query('anything')
|
9
|
+
end
|
10
|
+
it "gets synchronizations index" do
|
11
|
+
expect(Cartowrap).to receive(:make_request).and_return(Cartowrap::HTTPService::Response.new(200, "", ""))
|
12
|
+
@service.get_synchronizations
|
13
|
+
end
|
14
|
+
it "gets one synchronization" do
|
15
|
+
expect(Cartowrap).to receive(:make_request).and_return(Cartowrap::HTTPService::Response.new(200, "", ""))
|
16
|
+
@service.get_synchronization("import_id")
|
17
|
+
end
|
18
|
+
it "checks for synchronization status" do
|
19
|
+
expect(Cartowrap).to receive(:make_request).and_return(Cartowrap::HTTPService::Response.new(200, "", ""))
|
20
|
+
@service.check_synchronization("import_id")
|
21
|
+
end
|
22
|
+
it "forces a synchronization" do
|
23
|
+
expect(Cartowrap).to receive(:make_request).and_return(Cartowrap::HTTPService::Response.new(200, "", ""))
|
24
|
+
@service.force_synchronization("import_id")
|
25
|
+
end
|
26
|
+
it "creates a synchronization" do
|
27
|
+
expect(Cartowrap).to receive(:make_request).and_return(Cartowrap::HTTPService::Response.new(200, "", ""))
|
28
|
+
@service.create_synchronization("url", 900)
|
29
|
+
end
|
30
|
+
it "deletes a synchronization" do
|
31
|
+
expect(Cartowrap).to receive(:make_request).and_return(Cartowrap::HTTPService::Response.new(200, "", ""))
|
32
|
+
@service.delete_synchronization("import_id")
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'cartowrap'
|
3
|
+
describe Cartowrap::APIError do
|
4
|
+
it "is a Cartowrap::CartowrapError" do
|
5
|
+
expect(Cartowrap::APIError.new(nil, nil)).to be_a(Cartowrap::CartowrapError)
|
6
|
+
end
|
7
|
+
|
8
|
+
[:cdb_error_type, :cdb_error_code, :cdb_error_subcode, :cdb_error_message, :cdb_error_user_msg, :cdb_error_user_title, :http_status, :response_body].each do |accessor|
|
9
|
+
it "has an accessor for #{accessor}" do
|
10
|
+
expect(Cartowrap::APIError.instance_methods.map(&:to_sym)).to include(accessor)
|
11
|
+
expect(Cartowrap::APIError.instance_methods.map(&:to_sym)).to include(:"#{accessor}=")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it "sets http_status to the provided status" do
|
16
|
+
error_response = '{ "error": {"type": "foo", "other_details": "bar"} }'
|
17
|
+
expect(Cartowrap::APIError.new(400, error_response).response_body).to eq(error_response)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "sets response_body to the provided response body" do
|
21
|
+
expect(Cartowrap::APIError.new(400, '').http_status).to eq(400)
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with an error_info hash" do
|
25
|
+
let(:error) {
|
26
|
+
error_info = {
|
27
|
+
'type' => 'type',
|
28
|
+
'message' => 'message',
|
29
|
+
'code' => 1,
|
30
|
+
'error_subcode' => 'subcode',
|
31
|
+
'error_user_msg' => 'error user message',
|
32
|
+
'error_user_title' => 'error user title'
|
33
|
+
}
|
34
|
+
Cartowrap::APIError.new(400, '', error_info)
|
35
|
+
}
|
36
|
+
|
37
|
+
{
|
38
|
+
:cdb_error_type => 'type',
|
39
|
+
:cdb_error_message => 'message',
|
40
|
+
:cdb_error_code => 1,
|
41
|
+
:cdb_error_subcode => 'subcode',
|
42
|
+
:cdb_error_user_msg => 'error user message',
|
43
|
+
:cdb_error_user_title => 'error user title'
|
44
|
+
}.each_pair do |accessor, value|
|
45
|
+
it "sets #{accessor} to #{value}" do
|
46
|
+
expect(error.send(accessor)).to eq(value)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "sets the error message appropriately" do
|
51
|
+
expect(error.message).to eq("type: type, code: 1, error_subcode: subcode, message: message, error_user_title: error user title, error_user_msg: error user message [HTTP 400]")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with an error_info string" do
|
56
|
+
it "sets the error message \"error_info [HTTP http_status]\"" do
|
57
|
+
error_info = "Cartodb is down."
|
58
|
+
error = Cartowrap::APIError.new(400, '', error_info)
|
59
|
+
expect(error.message).to eq("Cartodb is down. [HTTP 400]")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "with no error_info and a response_body containing error JSON" do
|
64
|
+
it "should extract the error info from the response body" do
|
65
|
+
response_body = '{ "error": { "type": "type", "message": "message", "code": 1, "error_subcode": "subcode", "error_user_msg": "error user message", "error_user_title": "error user title" } }'
|
66
|
+
error = Cartowrap::APIError.new(400, response_body)
|
67
|
+
{
|
68
|
+
:cdb_error_type => 'type',
|
69
|
+
:cdb_error_message => 'message',
|
70
|
+
:cdb_error_code => 1,
|
71
|
+
:cdb_error_subcode => 'subcode',
|
72
|
+
:cdb_error_user_msg => 'error user message',
|
73
|
+
:cdb_error_user_title => 'error user title'
|
74
|
+
}.each_pair do |accessor, value|
|
75
|
+
expect(error.send(accessor)).to eq(value)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
describe Cartowrap::CartowrapError do
|
83
|
+
it "is a StandardError" do
|
84
|
+
expect(Cartowrap::CartowrapError.new).to be_a(StandardError)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe Cartowrap::BadCartodbResponse do
|
89
|
+
it "is a Cartowrap::APIError" do
|
90
|
+
expect(Cartowrap::BadCartodbResponse.new(nil, nil)).to be_a(Cartowrap::APIError)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe Cartowrap::OAuthTokenRequestError do
|
95
|
+
it "is a Cartowrap::APIError" do
|
96
|
+
expect(Cartowrap::OAuthTokenRequestError.new(nil, nil)).to be_a(Cartowrap::APIError)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe Cartowrap::ServerError do
|
101
|
+
it "is a Cartowrap::APIError" do
|
102
|
+
expect(Cartowrap::ServerError.new(nil, nil)).to be_a(Cartowrap::APIError)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe Cartowrap::ClientError do
|
107
|
+
it "is a Cartowrap::APIError" do
|
108
|
+
expect(Cartowrap::ClientError.new(nil, nil)).to be_a(Cartowrap::APIError)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe Cartowrap::AuthenticationError do
|
113
|
+
it "is a Cartowrap::ClientError" do
|
114
|
+
expect(Cartowrap::AuthenticationError.new(nil, nil)).to be_a(Cartowrap::ClientError)
|
115
|
+
end
|
116
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.expect_with :rspec do |expectations|
|
6
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
7
|
+
end
|
8
|
+
|
9
|
+
config.mock_with :rspec do |mocks|
|
10
|
+
mocks.verify_partial_doubles = true
|
11
|
+
end
|
12
|
+
end
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cartowrap
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vizzuality
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec-core
|
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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-expectations
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-mocks
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: multi_json
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Provides a common interface for some CartoDB functions.
|
98
|
+
email:
|
99
|
+
- info@vizzuality.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- MIT-LICENSE
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- lib/cartowrap.rb
|
108
|
+
- lib/cartowrap/api.rb
|
109
|
+
- lib/cartowrap/config/spring.rb
|
110
|
+
- lib/cartowrap/errors.rb
|
111
|
+
- lib/cartowrap/http_service.rb
|
112
|
+
- lib/cartowrap/http_service/endpoint.rb
|
113
|
+
- lib/cartowrap/http_service/response.rb
|
114
|
+
- lib/cartowrap/version.rb
|
115
|
+
- lib/tasks/cartowrap_tasks.rake
|
116
|
+
- spec/cases/api_spec.rb
|
117
|
+
- spec/cases/error_spec.rb
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
- spec/test_app/log/development.log
|
120
|
+
homepage: http://vizzuality.com
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.5.1
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: A simple CartoDB wrapper.
|
144
|
+
test_files:
|
145
|
+
- spec/test_app/log/development.log
|
146
|
+
- spec/cases/api_spec.rb
|
147
|
+
- spec/cases/error_spec.rb
|
148
|
+
- spec/spec_helper.rb
|