Skip to content

Commit 38e5de7

Browse files
committed
Merge pull request #9 from mtl2034/master
Add support for custom server URL (Arduino YUN)
2 parents 8d13294 + aa6697c commit 38e5de7

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

examples/Arduino Yun/test/Test.ino

+20-3
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ void basicObjectTest() {
4444
del.setClassName("Temperature");
4545
del.setObjectId(objectId);
4646
ParseResponse delResponse = del.send();
47-
String expectedResp = "{}\n";
48-
assert(expectedResp.equals(delResponse.getJSONBody()));
47+
String expectedResp = "{}";
48+
String actualResp = String(delResponse.getJSONBody());
49+
actualResp.trim();
50+
assert(expectedResp.equals(actualResp));
4951
delResponse.close();
5052

5153
Serial.println("test passed\n");
@@ -70,6 +72,20 @@ void objectDataTypesTest() {
7072
void queryTest() {
7173
Serial.println("query test");
7274

75+
ParseObjectCreate create1;
76+
create1.setClassName("Temperature");
77+
create1.add("temperature", 88.0);
78+
create1.add("leverDown", true);
79+
ParseResponse createResponse = create1.send();
80+
createResponse.close();
81+
82+
ParseObjectCreate create2;
83+
create2.setClassName("Temperature");
84+
create2.add("temperature", 88.0);
85+
create2.add("leverDown", false);
86+
createResponse = create2.send();
87+
createResponse.close();
88+
7389
ParseQuery query;
7490
query.setClassName("Temperature");
7591
query.whereEqualTo("temperature", 88);
@@ -96,12 +112,13 @@ void setup() {
96112
Bridge.begin();
97113

98114
// Initialize Serial
99-
Serial.begin(9600);
115+
Serial.begin(115200);
100116

101117
while (!Serial); // wait for a serial connection
102118

103119
// Initialize Parse
104120
Parse.begin("", "");
121+
Parse.setServerURL("https://my.server.somewhere/parse");
105122
}
106123

107124
void loop() {

src/internal/ParseClient.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ class ParseClient {
8282
*/
8383
void begin(const char *applicationId, const char *clientKey);
8484

85+
/*! \fn void setServerURL(const char *serverURL)
86+
* \brief Set the installation object id for this client.
87+
*
88+
* Set the custom server url for this client. This needs to be called
89+
* API request.
90+
*
91+
* \param serverURL The server URL to which client should connect.
92+
*
93+
*/
94+
void setServerURL(const char *serverURL);
95+
8596
/*! \fn void setInstallationId(const char *installationId)
8697
* \brief Set the installation object id for this client.
8798
*
@@ -146,7 +157,7 @@ class ParseClient {
146157
* \brief Directly call REST API in Parse.
147158
*
148159
* \param httpVerb - GET/DELETE/PUT/POST
149-
* \param httpPath - the endpoint of REST API e.g. /1/installations
160+
* \param httpPath - the endpoint of REST API e.g. /installations
150161
* \param requestBody - http request body in json format, leave it as "" for DELTE/GET requests
151162
* \param urlParams - leave it as "" unless to perform a Parse query,
152163
* use it to specify query condition e.g. where={"KEY1"":VALUE1}&limit=10&keys=KEY1,KEY2
@@ -160,7 +171,7 @@ class ParseClient {
160171
* \brief Directly call REST API in Parse.
161172
*
162173
* \param httpVerb - GET/DELETE/PUT/POST
163-
* \param httpPath - the endpoint of REST API e.g. /1/installations
174+
* \param httpPath - the endpoint of REST API e.g. /installations
164175
* \param requestBody - http request body in json format, leave it as "" for DELTE/GET requests
165176
* \param urlParams - leave it as "" unless to perform a Parse query,
166177
* use it to specify query condition e.g. where={"KEY1"":VALUE1}&limit=10&keys=KEY1,KEY2

src/internal/ParseRequest.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
ParseRequest::ParseRequest() {
2626
requestBody = "{";
27-
httpPath = "/1/";
27+
httpPath = "/";
2828
isBodySet = false;
2929
}
3030

src/internal/yun/ParseClient.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ void ParseClient::begin(const char *applicationId, const char *clientKey) {
4949
}
5050
}
5151

52+
void ParseClient::setServerURL(const char *serverURL) {
53+
if (serverURL) {
54+
Bridge.put("serverURL", serverURL);
55+
}
56+
}
57+
5258
void ParseClient::setInstallationId(const char *installationId) {
5359
strncpy(this->installationId, installationId, sizeof(this->installationId));
5460
if (installationId) {

0 commit comments

Comments
 (0)