Skip to content

Commit 494e622

Browse files
committed
Correct README
1 parent 165f018 commit 494e622

File tree

1 file changed

+40
-82
lines changed

1 file changed

+40
-82
lines changed

README.md

Lines changed: 40 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,40 @@ Please refer to the [SlicingDice official documentation](http://panel.slicingdic
2020
#include <SlicingDice.h>
2121
#include <ArduinoJson.h>
2222

23-
#define BUFFER_SIZE 256
24-
25-
SlicingDice sd = SlicingDice("API_KEY");
23+
// If you need a demo API key visit: https://panel.slicingdice.com/docs/#api-details-api-connection-api-keys-demo-key
24+
String apiKey = String("YOUR_API_KEY");
25+
// if false will use test end-point, otherwise production end-point
26+
int useProduction = false;
27+
SlicingDice sd = SlicingDice(apiKey, useProduction);
2628

2729
void setup() {
28-
// Open serial communication and wait for port to open
30+
// Open serial communications and wait for port to open:
2931
Serial.begin(9600);
3032
while (!Serial) {
3133
}
3234

33-
// Arduino network settings
35+
// Arduino network settings, should match your internet connection properties
3436
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
35-
byte ip[] = { 192, 168, 1, 10 };
36-
byte gateway[] = { 192, 168, 1, 1 };
37+
byte ip[] = { 192, 168, 0, 10 };
38+
byte gateway[] = { 192, 168, 0, 1 };
3739
byte subnet[] = { 255, 255, 255, 0 };
38-
byte dns[] = { 8, 8, 8, 8 };
39-
Ethernet.begin(mac, ip, dns, gateway, subnet);
40+
byte dnxs[] = { 8, 8, 8, 8 };
41+
Ethernet.begin(mac, ip, dnxs, gateway, subnet);
4042
}
4143

44+
// Send an indexation command to Slicing Dice API and print the result
4245
void loop() {
43-
// Create JSON object
44-
StaticJsonBuffer<BUFFER_SIZE> jsonBuffer;
46+
StaticJsonBuffer<200> jsonBuffer;
4547
JsonObject& queryIndex = jsonBuffer.createObject();
4648
JsonObject& nestedQueryIndex = queryIndex.createNestedObject("user1@slicingdice.com");
4749
nestedQueryIndex["age"] = 22;
50+
// Auto create non-existent fields
51+
queryIndex["auto-create-fields"] = true;
4852

4953
// Index object
5054
sd.index(queryIndex);
5155

52-
// Print response for debugging
56+
// Print result for debugging
5357
Serial.print("Status code: ");
5458
Serial.println(sd.statusCode);
5559
Serial.println(sd.response);
@@ -71,8 +75,9 @@ Whether you want to test the client installation or simply check more examples o
7175

7276
### Constructors
7377

74-
`SlicingDice(const char* apiKey)`
78+
`SlicingDice(const char* apiKey, boolean production)`
7579
* `apiKey (const char*)` - [API key](http://panel.slicingdice.com/docs/#api-details-api-connection-api-keys) to authenticate requests with the SlicingDice API.
80+
* `production(boolean)` - If true the client will send requests to production end-point, otherwise to tests end-point
7681

7782
`SlicingDice(const char* apiKey, const char* host)`
7883
* `apiKey (const char*)` - [API key](http://panel.slicingdice.com/docs/#api-details-api-connection-api-keys) to authenticate requests with the SlicingDice API.
@@ -83,6 +88,12 @@ Whether you want to test the client installation or simply check more examples o
8388
* `host (const char*)` - [Connection endpoint](http://panel.slicingdice.com/docs/#api-details-api-connection-connection-endpoints) to use when generating requests to SlicingDice.
8489
* `port (int)` - Port to connect to when generating requests. Particularly useful when connect to `http://localhost`.
8590

91+
`SlicingDice(const char* apiKey, const char* host, int port, boolean production)`
92+
* `apiKey (const char*)` - [API key](http://panel.slicingdice.com/docs/#api-details-api-connection-api-keys) to authenticate requests with the SlicingDice API.
93+
* `host (const char*)` - [Connection endpoint](http://panel.slicingdice.com/docs/#api-details-api-connection-connection-endpoints) to use when generating requests to SlicingDice.
94+
* `port (int)` - Port to connect to when generating requests. Particularly useful when connect to `http://localhost`.
95+
* `production(boolean)` - If true the client will send requests to production end-point, otherwise to tests end-point
96+
8697
### `void index(JsonObject& query)`
8798
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).
8899

@@ -92,93 +103,40 @@ Index data to existing entities or create new entities, if necessary. This metho
92103
#include <SlicingDice.h>
93104
#include <ArduinoJson.h>
94105

95-
#define BUFFER_SIZE 256
96-
97-
SlicingDice sd = SlicingDice("API_KEY");
106+
// If you need a demo API key visit: https://panel.slicingdice.com/docs/#api-details-api-connection-api-keys-demo-key
107+
String apiKey = String("YOUR_API_KEY");
108+
// if false will use test end-point, otherwise production end-point
109+
int useProduction = false;
110+
SlicingDice sd = SlicingDice(apiKey, useProduction);
98111

99112
void setup() {
100-
// Open serial communication and wait for port to open
113+
// Open serial communications and wait for port to open:
101114
Serial.begin(9600);
102115
while (!Serial) {
103116
}
104117

105-
// Arduino network settings
118+
// Arduino network settings, should match your internet connection properties
106119
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
107-
byte ip[] = { 192, 168, 1, 10 };
108-
byte gateway[] = { 192, 168, 1, 1 };
120+
byte ip[] = { 192, 168, 0, 10 };
121+
byte gateway[] = { 192, 168, 0, 1 };
109122
byte subnet[] = { 255, 255, 255, 0 };
110-
byte dns[] = { 8, 8, 8, 8 };
111-
Ethernet.begin(mac, ip, dns, gateway, subnet);
123+
byte dnxs[] = { 8, 8, 8, 8 };
124+
Ethernet.begin(mac, ip, dnxs, gateway, subnet);
112125
}
113126

127+
// Send an indexation command to Slicing Dice API and print the result
114128
void loop() {
115-
// Create JSON object
116-
StaticJsonBuffer<BUFFER_SIZE> jsonBuffer;
129+
StaticJsonBuffer<200> jsonBuffer;
117130
JsonObject& queryIndex = jsonBuffer.createObject();
118131
JsonObject& nestedQueryIndex = queryIndex.createNestedObject("user1@slicingdice.com");
119132
nestedQueryIndex["age"] = 22;
133+
// Auto create non-existent fields
134+
queryIndex["auto-create-fields"] = true;
120135

121136
// Index object
122137
sd.index(queryIndex);
123138

124-
// Print response for debugging
125-
Serial.print("Status code: ");
126-
Serial.println(sd.statusCode);
127-
Serial.println(sd.response);
128-
}
129-
```
130-
131-
#### Output example
132-
133-
```
134-
Status code: 200
135-
{
136-
"status": "success",
137-
"indexed-entities": 1,
138-
"indexed-fields": 1,
139-
"took": 0.023
140-
}
141-
```
142-
143-
### `void index(JsonObject& query, boolean autoCreateFields)`
144-
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).
145-
146-
#### Request example
147-
148-
```c
149-
#include <SlicingDice.h>
150-
#include <ArduinoJson.h>
151-
152-
#define BUFFER_SIZE 256
153-
154-
SlicingDice sd = SlicingDice("API_KEY");
155-
156-
void setup() {
157-
// Open serial communication and wait for port to open
158-
Serial.begin(9600);
159-
while (!Serial) {
160-
}
161-
162-
// Arduino network settings
163-
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
164-
byte ip[] = { 192, 168, 1, 10 };
165-
byte gateway[] = { 192, 168, 1, 1 };
166-
byte subnet[] = { 255, 255, 255, 0 };
167-
byte dns[] = { 8, 8, 8, 8 };
168-
Ethernet.begin(mac, ip, dns, gateway, subnet);
169-
}
170-
171-
void loop() {
172-
// Create JSON object
173-
StaticJsonBuffer<BUFFER_SIZE> jsonBuffer;
174-
JsonObject& queryIndex = jsonBuffer.createObject();
175-
JsonObject& nestedQueryIndex = queryIndex.createNestedObject("user1@slicingdice.com");
176-
nestedQueryIndex["age"] = 22;
177-
178-
// Index object
179-
sd.index(queryIndex, true);
180-
181-
// Print response for debugging
139+
// Print result for debugging
182140
Serial.print("Status code: ");
183141
Serial.println(sd.statusCode);
184142
Serial.println(sd.response);

0 commit comments

Comments
 (0)