cartodb-rb-client-rails-322 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.rvmrc +1 -0
- data/.travis.yml +15 -0
- data/Gemfile +15 -0
- data/LICENSE +28 -0
- data/README.markdown +365 -0
- data/Rakefile +10 -0
- data/cartodb-rb-client.gemspec +34 -0
- data/lib/cartodb-rb-client.rb +18 -0
- data/lib/cartodb-rb-client/cartodb.rb +6 -0
- data/lib/cartodb-rb-client/cartodb/client.rb +4 -0
- data/lib/cartodb-rb-client/cartodb/client/authorization.rb +92 -0
- data/lib/cartodb-rb-client/cartodb/client/cache.rb +14 -0
- data/lib/cartodb-rb-client/cartodb/client/connection.rb +4 -0
- data/lib/cartodb-rb-client/cartodb/client/connection/base.rb +44 -0
- data/lib/cartodb-rb-client/cartodb/client/connection/cartodb.rb +280 -0
- data/lib/cartodb-rb-client/cartodb/client/connection/postgres.rb +255 -0
- data/lib/cartodb-rb-client/cartodb/client/error.rb +68 -0
- data/lib/cartodb-rb-client/cartodb/client/utils.rb +20 -0
- data/lib/cartodb-rb-client/cartodb/helpers.rb +1 -0
- data/lib/cartodb-rb-client/cartodb/helpers/sql_helper.rb +36 -0
- data/lib/cartodb-rb-client/cartodb/init.rb +30 -0
- data/lib/cartodb-rb-client/cartodb/libs.rb +2 -0
- data/lib/cartodb-rb-client/cartodb/libs/object.rb +15 -0
- data/lib/cartodb-rb-client/cartodb/libs/string.rb +116 -0
- data/lib/cartodb-rb-client/cartodb/model.rb +11 -0
- data/lib/cartodb-rb-client/cartodb/model/base.rb +20 -0
- data/lib/cartodb-rb-client/cartodb/model/constants.rb +30 -0
- data/lib/cartodb-rb-client/cartodb/model/defaults.rb +15 -0
- data/lib/cartodb-rb-client/cartodb/model/geo.rb +101 -0
- data/lib/cartodb-rb-client/cartodb/model/getters.rb +75 -0
- data/lib/cartodb-rb-client/cartodb/model/persistence.rb +69 -0
- data/lib/cartodb-rb-client/cartodb/model/query.rb +66 -0
- data/lib/cartodb-rb-client/cartodb/model/schema.rb +121 -0
- data/lib/cartodb-rb-client/cartodb/model/scope.rb +163 -0
- data/lib/cartodb-rb-client/cartodb/model/setters.rb +37 -0
- data/lib/cartodb-rb-client/cartodb/types.rb +2 -0
- data/lib/cartodb-rb-client/cartodb/types/metadata.rb +97 -0
- data/lib/cartodb-rb-client/cartodb/types/pg_result.rb +17 -0
- data/lib/cartodb-rb-client/install_utils.rb +19 -0
- data/lib/cartodb-rb-client/version.rb +7 -0
- data/run_tests.sh +6 -0
- data/spec/client_spec.rb +357 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_add_and_remove_colums_in_a_previously_created_table.yml +635 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_allow_reserved_words_in_columns_names.yml +284 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_change_a_previously_created_column.yml +362 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_create_a_table_and_get_its_table_definition.yml +1634 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_create_a_table_forcing_the_schema_and_get_its_table_definition.yml +298 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_create_a_table_from_a_csv_file.yml +2947 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_create_a_table_with_MULTILINESTRING_type_geometry.yml +299 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_create_a_table_with_MULTIPOLYGON_type_geometry.yml +298 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_create_a_table_with_POINT_type_geometry.yml +580 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_delete_a_table_s_row.yml +410 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_drop_a_table.yml +380 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_escape_properly_input_data_in_insert_queries.yml +295 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_execute_a_select_query_and_return_results.yml +987 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_get_a_table_by_its_name.yml +298 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_import_any_kind_of_data_file.yml +6951 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_insert_a_row_in_a_table.yml +357 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_paginate_records.yml +3642 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_rename_an_existing_table.yml +299 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_return_errors_on_invalid_queries.yml +132 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_return_nil_when_requesting_a_table_which_does_not_exists.yml +218 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_return_user_s_table_list.yml +244 -0
- data/spec/fixtures/cassettes/CartoDB_client/should_update_a_row_in_a_table.yml +347 -0
- data/spec/fixtures/cassettes/CartoDB_model_data_methods/should_destroy_a_previously_created_record.yml +1920 -0
- data/spec/fixtures/cassettes/CartoDB_model_data_methods/should_initialize_attributes_of_the_model_without_persisting_them.yml +963 -0
- data/spec/fixtures/cassettes/CartoDB_model_data_methods/should_persist_into_cartodb_using_the_save_method.yml +1946 -0
- data/spec/fixtures/cassettes/CartoDB_model_data_methods/should_persist_into_cartodb_using_the_static_create_method.yml +1796 -0
- data/spec/fixtures/cassettes/CartoDB_model_data_methods/should_save_polygons_in_different_formats.yml +1801 -0
- data/spec/fixtures/cassettes/CartoDB_model_data_methods/should_update_an_existing_record.yml +2856 -0
- data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_add_more_columns_if_the_table_previously_exists.yml +1509 -0
- data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_contain_an_array_of_columns.yml +2007 -0
- data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_create_a_table_with_custom_name_if_specified.yml +357 -0
- data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_create_model_with_custom_data_types_columns.yml +565 -0
- data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_create_model_with_polygon_type_geometry_columns.yml +493 -0
- data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_create_the_table_in_cartodb_if_it_doesn_t_exists.yml +1048 -0
- data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_have_a_valid_CartoDB_Client_instance_as_a_connection_object.yml +971 -0
- data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_have_a_valid_table_name.yml +970 -0
- data/spec/fixtures/cassettes/CartoDB_model_metadata_methods/should_return_only_data_columns.yml +1096 -0
- data/spec/fixtures/cassettes/CartoDB_model_scopes/should_allow_to_select_the_specified_fiels.yml +25828 -0
- data/spec/fixtures/cassettes/CartoDB_model_scopes/should_count_all_records.yml +22401 -0
- data/spec/fixtures/cassettes/CartoDB_model_scopes/should_find_a_record_by_its_id.yml +21852 -0
- data/spec/fixtures/cassettes/CartoDB_model_scopes/should_order_results.yml +23701 -0
- data/spec/fixtures/cassettes/CartoDB_model_scopes/should_paginate_results.yml +35644 -0
- data/spec/fixtures/cassettes/CartoDB_model_scopes/should_return_all_records_paginated.yml +23699 -0
- data/spec/fixtures/cassettes/CartoDB_model_scopes/should_search_records_by_certain_filters.yml +7080 -0
- data/spec/fixtures/cassettes/cartodb_spec_models.yml +3409 -0
- data/spec/fixtures/cassettes/clean_tables.yml +224 -0
- data/spec/model/data_spec.rb +157 -0
- data/spec/model/metadata_spec.rb +124 -0
- data/spec/model/scopes_spec.rb +171 -0
- data/spec/model_specs_helper.rb +2 -0
- data/spec/spec_helper.rb +54 -0
- data/spec/support/cartodb_config.yml +11 -0
- data/spec/support/cartodb_config.yml.sample +16 -0
- data/spec/support/cartodb_factories.rb +33 -0
- data/spec/support/cartodb_helpers.rb +14 -0
- data/spec/support/cartodb_models.rb +29 -0
- data/spec/support/data/110m-glaciated-areas.zip +0 -0
- data/spec/support/data/CartoDB_csv_export.zip +0 -0
- data/spec/support/data/CartoDB_shp_export.zip +0 -0
- data/spec/support/data/rmnp.kml +51 -0
- data/spec/support/data/states.kml.zip +0 -0
- data/spec/support/database.yml +5 -0
- data/spec/support/shp/cereal.dbf +0 -0
- data/spec/support/shp/cereal.shp +0 -0
- data/spec/support/shp/cereal.shx +0 -0
- data/spec/support/shp/cereal.zip +0 -0
- data/spec/support/shp/parcelas.dbf +0 -0
- data/spec/support/shp/parcelas.shp +0 -0
- data/spec/support/shp/parcelas.shx +0 -0
- data/spec/support/shp/parcelas.zip +0 -0
- data/spec/support/shp/zonas.dbf +0 -0
- data/spec/support/shp/zonas.shp +0 -0
- data/spec/support/shp/zonas.shx +0 -0
- data/spec/support/shp/zonas.zip +0 -0
- data/spec/support/whs_features.csv +315 -0
- data/spec/support/whs_features.csv.zip +0 -0
- data/spec/support/whs_features_temp.csv +315 -0
- metadata +400 -0
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use --create 1.9.3@cartodb-rb-client > /dev/null
|
data/.travis.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
language: ruby
|
2
|
+
bundler_args: --without development
|
3
|
+
script: "rspec --format=documentation spec"
|
4
|
+
|
5
|
+
rvm:
|
6
|
+
- 1.9.2
|
7
|
+
- 1.9.3
|
8
|
+
gemfile:
|
9
|
+
- Gemfile
|
10
|
+
notifications:
|
11
|
+
recipients:
|
12
|
+
- ferdev+travis@vizzuality.com
|
13
|
+
branches:
|
14
|
+
only:
|
15
|
+
- master
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in cartodb-rb-client.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :development do
|
7
|
+
gem "bundler", "> 1.0.0"
|
8
|
+
gem 'debugger'
|
9
|
+
end
|
10
|
+
|
11
|
+
group :test do
|
12
|
+
gem "rspec", "~> 2.10.0"
|
13
|
+
gem "spork", "~> 0.9.0"
|
14
|
+
gem "vcr"
|
15
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Copyright (c) 2011, Vizzuality
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
1. Redistributions of source code must retain the above copyright
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
8
|
+
2. Redistributions in binary form must reproduce the above copyright
|
9
|
+
notice, this list of conditions and the following disclaimer in the
|
10
|
+
documentation and/or other materials provided with the distribution.
|
11
|
+
3. All advertising materials mentioning features or use of this software
|
12
|
+
must display the following acknowledgement:
|
13
|
+
This product includes software developed by Vizzuality.
|
14
|
+
4. Neither the name of Vizzuality nor the
|
15
|
+
names of its contributors may be used to endorse or promote products
|
16
|
+
derived from this software without specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY
|
19
|
+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
20
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
22
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
23
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
24
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
25
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
27
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
+
|
data/README.markdown
ADDED
@@ -0,0 +1,365 @@
|
|
1
|
+
cartoDB Ruby Client [![Build Status](https://secure.travis-ci.org/Vizzuality/cartodb-rb-client.png)](http://travis-ci.org/Vizzuality/cartodb-rb-client)
|
2
|
+
===================
|
3
|
+
|
4
|
+
cartoDB ruby client that allows an easy and simple interaction with the cartoDB API.
|
5
|
+
|
6
|
+
Requirements
|
7
|
+
-------------
|
8
|
+
|
9
|
+
The only requirement is an Internet connection and a working version of the Ruby language interpreter. Current ruby versions supported are 1.8.7 and 1.9.2
|
10
|
+
|
11
|
+
Setup
|
12
|
+
------
|
13
|
+
|
14
|
+
1. Install the client gem:
|
15
|
+
|
16
|
+
gem install cartodb-rb-client
|
17
|
+
|
18
|
+
or if you are using bundler, put this line in your Gemfile:
|
19
|
+
|
20
|
+
gem 'cartodb-rb-client'
|
21
|
+
|
22
|
+
2. Log into http://cartodb.com, and grab your API_KEY or your OAUTH credentials and put them in a YAML file:
|
23
|
+
|
24
|
+
For the API_KEY:
|
25
|
+
|
26
|
+
*cartodb\_config.yml:*
|
27
|
+
|
28
|
+
host: 'YOUR_CARTODB_DOMAIN'
|
29
|
+
api_key: 'YOUR_API_KEY'
|
30
|
+
|
31
|
+
For the OAUTH Credentials:
|
32
|
+
|
33
|
+
*cartodb\_config.yml:*
|
34
|
+
|
35
|
+
host: 'YOUR_CARTODB_DOMAIN'
|
36
|
+
oauth_key: 'YOUR_OAUTH_KEY'
|
37
|
+
oauth_secret: 'YOUR_OAUTH_SECRET'
|
38
|
+
oauth_access_token: 'YOUR_OAUTH_ACCES_TOKEN'
|
39
|
+
oauth_access_token_secret: 'YOUR_OAUTH_ACCES_TOKEN_SECRET'
|
40
|
+
|
41
|
+
We also support xAuth protocol. In order to use it, provide your username and password instead of your access token:
|
42
|
+
|
43
|
+
*cartodb\_config.yml:*
|
44
|
+
|
45
|
+
host: 'YOUR_CARTODB_DOMAIN'
|
46
|
+
oauth_key: 'YOUR_OAUTH_KEY'
|
47
|
+
oauth_secret: 'YOUR_OAUTH_SECRET'
|
48
|
+
username: 'YOUR_CARTODB_USERNAME'
|
49
|
+
password: 'YOUR_CARTODB_PASSWORD'
|
50
|
+
|
51
|
+
3. Setup your cartoDB connection object:
|
52
|
+
|
53
|
+
CartoDB::Init.start YAML.load_file(Rails.root.join('config/cartodb_config.yml'))
|
54
|
+
|
55
|
+
And that's it. Now you should be able to run querys against the cartoDB servers using the CartoDB::Connection object.
|
56
|
+
|
57
|
+
Note: You have to use strings instead of symbols for the configuration hash keys.
|
58
|
+
|
59
|
+
Using the cartoDB API
|
60
|
+
-----------
|
61
|
+
|
62
|
+
List of supported methods to interact with cartoDB:
|
63
|
+
|
64
|
+
####1. Create table.
|
65
|
+
|
66
|
+
Creates a new table in cartoDB. The table's name will be normalized, for example, 'table #1' will become 'table\_1'.
|
67
|
+
|
68
|
+
Arguments:
|
69
|
+
|
70
|
+
- **table\_name**: table's name.
|
71
|
+
|
72
|
+
- **schema_or_file**: this parameter can be a list of fields the table will contain, or a File class containing the data the table will contain. It supports all file types supported by cartoDB.
|
73
|
+
|
74
|
+
- **the\_geom\_type**: Type of geometry the\_geom field will have. Currently we only support 'POINT', but we'll support more types soon.
|
75
|
+
|
76
|
+
Example 1:
|
77
|
+
|
78
|
+
CartoDB::Connection.create_table 'table #1', [{:name => 'field1', :type => 'text'}], 'POINT'
|
79
|
+
|
80
|
+
Results:
|
81
|
+
|
82
|
+
{:id => 1,
|
83
|
+
:name => "table_1",
|
84
|
+
:schema =>
|
85
|
+
[["cartodb_id", "number"],
|
86
|
+
["field1", "string"],
|
87
|
+
["updated_at", "date"],
|
88
|
+
["created_at", "date"]]}
|
89
|
+
|
90
|
+
Example 2:
|
91
|
+
|
92
|
+
CartoDB::Connection.create_table 'whs_sites', File.open("#{File.dirname(__FILE__)}/support/whs_features.csv", 'r')
|
93
|
+
|
94
|
+
Results:
|
95
|
+
|
96
|
+
{:id=>242,
|
97
|
+
:name=>"_20120314_21932_1fx2580whs_features",
|
98
|
+
:schema=>
|
99
|
+
[["cartodb_id", "number"],
|
100
|
+
["the_geom", "geometry", "geometry", "point"],
|
101
|
+
["comments", "string"],
|
102
|
+
["country", "string"],
|
103
|
+
["criteria", "string"],
|
104
|
+
["date_of_inscription", "string"],
|
105
|
+
["description", "string"],
|
106
|
+
["edited_region", "string"],
|
107
|
+
["endangered_reason", "string"],
|
108
|
+
["endangered_year", "string"],
|
109
|
+
["external_links", "string"],
|
110
|
+
["iso_code", "string"],
|
111
|
+
["latitude", "string"],
|
112
|
+
["longitude", "string"],
|
113
|
+
["name", "string"],
|
114
|
+
["region", "string"],
|
115
|
+
["size", "string"],
|
116
|
+
["title", "string"],
|
117
|
+
["type", "string"],
|
118
|
+
["whs_site_id", "string"],
|
119
|
+
["whs_source_page", "string"],
|
120
|
+
["wikipedia_link", "string"],
|
121
|
+
["created_at", "date"],
|
122
|
+
["updated_at", "date"]]}
|
123
|
+
|
124
|
+
####2. Add column.
|
125
|
+
|
126
|
+
Adds a new column to an existing table.
|
127
|
+
|
128
|
+
Arguments:
|
129
|
+
|
130
|
+
- **table_name**: table's name.
|
131
|
+
- **column_name**: new column's name.
|
132
|
+
- **column_type**: new column's data type. Supported types: string, numeric, date, boolean and geometry.
|
133
|
+
|
134
|
+
Example:
|
135
|
+
|
136
|
+
CartoDB::Connection.add\_column 'table_1', 'my_column', 'numeric'
|
137
|
+
|
138
|
+
Results:
|
139
|
+
|
140
|
+
[]
|
141
|
+
|
142
|
+
####3. Drop column.
|
143
|
+
|
144
|
+
Removes an existing column in the specified table.
|
145
|
+
|
146
|
+
Arguments:
|
147
|
+
|
148
|
+
- **table_name**: table's name which column will be dropped.
|
149
|
+
- **column_name**: name of the column to be dropped.
|
150
|
+
|
151
|
+
Example:
|
152
|
+
|
153
|
+
CartoDB::Connection.drop\_column 'table_1', 'my_column'
|
154
|
+
|
155
|
+
Results:
|
156
|
+
|
157
|
+
[]
|
158
|
+
|
159
|
+
####4. Change column.
|
160
|
+
|
161
|
+
Changes name and data type of an existing column.
|
162
|
+
|
163
|
+
Arguments:
|
164
|
+
|
165
|
+
- **table_name**: table's name which column will be changed.
|
166
|
+
- **old_column_name**: current name of the column to be changed.
|
167
|
+
- **new_column_name**: new name for the column.
|
168
|
+
- **column_type**: new data type of the column.
|
169
|
+
|
170
|
+
Example:
|
171
|
+
|
172
|
+
CartoDB::Connection.change\_column 'table_1', 'field1', 'myfield', 'boolean'
|
173
|
+
|
174
|
+
Results:
|
175
|
+
|
176
|
+
[]
|
177
|
+
|
178
|
+
####5. List tables.
|
179
|
+
|
180
|
+
List all tables in your cartoDB account.
|
181
|
+
|
182
|
+
Example:
|
183
|
+
|
184
|
+
CartoDB::Connection.tables
|
185
|
+
|
186
|
+
Results:
|
187
|
+
|
188
|
+
{:total_entries => 1,
|
189
|
+
:tables =>
|
190
|
+
[{:id => 1,
|
191
|
+
:name => "table_1",
|
192
|
+
:privacy => "PUBLIC",
|
193
|
+
:tags => "",
|
194
|
+
:schema =>
|
195
|
+
[["cartodb_id", "number"],
|
196
|
+
["the_geom", "geometry", "geometry", "point"],
|
197
|
+
["field1", "string"],
|
198
|
+
["created_at", "string"],
|
199
|
+
["updated_at", "string"]],
|
200
|
+
:updated_at => Mon, 12 Sep 2011 00:00:00 +0000,
|
201
|
+
:rows_counted => 1}]}
|
202
|
+
|
203
|
+
####6. Table's detail
|
204
|
+
|
205
|
+
Shows information about the specified table.
|
206
|
+
|
207
|
+
Arguments:
|
208
|
+
|
209
|
+
- **table_name**: Name of the table you want to get info.
|
210
|
+
|
211
|
+
Example:
|
212
|
+
|
213
|
+
CartoDB::Connection.table 'table_1'
|
214
|
+
|
215
|
+
Results:
|
216
|
+
|
217
|
+
{:id => 1,
|
218
|
+
:name => "table_1",
|
219
|
+
:privacy => "PRIVATE",
|
220
|
+
:tags => "",
|
221
|
+
:schema =>
|
222
|
+
[["cartodb_id", "number"],
|
223
|
+
["myfield", "boolean"],
|
224
|
+
["updated_at", "date"],
|
225
|
+
["created_at", "date"]]}
|
226
|
+
|
227
|
+
####7. Drop table.
|
228
|
+
|
229
|
+
Deletes the specified table.
|
230
|
+
|
231
|
+
Arguments:
|
232
|
+
|
233
|
+
- **table_name**: Name of the table to delete.
|
234
|
+
|
235
|
+
Example:
|
236
|
+
|
237
|
+
CartoDB::Connection.drop_table 'table_1'
|
238
|
+
|
239
|
+
Results:
|
240
|
+
|
241
|
+
[]
|
242
|
+
|
243
|
+
####8. Get single row.
|
244
|
+
|
245
|
+
You can get a single row with this method by specifying its cartodb_id.
|
246
|
+
|
247
|
+
Arguments:
|
248
|
+
|
249
|
+
- **table_name**: Name of the table.
|
250
|
+
- **row_id**: Id of the row we want.
|
251
|
+
|
252
|
+
Example:
|
253
|
+
|
254
|
+
CartoDB::Connection.row 'table_1', 1
|
255
|
+
|
256
|
+
Result:
|
257
|
+
|
258
|
+
{:id => 1,
|
259
|
+
:updated_at => Tue, 13 Sep 2011 00:00:00 +0000,
|
260
|
+
:created_at => Tue, 13 Sep 2011 00:00:00 +0000,
|
261
|
+
:cartodb_id => 1,
|
262
|
+
:field1 => "cartoDB is awesome!"}
|
263
|
+
|
264
|
+
|
265
|
+
####9. Insert row.
|
266
|
+
|
267
|
+
Inserts a new row in the specified table.
|
268
|
+
|
269
|
+
Arguments:
|
270
|
+
|
271
|
+
- **table_name**: Name of the table.
|
272
|
+
- **row**: A ruby hash with the name of the columns we want to insert
|
273
|
+
data in, and its values.
|
274
|
+
|
275
|
+
Example:
|
276
|
+
|
277
|
+
CartoDB::Connection.insert_row 'table_1', :field1 => 'cartoDB is
|
278
|
+
awesome!'
|
279
|
+
|
280
|
+
Results:
|
281
|
+
|
282
|
+
{:id => 1,
|
283
|
+
:updated_at => Tue, 13 Sep 2011 00:00:00 +0000,
|
284
|
+
:created_at => Tue, 13 Sep 2011 00:00:00 +0000,
|
285
|
+
:cartodb_id => 1,
|
286
|
+
:field1 => "cartoDB is awesome!"}
|
287
|
+
|
288
|
+
####10. Update row.
|
289
|
+
|
290
|
+
Updates a single row in the specified table.
|
291
|
+
|
292
|
+
Arguments:
|
293
|
+
|
294
|
+
- **table_name**: Name of the table.
|
295
|
+
- **row_id**: Id of the row we want to update.
|
296
|
+
- **row**: A ruby hash containing the column names and values for the
|
297
|
+
update.
|
298
|
+
|
299
|
+
Example:
|
300
|
+
|
301
|
+
CartoDB::Connection.update_row 'table_1', 1, :field1 => 'cartoDB is
|
302
|
+
*really* awesome!'
|
303
|
+
|
304
|
+
Result:
|
305
|
+
|
306
|
+
{:id => 1,
|
307
|
+
:updated_at => Tue, 13 Sep 2011 00:00:00 +0000,
|
308
|
+
:created_at => Tue, 13 Sep 2011 00:00:00 +0000,
|
309
|
+
:cartodb_id => 1,
|
310
|
+
:field1 => "cartoDB is *really* awesome!"}
|
311
|
+
|
312
|
+
####11. Delete row.
|
313
|
+
|
314
|
+
Deletes a row in the specified table.
|
315
|
+
|
316
|
+
Arguments:
|
317
|
+
|
318
|
+
- **table_name**: Name of the table.
|
319
|
+
- **row_id**: Id of the row we want to delete.
|
320
|
+
|
321
|
+
Example:
|
322
|
+
|
323
|
+
CartoDB::Connection.delete_row 'table_1', 1
|
324
|
+
|
325
|
+
Result:
|
326
|
+
|
327
|
+
{:time => 0.008, :total_rows => 0, :rows => []}
|
328
|
+
|
329
|
+
####12. Execute a sql query.
|
330
|
+
|
331
|
+
Executes an sql query against your database in cartoDB.
|
332
|
+
|
333
|
+
Arguments:
|
334
|
+
|
335
|
+
- **sql**: String containing the query we want to execute.
|
336
|
+
- **options**: A ruby hash containing optional params to run the query.
|
337
|
+
Currently we support pagination using the :page and :rows_per_page
|
338
|
+
parameters in the options argument.
|
339
|
+
|
340
|
+
Example:
|
341
|
+
|
342
|
+
# At first, lets introduce some dummy data for the test
|
343
|
+
10.times{ CartoDB::Connection.insert_row 'table_1', :field1 => 'cartoDB is awesome!'}
|
344
|
+
|
345
|
+
# And now, the query itself
|
346
|
+
CartoDB::Connection.query 'SELECT * FROM table_1', :page => 1,
|
347
|
+
:rows_per_page => 5
|
348
|
+
|
349
|
+
Results:
|
350
|
+
|
351
|
+
{:time=>0.017,
|
352
|
+
:total_rows=>10,
|
353
|
+
:rows=>[{:updated_at=>Tue, 13 Sep 2011 00:00:00 +0000,
|
354
|
+
:created_at=>Tue, 13 Sep 2011 00:00:00 +0000,
|
355
|
+
:cartodb_id=>2,
|
356
|
+
:field1=>"cartoDB is awesome!"},
|
357
|
+
...
|
358
|
+
]}
|
359
|
+
|
360
|
+
More info
|
361
|
+
---------
|
362
|
+
|
363
|
+
You can also check the oficial [cartoDB Documentation](http://developers.cartodb.com/) if you want more info about the cartoDB API.
|
364
|
+
|
365
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "cartodb-rb-client/version"
|
4
|
+
require "cartodb-rb-client/install_utils"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "cartodb-rb-client-rails-322"
|
8
|
+
s.version = Cartodb::Rb::Client::VERSION
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.authors = ["Fernando Espinosa"]
|
11
|
+
s.email = ["ferdev@vizzuality.com"]
|
12
|
+
s.homepage = %q{http://github.com/vizzuality/cartodb-rb-client}
|
13
|
+
s.licenses = ["BSD"]
|
14
|
+
s.summary = %q{Ruby client for the cartoDB API}
|
15
|
+
s.description = %q{Allows quick and easy connection to the cartodb API.}
|
16
|
+
|
17
|
+
s.required_rubygems_version = ">= 1.3.6"
|
18
|
+
|
19
|
+
s.rubyforge_project = "cartodb-rb-client"
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
s.add_dependency 'typhoeus', '0.3.3'
|
26
|
+
s.add_dependency 'oauth', '0.4.5'
|
27
|
+
s.add_dependency 'mime-types', '>= 1.16'
|
28
|
+
s.add_dependency 'activesupport', '>= 3.0.0'
|
29
|
+
s.add_dependency 'i18n', '>= 0.5.0', '<= 0.8.0'
|
30
|
+
s.add_dependency 'rgeo', '>= 0.3.2'
|
31
|
+
s.add_dependency 'rgeo-geojson', '>= 0.2.1'
|
32
|
+
s.add_dependency('pg', '>= 0.11.0', '<= 0.13.2') if postgresql_installed?
|
33
|
+
s.add_dependency 'json', '>= 1.5.3'
|
34
|
+
end
|