How does ember fetch perform ajax query? - javascript

I'm using ember-fetch and from it's source code I cannot figure out where it made the call XHR call.
In another word, where does it call window.XMLHttpRequest?
Coming from a jQuery background, I'm also trying to figure out where can we specify option such as processData = false as seen in here, but this time I want it in ember-fetch-way.

In another word, where does it call window.XMLHttpRequest?
Short answer is: it doesn’t. Its repo says “HTML5 fetch polyfill from github wrapped and bundled for ember-cli users”, so it does what is says on the tin, it uses the Fetch API instead.
(…) I'm also trying to figure out where can we specify option such as processData = false
Right, if I understand this correctly, fetch by default does not process the data it gets, that’s why you see so many examples with something like response.json() (like on the repo you linked).

Related

Image4io and NodeJS: Documentation is clearly outdated. How do I upload an image?

I guess this is as much a call to attention on the fact that the documentation seems to be outright incorrect in its application, as well as just generally lacking. Normally, I would send that part of the message to them personally, but, their contact form is also giving me errors and not sending, so it's not like I have the means to anyway. In the mean time, I'm more worried about getting this code to work, so hopefully someone experienced with this SDK or an Image4io team member sees this and can provide a public answer for others stumbling into this road block.
For starters, I initialized the Image4io object as described in the github here: https://github.com/Image4IO/image4ionodeSDK/
website documentation: https://image4.io/en/documentation/api-sdk/#operation/UploadImage
The image upload example provided on the website's documentation looks like this:
let client=new Image4ioAPI.Image4ioAPI(apiKey,apiSecret);
var request = new Models.UploadImagesRequest("/folderName", true, true);
request.Add("/path/to/image/location/name-of-the-image.jpg", "name-of-the-image", "name-of-the-image.jpg");
let response=client.UploadImage(request);
3 out of the very sparse 4 lines of code they provide give errors. Where did this Models object come from? There is no corresponding class in the import and the code example obviously doesn't show where it was defined. Just what is it and where did it come from?
Well, I found a matching function "UploadImagesRequest" in the original import class, so my guess is Models was deprecated and its functionality was moved into the Image4io class object. If that was the case the solution would be to simply access that function instead... But it's not used the same. It has 4 arguments, the 4th being a "Image4io.UploadFile[]" type. This type has no use examples in the documentation or further details describing what it is exactly. I assume image byte data goes in there somehow, but how?
Finally we have request.Add... except we don't because that isn't a function :( it looks like this was used to actually get the image data (maybe of the type UploadFile?) based on the path of the image. If this function is gone now, how do get file data for use in the upload request function?
Any and all help in figuring out this SDK would be greatly appreciated. Google searches yielded no meaningful results, so hopefully we can help in that department as well. For all I know I just got the wrong version somehow. I guess I could try downgrading to a version that matches the documentation but... that's not a fix in my eyes at all.
Let me know if there's any more info I could provide to help
You can upload image like this:
var client=new Image4ioClient(API_KEY,API_SECRET);
var files=Array();
files.push(new UploadFile("./test.jpg","test.jpg"));
client.UploadImage(new UploadImagesRequest("/",true,false,files))
.then(res=>console.log(res))
If you have binary data at hand, you can write it to a temporary file and then upload them.

AZDO Release Pipeline Gate Success Criteria for Rest-API

I am trying to use the Release Pipeline Gate feature using an Invoke REST API. I am getting the Response successfully, however, I have issues with the success criteria.
The result I am getting from the API Call:
{"projectStatus":{"status":"NONE","conditions":[],"periods":[]}}
Now the issue I am having is with setting up the criteria. If it was per say only {"status":"NONE","conditions":[],"periods":[]} it would've been easy as eq(root['#status'], 'NONE') would've worked, but what can I do in the case above?
I've tried absolutely everything and nothing works. I've followed a lot of examples but I couldn't find an example like this one.
Could you please assist?
After many tests, I managed to find the solution:
eq(jsonpath('$.projectStatus.status')[0],'NONE')
Works flawlessly...

Is is possible to pretty-print output JSON in hapi-swagger?

I'm using hapi-swagger (https://github.com/glennjones/hapi-swagger) to generate Swagger docs for my API. I get the ability to try out the APIs via the browser using this as well, which is great. The problem is that the results of the API call are in a compact format--large JSON structures on a single line. It makes sense that the API should produce output like this, but I would like the swagger web client to pretty-print it for me.
I note that regular Swagger seems to be able to do this, based on my reading of this issue (https://github.com/swagger-api/swagger-core/issues/810) but I'm unsure if it's possible to pass along options that get that same behavior in hapi-swagger.
Is it possible, and if so, how do I do it?

Call JavaScript function from Ruby on Rails model

I have built a Rails app that has an API that returns a JSON object. I want to allow users to write their own scripts and store them. These scripts will then be executed when the user makes an API call to the app and injected as part of the response.
An example would be when a user calls my API, their javascript would be called and whatever is returned from their script would be saved as a string and used by one of my models and used as part of the JSON object - not the full response.
I want to know how to call a javascript function from a rails model, save the output of the javascript as a string in Ruby, and then be able to process whatever is returned before making the API response.
The current answers seem to only be related to the controllers and rendering as JS, but I would like to execute the script from the model.
It should be something like:
string = execute_javascript("return 'hello world';")
This is more related to pure Ruby than Rails as I am just wanting to call it from a standard Ruby class and save the output as a string. I also need to consider the security implications of doing this, but first would like to know how to do it
The simplest solution to execute most common Javascript code is using ExecJS gem. If you are using the Rails standard gem bundle then ExecJS is already included with Rails Coffeescript. A short example:
require "execjs"
ExecJS.eval "'red yellow blue'.split(' ')"
# => ["red", "yellow", "blue"]
The above solution is only good if you are running a prototype. In production, you would want to somehow run the user code in sandbox and preferably on the whole different server. You would also need to ensure the code won't take 100% resource of your server while executing and screen the code to ensure it won't do anything malicious.
You can call javascript function in Helper class and then include that helper inside your model where you need it.

Is it possible to use the Disqus API to get comments from a specific url?

I would also like to do this using javascript client-side scripting only if possible.
You could always use jQuery for the AJAX calls as almost everything on Disqus is now get.
First you would have to get the thread id from using (http://disqus.com/api/docs/threads/list/):
http://disqus.com/api/3.0/threads/list.json?api_key=API_PUBLIC_KEY_HERE&forum=[shortforumid]&thread=link:[link]
The most important part is for the thread= to have link:[link] as the link: says we are using a URL.
After you get the thread id, you will have to visit (http://disqus.com/api/docs/posts/list/):
http://disqus.com/api/3.0/posts/list.json?api_key=API_PUBLIC_KEY_HERE&thread=[thread id]
Just as a reminder, you do not need to put in the brackets...
The accepted answer consists in 2 different calls to Disqus API, to avoid the limit usage you could use only 1 call for obtains a list of comments by an url:
http://disqus.com/api/3.0/posts/list.json?api_key=API_PUBLIC_KEY_HERE&forum=[shortforumid]&thread=link:[link]

Categories

Resources