Find cities within a circle with Here.com API - geocoding

I need to find the cities (municipality) in a circle around a point, the only way I found to do that is to search for "city-hall" (800-8100-0163). I use with curl from php to retrieve the json result.
https://browse.search.hereapi.com/v1/browse?at={$coords}&in=circle:{$coords};r={$raggio}&lang=it&categories=800-8100-0163&limit=100&apiKey=<apiKey>
but some cities are missing in the result even if there's a city-hall in there so I think it's the wrong way to do that.
So my question is: is there a better way to achieve what I need?

It seems your request should be other.
If you search in Places Category System then should be parameter cat=800-8100-0163 and parameter (category system) should be cs=pds
Then request will look like: https://places.ls.hereapi.com/places/v1/browse?in=42.2722%2C13.3917%3Br%3D180718&cat=800-8100-0163&size=100&cs=pds&Accept-Language=it-It%2Cit%3Bq%3D0.9%2Cru-RU%3Bq%3D0.8%2Cru%3Bq%3D0.7%2Cde-DE%3Bq%3D0.6%2Cde%3Bq%3D0.5&app_id=WvHj2YKdvDQaKq1ZWCwL&app_code=W-ENnB-UBLqwG7sEhqyLMQ

Related

API RESTful Resource Naming

I always have the doubt that you can see below when i need to create theresource URLs for a REST API. I wonder if some one can help me.
Let's suppose that i have two models.
User
Post
User can submit his own posts and can comment his own and another posts.
Main resources URLs for User would be:
GET /users # Retrieve all users.
POST /users # Create a new user.
GET/DELETE/PUT /users/{user_id} # Get, remove and update an user.
Main resource URLs for Post would be:
GET /posts # Retrieve all posts.
POST /posts # Create a new post.
GET/DELETE/PUT /posts/{post_id} # Get, remove and update a post.
My problem come when for example i want:
Top 10 submitters (filter for a parameter(external link, discussion, all)). The URL should be:
GET /users/top?type=ext
GET /users/top?type=disc
GET /users/top # for all
Or maybe it should be:
GET /users?top=ext
GET /users?top=disc
GET /users?top=all
The same but with posts:
Top 10 commented post (filter for a parameter(external link, discussion, all)). The URL should be:
GET /posts/comments?type=ext
GET /posts/comments?type=disc
GET /posts/comments # for all
Or maybe it should be:
GET /posts?top=ext
GET /posts?top=disc
GET /posts?top=all
Any of above options are good for you or it should be another way?
Regards
I like to think of the REST URI as a model representation in itself.
So /users/top doesn't make a lot of sense but /posts/comments seems to be fine (as comments could also be a different model). But for your case, I recommend other set of query parameters as they're widely used for filtering & sorting requests. So in your case, I'd recommend something like:
GET /users?sort=ext&order=desc&limit=10
which would help me understand that I'm requesting 10 user resources which have been sorted for ext in the descending order. (you can even change it to type=ext if you want)
As usual; REST doesn't care what spellings you use.
One place you might look for inspiration is... stack overflow itself. Do these URI look familiar?
/questions?sort=newest
/questions?sort=featured
/questions?sort=votes
The API has pretty decent documentation, which will also offer hints at decent spellings to deal with paging and search ranges.
That said, IMDB takes a different approach - The Shawshank Redemption uses a straight forward "I am an element of a collection" spelling
http://www.imdb.com/title/tt0111161/
But the top rated titles of all time? they appear as a chart
http://www.imdb.com/chart/top
But i want to know if there is a standard according to #Hawkes answer or there is no standard at all.
No standard at all; just local spelling conventions. Which is, to some degree, part of the point of REST: the server can use whatever spellings for URI make sense, and the client just "follows its nose" based on its understanding of the processing rules for the media type and the data provided by the server.

RESTomancy: Getting products from category in Prestashop 1.5

