GET a slide, edit it, and POST it again with minor changes - go

I was hoping someone could help me with something i've been stuck on. I'm not even sure if it's possible to do.
So i basically have a huge Json file which includes all objects used for a certain slide Specifically i used this GET command:
GET https://slides.googleapis.com/v1/presentations/{presentationId}
I then got a huge 200.000 line Json response which has alot of stuff like colors for each thing, position of every element on each slide ect. I save this as a JSON file on my pc. I only need it once as a form of template.
Then my golang code dynamically edits some of its values (after converting it to structs ofc).
Now i want to POST it back up. It has a new name now, new ID, but 99,9% of the values are the same.
Is it possible to do this?
And sorry in advance. I know people here tend to get mad at "stupid questions" or if i forget to add something, but i'm new here, and i hope I can get some help. Been stuck for a long while.

Yes, you can. There is a Go client library that allows you to do this if you're not set on using a REST API. If you are set on using a REST API, you should be able to post this endpoint:
POST https://slides.googleapis.com/v1/presentations/{presentationId}:batchUpdate
Side note, the Google documentation (imo) is fantastic, a little googling goes a long ways :)

Related

how to pass object on Spring's REST Template using get

I am using a Spring REST template to pull data using POST and everything is working fine.
ResponseEntity<MyObject> resp= restTemplate.postForEntity("url", inputParam, MyObject.class);
But now since I am not doing any POST operation, I want to change it to GET. I can do this by adding all input params as url parameters and do:
ResponseEntity<MyObject> resp= restTemplate.getForEntity("url",MyObject.class);
But the problem is, inputParam has alot of parameters, so preparing the url manually is not the best solution. Also GET requests have length restrictions.
Is there any other better solution for handling this?
First of all, I think your second line should say getForEntity().
Secondly, there are numerous URL builder class options if you google around (including ones from Spring). So, I would use a URL building class to prepare the URL rather than manually doing it yourself which can get messy.
https://www.baeldung.com/spring-uricomponentsbuilder
https://square.github.io/okhttp/3.x/okhttp/okhttp3/HttpUrl.html
https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/UriBuilder.html
Length Restriction
There's a good SO entry here noting length restrictions of common browsers; so if its going through a browser then I'd stick to POST if you're potentially over the 2000 lower limit they suggest.
Technically there shouldn't be a limit according to https://www.w3.org/2001/tag/doc/get7#myths.
I think on a lot of back-end technologies there is no limit. So, if this is API-only and not going through a browser (like back-end to back-end) then you may be able to ignore those limits. I'd recommend looking into that specifically though and testing it with your back-end.
UniRest
Also, as a personal recommendation, I have found UniRest to be an amazingly useful REST client which makes most of my code much cleaner :). If you have time, maybe try giving that a shot.
http://unirest.io/java.html

How to keep track of some user data without displaying it in the URL

