forked from parse-community/parse-server
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow usage of analytics adapter (parse-community#2327)
* Allow usage of analytics adapter * Use promises in controller
- Loading branch information
Showing
5 changed files
with
57 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export class AnalyticsAdapter { | ||
appOpened(parameters, req) { | ||
return Promise.resolve({}); | ||
} | ||
|
||
trackEvent(eventName, parameters, req) { | ||
return Promise.resolve({}); | ||
} | ||
} | ||
|
||
export default AnalyticsAdapter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import AdaptableController from './AdaptableController'; | ||
import { AnalyticsAdapter } from '../Adapters/Analytics/AnalyticsAdapter'; | ||
|
||
export class AnalyticsController extends AdaptableController { | ||
appOpened(req) { | ||
return this.adapter.appOpened(req.body, req).then( | ||
function(response) { | ||
return { response: response }; | ||
}).catch((err) => { | ||
return { response: {} }; | ||
}); | ||
} | ||
|
||
trackEvent(req) { | ||
return this.adapter.trackEvent(req.params.eventName, req.body, req).then( | ||
function(response) { | ||
return { response: response }; | ||
}).catch((err) => { | ||
return { response: {} }; | ||
}); | ||
} | ||
|
||
expectedAdapterType() { | ||
return AnalyticsAdapter; | ||
} | ||
} | ||
|
||
export default AnalyticsController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
// AnalyticsRouter.js | ||
import PromiseRouter from '../PromiseRouter'; | ||
|
||
// Returns a promise that resolves to an empty object response | ||
function ignoreAndSucceed(req) { | ||
return Promise.resolve({ | ||
response: {} | ||
}); | ||
function appOpened(req) { | ||
const analyticsController = req.config.analyticsController; | ||
return analyticsController.appOpened(req); | ||
} | ||
|
||
function trackEvent(req) { | ||
const analyticsController = req.config.analyticsController; | ||
return analyticsController.trackEvent(req); | ||
} | ||
|
||
|
||
export class AnalyticsRouter extends PromiseRouter { | ||
mountRoutes() { | ||
this.route('POST','/events/AppOpened', ignoreAndSucceed); | ||
this.route('POST','/events/:eventName', ignoreAndSucceed); | ||
this.route('POST','/events/AppOpened', appOpened); | ||
this.route('POST','/events/:eventName', trackEvent); | ||
} | ||
} |