Disclaimers:
This is oriented towards Prestashop 1.5 but if the answer is: "this
is fixed in version 1.x" then I'll raise a petition to update our
shop.
I'm also tagging it as REST because I think I explained it throughly
enough so you don't need actual experience with Prestashop to understand it.
So in Prestashop we have this Web Services which lack support for use cases as simple as search by category.
1. Let's say you want to get all the products from categories 1, 3 and 17:
So what is the solution?
Well, you can do something in the lines of this answer: https://stackoverflow.com/a/34061229/4209853
where you get all the products from categories 1, 3 and 17 and then you make another call for products filtering by those ID's.
'filter[id]' => '['.implode('|',$productIDsArrayIGotBefore).']',
it's ugly and 20th centurish, but well... if it gets the job done... except it doesn't.
You see, this is a call for getting a resource, and someone somewhere decided:
Hey, we have all this nice HTTP action verbs, so let's use them for REST CRUD interfaces: POST for C, GET for R, PUT for U and DELETE for D. Neat.
And that's nice and all, but when combined with the lack of expressive power of Prestashop's Web Services means it's stupidly easy to run into, you guessed it? Yes, 414.
Error HTTP 414 Request URI too long
and we all know that modifying Apache so it accepts longer request URIs is not the neat scalable solution.
So we could try to split the array and make multiple calls, which is just conceptually ugh. Not just because of the performance hit of making multiple queries, but also because we would need to take into account the number of characters of all IDs concatenated to make the calculation of how many we can (safely) ask for in one call. And all that would have their own caveats, like:
2. What if we want to also filter them e.g. active=1?
Now we're in for a ride, because we can't know beforehand how many calls we will need to make.
Let's define:
N are the IDs I got from categories
n is the number of IDS I can safely ask for
T is the number of (filtered) products I want
tare the (filtered) products I already have
k are the (filtered) products we receive from the call
So we would end up with something like:
do{
n0= max(T-t, n);
k= get(products, n0);
t +=k;
}while(count(k)!=0 and count(t)<T and !empty(N))
..which is just... bonkers.
The only elegant solution I can come up with is creating a new Prestashop Web Service that acts as a wrapper, receiving the petition through POST and forwarding it to the Prestashop service.
But, befores that... do you have a better solution using some kind of RESTomancy I may be missing?

OSM Nominatim search strange behaviour

I have ran into some troubles using Open Street Map Nominatim search API. I am trying to search and geocode addresses, but for some queries, the results are quite strange.
For example, when I use query:
http://nominatim.openstreetmap.org/search?format=json&countrycodes=cz&limit=10&accept-language=cz&addressdetails=1&q=Jihlava
I get expected results - city Jihlava.
But when I use queries like (only part of name):
http://nominatim.openstreetmap.org/search?format=json&countrycodes=cz&limit=10&accept-language=cz&addressdetails=1&q=Jihl
or
http://nominatim.openstreetmap.org/search?format=json&countrycodes=cz&limit=10&accept-language=cz&addressdetails=1&q=Jihla
or
http://nominatim.openstreetmap.org/search?format=json&countrycodes=cz&limit=10&accept-language=cz&addressdetails=1&q=Jihlav
I get empty result list.
Is there anything wrong with my query?
Thanks.
That's expected behavior, for now. Nominatim has no auto-correction feature yet. Thus only partly matching queries aren't always handled correctly.
If you need auto-correction then please see if one of the other search engines for OSM fits your needs.

Best practice for implementing GET operation in Restful service

I am trying to find if there is any best practices involved in developing/implementing a GET operation.
I was going through the web resource documentation of jersey.
URL : http://jersey.java.net/nonav/apidocs/1.4/jersey/com/sun/jersey/api/client/WebResource.html
If we look at the methods that are available, the 'get' doesn't accept entity.
Is it recommended to implement get operation which doesnt accept entity but only get request parameters from Query Parameters?
Thanks,
GK
Yes. Think of the URI as the unique identifier to the object/resource you are GETing. I typically use query params for a GET if required. More normally I just have a GET something like this: GET: https:/myservice.com/myobject/id. This path is usually returned from a PUT or POST operation on MyObject. If I want to look up one or more I then use query params for the criteria.
There are a number of best practices out there. One that seems to bring together most of the common ones in a readable format is provided by Apigee. You can obtain it from http://info.apigee.com/Portals/62317/docs/web%20api.pdf

Objects with location, anyone figured it out?

This statment is found in the graph api (https://developers.facebook.com/docs/reference/api/)
Objects with location. The following will return information about
objects that have location information attached. In addition, the
returned objects will be those in which you or your friend have been
tagged, or those objects that were created by you or your friends.
But it is not stated how to make this call, has anyone figured it out?
In order to get pure checkins the following is used: https://graph.facebook.com/search?type=checkin
But it is not stated how to make this call, has anyone figured it out?
Like any other Graph API call …? With a simple HTTP request, probably including an access token, or with the help of one of the SDKs, which take care of the more basic aspects of this for you.
If you do a search for location objects you need to include the point and radius for your search, see example below for a search over the center of Gothenburg with 1000 meter distance (max for distance is 50000 meters)
https://graph.facebook.com/search?type=location&center=57.708549,11.975098&distance=1000&access_token=xxx