Items: Get item revision difference returns empty array - podio

I am trying to return the diffence in field values between two revisions using app authentication but I'm getting an empty array.
And when trying to use the api function "Get Item revision" I'm getting "Object not found" response.
Any help would be much appreciated :)
const podio = new Podio({
authType: 'app',
clientId: clientId,
clientSecret: clientSecret });
podio.authenticateWithApp(app_id, appToken, (err) => {
if (err) throw new Error(err);
podio.isAuthenticated().then(function () {
// ready to make API calls
apiRoutes.get('/item', function (req, res) {
podio.request('GET', `/item/702620400/revision/1899410196/1910867632`).then(function (responseData) {
res.json(responseData);
});
});
}).catch(err => res.send(err));
});

Podio documentation is not clear enough when describes calls for item revisions. Here is how it works, example in Ruby:
item_revisions = Podio::ItemRevision.find_all_by_item_id(item_id)
last = item_revisions.length - 1
revision_last = Podio::ItemRevision.find(item_id, last)
revision_beforelast = Podio::ItemRevision.find(item_id, last - 1)
diff = Podio::ItemDiff.find_by_item_and_revisions(item_id, last - 1, last)
Misleading part is revision_id vs revision vs item_revision_id.
For "Get Item revision" and "Get item revision difference" calls please use revision which goes for each item from 0 and increases by 1 with each new revision. Last revision available for item is item_revisions.length - 1 from example above.

Related

How "equals" in express-validator works?

I have to validate two fields are equals. In this case both passwords are the same. The problem it is that the "equals" from express-validator is not working.
This is the code:
app.post('/register', [
isNotLogged,
check('email', 'The email must be a valid one').isEmail(),
check('nickname', 'The nickname must be filled').notEmpty(),
check('password', 'The password must contain minimum eight characters, at least one letter and one number')
.matches("^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{8,}$"),
//This is not working
check('passwordConfirm', 'The passwords must match').equals('password'),
validateResults
], register)
Unfortunately Express-Validator doesn't work with Validator.js's equals(), you'll have to use one of Express-Validator's middlewares and not its Validator.js affility.
Here is an example straight from Express-Validator's website which seems fit your use case:
body('oldPassword')
// if the new password is provided...
.if((value, { req }) => req.body.newPassword)
// OR
.if(body('newPassword').exists())
// ...then the old password must be too...
.notEmpty()
// ...and they must not be equal.
.custom((value, { req }) => value !== req.body.newPassword);
You do not need to use Express-Validator's check middleware as you are throwing away your ability to utilise Validator.js's validators. Instead of check you could use isEmail() and exists() (an Express-Validator validator). Also, you don't need to have your middlewares as part of an array (although you can):
app.post('/register',
isNotLogged,
body('email').isEmail().withMessage('The email must be a valid one').bail().trim(),
body('nickname').exists({ checkNull: true }).withMessage('The nickname must be filled').bail().trim(),
body('password').trim().if((value, { req }) => (typeof req.body.passwordConfirm !== 'undefined')).bail().custom((value, { req }) => value !== req.body.passwordConfirm).withMessage('The email must be a valid one').bail().trim().matches("^(?=.*[A-Za-z])(?=.*\\d)[A-Za-z\\d]{8,}$"),
validateResults,
register
);
Here the body() function would come from const { body } = require('express-validator') theres a few others similar for query paramaters, header parameters ect, all are documented here.
I also used some trim()s and bails()s just to be safe. You can read up on those here and here.
I solve this problem like this:
code before:
const registrar = async (req, res) => {
await check('password').isLength({ min:6}).withMessage('password short ').run(req);
await check('repetir_password').equals('password').withMessage('password diferente?').run(req);
let resultado = validationResult(req);
res.json(resultado.array());
};
after:
correct code: change
'password'
by
req.body.password
const registrar = async (req, res) => {
await check('password').isLength({ min: 6 }).withMessage('password corta ').run(req);
await check('repetir_password').equals(req.body.password).withMessage('password diferente?').run(req);
let resultado = validationResult(req);
res.json(resultado.array());
};

Vue.js Nuxt - cannot access Array (value evaluated upon first expanding error)

I have the following function which gives me an array called URLs
const storageRef = this.$fire.storage.ref().child(fileName)
try {
const snapshot = storageRef.put(element).then((snapshot) => {
snapshot.ref.getDownloadURL().then((url) => {
urls.push(url)
})
})
console.log('File uploaded.')
} catch (e) {
console.log(e.message)
}
});
console.log(urls)
console.log("about to run enter time with imageurls length " + urls.length)
When I run console.log(URLs) initially I do see the array like the following
[]
0: "testvalue"
length: 1
__proto__: Array(0)
However, there is a small information icon stating
This value was evaluated upon first expanding. The value may have changed since.
Because of this, when I try to get the length of URLs, I get zero, meaning the value is being updated.
Does anyone know what's happening? I am using Vue.JS/Nuxt.

