Skip to content

Commit 6eb9144

Browse files
authored
Merge pull request #3 from SlicingDice/feature/correct-documentation
Correct README
2 parents c36587a + c3e3ebf commit 6eb9144

File tree

4 files changed

+40
-113
lines changed

4 files changed

+40
-113
lines changed

README.md

Lines changed: 32 additions & 87 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+
boolean 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 };
3840
byte dns[] = { 8, 8, 8, 8 };
3941
Ethernet.begin(mac, ip, dns, 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,17 +75,11 @@ Whether you want to test the client installation or simply check more examples o
7175

7276
### Constructors
7377

74-
`SlicingDice(const char* apiKey)`
75-
* `apiKey (const char*)` - [API key](http://panel.slicingdice.com/docs/#api-details-api-connection-api-keys) to authenticate requests with the SlicingDice API.
76-
77-
`SlicingDice(const char* apiKey, const char* host)`
78+
`SlicingDice(const char* apiKey, boolean production, const char* host, int port)`
7879
* `apiKey (const char*)` - [API key](http://panel.slicingdice.com/docs/#api-details-api-connection-api-keys) to authenticate requests with the SlicingDice API.
79-
* `host (const char*)` - [Connection endpoint](http://panel.slicingdice.com/docs/#api-details-api-connection-connection-endpoints) to use when generating requests to SlicingDice.
80-
81-
`SlicingDice(const char* apiKey, const char* host, int port)`
82-
* `apiKey (const char*)` - [API key](http://panel.slicingdice.com/docs/#api-details-api-connection-api-keys) to authenticate requests with the SlicingDice API.
83-
* `host (const char*)` - [Connection endpoint](http://panel.slicingdice.com/docs/#api-details-api-connection-connection-endpoints) to use when generating requests to SlicingDice.
84-
* `port (int)` - Port to connect to when generating requests. Particularly useful when connect to `http://localhost`.
80+
* `production(boolean)` - (Default: true) If true the client will send requests to production end-point, otherwise to tests end-point.
81+
* `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.
82+
* `port (int)` - (Default: 80) Port to connect to when generating requests. Particularly useful when connect to `http://localhost`.
8583

8684
### `void index(JsonObject& query)`
8785
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).
@@ -92,93 +90,40 @@ Index data to existing entities or create new entities, if necessary. This metho
9290
#include <SlicingDice.h>
9391
#include <ArduinoJson.h>
9492

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

9999
void setup() {
100-
// Open serial communication and wait for port to open
100+
// Open serial communications and wait for port to open:
101101
Serial.begin(9600);
102102
while (!Serial) {
103103
}
104104

105-
// Arduino network settings
105+
// Arduino network settings, should match your internet connection properties
106106
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
107-
byte ip[] = { 192, 168, 1, 10 };
108-
byte gateway[] = { 192, 168, 1, 1 };
107+
byte ip[] = { 192, 168, 0, 10 };
108+
byte gateway[] = { 192, 168, 0, 1 };
109109
byte subnet[] = { 255, 255, 255, 0 };
110110
byte dns[] = { 8, 8, 8, 8 };
111111
Ethernet.begin(mac, ip, dns, gateway, subnet);
112112
}
113113

114+
// Send an indexation command to Slicing Dice API and print the result
114115
void loop() {
115-
// Create JSON object
116-
StaticJsonBuffer<BUFFER_SIZE> jsonBuffer;
116+
StaticJsonBuffer<200> jsonBuffer;
117117
JsonObject& queryIndex = jsonBuffer.createObject();
118118
JsonObject& nestedQueryIndex = queryIndex.createNestedObject("user1@slicingdice.com");
119119
nestedQueryIndex["age"] = 22;
120+
// Auto create non-existent fields
121+
queryIndex["auto-create-fields"] = true;
120122

121123
// Index object
122124
sd.index(queryIndex);
123125

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
126+
// Print result for debugging
182127
Serial.print("Status code: ");
183128
Serial.println(sd.statusCode);
184129
Serial.println(sd.response);

SlicingDice.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
#include "SlicingDice.h"
22

3-
4-
SlicingDice::SlicingDice(String apiUserKey) {
5-
construct(apiUserKey, "api.slicingdice.com", 80, true);
6-
}
7-
8-
SlicingDice::SlicingDice(String apiUserKey, const char* customHost) {
9-
construct(apiUserKey, customHost, 80, true);
10-
}
11-
12-
SlicingDice::SlicingDice(String apiUserKey, const char* customHost, int customPort) {
13-
construct(apiUserKey, customHost, customPort, true);
14-
}
15-
16-
SlicingDice::SlicingDice(String apiUserKey, const char* customHost, int customPort, boolean production) {
17-
construct(apiUserKey, customHost, customPort, production);
3+
SlicingDice::SlicingDice(String apiUserKey, boolean useProduction, const char* customHost, int customPort) {
4+
construct(apiUserKey, customHost, customPort, useProduction);
185
}
196

207
void SlicingDice::construct(String apiUserKey, const char* customHost, int customPort, boolean production) {

SlicingDice.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
class SlicingDice {
88

99
public:
10-
SlicingDice(String apiUserKey);
11-
SlicingDice(String apiUserKey, const char* customHost);
12-
SlicingDice(String apiUserKey, const char* customHost, int customPort);
13-
SlicingDice(String apiUserKey, const char* customHost, int customPort, boolean production);
10+
SlicingDice(String apiUserKey, boolean useProduction = false, const char* customHost = "api.slicingdice.com", int customPort=80);
1411

1512
void index(JsonObject& query);
1613
int statusCode;

tests_and_examples/Simple.ino

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
#include "SlicingDice.h"
1+
#include <SlicingDice.h>
22
#include <ArduinoJson.h>
33

44
// Demo API key, if you need a new demo API key visit: https://panel.slicingdice.com/docs/#api-details-api-connection-api-keys-demo-key
55
String apiKey = String("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfX3NhbHQiOiJkZW1vMThtIiwicGVybWlzc2lvbl9sZXZlbCI6MywicHJvamVjdF9pZCI6MTc5LCJjbGllbnRfaWQiOjEwfQ.OTb6REW9JtYF9wVUZhXajq4wheU5ULNbM5iEmMCYhhM");
6-
const char* host = "api.slicingdice.com";
7-
int port = 80;
86
// if false will use test end-point, otherwise production end-point
9-
int useProduction = false;
10-
SlicingDice sd = SlicingDice(apiKey, host, port, useProduction);
7+
boolean useProduction = false;
8+
SlicingDice sd = SlicingDice(apiKey, useProduction);
119

1210
void setup() {
1311
// Open serial communications and wait for port to open:
@@ -20,8 +18,8 @@ void setup() {
2018
byte ip[] = { 192, 168, 0, 10 };
2119
byte gateway[] = { 192, 168, 0, 1 };
2220
byte subnet[] = { 255, 255, 255, 0 };
23-
byte dnxs[] = { 8, 8, 8, 8 };
24-
Ethernet.begin(mac, ip, dnxs, gateway, subnet);
21+
byte dns[] = { 8, 8, 8, 8 };
22+
Ethernet.begin(mac, ip, dns, gateway, subnet);
2523
}
2624

2725
// Send an indexation command to Slicing Dice API and print the result

0 commit comments

Comments
 (0)