Action script 3 /Json Vend api - json

I have undertaken a project to create a mobile application using flash professional 6.
I am creating the app for a friend of mine who has just opened a store and has signed up to using the vend P.O.S system.
He wants the app to be able to get and post data from the vend system via the api.
The API vend give is a RESTful api that returns responses as json.
My question is how would i go about starting this in flash professional 6?
i am using flash professional as i am used to it and, i know since flash player 11, comes with a json encoder/decoder. However i am not sure whether this would actually help me in achieving what i need.
Would it be for instance better to have flash communicate with a php file that in turn posts and gets from the api ,or just have it communicate with the api itself?
Would i instead of using json to post data be better off having the app post using rest?
what is the authentication process in flash to access the server to use the api?
I have read up on urlrequest and urloaders in actionscript3, but i am still confused as how to implement this to get the desired out come.
if any one could point me in the right direction of post some sample script that could show a draft that i need that would be perfect.
cheers

I don't know the Vend API but you can do JSON with the AS3 API from the client (unless the terms and conditions of the service mandate conditions on any API keys, for example).
On first glance, the code snippets from How to post JSON data using Actionscript 3.0? should still work. The update I notice there is that you can use the new JSON class directly instead of the com.adobe.serialization.json namespace.

this is the answer to my question. its simple but it does what i need.
var myRequest:URLRequest = new URLRequest("https://www.yourdomian.com");
var myLoader = new URLLoader();
myLoader.addEventListener(Event.COMPLETE, onload);
myLoader.load(myRequest);
function onload(evt:Event):void
{
var myOutput:Object = JSON.parse(myLoader.data);
trace(myOutput);
}

Related

Autodesk - Get manifest info with Javascript

Is there an easy accessible function to get manifest data in javascript to check if the model is done translating?
something like viewerApp.getManifest().progress. Where viewerApp is a ViewingApplication.
Is there something like this, or should I retrieve the data via server code and pass it on to javascript.
No, there is not an client side API as you mentioned to get the progress of model translation.
I am interested in the reason why doing that way. Actually, the ViewingApplication is a client side API and is used to view the model when the model is already translated, it's not suggested to request the translation progress by this API.
If you want to get the status of the translation progress, Yes, using the GET :urn/Manifest to get the progress.

beginner: Json Result serialization in a asp.net mvc page without jquery/javascript/ajax

i am a programming student, working with a asp.net mvc 4 web app, i am testing a simple web app that uses the http://openweathermap.org/api so when i click a link, it executes the Action Result on the home controller, the code to get the data from the api is in this action result and it fetches the api json data and stores it in a viewbag.message that is then passed back to the view. I have that much working in so far as i can get the json result and see it on the view. I am not sure how to proceed & the pages i have looked up seem to be centered around ajax jquery
My question is about the serializing/displaying the json result without adding any plugins or anything just yet, i would like to format / serialise it so it looks better maybe fit it into a table or something, but without getting into ajax & jquery just yet as i haven't learned that part yet.
I have removed the api key from the code.
public ActionResult getWeather()
{
var uri = "http://api.openweathermap.org/data/2.5/forecast?id=7778677&APPID=123456789";
WebClient client = new WebClient();
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
var resultContent = client.DownloadString(uri);
ViewBag.Message = resultContent;
return View();
}
And here is the result view:
screenshot of result view showing the json data from the api
I hope i am explaining myself correctly,
Thank You.
M.
.NET 4 has a built-in JSON serializer/deserializer, but if you can, use NuGet to get NewtonSofts JSON Framework as it is much more flexible and powerful.
With it, you could do something along the lines of this within your backing code for your view, or maybe even in your view's template with Razor:
WeatherDataModel[] myWeatherData = JsonConvert.DeserializeObject<WeatherDataModel>(ViewBag.Message);
(This assumes you have a model for the weather data that matches up with the data you get from the openweathermap api.)
You should then be able to use a loop to get the data in your WeatherDataModel array into a table.
Another option, if you are willing to take a small leap into jquery, can be found in the answer to this question:
How to load JSON data into Bootstrap table?
It makes use of a very simple snippet of javascript/jquery and bootstrap.
In your case, you would set the data to use the JSON you stored in the ViewBag.Message:
$(function () {
$('#table').bootstrapTable({
data: ViewBag.Message
});
});
If you built your app in VS 2015 and used the MVC 4 template, you may very well already have bootstrap built into your project. If not, you can easily import it with NuGet.
I haven't done much in MVC 4 for a while now, and so I will point you to this question's answer about where best to place your scripts: Proper place to load jQuery in MVC Layout view
Good luck!

