Skip to content

Commit

Permalink
Merge pull request #9 from mtl2034/master
Browse files Browse the repository at this point in the history
Add support for custom server URL (Arduino YUN)
  • Loading branch information
francip committed Mar 4, 2016
2 parents 8d13294 + aa6697c commit 38e5de7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
23 changes: 20 additions & 3 deletions examples/Arduino Yun/test/Test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ void basicObjectTest() {
del.setClassName("Temperature");
del.setObjectId(objectId);
ParseResponse delResponse = del.send();
String expectedResp = "{}\n";
assert(expectedResp.equals(delResponse.getJSONBody()));
String expectedResp = "{}";
String actualResp = String(delResponse.getJSONBody());
actualResp.trim();
assert(expectedResp.equals(actualResp));
delResponse.close();

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

ParseObjectCreate create1;
create1.setClassName("Temperature");
create1.add("temperature", 88.0);
create1.add("leverDown", true);
ParseResponse createResponse = create1.send();
createResponse.close();

ParseObjectCreate create2;
create2.setClassName("Temperature");
create2.add("temperature", 88.0);
create2.add("leverDown", false);
createResponse = create2.send();
createResponse.close();

ParseQuery query;
query.setClassName("Temperature");
query.whereEqualTo("temperature", 88);
Expand All @@ -96,12 +112,13 @@ void setup() {
Bridge.begin();

// Initialize Serial
Serial.begin(9600);
Serial.begin(115200);

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

// Initialize Parse
Parse.begin("", "");
Parse.setServerURL("https://my.server.somewhere/parse");
}

void loop() {
Expand Down
15 changes: 13 additions & 2 deletions src/internal/ParseClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@ class ParseClient {
*/
void begin(const char *applicationId, const char *clientKey);

/*! \fn void setServerURL(const char *serverURL)
* \brief Set the installation object id for this client.
*
* Set the custom server url for this client. This needs to be called
* API request.
*
* \param serverURL The server URL to which client should connect.
*
*/
void setServerURL(const char *serverURL);

/*! \fn void setInstallationId(const char *installationId)
* \brief Set the installation object id for this client.
*
Expand Down Expand Up @@ -146,7 +157,7 @@ class ParseClient {
* \brief Directly call REST API in Parse.
*
* \param httpVerb - GET/DELETE/PUT/POST
* \param httpPath - the endpoint of REST API e.g. /1/installations
* \param httpPath - the endpoint of REST API e.g. /installations
* \param requestBody - http request body in json format, leave it as "" for DELTE/GET requests
* \param urlParams - leave it as "" unless to perform a Parse query,
* use it to specify query condition e.g. where={"KEY1"":VALUE1}&limit=10&keys=KEY1,KEY2
Expand All @@ -160,7 +171,7 @@ class ParseClient {
* \brief Directly call REST API in Parse.
*
* \param httpVerb - GET/DELETE/PUT/POST
* \param httpPath - the endpoint of REST API e.g. /1/installations
* \param httpPath - the endpoint of REST API e.g. /installations
* \param requestBody - http request body in json format, leave it as "" for DELTE/GET requests
* \param urlParams - leave it as "" unless to perform a Parse query,
* use it to specify query condition e.g. where={"KEY1"":VALUE1}&limit=10&keys=KEY1,KEY2
Expand Down
2 changes: 1 addition & 1 deletion src/internal/ParseRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

ParseRequest::ParseRequest() {
requestBody = "{";
httpPath = "/1/";
httpPath = "/";
isBodySet = false;
}

Expand Down
6 changes: 6 additions & 0 deletions src/internal/yun/ParseClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ void ParseClient::begin(const char *applicationId, const char *clientKey) {
}
}

void ParseClient::setServerURL(const char *serverURL) {
if (serverURL) {
Bridge.put("serverURL", serverURL);
}
}

void ParseClient::setInstallationId(const char *installationId) {
strncpy(this->installationId, installationId, sizeof(this->installationId));
if (installationId) {
Expand Down

0 comments on commit 38e5de7

Please sign in to comment.