Skip to content

Commit

Permalink
Merge 28e1b3b into f9dbe81
Browse files Browse the repository at this point in the history
  • Loading branch information
daltonmatos committed Sep 22, 2017
2 parents f9dbe81 + 28e1b3b commit ceb47e4
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.DS_Store
*.iml
.idea/*
*.swp

# npm
node_modules/
Expand Down
6 changes: 5 additions & 1 deletion src/js/plugin/PluginLoader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react/addons";

import config from "../config/config";
import ajaxWrapper from "../helpers/ajaxWrapper";

import URLUtil from "../helpers/URLUtil";
import PluginDispatcher from "./shared/PluginDispatcher";
Expand All @@ -10,6 +11,8 @@ import PluginActions from "./shared/PluginActions";
import PluginHelper from "./shared/PluginHelper";
import PluginDispatcherProxy from "./PluginDispatcherProxy";

import PluginAPI from "./sdk/PluginAPI";

const PLUGIN_STARTUP_TIMEOUT = 10000; // in ms

const PluginLoader = {
Expand Down Expand Up @@ -45,7 +48,8 @@ const PluginLoader = {
PluginMountPoints: PluginMountPoints,
pluginId: pluginId,
React: React,
UIVersion: config.version
config: Object.freeze(config),
PluginAPI: PluginAPI
});

let dispatchToken = PluginDispatcher.register(function (event) {
Expand Down
13 changes: 13 additions & 0 deletions src/js/plugin/sdk/PluginAPI.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

import MarathonService from "./services/MarathonService";
import MarathonActions from "./actions/MarathonActions";

const version = "0.0.1";

var PluginAPI = {
version: version,
MarathonService: MarathonService,
MarathonActions: MarathonActions
};

export default Object.freeze(PluginAPI);
29 changes: 29 additions & 0 deletions src/js/plugin/sdk/actions/MarathonActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import MarathonService from "../services/MarathonService";
import Utils from "../utils";

export default class MarathonActions {

static getDeployments() {
return MarathonService.request({
resource: "/v2/deployments"
});
}

static getGroup(group) {
let groupName = Utils.addLeadingSlashIfNedded(group);
return MarathonService.request({
resource: `/v2/groups${groupName}`
});
}

static getGroups() {
return this.getGroup("/");
}

static getApp(appId) {
return MarathonService.request({
resource: `/v2/apps${appId}`
});
}

};
23 changes: 23 additions & 0 deletions src/js/plugin/sdk/services/MarathonService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

import config from "../../../config/config";
import ajaxWrapper from "../../../helpers/ajaxWrapper";
import Utils from "../utils";

export default class MarathonService {

static request(opts = {}) {
let method = "GET";
let resource = Utils.addLeadingSlashIfNedded(opts.resource);

if (opts.method) {
method = opts.method;
}

return ajaxWrapper({
url: `${config.apiURL}${resource}`,
method: method,
data: opts.data
});
}

};
11 changes: 11 additions & 0 deletions src/js/plugin/sdk/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

export default class Utils {

static addLeadingSlashIfNedded(value) {
if (value && value[0] !== "/") {
return "/" + value;
}
return value;
};

};

0 comments on commit ceb47e4

Please sign in to comment.