grails to build Web interface using REST API

I am fairly new to Grails, and I have a few questions on how to proceed.
I have a REST API which I will use to retrieve the data , for exemple :
http://localhost/api/data/list
Which gives this result :
{"data":[{"col1":"blabla","col2":0},{"col1":"moreblabla","col2":1}]}
I want to use Grails to build an interface for those data (show, edit, add, delete)
Should I create a domain called Data ?
How do I tell Grails to to use the REST API and not a database ?
I am really clueless so I hope you can light the way ;)
Thank you.
Grails currently doesn't have a GORM plugin for using a REST endpoint as a persistence store. That is planned functionality, but is not slated to land until later this year (2012 - Q4).
That being said, you can write a service that will allow you to do basic CRUD operations on an object and get/persist to and from your REST endpoint. The place to start with that is the HttpBuilder, and perhaps the REST client plugin.

Flex, using navigateToURL to send an AMF object and open the response in a new window

I have an application that connects to an AMF gateway exclusively (in a certain mode) and I have a service that renders some HTML that I want to display in a new window outside of the Flex application.
Is it possible, in Flex, to use navigateToURL to send an AMF object and open the response in a new window?
EDIT: More specifically, does anyone have insight into how an AMF request can be properly constructed in actionscript and sent via the POST data of a URLRequest?
UPDATE: Still looking for a clear spec for AMF that makes it obvious how to construct the service call related headers in AMF and what headers are required. Some guidance in this area would be helpful. I've done more reading and have seen some people talk about some custom solutions they have that work in a similar way to what I've mentioned above, although it seems like those solutions are guarded assets. But this further enforces my belief that this is quite possible.
I'd say no... Even if you could create an AMF packet by hand in AS3, how would you pass it to the URL using navigateToURL? How would the browser know how to handle the AMF values returned from your service call?
I suggest you call the AMF gateway service in your Flash app; do the processing that needs done; and then return a URL to the results. In the result handler method, you can open the URL using navigateToURL.
#Flextras is along the right lines - the AMF gateway in particular with AMFPHP isn't used with a URLRequest, instead you use the RPC remoting - most typically RemoteObject where you specify the receiving gateway (ie: endpoint or more generically the destination channel - but this one needs to be in your services-config which resides on the server), and you typically assign a responder to handle the result/failure events (in which your response is almost always a class marked as a [RemoteAlias]).
See: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/rpc/remoting/mxml/RemoteObject.html#includeExamplesSummary

Facebook Event Json Mesage- how can i get it?

I would like to ask if someone know how to grab a facebook event json message. It doesnt matter if it has to happen programatically. I just want to be able to read the message one way or another.
thanks in advance.
P.s. Maybe an awful question but here you go !!!
I once had to code a small chunk of code to parse a json-encapsulated message. However recently I found out there's a handy solution for it if you use Java
Resty is a small, convenient library
to talk to RESTful services from Java.
It’s surprisingly complex to do the
simplest HTTP calls with the standard
Java library. Resty hopes to change
that.
http://beders.github.com/Resty/Resty/Overview.html
Resty r = new Resty();
Object name = r.json("http://ws.geonames.org
/postalCodeLookupJSON?postalcode=66780&country=DE")
.get("postalcodes[0].placeName");
Just import a small jar lib and you'll be surprised. I currently use this class for getting info from url API.