How to check the result from AWSTask - ios

I am calling an API from AWS, whose model isn't with me right now, I want to know what JSON it returns in response to a request so that I can build the model and use it. Is there a way to print the JSON ? I tried printing result property of task but its empty ( may be its obvious), is there a way to do this ?

Related

"Got a result missing the "id" property" - Zapier

I want to make an app on zapier. Every process I have done clearly according to zapier request. My each process got success by zapier like API authentication and all. When I run my app on zapier I get authenticate, but at last it gives an error
" Got a result missing the "id" property ".
What should I do? I think zapier want id property in the front position of the array, but during authentication my element in array got fluctuate and I got id in below position.
There's more info about that message here: https://zapier.com/developer/documentation/v2/ZDE009/
Basically, you need to return an array of objects from your trigger, and each item in the array must have an "id" property.
in the front position of the array
the order doesn't matter, since all of the objects need one.

IOS/Objective-C/JSON:Obtain single value from Web Service in JSON

I want to obtain a single value from a web service in JSON, just a file name i.e. "picture.png"; based on some parameters passed.
Can IOS (I guess NSJSONSerialization JSONObjectWithData:) handle this single value in JSON or on the server side should I have it send a dictionary key as in {"pic": "picture.gif"}
If there is no picture, I am returning "nopic" so again should I have it return "error" or {"error": "nopic"}
I gather the various JSON specifications are conflicting on this point so my interest is just practical...how best to handle this case.
Thanks for any guidance on this

Access only one attribute of API in response - Ruby on Rails 4

I am calling an API that returns an array of JSON objects and I can access return values of the API call
[{"param1":1,"param2":"blah1"},
{"param1":2,"param2":"blah2"},
{"param1":3,"param2":"blah3"}]
I know that i can access each Param1 through iteration or by static indexing like #client[0].param1 #client[1].param1 #client[2].param1 but the thing is , i don't want param2 and i want just param1 . is there any way , to access param1 without iteration or static indexing
so that i could get the below result in response
[{"param1":1},
{"param1":2},
{"param1":3}]
Update
The thing to notice is that i want to filter the result while making
the request (before getting the response when we know the attribute
name)
Try to use delete.
Deletes and returns a key-value pair from hsh whose key is equal to
key. If the key is not found, returns the default value. If the
optional code block is given and the key is not found, pass in the key
and return the result of block.
data = [{"param1":1,"param2":"blah1"},
{"param1":2,"param2":"blah2"},
{"param1":3,"param2":"blah3"}]
data.each {|x| x.delete("param2")}
For more information about delete.
I hope this help you.

Grails: Accessing the request paramters without wiping them out

According to the document on command objects and data binding. Once you read the params object, that object can never be reused again.
From the documentation:
Binding The Request Body To Command Objects
http://grails.org/doc/2.3.x/guide/theWebLayer.html#commandObjects
Note that the body of the request is being parsed to make that work. Any attempt to read the body of the request after that will fail since the corresponding input stream will be empty. The controller action can either use a command object or it can parse the body of the request on its own (either directly, or by referring to something like request.JSON), but cannot do both.
I'm trying to view the parameters within a filter (which is hit before the controller is requested). Would logging the parameters to a log cause the controller to get a null param object? From the documentation that looks to be the case. However, how can I get access to the params without wiping them out in the filter?
Once you read the params object, that object can never be reused
again.
That is not correct. You can read request parameters over and over again. What cannot be read over and over again is the body of the request. The body and the request parameters are 2 different things.

REST call may results in two different JSON objects. What design pattern should I use?

My web application makes a REST call. If the call is successful, it will return a 'weather' json object. If the call fails, it will return a json error object.
I want to make a class that parses the resulting JSON and returns a Weather object if the call succeeded and an Error Object if the call failed.
I'm thinking of using the Factory pattern but I'm not sure if that's a good approach because the two objects are very different from one another. What is a good way to design this code?
A common approach I use is to have Weather and Error both be Response objects and have a ResponseFactory create them.
I strongly encourage you to use proper HTTP codes when designing your service as they give a more general view of the state and success of each call.
You need first to check the result of the call, and then make a decision on how to handle it, with the possibility of handling all error codes with an error callback that returns an Error JSON object, and a success callback to return a Weather JSON object. You can use the HTTP codes to create a proper response and further subdivide the logic to return more specific errors, if needed.
The use of a Factory pattern seems overkill, specially given that the objects don't relate to each other.
It really depends on the environment you'll be using your API.
As a rule of thumb, rely on the HTTP code - if you get a 404 or a 500 of course you can't come up with a parsed response.
Format your error responses in a consistent way, e.g.
404 { "message" : "Resource not found" }
400 { "message" : "Wrong parameters given" }
So you know how to parse them.
If you get a 200 OKyou know everything was right, and you can parse your response with no problem at all.
Does the Content-Type header vary depending on the type of response?
As some have noted in their answers, the HTTP status code should be used to determine "Was there an error", but just as important is the interpretation of the content type returned.
Hoping the Content-Type header does vary, I would suggest using a registry of parsers, registered by content-type they handle, and then delegate to them to handle understanding how to convert a particular content type into the object you want. In Ruby, since you didn't specify a particular language:
case response.status:
when 200..299
return parsers[response.content_type].parse(response.body)
when 400..499
raise parsers[response.content_type].parse(response.body)
else
raise "Unhandled response status"
Doing so separates the two concerns:
Determining if there was an error
Parsing of content types into classes/types in your application.

Resources