cache app with google map distance matrix api
I am trying to write an application that will take some information on the database make a call to the Google API distance matrix and get the information to use with rest of the application without using the ensemble part of the development is this possible and how can I do my communication with the API from a cache class thanks in advance
It's quite easy to do so. You have to use %Net.HttpRequest class for this. I think it would be better if you try to do it yourself first with knowing how to start. You can find some simple examples in documentation by provided link. And you don't need Ensemble.
@Dmitry Maslennikov I have done this for starters but got an error ^
<INVALID OREF>zTalkToTheWorld
here is my code
Method TalkToTheWorld() { Set httprequest=##class(%Net.HttpRequest).%New() Set httprequest.Server="https://maps.googleapis.com/maps/api/distancematrix/json?origins=BRISTOL&destinations=LONDON&key=TZhydlRg6-dUm-EoIuees43456rtyu7 " Do httprequest.Get("/") Do httprequest.HttpResponse.OutputToDevice() Do httprequest.Get("/cache/") Do httprequest.HttpResponse.OutputToDevice() }
@Dan Pasco Thanks really appreciate
if you look in the following article i've posted today,
https://community.intersystems.com/post/story-support-how-quest-raw-deflate-compressiondecompression-function-leads-node-callout-server
there is a code example of a similar utils.Http:getJSON() method included.
Thank you Dan :)
This error happens because you got another error in the request, do not forget to check status.
But anyway. As you need to call https, you should first configure SSL Configuration manually through management portal. You have to fill only Name field, any name on your choice.
Or the same but programmatically.
And full working example
And call in terminal
My example should work on versions 2016.2 and later, tested on 2017.2
i would start using "postman" to try out google restful api for your particular needs. To see what exactly you need to sent (request) and what you get in return (response). With that in place you can start coding some kind of wrapper methods using %Net.HttpRequest for doing the same requests and preparing the appropriate results from the response for your further processing, as you've already figured out before by using postman.
HTH, Bernd
This method call is not part of any release but, as others have mentioned, you can use %Net.Http to submit a request and receive a response. I can help you write that request. How does this look?
USER>set matrix = ##class(<your classname goes here>).GetJSON("https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=40.6655101,-73.89188969999998&destinations=40.6905615%2C-73.9976592%7C40.6905615%2C-73.9976592%7C40.6905615%2C-73.9976592%7C40.6905615%2C-73.9976592%7C40.6905615%2C-73.9976592%7C40.6905615%2C-73.9976592%7C40.659569%2C-73.933783%7C40.729029%2C-73.851524%7C40.6860072%2C-73.6334271%7C40.598566%2C-73.7527626%7C40.659569%2C-73.933783%7C40.729029%2C-73.851524%7C40.6860072%2C-73.6334271%7C40.598566%2C-73.7527626&key=<you api key goes here>",{"SSLConfiguration":"<your SSL Configuration goes here>"})
USER>write matrix.%ToJSON()
{"httpStatus":"200","message":"HTTP/1.1 200 OK","content":{"destination_addresses":["67-89 Pacific St, Brooklyn, NY 11201, USA","67-89 Pacific St, Brooklyn, NY 11201, USA","67-89 Pacific St, Brooklyn, NY 11201, USA","67-89 Pacific St, Brooklyn, NY 11201, USA","67-89 Pacific St, Brooklyn, NY 11201, USA","67-89 Pacific St, Brooklyn, NY 11201, USA","585 Schenectady Ave, Brooklyn, NY 11203, USA","66-0-66-26 103rd St, Rego Park, NY 11374, USA","931-947 N Village Ave, Rockville Centre, NY 11570, USA","300-448 Beach 19th St, Far Rockaway, NY 11691, USA","585 Schenectady Ave, Brooklyn, NY 11203, USA","66-0-66-26 103rd St, Rego Park, NY 11374, USA","931-947 N Village Ave, Rockville Centre, NY 11570, USA","300-448 Beach 19th St, Far Rockaway, NY 11691, USA"],"origin_addresses":["566 Vermont St, Brooklyn, NY 11207, USA"],"rows":[{"elements":[{"distance":{"text":"6.7 mi","value":10754},"duration":{"text":"37 mins","value":2201},"status":"OK"},{"distance":{"text":"6.7 mi","value":10754},"duration":{"text":"37 mins","value":2201},"status":"OK"},{"distance":{"text":"6.7 mi","value":10754},"duration":{"text":"37 mins","value":2201},"status":"OK"},{"distance":{"text":"6.7 mi","value":10754},"duration":{"text":"37 mins","value":2201},"status":"OK"},{"distance":{"text":"6.7 mi","value":10754},"duration":{"text":"37 mins","value":2201},"status":"OK"},{"distance":{"text":"6.7 mi","value":10754},"duration":{"text":"37 mins","value":2201},"status":"OK"},{"distance":{"text":"3.4 mi","value":5426},"duration":{"text":"19 mins","value":1136},"status":"OK"},{"distance":{"text":"8.5 mi","value":13740},"duration":{"text":"23 mins","value":1399},"status":"OK"},{"distance":{"text":"15.9 mi","value":25546},"duration":{"text":"29 mins","value":1755},"status":"OK"},{"distance":{"text":"13.2 mi","value":21296},"duration":{"text":"34 mins","value":2040},"status":"OK"},{"distance":{"text":"3.4 mi","value":5426},"duration":{"text":"19 mins","value":1136},"status":"OK"},{"distance":{"text":"8.5 mi","value":13740},"duration":{"text":"23 mins","value":1399},"status":"OK"},{"distance":{"text":"15.9 mi","value":25546},"duration":{"text":"29 mins","value":1755},"status":"OK"},{"distance":{"text":"13.2 mi","value":21296},"duration":{"text":"34 mins","value":2040},"status":"OK"}]}],"status":"OK"}}
And with a little work, this can also be invoked as an SQL function:
Row count: 1 Performance: 0.398 seconds 54 global references 2349 lines executed 0 disk read latency (ms) Cached Query: %sqlcq.pSYS.cls4 Last update: 2018-01-30 07:09:30.073
Print
1 row(s) affected