RestClient undefined method `delete_if' for #<String:0x4b699a8> - ruby-on-rails

OK so, I'm using RestClient and sending this:
{"x_select_params":["account.*"],"domain":"thedomain"}
Via
response = RestClient.get servername, #payload
And I get
undefined method `delete_if' for #<String:0x4b699a8>
In response.
I know that the request is good as it works fine when I use the Chrome rest client extension, I'm thinking that RestClient is having an issue in parsing the response, which is supposed to look like this:
{
"user": {
"id": 4035,
"first_name": "Chris",
"last_name": "Penta",
"status": "PENDING",
"domain": "thedomain",
"default_account_id": 111315004004010,
"primary_alias_id": 131090,
"accounts": [
{
"id": 111315004004010,
"urn": "111315004004010",
"balance": 0,
"status": 0,
"currency_code": 840
}
]
}
}
Is this a bug in RestClient that needs patching? And if so, anyone know how to fix?
Thanks...Chris

I found this error when the headers were in a json format. They needed to be a hash to work.

Related

Twitter API 2.0 - Unable to fetch user.fields

I am using API version 2.0 and unable to fetch the user.fields results. All other parameters seem to be returning results correctly. I'm following this documentation.
url = "https://api.twitter.com/2/tweets/search/all"
query_params = {
"query": "APPL",
"max_results": "10",
"tweet.fields": "created_at,lang,text,author_id",
"user.fields": "name,username,created_at,location",
"expansions": "referenced_tweets.id.author_id",
}
response = requests.request("GET", url, headers=headers, params=query_params).json()
Sample result:
{
'author_id': '1251347502013521925',
'text': 'All conspiracy. But watch for bad news on Apple. Such a vulnerable stocktechnically for the biggest market cap # $2.1T ( Thanks Jay). This is the glue for the bulls. But, they stopped innovating when Steve died, built a fancy office and split the stock. $appl',
'lang': 'en',
'created_at': '2021-06-05T02:33:48.000Z',
'id': '1401004298738311168',
'referenced_tweets': [{
'type': 'retweeted',
'id': '1401004298738311168'
}]
}
As you can see, the following information is not returned: name, username, and location.
Any idea how to retrieve this info?
Your query does actually return the correct data. I tested this myself.
A full example response will be structured like this:
{
"data": [
{
"created_at": "2021-06-05T02:33:48.000Z",
"lang": "en",
"id": "1401004298738311168",
"text": "All conspiracy. But watch for bad news on Apple. Such a vulnerable stocktechnically for the biggest market cap # $2.1T ( Thanks Jay). This is the glue for the bulls. But, they stopped innovating when Steve died, built a fancy office and split the stock. $appl",
"author_id": "1251347502013521925",
"referenced_tweets": [
{
"type": "retweeted",
"id": "1401004298738311168"
}
]
}
],
"includes": {
"users": [
{
"name": "Gary Casper",
"id": "1251347502013521925",
"username": "Hisel1979",
"created_at": "2020-07-11T13:39:58.000Z"
}
]
}
}
The sample result you provided comes from within the data object. However, the expanded object data will be nested in the includes object (in your case name, username, and location). The corresponding user object can be referenced via the author_id field.

Get JSON Object from JSON Response in Swift

I want to fetch LoginOperationResponseBody key from the following JSON response in Swift.
[
{
"LoginOperationResponseHeader": {
"ReponseCode": 1,
"ReponseType": "Success",
"ReponseDesc": "Login com successo"
},
"LoginOperationResponseBody": {
"UserName": "dev hélio africano monteiro querido varela",
"Email": "helio.varela#uniteltmais.cv",
"Perfil": "perfil_002",
"TipoCliente": "Particular",
"NIF": 0,
"PhotoId": 47212,
"NomeCompleto": "dev hélio africano monteiro querido varela",
"Number": 9100141,
"TipoClienteId": 1,
"TelefoneFixo": 0,
"UserID": 122,
"Morada": 0,
"ClientId": 22106,
"SessionId": "BBA72CDD-6BAA-4C22-AE95-8A674764CE7D",
"ClientNumber": 1000481
}
}
]
If anyone could help me would be appreciated. I can fetch it if there is a key on first array Object but how can I get it without key.
Thanks in advance.
let loginOperationResponseBody = response[0]["LoginOperationResponseBody"]
I found it by myself.

How to send push notification from Rest API

