How to log the Graphql success response in ruby - ruby-on-rails

I am working on Ruby programming. Getting graphql client call response in the below format.
response is
[#<GraphQL::Client::Response:0x00000001169729a0 #original_hash={"data"=>{"provisioningAddEntitlementToAccounts"=>{"result"=>[{"accountId"=>11571824, "status"=>"SUCCESS"}, {"accountId"=>11571825, "status"=>"SUCCESS"}]}}}, #data=#<#<Module:0x000000011537e220>::RootMutationType provisioningAddEntitlementToAccounts=...>, #errors=#<GraphQL::Client::Errors #messages={} #details={}>, #extensions=nil>]
In some rare cases there is a chance to get "Account Not Found" response for some account Id's and "SUCCESS" for some account Id's.
So I would like to store all the account Id's which are getting "SUCCESS" response only into some variable.
Can you please someone help me on this.

Related

API Negatif Scenario with Rest-Assured and Junit

I want to make an API negative test scenario with Rest-Assured Library. I'm creating a get request for a data that doesn't exist. When I print this response to the console, I want to see the text 'not found' Because postman says this is the request body. But my test failed on get method. I am getting that error
io.restassured.internal.http.HttpResponseException: status code: 404, reason phrase: Not Found
Actually I know the status code is 404. But I can not test about it. How can i write that negative scenario
Response response = given().
when().
get("https://restful-booker.herokuapp.com/booking/1001");

How to detect when an OAuth2 refresh-token expired

When accessing Google-Drive, an access-token can expire and we can use the refresh-token to get a new access-token. There are a number of possible reasons though, that the refresh-token itself stops working or expires, see:
https://developers.google.com/identity/protocols/OAuth2#expiration
So my question, what happens if the refresh-token has expired after the 6 months, how can I detect it? Does the request for refreshing the access-token fail with 403 forbidden, or does it return a JSON containing an error message, or something else?
Unfortunately it is hard to find any information about this, and to test it out one has to wait for 6 month...
Solution:
Thanks to Gary Archers answer I could produce the situation with an invalid refresh-token and this is the response I got, maybe it helps somebody else:
HTTP-status-code: 400
JSON:
{
"error": "invalid_grant",
"error_description": "Bad Request"
}
Almost all implementations I've seen return a known error code of 'invalid_grant' that you can check for. It will look something like this, with the server returning a JSON response with an error field and an optional error_description. At this point you need to redirect the user to reauthenticate:

Microsoft Graph WebHook: Subscription validationtoken blank?

I'm trying to setup a MS Graph webhook subscription for messages, but it appears that Graph is sending a blank validationToken. I'm connecting to https://graph.microsoft.com/beta/subscriptions
My API endpoint works in Postman and successfully returns a plaintext response with only the validationtoken, but when I call MS Graph, I get the following error "Subscription validation request failed. Response must exactly match validationToken query parameter". I've also tried both validationtoken and validationToken as the parameter to look for.
Full error message
"{\r\n \"error\": {\r\n \"code\": \"InvalidRequest\",\r\n \"message\": \"Subscription validation request failed. Response must exactly match validationToken query parameter.\",\r\n \"innerError\": {\r\n \"request-id\": \"f1546835-606d-4bd8-ab3c-dfb2c75285aa\",\r\n \"date\": \"2018-08-10T03:45:56\"\r\n }\r\n }\r\n}"
To create a subscription you need to expose a notification URL with https (You can look at Graph documentation at https://developer.microsoft.com/en-us/graph/docs/concepts/webhooks).
When you send your create subscription request, the first post message your notification URL will receive is a message with a validation token. You have to send this validation token back. Now you should receive notifications on your specified notification URL. Looking at this failure, it looks like the notification URL is not sending the validation token back.
The response should not vary between Postman and MSGraph. If you are still seeing issues, please share your notification url and we will try to get a repro.

How do you turn the PDT response from PayPal into a hash?

I'm trying to use the PDT system on PayPal to manage payments on my site. My site is correctly receiving the transaction id which is sent back to paypal in order to receive the transaction data.
This is the code which I am using to post the transaction id to paypal and receive a response.
response = Net::HTTP.post_form(URI.parse("#{Rails.application.secrets.paypal_host}/cgi-bin/webscr?"), values)
puts response.body
I am receiving the correct response where response.body shows this in the terminal.
SUCCESS
transaction_subject=SPORTS+PACKAGE+%281+Week%29
payment_date=23%3A32%3A01+Jul+20%2C+2017+PDT
txn_type=subscr_payment
subscr_id=I-WHFVMBY57NX2
last_name=Lucas
residence_country=US
item_name=SPORTS+PACKAGE+%281+Week%29
payment_gross=
mc_currency=AUD
business=merchant-success%40puntsquad.com
payment_type=instant
protection_eligibility=Ineligible
payer_status=verified
payer_email=buyer-success%40puntsquad.com
txn_id=8M5887849L359363Y
receiver_email=merchant-success%40puntsquad.com
first_name=George
payer_id=667TSNBH7R7X4
receiver_id=WJYE8WGSREP98
payment_status=Completed
payment_fee=
mc_fee=2.00
mc_gross=50.00
charset=windows-1252
My problem is I am unsure of how I am able to access these values.
You can convert the response body to a hash as follows
hsh = CGI::parse(response.body)
puts hsh['transaction_subject']

Yelp Place API returning "Invalid Signature" Error only from Nginx on EC2

Problem: I am getting an "Invalid Signature" error from Yelp API only from production (running on nginx server in AWS) When I run locally on my localhost:3000, there is no signature error, and everything works fine.
I am using the yelp gem in rails. Here's some code in ruby.:
$client = Yelp::Client.new({
consumer_key: $SL_CONSUMER_KEY,
consumer_secret: $SL_CONSUMER_SECRET,
token: $SL_TOKEN,
token_secret: $SL_TOKEN_SECRET
})
begin
$client.search("Los Angeles")
rescue => error
puts error.message
puts error.inspect
end
error.message prints out: "Signature was invalid"
error.inspect prints out: < Yelp::Error::InvalidSignature: Signature was invalid >
Everything works when I run locally on rails' Webrick server but when I run it in production, I get an "Invalid Signature" error.
Has anyone seen this? I've looked at some relevant posts, but this seems different. Thanks!
This will probably not pertain to most people, but the off chance it could help someone, here it is:
My "time" was effed up on my EC2 instance. So for example, in ruby, Time.now was not printing the actual time. (I think it was off by a few minutes or so).
Anyway, Yelp API requires a oauth_timestamp when you send a request. Of course, then, my request was timing out b/c the time was off.
How did I found this error out?
I just pinged the URL on my browser with the oauth, token, oauth_timestamp, etc. (few more) as query params. The browser spits out the error response in JSON, and it was saying that my request was timing out. When you use the ruby Yelp Client and catch the exception in code, it doesn't spit out the error response in terminal, so it's a bit more difficult to locate the exact root of the error.
How I solved it:
I re-calibrated the time in my ec2 instance by following the directions here: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html
Problem is solved. Peace.
Invalid signature error in Yelp API occurs due to two reasons .
First , Either of your four keys i.e consumer_key , consumer_secret_key , Token & Token Secret is invalid . Secondly Parameters passed to Yelp API Function are either invalid or any of those are nil .

Resources