Skip to content

Commit 9746558

Browse files
Merge pull request #4 from SlicingDice/renaming
Rename index() to insert()
2 parents 4ecc253 + de85e24 commit 9746558

File tree

5 files changed

+45
-33
lines changed

5 files changed

+45
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## [Unreleased]
44
### Added
5+
- CLIENT: Rename method index() to insert()
56
- CLIENT: Create requester and main method
67

78
## [0.3] - 2016-09-15

README.md

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ Official Arduino client for [SlicingDice](http://www.slicingdice.com/), Data War
88

99
If you are new to SlicingDice, check our [quickstart guide](http://panel.slicingdice.com/docs/#quickstart-guide) and learn to use it in 15 minutes.
1010

11-
Please refer to the [SlicingDice official documentation](http://panel.slicingdice.com/docs/) for more information on [analytics databases](http://panel.slicingdice.com/docs/#analytics-concepts), [data modeling](http://panel.slicingdice.com/docs/#data-modeling), [indexing](http://panel.slicingdice.com/docs/#data-indexing), [querying](http://panel.slicingdice.com/docs/#data-querying), [limitations](http://panel.slicingdice.com/docs/#current-slicingdice-limitations) and [API details](http://panel.slicingdice.com/docs/#api-details).
11+
Please refer to the [SlicingDice official documentation](http://panel.slicingdice.com/docs/) for more information on [analytics databases](http://panel.slicingdice.com/docs/#analytics-concepts), [data modeling](http://panel.slicingdice.com/docs/#data-modeling), [data insertion](http://panel.slicingdice.com/docs/#data-insertion), [querying](http://panel.slicingdice.com/docs/#data-querying), [limitations](http://panel.slicingdice.com/docs/#current-slicingdice-limitations) and [API details](http://panel.slicingdice.com/docs/#api-details).
1212

1313
### Note
1414

15-
SlicingDice's Arduino client currently supports only indexing commands. Let us
15+
SlicingDice's Arduino client currently supports only data insert commands. Let us
1616
know if you application requires Arduino to query data from SlicingDice
1717
and we'll make sure to add this feature to our backlog.
1818

@@ -47,17 +47,20 @@ void setup() {
4747
Ethernet.begin(mac, ip, dns, gateway, subnet);
4848
}
4949

50-
// Send an indexation command to Slicing Dice API and print the result
50+
// Send an insert command to Slicing Dice API and print the result
5151
void loop() {
5252
StaticJsonBuffer<200> jsonBuffer;
53-
JsonObject& queryIndex = jsonBuffer.createObject();
54-
JsonObject& nestedQueryIndex = queryIndex.createNestedObject("[email protected]");
55-
nestedQueryIndex["age"] = 22;
53+
JsonObject& data = jsonBuffer.createObject();
54+
JsonObject& nestedInsertion = data.createNestedObject("[email protected]");
55+
nestedInsertion["age"] = 22;
56+
5657
// Auto create non-existent fields
57-
queryIndex["auto-create-fields"] = true;
58+
JsonArray& autoCreate = data.createNestedArray("auto-create");
59+
autoCreate.add("table");
60+
autoCreate.add("column");
5861

59-
// Index object
60-
sd.index(queryIndex);
62+
// Insert object
63+
sd.insert(data);
6164

6265
// Print result for debugging
6366
Serial.print("Status code: ");
@@ -72,12 +75,12 @@ Whether you want to test the client installation or simply check more examples o
7275

7376
## Reference
7477

75-
`SlicingDice` encapsulates logic for sending requests to the [index endpoint](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-index).
78+
`SlicingDice` encapsulates logic for sending requests to the [insert endpoint](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-insert).
7679

7780
### Attributes
7881

79-
* `statusCode (int)` - HTTP status code after indexing to SlicingDice. Should be `200` in ordinary circumstances or one of the HTTP requests defined at the [API errors](http://panel.slicingdice.com/docs/#api-details-api-errors) section.
80-
* `response (String)` - Response after indexing data. Useful for debugging purposes.
82+
* `statusCode (int)` - HTTP status code after inserting to SlicingDice. Should be `200` in ordinary circumstances or one of the HTTP requests defined at the [API errors](http://panel.slicingdice.com/docs/#api-details-api-errors) section.
83+
* `response (String)` - Response after inserting data. Useful for debugging purposes.
8184

8285
### Constructors
8386

@@ -87,8 +90,8 @@ Whether you want to test the client installation or simply check more examples o
8790
* `host (const char*)` - (Default: api.slicingdice.com) [Connection endpoint](http://panel.slicingdice.com/docs/#api-details-api-connection-connection-endpoints) to use when generating requests to SlicingDice.
8891
* `port (int)` - (Default: 80) Port to connect to when generating requests. Particularly useful when connect to `http://localhost`.
8992

90-
### `void index(JsonObject& query)`
91-
Index data to existing entities or create new entities, if necessary. This method corresponds to a [POST request at /index](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-index).
93+
### `void insert(JsonObject& query)`
94+
Insert data to existing entities or create new entities, if necessary. This method corresponds to a [POST request at /insert](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-insert).
9295

9396
#### Request example
9497

@@ -117,17 +120,20 @@ void setup() {
117120
Ethernet.begin(mac, ip, dns, gateway, subnet);
118121
}
119122

120-
// Send an indexation command to Slicing Dice API and print the result
123+
// Send an insertation command to Slicing Dice API and print the result
121124
void loop() {
122125
StaticJsonBuffer<200> jsonBuffer;
123-
JsonObject& queryIndex = jsonBuffer.createObject();
124-
JsonObject& nestedQueryIndex = queryIndex.createNestedObject("[email protected]");
125-
nestedQueryIndex["age"] = 22;
126+
JsonObject& data = jsonBuffer.createObject();
127+
JsonObject& nestedInsertion = data.createNestedObject("[email protected]");
128+
nestedInsertion["age"] = 22;
129+
126130
// Auto create non-existent fields
127-
queryIndex["auto-create-fields"] = true;
131+
JsonArray& autoCreate = data.createNestedArray("auto-create");
132+
autoCreate.add("table");
133+
autoCreate.add("column");
128134

129-
// Index object
130-
sd.index(queryIndex);
135+
// Insert object
136+
sd.insert(data);
131137

132138
// Print result for debugging
133139
Serial.print("Status code: ");
@@ -142,8 +148,8 @@ void loop() {
142148
Status code: 200
143149
{
144150
"status": "success",
145-
"indexed-entities": 1,
146-
"indexed-fields": 1,
151+
"inserted-entities": 1,
152+
"inserted-fields": 1,
147153
"took": 0.023
148154
}
149155
```

SlicingDice.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ void SlicingDice::construct(String apiUserKey, const char* customHost, int custo
1111
useProduction = production;
1212
}
1313

14-
/* Index data on Slicing Dice API
14+
/* Insert data on Slicing Dice API
1515
*
1616
* query - the query to send to Slicing Dice API
1717
*/
18-
void SlicingDice::index(JsonObject& query) {
18+
void SlicingDice::insert(JsonObject& query) {
1919
char queryConverted[query.measureLength() + 1];
2020
query.printTo(queryConverted, sizeof(queryConverted));
2121
makeRequest(queryConverted);
@@ -37,7 +37,7 @@ void SlicingDice::makeRequest(const char* query){
3737
testEndPoint = String("test/");
3838
}
3939

40-
client.println("POST /v1/" + testEndPoint + "index HTTP/1.1");
40+
client.println("POST /v1/" + testEndPoint + "insert HTTP/1.1");
4141
client.println(F("Content-Type: application/json"));
4242
String hostString = String(host);
4343
client.println("Host: " + hostString);

SlicingDice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class SlicingDice {
99
public:
1010
SlicingDice(String apiUserKey, boolean useProduction = false, const char* customHost = "api.slicingdice.com", int customPort=80);
1111

12-
void index(JsonObject& query);
12+
void insert(JsonObject& data);
1313
int statusCode;
1414
String response;
1515

tests_and_examples/Simple.ino

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,19 @@ void setup() {
2222
Ethernet.begin(mac, ip, dns, gateway, subnet);
2323
}
2424

25-
// Send an indexation command to Slicing Dice API and print the result
25+
// Send an insert command to Slicing Dice API and print the result
2626
void loop() {
2727
StaticJsonBuffer<200> jsonBuffer;
28-
JsonObject& queryIndex = jsonBuffer.createObject();
29-
JsonObject& nestedQueryIndex = queryIndex.createNestedObject("[email protected]");
30-
nestedQueryIndex["age"] = 22;
31-
queryIndex["auto-create-fields"] = true;
32-
sd.index(queryIndex);
28+
JsonObject& insertion = jsonBuffer.createObject();
29+
JsonObject& nestedQueryInsertion = insertion.createNestedObject("[email protected]");
30+
nestedQueryInsertion["age"] = 22;
31+
32+
// Auto create non-existent fields
33+
JsonArray& autoCreate = insertion.createNestedArray("auto-create");
34+
autoCreate.add("table");
35+
autoCreate.add("column");
36+
37+
sd.insert(insertion);
3338
Serial.print("Status code: ");
3439
Serial.println(sd.statusCode);
3540
Serial.println(sd.response);

0 commit comments

Comments
 (0)