How to auto reference to other post in Sanity.io?

i recently tried sanity.io CMS to manage content on my personal blog. however i'm facing a little difficulty to find part in the documentation about 'auto referencing' (this just my term). i want for each my blog post to have data of next and previous post, so i can create button at the bottom to navigate to next or previous blog post. how can i achieve it? thankss
To me, this is a job for a query rather than a reference.
There is no way to "auto-reference" something the way you are describing however there are a few ways you can achieve your effect:
1. Manually link them
2. Create a custom input field that queries for your previous/next posts. More on custom input components here: https://www.sanity.io/docs/custom-input-widgets
3. Use a GROQ query to get all posts and the find the ones you need (in JS):
const posts = await Sanity.fetch(`*[_type == 'post']`);
const currentPostIndex = posts.findIndex(post => post.id === currentPost.id);
const previousPost = posts[currentPostIndex - 1];
const nextPost = posts[currentPostIndex + 1];
4. Add date queries to get the adjacent posts with GROQ (in JS):
const posts = await Sanity.fetch(`*[_type == 'post' && _id == '${currentPost.id}' ][0] {
'currentPost': {
...
},
'previousPost': *[_type == 'post' && _createdAt < ^._createdAt][0],
'nextPost': *[_type == 'post' && _createdAt > ^._createdAt] | order(_createdAt asc)[0]
}`);
const currentPostIndex = posts.findIndex(post => post.id === currentPost.id);
const previousPost = posts[currentPostIndex - 1];
const nextPost = posts[currentPostIndex + 1];
More info on GROQ https://www.sanity.io/docs/query-cheat-sheet

Community Connector getData() Request only uses the first two schema fields, not all four

I am building a Community Connector between Google Data Studio and SpyFu.com, in order to funnel SEO information for a specific url into the GDS Dashboard.
However, My getData() request only contains the first two fields from my Schema. As you can see, I have four listed in the code. The result is only the first two fields in the schema are printed to GDS.
I've been through tutorials, official documentation, YouTube videos, looked this issue up on google and checked out the community resources on GitHub.
//Step Two: Define getConfig()
function getConfig(request) {
var cc = DataStudioApp.createCommunityConnector();
var config = cc.getConfig();
config.newInfo()
.setId('instructions')
.setText('Give me SpyFu information on the following domain:');
config.newTextInput()
.setId('domain')
.setName('Enter the domain to search')
.setHelpText('e.g. ebay.com')
.setPlaceholder('ebay.com');
config.newTextInput()
.setId('SECRET_KEY')
.setName('Enter your API Secret Key')
.setHelpText('e.g. A1B2C3D4')
.setPlaceholder('A1B2C3D4');
config.setDateRangeRequired(false);
return config.build();
}
//Step Three: Define getSchema()
function getFields(request) {
var cc = DataStudioApp.createCommunityConnector();
var fields = cc.getFields();
var types = cc.FieldType;
var aggregations = cc.AggregationType;
fields.newDimension()
.setId('Keyword')
.setName('Keywords')
.setDescription('The keywords most often attributed to this domain.')
.setType(types.TEXT);
fields.newMetric()
.setId('Rank')
.setName('Rankings')
.setDescription('The ranking of the target site keyword on the Google Search Page.')
.setType(types.NUMBER);
fields.newMetric()
.setId('Local_Monthly_Searches')
.setName('Local Searches per Month')
.setDescription('Number of times, locally, that people have searched for this term within in the last month.')
.setType(types.NUMBER);
fields.newMetric()
.setId('Global_Monthly_Searches')
.setName('Global Searches per Month')
.setDescription('Number of times, globally, that people have searched for this term within in the last month.')
.setType(types.NUMBER);
return fields;
}
function getSchema(request) {
var fields = getFields(request).build();
return { schema: fields };
}
//Step Four: Define getData()
function responseToRows(requestedFields, response, domain) {
// Transform parsed data and filter for requested fields
return response.map(function(Array) {
var row = [];
requestedFields.asArray().forEach(function (field) {
switch (field.getId()) {
case 'Keyword':
return row.push(Array.term);
case 'Rank':
return row.push(Array.position);
case 'Local_Monthly_Searches':
return row.push(Array.exact_local_monthly_search_volume);
case 'Global_Monthly_Searches':
return row.push(Array.exact_global_monthly_search_volume);
case 'domain':
return row.push(domain);
default:
return row.push('');
}
});
return { values: row };
});
}
function getData(request) {
console.log("Request from Data Studio");
console.log(request);
var requestedFieldIds = request.fields.map(function(field) {
return field.name;
});
var requestedFields = getFields().forIds(requestedFieldIds);
// Fetch data from API
var url = [
'https://www.spyfu.com/apis/url_api/organic_kws?q='
+ request.configParams.domain
+ '&r=20'
+ '&p=[1 TO 10]'
+ '&api_key='
+ request.configParams.SECRET_KEY,
];
try {
var response = UrlFetchApp.fetch(url.join(''));
} catch (e) {
DataStudioApp.createCommunityConnector()
.newUserError()
.setDebugText('Failed URL Fetch Attempt. Exception details: ' + e)
.setText('There was an error accessing this domain. Try again later, or file an issue if this error persists.')
.throwException();
}
console.log("Response from API");
console.log(response);
//Parse data from the API
try {
var parsedResponse = JSON.parse(response);
} catch (e) {
DataStudioApp.createCommunityConnector()
.newUserError()
.setDebugText('Error parsing the JSON data. Exception details: ' + e)
.setText('There was an error parsing the JSON data. Try again later, or file an issue if this error persists.')
.throwException();
}
var rows = responseToRows(requestedFields, parsedResponse);
return {
schema: requestedFields.build(),
rows: rows
};
}
I need the GDS to post four columns of data. They are, "Keyword", "Rank", "Local Monthly Searches" and "Global Monthly searches".
I cannot figure out how to create a "fixed schema" so that the system always prints these four columns of data at every request. The tutorials and various documentation say it's possible, but not how to do it. Please help!
The number of metrics initially called up by the Google Community Connector is handled from the front-end, via Google Data Studio.
The back-end system (the Connector) only initially posts the default dimension and default metric. Getting the rest of the schemas to post should be handled when you are building a report on Google Data Studio. Simply click on the data set, select "data" on the right-hand menu, scroll down to either Metrics or Dimensions, and pick the ones you wish to add to the current set.
Note that these are the fields you established earlier in the coding process, when you were setting up your schemas.
Here, you're filtering your defined schema for fields that are present on the request object received by getData().
var requestedFieldIds = request.fields.map(function(field) {
return field.name;
});
var requestedFields = getFields().forIds(requestedFieldIds);
The visualization in Google Data Studio that is the catalyst for the request will determine which fields are requested.

