Skip to content

Commit

Permalink
Merge pull request #32 from pbrosi-sag/master
Browse files Browse the repository at this point in the history
webmethods-io example custom connector for home automation
  • Loading branch information
peterlamar authored Jan 6, 2020
2 parents 042172a + daae00e commit c284df0
Show file tree
Hide file tree
Showing 22 changed files with 861 additions and 0 deletions.
1 change: 1 addition & 0 deletions netatmo-security-connector/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NetatmoSecurity/node_modules/
1 change: 1 addition & 0 deletions netatmo-security-connector/NetatmoSecurity/.flowapprc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"service_name":"NetatmoSecurity_fl91ccd279ad5dcd19d902bc"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
module.exports = {

name: "gethomedata",

title: "Gethomedata",

description: "",
version: "v1",

input:{
title: "Gethomedata",
type: "object",
properties: {
home_id :{
title: "home_id",
displayTitle: "Home ID",
type: "string"
}
}
},

output: {
title: "output",
type: "object",
displayTitle: "Output",
properties: {

}
},

mock_input:{},

execute: function(input, output){
// to access auth info use input.auth , eg: input.auth.username
// and to return output use output callback like this output(null, { 'notice' : 'successful'})
// your code here
// output(null, { data : "OK"});
var request = require("request");

var options = {
"method": "get",
"url": "https://api.netatmo.com/api/gethomedata",
"headers": {
"Accept": "application/json",
"Authorization": "Bearer " + input.auth.access_token
}
}
request(options, function(err, response, body) {
if (err) {
return output(err);
}
try {
if (body && typeof(body) === "string") {
body = JSON.parse(body);
}
} catch (e) {
return output(body);
};
if (response.statusCode === 401) {
return output("Invalid access token");
}
if (response.statusCode !== 200) {
return output("Error Details");
}
if (response.statusCode === 200) {
return output(null, body);
}
output(body);

})



}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module.exports = {

name: "gethomestatus",

title: "Gethomestatus",

description: "",
version: "v1",

input:{
title: "Gethomestatus",
type: "object",
properties: {
home_id :{
title: "home_id",
displayTitle: "Home ID",
type: "string"
}
}
},

output: {
title: "output",
type: "object",
displayTitle: "Output",
properties: {

}
},

mock_input:{},

execute: function(input, output){
// to access auth info use input.auth , eg: input.auth.username
// and to return output use output callback like this output(null, { 'notice' : 'successful'})
// your code here
// output(null, { data : "OK"});


var request = require("request");

var options = {
"method": "get",
"url": "https://api.netatmo.com/api/homestatus?home_id=" + input.home_id,
"headers": {
"Accept": "application/json",
"Authorization": "Bearer " + input.auth.access_token
}
}
request(options, function(err, response, body) {
if (err) {
return output(err);
}
try {
if (body && typeof(body) === "string") {
body = JSON.parse(body);
}
} catch (e) {
return output(body);
};
if (response.statusCode === 401) {
return output("Invalid access token");
}
if (response.statusCode !== 200) {
return output(body);
}
if (response.statusCode === 200) {
return output(null, body);
}
output(body);

})


}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
module.exports = {

name: "getnextevents",

title: "Getnextevents",

description: "",
version: "v1",

input:{
title: "Getnextevents",
type: "object",
properties: {
home_id :{
title: "home_id",
displayTitle: "Home ID",
type: "string"
},
event_id :{
title: "event_id",
displayTitle: "Before this event",
type: "string"
},
size: {
title: "size",
displayTitle: "Number of events (default 30)",
type: "string"
}
}
},

output: {
title: "output",
type: "object",
displayTitle: "Output",
properties: {
}
},

mock_input:{},

execute: function(input, output){
// to access auth info use input.auth , eg: input.auth.username
// and to return output use output callback like this output(null, { 'notice' : 'successful'})
// your code here

var request = require("request");

var options = {
"method": "get",
"url": "https://api.netatmo.com/api/getnextevents?home_id=" + input.home_id + "&event_id=" + input.event_id + "&size=" + input.size,
"headers": {
"Accept": "application/json",
"Authorization": "Bearer " + input.auth.access_token
}
}
request(options, function(err, response, body) {
if (err) {
return output(err);
}
try {
if (body && typeof(body) === "string") {
body = JSON.parse(body);
}
} catch (e) {
return output(body);
};
if (response.statusCode === 401) {
return output("Invalid access token");
}
if (response.statusCode !== 200) {
return output(body);
}
if (response.statusCode === 200) {
return output(null, body);
}
output(body);

})

}

}
4 changes: 4 additions & 0 deletions netatmo-security-connector/NetatmoSecurity/auth.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"username": "<username>",
"password": "<password>"
}
13 changes: 13 additions & 0 deletions netatmo-security-connector/NetatmoSecurity/authentication.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
label: "Connect to NetatmoSecurity",
mock_input: {
access_token: ""
},
oauth: "netatmo_camera_4a4b969c20",
validate: function (input, output) {
// auth credentials will be available in input.auth.access_token
// callback pattern
// output(error, success)
output(null, true)
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions netatmo-security-connector/NetatmoSecurity/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "NetatmoSecurity",
"description": "Netatmo Security Camera connector",
"triggers": [],
"actions": [
"/v1/gethomedata",
"/v1/gethomestatus",
"/v1/getnextevents"
],
"version": 1,
"auth_type": "oauth",
"docs_link": "http://docs.example.com",
"oauth_provider": "netatmo_camera_4a4b969c20",
"oauthStatus": "deployed",
"appId": "44e90f51-9b6c-4651-a22a-bf756bf0adce",
"guid": "8be1585c-a8c5-4d57-9b1d-fc3780d6cc69"
}
51 changes: 51 additions & 0 deletions netatmo-security-connector/NetatmoSecurity/oauth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"type": "oauth2",
"title": "netatmo_camera",
"clientId": "<clientID>",
"clientSecret": "<secret>",
"authURL": "https://api.netatmo.com/oauth2/authorize",
"tokenURL": "https://api.netatmo.com/oauth2/token",
"preAuthProcessing": {
},
"authQueryParams": {
"state": "ab82aff8dd2caf097e6",
"scope": "read_camera"
},

"preTokenProcessing": {
},

"tokenParams": {
"method": "",
"headers": {},
"data": {
"client_id": "{client_id}",
"client_secret": "{client_secret}",
"redirect_uri": "{redirect_uri}",
"grant_type": "authorization_code"
}
},
"preRefreshProcessing": {
},
"refreshParams": {
"client_id": "{client_id}",
"client_secret": "{client_secret}",
"redirect_uri": "{redirect_uri}",
"grant_type": "refresh_token"
},
"requiredParams": [
],
"refreshURL": "{tokenURL}",
"scope": {
"Read Camera Scope": "read_camera"
},
"validate": {
"url": "ANY API URL TO VALIDATE TOKEN OF THIRD PARTY SERVICE",
"headers": {
"Authorization": "Bearer {access_token}"
},
"query": {
}
},
"redirectURL": "https://auth-int.webmethods.io/auth/oauth/netatmo_camera_4a4b969c20/fl91ccd279ad5dcd19d902bc/return"
}
Loading

0 comments on commit c284df0

Please sign in to comment.