I'm developing a web app with two languages, German and English. I have implemented searching on my webpage, and I want to keep track of the user's locale when searching.
How can I achieve this:
http://localhost:8080/user/search?search=pax?lang=de
instead of:
http://localhost:8080/user/search?search=pax
In my form I have:
action="/user/search"
I tried
action="<spring:message code="user.search.movie.link"/>
user.search.movie.link = /user/search or /user/search?lang=de
but it doesn't work.
Putting information in URL parameters is good in some cases*, but probably not this one. It seems likely that a user chooses their language setting once, around login time, and then rarely if ever changes it. Or it might even be set automatically. If so, language is something you might want to store in the user's session, or a persistent store like a database if you're using one. You seem to be using Spring, and I don't know a lot about their session handling, but their docs are at https://docs.spring.io/spring-session/docs/current/reference/html5/.
*: for more on this, you might want to read up on the differences between GET requests and POST requests (here's one of many SO posts on the topic). The most relevant part for you is that GETs are the ones that have visible parameters in the URL, but there are lots of other reasons to use one over the other.

using entsp in GSA - making no difference to the results

I was hoping someone had some experience using the entsp flag in GSA and was able to point out what I am doing wrong. I've read the documentation but can't figure it out.
The query string I am passing through is:
?as_sitesearch=examplesite.com&callback=angular.callbacks._1&collection=hybrid_site_colection&entsp=a__di_site_biasing&frontend=jsonp&num=10&query=test&start=0
I've set up the biasing in the GSA, and when I apply it to the frontend itself, it behaves. But I was hoping to pass it in dynamically, as I believed you could (we are likely to want to dynamically pass through one of a few biasing, depending on where the user is coming from), it makes no difference.
Am I missing a tag, or can someone see anything else wrong?
Sorry, peoples, I've seen now that the problem is that we are going through a JSON bridge that isn't passing through my variables.
When I go directly to the GSA with a frontend, it works.

Extract value from javascript object in site using xpath and import.io

I want extract a number provided by javascript object in site, but I really don't understand that I am doing.
I tried different versions using alike examples and guidelines in import.io site and other tutorial sites, but I got only 1 of two results: extracted all numbers on given page or nothing at all.
I tried e.g. //[contains(.,"Unikālo apmeklējumu skaits:")]#type ; //[contains(.,"Unikālo apmeklējumu skaits:")] . Most likely it's necessary to add there something else, but I just don't know that.
Link I am interested in to extract from is: https://www.ss.lv/msg/lv/clothes-footwear/womens-clothes/trousers/ikcbb.html and information necessary is a number after text "Unikālo apmeklējumu skaits:" which is given by javascript.
Hopefully someone will be able to help me with this problem.
For someone who is new in web-scraping this should be a hard task, I'll ty to explain it. First of all, the xpath to get to that location could be something like this:
'//td[#class="msg_footer" and contains(text(), "Unik")]'
Now you have that tag (and what it contains), but if you check it doesn't contain the number you need, that content is being dynamically loaded with a javascript, and the javascript is this one:
<script type="text/javascript"><!--
var ss_w='rādīt numuru';
document.write( '<scr'+'ipt id="contacts_js" src="/js/2015-10-27/37863/VHoBGkpqSV8bfwkdTX9AXEpZXCVDlASIQ1ZV3kK.js?t='+new Date()+'"></scr'+'ipt>' );
--></script>
which could be gotten from the response with this xpath:
'//script[contains(text(), "contacts_js")]/text()'
from that string, you should replicate the url that comes in src, so this url for example:
/js/2015-10-27/37863/VHoBGkpqSV8bfwkdTX9AXEpZXCVDlASIQ1ZV3kK.js?t=
and add to the end the current date, as javascript creates it with new Date(). Then you should make a request to that url (adding the previous response domain), so something like:
https://www.ss.lv/js/2015-10-27/37863/VHoBGkpqSV8bfwkdTX9AXEpZXCVDlASIQ1ZV3kK.js?t=Wed%20Oct%2028%202015%2020:56:42%20GMT-0500%20(PET)
check that the date is urlencoded. it should return a response like:
var PHONE_CNT=-1;var PHONE_CNT2=-1;var PHONE_CNT3=-1;var EMAIL_CNT=-1;var SHOW_CNT=22;var PH_c="";var PH_1=0;var PH_2=0;var PH_3=0;
pcc_id=0;PH_1=gpzd("JTg3aCU3QyU1QnolN0MlN0JYcWh6JTVCdCU5NSU4QyU5MnV4ayU5QXElN0IlOTQlNUNweiU5MGtvJTdCJThFJTVF","55937369");
where you can check that the value inside SHOW_CNT is the number you want.
If you want to know how I figured out which request and which script was populating that response tag, well that I did using firebug, searching for SHOW_CNT inside all of the responses that involve calling to your URL, which pointed to the request I specified, and then trying to check who was requesting that.
Hope it helped.
support#import.io are the guys to speak to, they give free advice and help trouble shoot problems just like this all the time.
There are all kinds of tips and tricks you can use... for example import.io provide (an undocumented beta) JavaScript Pre-render service that would likely work for you in this scenario. API publish failures are sometimes caused by timeouts while waiting for sites to render JS, this would fix that.
http://support.import.io/knowledgebase/articles/623235-infinite-scroll-and-javascript-prerender-beta
I hope this helps.

interpreting ajax code

I have traced some ajax stuff and I am trying to figure out what it means. I was hoping to translate it into a url but it seems to involve some Get request based on searched I did.
An help appreciated.
**new Ajax.Request(fspring.baseURL+"search/getProfileResults",
{parameters:{ajax:1,q:_4,page:_5},onStatOK:function(_6){ var _7=new Element("div");
I thought it would be the baseURL in this case
http://helloworld.com/search/getProfileResults and I know it needs two parameters
fspring.baseURL could be anything, so I can't really help you there. It doesn't ring a bell to me for any particular Javascript library.
The parameters object will be converted by Prototype into a querystring, in this case it'll look something like this:
http://helloworld.com/search/getProfileResults?ajax=1&q=_4&page=_5
Except _4 and _5 will be replaced with the variable contents.
An easier way to figure out what's going on would be to just open up the page in Firebug and look in the Console to see what the AJAX query was.

Resources