Eventbrite API date range parameter for organizer_list_events

I need a way to search via the eventbrite api past events, by organizer, that are private, but I also need to be able to limit the date range. I have not found a viable solution for this search. I assume the organizer_list_events api would be the preferred method, but the request paramaters don't seem to allow for the date range, and I am getting FAR too many returns.
I'm having some similar issues I posted a question to get a response about parsing the timezone, here's the code I'm using to get the dates though and exclude any events before today (unfortunately like you said I'm still getting everything sent to me and paring things out client side)
Note this is an AngularJS control but the code is just using the EventBrite javascript API.
function EventCtrl($http, $scope)
{
$scope.events=[];
$scope.noEventsDisplay = "Loading events...";
Eventbrite({'app_key': "EVC36F6EQZZ4M5DL6S"}, function(eb){
// define a few parameters to pass to the API
// Options are listed here: http://developer.eventbrite.com/doc/organizers/organizer_list_events/
//3877641809
var options = {
'id' : "3588304527",
};
// provide a callback to display the response data:
eb.organizer_list_events( options, function( response ){
validEvents = [];
var now = new Date().getTime();
for(var i = 0; i<response.events.length; i++)
{
var sd = response.events[i].event.start_date;
var ed = response.events[i].event.end_date;
var parsedSD = sd.split(/[:-\s]/);
var parsedED = ed.split(/[:-\s]/);
var startDate = new Date(parsedSD[0], parsedSD[1]-1, parsedSD[2], parsedSD[3], parsedSD[4], parsedSD[5]);
var endDate = new Date(parsedED[0], parsedED[1]-1, parsedED[2], parsedED[3], parsedED[4], parsedED[5]);
if(endDate.getTime()<now)
continue;
response.events[i].event.formattedDate = date.toDateString();
validEvents.push(response.events[i])
}
if(validEvents.length == 0)
{
$scope.$apply(function(scope){scope.noEventsDisplay = "No upcoming events to display, please check back soon.";});
}
else
{
$scope.$apply(function(scope){scope.noEventsDisplay = "";});
}
$scope.$apply(function(scope){scope.events = validEvents;});
//$('.event_list').html(eb.utils.eventList( response, eb.utils.eventListRow ));
});
});
}