Using HTTParty to post json to Google Places - ruby-on-rails

I'm trying to figure out how to write a google places POST request using HTTParty. I was able to do a GET request but can't figure out how to work around the fact that Google Places has a nested parameter to post into. Here is the json syntax from the api documentation. Can someone help me translate this into the syntax that can work with HTTParty.post
POST https://maps.googleapis.com/maps/api/place/add/json?sensor=true_or_false&key=api_key HTTP/1.1
Host: maps.googleapis.com
{
"location": {
"lat": -33.8669710,
"lng": 151.1958750
},
"accuracy": 50,
"name": "Google Shoes!",
"types": ["shoe_store"],
"language": "en-AU"
}

The httparty gem includes an example that posts nested JSON to a server.

Related

Album mbId in track's metadata

I am using MusicBrainz to get a track's meta data. I want to get the track's album's mbid. I am doing the following lookup using ISRC code.
https://musicbrainz.org/ws/2/isrc/USRC11600201?fmt=json
But in response I don't get any metadata related to the album of the track. I get the following response:
{
"isrc": "USRC11600201",
"recordings": [
{
"disambiguation": "single remix",
"title": "Cheap Thrills",
"id": "92e27a47-3546-4bc2-a9f7-b19e43d7a531",
"length": 223000,
"video": false
},
{
"length": 218540,
"video": false,
"title": "Cheap Thrills",
"disambiguation": "",
"id": "5845e975-33b4-4b0d-8e74-8f57d128b3d1"
}
]
}
I have tried various combinations of the "inc" sub query parameter as well but nothing works. Please help me out. I am really stuck at this.
Using inc=releases in the URL parameters should be enough to get you the information that you want. However, it seems like there's a bug with MusicBrainz's JSON web service (which is still officially in beta), as you can see in the difference between the XML and JSON end points' output:
https://musicbrainz.org/ws/2/isrc/USRC11600201?inc=releases&fmt=json (JSON) vs. https://musicbrainz.org/ws/2/isrc/USRC11600201?inc=releases (XML).
One obvious solution/work-around here would be to switch to using the more mature XML endpoint. If that is not an option, you can use the Recording MBIDs given in the JSON output to look up releases associated with those Recordings, e.g., https://musicbrainz.org/ws/2/recording/5845e975-33b4-4b0d-8e74-8f57d128b3d1?inc=releases&fmt=json (note that inc=releases is also needed here to get the information about the releases, and it actually works when looking up recordings).
So to get the details of the album of a track when I have the ISRC of the track, we need to do the following get request:
https://musicbrainz.org/ws/2/isrc/GBUM71604605?inc=releases
It will give a response in xml. The xml api is more stable click for more details on this
As I need the response in json, we can use a library like xml to json and vice-versa library
As much as I have seen the xml response from the MusicBrainz api is more accurate and gives a lot of information.

how to get a mocked http response from swagger.yaml in a maven project

I am aware that swagger core , swagger inflector read a swagger.yaml / json file in creating a http response, Now we have a use wire mock to stub response where the content for the stub has to come from the swagger file.
I have gone through many examples but unable to figure out the right function to convert the swagger.yaml/json to return the http response. Please help me
SwaggerHub can be used to define your API in JSON or YAML. The UI provided alongside shows the API vividly. The UI has the option to trigger a newly defined API and check the response as a model - the structure of JSON response body. If "example" has been given in the API specification, it's fetched in the response.
If this response model works as per requirement, it can be then used in WireMock to generate stubbed responses having canned data. A swagger specification fragment and response model shown below -
API specification -
"swagger": "2.0",
"info":{
"version":"v0.1",
"title":
"Capital city finder",
"description":"Search capital city by country name"
},
"definitions":{
"city":{
"properties":{
"countryName":{
"type":"string",
"example":"United Kingdom"
},
"capitalCity":{
"type":"string",
"example":"London"
},
"nationalAnimal":{
"type":"string",
"example":"Lion"
},
"popularFood":{
"type":"string",
"example":"Fish & Chips"
}
... ... ...
Response Model -
[
{
"countryName": "United Kingdom",
"capitalCity": "London",
"nationalAnimal": "Lion",
"popularFood": "Fish & Chips"
}
]
Not sure if this is still relevant to you now.

POST request to test Rails API using

I am new to programming with Rails API.
To test my Rails API, I need to build a manual POST request with data format like
{
"user":
{
"email": "abc#gmail.com",
"name": "abc",
}
}
I am trying to use Simple REST Client but not able to get the URL with data in the above format. How do I write the URL to get the data in the right format?

In Mandrill's API, is there any way to know the size limits of JSON attributes in their Responses?

I'm looking at the Mandrill API documentation e.g. https://mandrillapp.com/api/docs/messages.JSON.html#method=info. In the JSON response there may be seomthing like the following
{
"ts": 1365190001,
"url": "http://www.example.com",
"ip": "55.55.55.55",
"location": "Georgia, US",
"ua": "Linux/Ubuntu/Chrome/Chrome 28.0.1500.53"
}
Is there are way to know how large the String's may be for these attributes? i.e. how many characters might be returned for "ua" or "url" etc... I'm asking as I need to capture and store some of this data in Oracle, but I don't want to LOB everything!

Google Contacts API not showing emails, nor max results

I'm using the Google Contacts API to get back formatted JSON, hopefully containing ALL of a user's contacts' email addresses. I use this information to search my database for the user's friends.
Neither of these results occur.
Here's the URI that's called (broken up by paramater for slightly better readability:
http://www-opensocial.googleusercontent.com/api/people/#me/#all/?
filterby=emails&max_results=1000
&oauth_consumer_key=XXXXXXX
&oauth_nonce=h7ZEI
&oauth_signature=6U2ywoPRFu8iJdQhjMRk%2FZlf%2FBg%3D
&oauth_signature_method=HMAC-SHA1
&oauth_timestamp=1283979209
&oauth_token=1%2Fwv9OYV4LuffVLv6OqlFJLOtTlBo5sYYQkHbZznlLrNk
&oauth_version=1.0
&orderby=starttime
Here's some truncated and anonymized JSON I have returned.
{
"startIndex": 0,
"totalResults": 615,
"entry": [
{
"id": "XXXXXXXXXXXXXXXXXXX",
"name": {
"formatted": "XXXXX XXXXXX",
"familyName": "XXXXXXX",
"givenName": "XXXXXX"
},
"displayName": "XXXXX XXXXXX"
},
],
"itemsPerPage": 20
}
Any thoughts on what's going wrong here would be great.
Hate to answer my own question so soon, but I was using the wrong initial scope. I was using Google's Open Social feed rather than the Google Contacts feed.

Resources