I have created my App in Firebase and configured for cloud messaging.
When I am sending the notification from Firebase Console, device gets the notification but if I try to send via Rest API (Using PostMan).
Then notification not coming to device but the response is showing as Success.
Here is my PostMan request
URI - https://fcm.googleapis.com/fcm/send
Header: Content-Type:application/json Authorization:key=MY_SERVER_KEY
Body: { "data": { "title": "Firebase", "detail": "I am firebase" },
"to" : "MY FCM TOKEN HERE" }
Response : {
"multicast_id": 7834540847388366233,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1532422122326299%ebf5f25ef9fd7ecd"
}
] }
I have searched and it seems the way mentioned in documentation is same as I am following
Can anyone let me know why it is not working?
Thanks
I am posting here so as to guide others. As per the guidance of #rv7284, We need to send the data in notification key rather any other key.
So While requesting the body should look like this, Other request parameter like header and all will be same as mentioned in the question.
{ "notification": {
"title": "Firebase",
"detail": "I am firebase"
},
"to" : "YOUR FCM TOKEN"
}

How to retrieve data from response body when using trigger URL

I am using trigger URL to run a test case created on Runscope. In response I am getting only details as shown in Runscope documentation. For eg.
Response Sample data:
{
"data": [],
"error": null,
"meta": {"status": "success"}
}
But I need the data in response body retrieved from server for request made.For eg.
{
"Status": "OK",
"Body": [{"userId": 12345,"sessionId": "abcd:1234"}]
}
I am using HttpRequest and HttpResponse for the same.
Why don't you use something like this :
https://www.npmjs.com/package/dyson#installation
It is used to mock results via api .

Neo4j REST batch Illegal character in path at index 2: ./{0}/properties/

The Request:
[{
"method": "GET",
"to": "/node/1890",
"id": 0
},
{
"method": "PUT",
"to": "{0}/properties/Name",
"body": "NewName",
"id": 1
}]
The Response:
{
"message": "Illegal character in path at index 2: ./{0}/properties/Name",
"exception": "IllegalArgumentException",
"fullname": "java.lang.IllegalArgumentException",
"stacktrace": ["java.net.URI.create(URI.java:859)", "java.net.URI.resolve(URI.java:1043)", "org.neo4j.server.rest.batch.BatchOperations.calculateTargetUri(BatchOperations.java:100)", "org.neo4j.server.rest.batch.BatchOperations.performRequest(BatchOperations.java:181)", "org.neo4j.server.rest.batch.BatchOperations.parseAndPerform(BatchOperations.java:159)", "org.neo4j.server.rest.batch.NonStreamingBatchOperations.performBatchJobs(NonStreamingBatchOperations.java:48)", "org.neo4j.server.rest.web.BatchOperationService.batchProcess(BatchOperationService.java:117)", "org.neo4j.server.rest.web.BatchOperationService.performBatchOperations(BatchOperationService.java:72)", "java.lang.reflect.Method.invoke(Method.java:601)", "org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)"],
"cause": {
"message": "Illegal character in path at index 2: ./{0}/properties/Name",
"exception": "URISyntaxException",
"stacktrace": ["java.net.URI$Parser.fail(URI.java:2829)", "java.net.URI$Parser.checkChars(URI.java:3002)", "java.net.URI$Parser.parseHierarchical(URI.java:3086)", "java.net.URI$Parser.parse(URI.java:3044)", "java.net.URI.<init>(URI.java:595)", "java.net.URI.create(URI.java:857)", "java.net.URI.resolve(URI.java:1043)", "org.neo4j.server.rest.batch.BatchOperations.calculateTargetUri(BatchOperations.java:100)", "org.neo4j.server.rest.batch.BatchOperations.performRequest(BatchOperations.java:181)", "org.neo4j.server.rest.batch.BatchOperations.parseAndPerform(BatchOperations.java:159)", "org.neo4j.server.rest.batch.NonStreamingBatchOperations.performBatchJobs(NonStreamingBatchOperations.java:48)", "org.neo4j.server.rest.web.BatchOperationService.batchProcess(BatchOperationService.java:117)", "org.neo4j.server.rest.web.BatchOperationService.performBatchOperations(BatchOperationService.java:72)", "java.lang.reflect.Method.invoke(Method.java:601)", "org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)"],
"fullname": "java.net.URISyntaxException"
}
}
What's the problem here?
No errors in messages.log or any other logs for that matter. Not sure why the logs are empty. I had to turn off the X-Stream header to get this much info.
Now I know that since I already know the node's ID I can just reference it directly, and I will. However, it seems like it is an issue that should work.
I guess the URL for the 2nd request should be
/node/{0}/properties/foo

Resources