Hi I have got the following method which fetches the JSON data
$("#Result").click(function () {
$.ajax({
type: "POST",
url: "SampleWebForm.aspx/FetchLibraryDetails",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
// Replace the div's content with the page method's return.
$("#Result").text(msg.resources.description.title);
}
});
});
The JSON result from the call is as below
LibraryData{
"resources": {
"description": {
"title": "Getting started with the online library",
"body": "The online library contains amazing resources and can seem overwhelming. This guide gives a very basic introduction. Over your years of study with us you will learn a lot more about resources and how to find and manage them.",
"image": "http:\/\/www.testWebsite.com\/library\/files\/library\/imagecache\/node_standard\/web-journal%20shelves.JPG",
"link": "http:\/\/www.testWebsite.com\/library\/node\/91194"
},
"items": [{
"title": "Large-scale open innovation: open source vs. patent pools",
"body": "Thierry Rayna (2010), 'Large-scale open innovation: open source vs. patent pools', International Journal of Technology Management, vol. 52, no. 3\/4, pp:477-0",
"image": "http:\/\/www.testWebsite.com\/libraryservices\/covers\/?id=0140-6736",
"link": "http:\/\/www.testWebsite.com\/libraryservices\/resource\/article:7477"
},
{
"title": "Introduction to Library Services",
"body": "A great introductory session that will explore the online library. You will know how to find information in your subject and be shown some key resources and services to help with your studies.",
"image": "http:\/\/www.testWebsite.com\/library\/files\/library\/imagecache\/node_standard\/web-journal%20shelves.JPG",
"link": "http:\/\/www.testWebsite.com\/library\/node\/97689"
}]
},
"access": {
"items": [{
"title": "Large-scale open innovation: open source vs. patent pools",
"body": "Thierry Rayna (2010), 'Large-scale open innovation: open source vs. patent pools', International Journal of Technology Management, vol. 52, no. 3\/4, pp:477-0",
"image": "http:\/\/www.testWebsite.com\/libraryservices\/covers\/?id=0140-6736",
"link": "http:\/\/www.testWebsite.com\/libraryservices\/resource\/article:7477"
},
{
"title": "Getting started with the online library",
"body": "The online library contains amazing resources and can seem overwhelming. This guide gives a very basic introduction. Over your years of study with us you will learn a lot more about resources and how to find and manage them.",
"image": "http:\/\/www.testWebsite.com\/library\/files\/library\/imagecache\/node_standard\/web-journal%20shelves.JPG",
"link": "http:\/\/www.testWebsite.com\/library\/node\/91194"
}],
"description": {
"title": "Getting started with the online library",
"body": "The online library contains amazing resources and can seem overwhelming. This guide gives a very basic introduction. Over your years of study with us you will learn a lot more about resources and how to find and manage them.",
"image": "http:\/\/www.testWebsite.com\/library\/files\/library\/imagecache\/node_standard\/web-journal%20shelves.JPG",
"link": "http:\/\/www.testWebsite.com\/library\/node\/91194"
}
},
"search": {
"items": [{
"title": "Large-scale open innovation: open source vs. patent pools",
"body": "Thierry Rayna (2010), 'Large-scale open innovation: open source vs. patent pools', International Journal of Technology Management, vol. 52, no. 3\/4, pp:477-0",
"image": "http:\/\/www.testWebsite.com\/libraryservices\/covers\/?id=0140-6736",
"link": "http:\/\/www.testWebsite.com\/libraryservices\/resource\/article:7477"
},
{
"title": "Getting started with the online library",
"body": "The online library contains amazing resources and can seem overwhelming. This guide gives a very basic introduction. Over your years of study with us you will learn a lot more about resources and how to find and manage them.",
"image": "http:\/\/www.testWebsite.com\/library\/files\/library\/imagecache\/node_standard\/web-journal%20shelves.JPG",
"link": "http:\/\/www.testWebsite.com\/library\/node\/91194"
}],
"description": {
"title": "Getting started with the online library",
"body": "The online library contains amazing resources and can seem overwhelming. This guide gives a very basic introduction. Over your years of study with us you will learn a lot more about resources and how to find and manage them.",
"image": "http:\/\/www.testWebsite.com\/library\/files\/library\/imagecache\/node_standard\/web-journal%20shelves.JPG",
"link": "http:\/\/www.testWebsite.com\/library\/node\/91194"
}
},
"helpdesk": {
"items": [{
"title": "Large-scale open innovation: open source vs. patent pools",
"body": "Thierry Rayna (2010), 'Large-scale open innovation: open source vs. patent pools', International Journal of Technology Management, vol. 52, no. 3\/4, pp:477-0",
"image": "http:\/\/www.testWebsite.com\/libraryservices\/covers\/?id=0140-6736",
"link": "http:\/\/www.testWebsite.com\/libraryservices\/resource\/article:7477"
},
{
"title": "Getting started with the online library",
"body": "The online library contains amazing resources and can seem overwhelming. This guide gives a very basic introduction. Over your years of study with us you will learn a lot more about resources and how to find and manage them.",
"image": "http:\/\/www.testWebsite.com\/library\/files\/library\/imagecache\/node_standard\/web-journal%20shelves.JPG",
"link": "http:\/\/www.testWebsite.com\/library\/node\/91194"
}],
"description": {
"title": "Getting started with the online library",
"body": "The online library contains amazing resources and can seem overwhelming. This guide gives a very basic introduction. Over your years of study with us you will learn a lot more about resources and how to find and manage them.",
"image": "http:\/\/www.testWebsite.com\/library\/files\/library\/imagecache\/node_standard\/web-journal%20shelves.JPG",
"link": "http:\/\/www.testWebsite.com\/library\/node\/91194"
}
}
}
My Question
Basically I am getting a set of JSON data (as above) on to the "data" object.
While debugging I can see the whole json data in the "data" object and can write on to a div tag using “data.d”
But I want to display the data separately from the JSON result Like
4 DIVs resources, access, search & helpdesk.
Under each of these I want to display the corresponding Description and items (each having title, body, image and link).
You have several different options, you can loop through the json object and hand roll some html to do what you want.
or - a much better way would be to use a library that supports templates like Knockout or Angular
If all you need is templates I would go with something like Knockout
Check out the Note 2 example - Using "foreach" option with named template
I personally like Angular, however it may be overkill for your situation
You can iterate over your Object and append some HTML-Element with propertys or Key-Value-Pairs like:
for (var key in obj) {
// do something
if (obj.hasOwnProperty(key)) {
// do somthing else
}
}
Related
I've found this example that is using the Catalog URL Reference for populating custom slots in Alexa Skill.
The problem is that I don't know how to populate this catalog.
I was able to create the model catalog using ask cli like this:
ask api create-model-catalog -n catalog_name -d "description"
That produces me the catalogId in the form "catalogId" : "amzn1.ask.interactionModel.catalog.blabla" like the one in the GitHub example in the first link.
The problem is that I don't know how to put the values (for example the ingredients.json in the above example) inside that catalog.
I've tried using
ask api create-model-catalog-version -c catalogId -f ingredients.json
But what I obtain is
Call create-model-catalog-version error.
Error code: 400
{
"message": "Request is not valid.",
"violations": [
{
"message": "'source' field of the request is invalid."
}
]
}
In the documentation, there isn't an example of how to deal with this so I'm stuck at this point.
Thanks for your help
In order to create and use a catalog in your alexa skill, you have to:
Upload the catalog file into a bucket or another public storage endpoint.
After that, you have to specify a JSON file with the following content (eg. catalog.json):
{
"type": "URL",
"url": "[your catalog url]"
}
Use the ask api to create the catalog, as you mentioned, to get your catalog-id:
ask api create-model-catalog --catalog-name "IngredientsCatalog"
--catalog-description "Ingredients"
Create a model catalog version by using the file that contains your catalog URL:
ask api create-model-catalog-version --file .\catalog.json --catalog-id [your catalog-id]
This call will provide a command to track the create version status. Something like:
ask api get-model-catalog-update-status -c [your catalog-id] -u [request id]
If the version has been created successfully, then you can set it on your skill interaction model:
"types": [
{
"name": "Ingredient",
"valueSupplier": {
"type": "CatalogValueSupplier",
"valueCatalog": {
"catalogId": "[your catalog-id]",
"version": "[the desired version number]"
}
}
}
]
I can add a little more here that may be helpful:
In step 1 in the answer above, from my testing the S3 bucket must be public. Also, below is the format of the JSON that you will want to use, including the use of synonyms which is not described in the official Amazon example. Note that you don't have to include an ID as shown in that example.
{
"values": [
{
"name": {
"value": "hair salon",
"synonyms": [
"hairdresser",
"beauty parlor"
]
}
},
{
"name": {
"value": "hospital",
"synonyms": [
"emergency room",
"clinic"
]
}
},
]
}
I am trying to call a simple web-action from my dialog node. Both service and cloud space is hosted in London, still I am getting error that "Direct CloudFunctions calls are not supported on this platform".
I have created a simple skill and added 3 nodes to it, 1 is welcome node, second is test node in that I have added action of type web-action and created a webaction on cloud that returns a simple message. Below is the details for test node and action.
{
"output": {
"generic": [
{
"values": [
{
"text": "Hi how are you $message"
}
],
"response_type": "text",
"selection_policy": "sequential"
}
]
},
"actions": [
{
"name": "/namespace_dev/default/Call DB",
"type": "web_action",
"parameters": {
"mob_num": "$MNum"
},
"credentials": "my cloud function creds",
"result_variable": "message"
}
]
}
Below is the web-action code.
function main(params) {
return { message: 'Hello World' };
}
Node when test node is invoked the action should get executed but I am getting below error.
Dialog node error
Direct CloudFunctions calls are not supported on this platform
Can someone please suggest what mistake I am doing?
Currently, as stated in the Actions Docs, the actions are accessible only in Germany and US South. However, this document differs based on the language you read in. In the German Version, which is my default, you might read this:
Gegenwärtig können Sie eine Cloud Functions-Aktion über Watson Assistant-Instanzen aufrufen, die in den Regionen 'Vereinigte Staaten (Süden)' oder 'Deutschland' gehostet werden.
which translates (using Google) to this:
Currently, you can invoke a Cloud Functions action through Watson Assistant instances hosted in the United States (South) or Germany regions.
If I switch to the English Version of the Documentation, this information disappears.
I am creating an API and I need to create a Post which is defined as:
{
"Title": "Blog first post",
"Body": "Some body text for the post",
"PublishedAt": "2016-02-08",
"Category": {
"Id": "20",
"Name": "Travel"
},
"Tags": [
{ "Id": "12", "Name": "Vacation" },
{ "Id": "18", "Name": "Beach" }
]
}
What would you post to the API? The following?
{
"Title": "Blog first post",
"Body": "Some body text for the post",
"PublishedAt": "2016-02-08",
"Category": {
"Id": "20",
},
"Tags": [
{ "Id": "12" },
{ "Id": "18" }
]
}
Or would you do this by steps as follows:
POST /category/20/posts
POST /posts/recently-created-post-id/tags >> Add tags one by one?
But what to do when the entire data is ready to post?
What is the standard for this situations in a REST API?
Depends on how you want to present your API and how thorough you want it to be. I would do the following given your models.
I would have one endpoint at POST /posts and would send the entire body of the post model.
I would also have one endpoint at POST /posts/{id}/tags to allow tags to be submitted after the post is created. So a call to POST /posts/{id}/tags would receive a body of:
{ "Id" : 12 }
For simplicity sake, many people would recommend that you stick to only one level which would mean you would create an endpoint for PUT /posts/{id} or PATCH /posts/{id} and submit your new tags through those endpoints. A PUT request would submit the full body you used in the POST along with any new tags. The purpose of a PUT is to replace the existing post model entirely with the new body. A PATCH request would submit a body that adhere's to a REST PATCH endpoint which allows modifications to an object model without submitting the entire model.
If you were going with the multi-level model, you would need to support PUT and PATCH requests at the endpoint PUT /posts/{id}/tags/{tagid} and PATCH /posts/{id}/tags/{tagid}. Since your tags only contain a reference id, PUT and PATCH does not make sense because all you want to do is add or delete tags.
I assume you would also need to handle tag deletions. With the one level endpoint approach, you would submit the entire post model without the tag you wanted to remove via a PUT request to /posts/{id}. For example, if you wanted to delete tag 12 your :
{
"Title": "Blog first post",
"Body": "Some body text for the post",
"PublishedAt": "2016-02-08",
"Category": {
"Id": "20",
},
"Tags": [
{ "Id": "18" }
]
}
If you wanted to go with the multi-level approach, you would issue a DELETE request to /posts/{id}/tags/12.
There's no hard and fast rule for these situations in REST.
If we assume that the client wants to create everything in one go and wait the least amount of time possible for a response, common sense would suggest keeping everything in one request to avoid (a)synchronicity problems between the main POST and POSTs for the tags.
I'm trying to get a grip on Ext.direct. On the official page there is this description of the API:
The purpose of the API component of the Ext Direct stack is to output the method configurations for Ext Direct to create client-side stubs. By generating these proxy methods, we can seamlessly call server-side methods as if they were client-side methods without worrying about the interactions between the client and server-side.
I just don't quite get what it means by ...to output the method configurations for Ext Direct to create client-side stubs. Would someone care to explain what this means at a grassroots level?
This will make more sense if you look at the output from the api.php resource included in the following example.
Note that this is being loaded on the page as a <script/> tag, ie:
<script type="text/javascript" src="php/api.php"></script>
When you open the src link you'll see the following JavaScript being generated by server-side PHP (see block of javascript code below).
In other words, PHP is doing the bit where it ... output(s) the method configurations for Ext Direct to create client-side (ie JavaScript) stubs.
Now the next question you should be asking if you want to make sense of this is: Why bother generating client side JavaScript using server side PHP (or other language of choice)?.
Ext.ns("Ext.app");
Ext.app.REMOTING_API={
"url": "php\/router.php",
"type": "remoting",
"actions": {
"TestAction": [{
"name": "doEcho",
"len": 1
}, {
"name": "multiply",
"len": 1
}, {
"name": "getTree",
"len": 1
}, {
"name": "getGrid",
"len": 1
}, {
"name": "showDetails",
"params": [
"firstName",
"lastName",
"age"
]
}],
"Profile": [{
"name": "getBasicInfo",
"len": 2
}, {
"name": "getPhoneInfo",
"len": 1
}, {
"name": "getLocationInfo",
"len": 1
}, {
"name": "updateBasicInfo",
"len": 0,
"formHandler": true
}]
}
};
This seems to be mimicking the way a WSDL works in that it can provide a service description and list all the options available for quering. In other words: Ext.Direct API is taking a concept from SOAP and applying it to a Javascript setting.
The back-end contains the API so this is the easiest place to generate a service definition with all the method names and signatures. Once the Ext.Direct API method stubs are provided (in the back-end), the front-end Ext.Direct library will do the plumbing and turn these into actual functionality that can be queried and used in JavaScript. Much in the same way as SOAP proxy classes can be automatically generated (in PHP/C# or Java) using the WSDL.
Personally I think this is a bit too airy-fairy for my liking. Most APIs are pretty straight forward and trying to implement something akin to WSDL actually makes consumption a lot harder than it would be if you just talk to it directly.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I created a google weather api which allowed a user to type in a city and get weather details back for 3 days.
Google have since shut this service down.
With yahoo api i need a WOEID to get the weatehr details. Is there a way for me to get weather from yahoo for 3 days and change a location to a WOEID in the process or should i look at alternative api. An example of what yahoo api requires is below.
http://weather.yahooapis.com/forecastrss?p=SFXX0044&u=c&d=5
I would strongly recommend using forecast.io, which is very easy to use APIs with rich weather data sources
I'm using OpenWeatherMap for my website. One alternative you may check out.
Another good alternative would be the OpenWeatherMap. for any given location it offers the urrent conditions, the weather forcast and a very attractive interactive map.
The OpenWeatherMap offers historical data, although the list of available cities of the free weather data plan is limited. Unlike the Weather Underground API it allows for a lot more than 500 calls per day.
You can check out this free weather API - https://www.mashape.com/george-vustrey/ultimate-weather-forecasts#!documentation
Sample result of San Francisco 7-day weather:
[
{
"day_of_week": "Mon",
"high": "80.23",
"low": "56.19",
"condition": "Partly cloudy in the evening."
},
{
"day_of_week": "Tue",
"high": "78.32",
"low": "59.2",
"condition": "Mostly cloudy throughout the day."
},
{
"day_of_week": "Wed",
"high": "87.21",
"low": "57.64",
"condition": "Mostly cloudy throughout the day."
},
{
"day_of_week": "Thu",
"high": "90.1",
"low": "60.91",
"condition": "Clear throughout the day."
},
{
"day_of_week": "Fri",
"high": "88.66",
"low": "57.88",
"condition": "Clear throughout the day."
},
{
"day_of_week": "Sat",
"high": "86.5",
"low": "54.11",
"condition": "Partly cloudy in the morning."
},
{
"day_of_week": "Sun",
"high": "89.62",
"low": "52.42",
"condition": "Clear throughout the day."
}
]
I'd look at an alternative. Getting the WOEID is complex (and changing to a pay-per search model), and Yahoo's API doesn't offer much more than the current conditions at the location.
The Weather Underground API is one that offers a fairly rich amount of history. However, if you exceed 500 calls/day, it will cost you at least $520 per month for their API access.
There are other weather APIs out there. Most history APIs are paid services. It pays to shop around for the best price for what you need.
If you're site is country-specific, your country may have a free data product. Look at the NOAA data services for the USA or the Met Office services in the UK for example.
Yahoo! weather APIs is DEAD at 3rd April, 2013.
You can use Metwit weather api.
If you can implement them client-side: 200 request/day (ip based throttling) no authentication required. Worldwide coverage, JSON and REST compliant. You can register for extra API calls for free and if you still need it to call them server side the basic plan is pretty cheap.
Here a little example in jQuery: http://jsbin.com/isukam/1 that use our weather resource.
Full disclosure: I own this sweet piece of API.