node-snapchat-marketing
Advanced tools
Comparing version 1.0.1 to 1.0.2
52
index.js
@@ -15,4 +15,5 @@ const fetch = require("node-fetch") | ||
me: "https://adsapi.snapchat.com/v1/me", | ||
mediaBase: "https://adsapi.snapchat.com/v1/adaccounts", | ||
organizations: "https://adsapi.snapchat.com/v1/me/organizations", | ||
specificOrganization: "https://adsapi.snapchat.com/v1/organizations" | ||
specificOrganization: "https://adsapi.snapchat.com/v1/organizations", | ||
}, | ||
@@ -43,3 +44,3 @@ httpOptions: {} | ||
Snap.prototype.me = function() | ||
Snap.prototype.me = function(callback) | ||
{ | ||
@@ -59,2 +60,4 @@ this.httpOptions = { | ||
// Organizations | ||
// TODO - Add withAdAccounts option | ||
Snap.prototype.getAllOrganizations = function(callback) | ||
@@ -93,2 +96,42 @@ { | ||
// Media | ||
Snap.prototype.createMedia = function(options, callback) | ||
{ | ||
if(typeof options === 'function') | ||
throw new Error("Must pass in options") | ||
this.httpOptions = { | ||
method:'POST', | ||
withCredentials:true, | ||
credentials:'include', | ||
headers : { | ||
'Authorization': 'Bearer ' + this.options.accessToken, | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify(options) | ||
} | ||
console.log(this.options.urls.mediaBase +`/${options.media[0].ad_account_id}/media`); | ||
request(this.options.urls.mediaBase +`/${options.media[0].ad_account_id}/media`, this.httpOptions, callback) | ||
} | ||
Snap.prototype.getAllMedia = function(ad_account_id, callback) | ||
{ | ||
if(typeof options === 'function') | ||
throw new Error("Must pass in options") | ||
this.httpOptions = { | ||
method:'GET', | ||
withCredentials:true, | ||
credentials:'include', | ||
headers : { | ||
'Authorization': 'Bearer ' + this.options.accessToken, | ||
'Content-Type': 'application/json' | ||
} | ||
} | ||
request(this.options.urls.mediaBase +`/${ad_account_id}/media`, this.httpOptions, callback) | ||
} | ||
// Other | ||
Snap.prototype.setAccessToken = function(accessToken) | ||
@@ -102,3 +145,3 @@ { | ||
fetch(url, options).then(res => res.json()).then(resData => { | ||
if(resData.request_status === 'SUCCESS') | ||
if(resData.access_token || resData.request_status === 'SUCCESS') | ||
callback(null, resData) | ||
@@ -108,4 +151,7 @@ else | ||
}) | ||
.catch(err => { | ||
callback(err, null) | ||
}) | ||
} | ||
module.exports = Snap |
{ | ||
"name": "node-snapchat-marketing", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Nodejs client for unofficial Snapchat Marketing API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4784
131