Created
August 21, 2014 06:37
-
-
Save nikoma/3a7868536de07ffe3fac to your computer and use it in GitHub Desktop.
Apphera draft library
This file contains hidden or 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
//'use strict'; | |
// | |
ApplicationConfiguration.registerModule('apphera'); |
This file contains hidden or 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
(function () { | |
'use strict'; | |
var apphera = function ($http) { | |
var base_url = '/api/'; | |
var dashboardApi = 'http://localhost:3000/api/'; | |
//Accounts | |
var getAccounts = function () { | |
return $http.get(base_url + 'accounts') | |
.then(function (response) { | |
return response.data; | |
}); | |
}; | |
var createAccount = function (account) { | |
return $http.post(base_url + 'accounts', account) | |
.then(function (response) { | |
return response.data; | |
}); | |
}; | |
//Aggregates | |
//Categories | |
var getCategories = function () { | |
return $http.get(base_url + 'categories', { cache: true}) | |
.then(function (response) { | |
return response.data; | |
}); | |
}; | |
var getCountries = function () { | |
return $http.get(base_url + 'country_codes', { cache: true}) | |
.then(function (response) { | |
return response.data; | |
}); | |
}; | |
//Competitors - Get system identified competitors | |
var getCompetitors = function (account_id, organization_id) { | |
return $http.get(base_url + 'competitors/' + account_id + '/' + organization_id) | |
.then(function (response) { | |
return response.data; | |
}); | |
}; | |
//Find competitors by geography and category. Need to use either Apphera API or have a rich dataset | |
var getGeoCompetitors = function (radius, latitude, longitude, category_id) { | |
return $http.get(base_url + 'geocomps', { | |
params: { r: radius, lat: latitude, lon: longitude, cat: category_id}}) | |
.then(function (response) { | |
return response.data; | |
}); | |
}; | |
//Content Providers | |
var getContentProviders = function () { | |
return $http.get(base_url + 'content_providers', { cache: true}) | |
.then(function (response) { | |
return response.data; | |
}); | |
}; | |
var createFacebookPost = function (facebookPost) { | |
return $http.post(base_url + 'facebook/post') | |
.then(function (response) { | |
return response.data; | |
}); | |
}; | |
var createFacebookPageCredentials = function(){ | |
return $http.post(base_url + 'facebook/page/credentials') | |
.then(function(response){ | |
return response.data; | |
}); | |
}; | |
//Foursquare | |
//Keywords | |
var getKeywords = function () { | |
return $http.get(base_url + 'keywords') | |
.then(function (response) { | |
return response.data; | |
}); | |
}; | |
var createKeyword = function (keyword) { | |
return $http.post(base_url + 'keywords', keyword) | |
.then(function (response) { | |
return response.data; | |
}); | |
}; | |
//Links | |
var getLinks = function (account_id, organization_id) { | |
return $http.get(base_url + 'links/' + account_id + '/' + organization_id) | |
.then(function (response) { | |
return response.data; | |
}); | |
}; | |
//Markets | |
var getMarkets = function () { | |
return $http.get(base_url + 'markets', { cache: true}) | |
.then(function (response) { | |
return response.data; | |
}); | |
}; | |
//Tracks | |
var getTracks = function () { | |
return $http.get(base_url + 'tracks', { cache: true}) | |
.then(function (response) { | |
return response.data; | |
}); | |
}; | |
var getTrackResults = function (track, keywordId, market) { | |
if (market !== undefined && track === 'search') { | |
return $http.get(base_url + 'tracks/' + keywordId + '/' + track + '/' + market) | |
.then(function (response) { | |
return response.data; | |
}); | |
} else { | |
return $http.get(base_url + 'tracks/' + keywordId + '/' + track) | |
.then(function (response) { | |
return response.data; | |
}); | |
} | |
}; | |
//Organizations | |
var getOrganizations = function (accountId) { | |
return $http.get(base_url + 'organizations/' + accountId) | |
.then(function (response) { | |
return response.data; | |
}); | |
}; | |
var createOrganization = function (organization) { | |
return $http.post(base_url + 'organizations', organization) | |
.then(function (response) { | |
return response.data; | |
}); | |
}; | |
var updateOrganization = function (organization) { | |
return $http.put(base_url + 'organizations', organization) | |
.then(function (response) { | |
return response.data; | |
}); | |
}; | |
// Available methods | |
return { | |
createAccount: createAccount, | |
getAccounts: getAccounts, | |
getContentProviders: getContentProviders, | |
getCompetitors: getCompetitors, | |
getGeoCompetitors: getGeoCompetitors, | |
getCategories: getCategories, | |
getCountries: getCountries, | |
createFacebookPost: createFacebookPost, | |
createFacebookPageCredentials: createFacebookPageCredentials, | |
getKeywords: getKeywords, | |
getLinks: getLinks, | |
getTrackResults: getTrackResults, | |
getMarkets: getMarkets, | |
getOrganizations: getOrganizations, | |
createOrganization: createOrganization, | |
updateOrganization: updateOrganization, | |
createKeyword: createKeyword, | |
dashboardApi: dashboardApi | |
}; | |
}; | |
var module = angular.module('apphera'); | |
module.factory('apphera', apphera); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment