GMail API Stopped working with Ruby client since April 11 - ruby

Was any breaking change made by Google on GMail API on 11th April, 2020 ?
We have a ruby web application which also has a Chrome extension. (pretty old, ruby 2.1.0) which uses google-api-client version 0.6.4 and was working great so far, but then since April 11, the app stopped working in a way that all the call to GMail APIs are failing with 404 error.
To give a clue, we have a library from where we call google client to perform actions, something like this:
def thread_metadata(id)
#metadata ||= execute(gmail_api.users.threads.get,
{
'collection' => 'public',
'userId' => 'me',
'id' => id,
'format' => 'metadata',
'metadataHeaders' => 'Subject'
}
)
However, the response which we get from Google is 404 with a message something like this:
he requested URL /discovery/v1/apis/gmail/v1/gmail/v1/users/me/threads/16365500056684b0?collection=public&format=full was not found on this server. That’s all we know.
I don't have any clue what has gone wrong except that the 404 error which started coming in suddenly since April 11.

You'll need to update your google-api-client gem, as of v0.8.6 they changed where the baseUrl is to make requests. Presumably the path the old gems were still using remained unchanged until recently.
The method_base used to generate the URI returns something different pre-0.8.6:
irb(main):046:0> gmail_api.method_base
=> #<Addressable::URI:0x3ff4ff4e319c URI:https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest>
In 0.8.6+:
irb(main):009:0> gmail_api.method_base
=> #<Addressable::URI:0x3ff97faf4610 URI:https://www.googleapis.com/>

Related

Add support for rendering views to a rails api only application

I built an api only rails app, but since i'm using a 3rd party email service, I need to be able to render the email template into a string to pass it to the mailing service wrapper gem. So far any attempt to render templates into a string returns an empty string, and i suspect it is because the application is configured to be API only. Ho do I add support to rendering templates into a string?
If this is not the case, please let me know. I'm using postmark mail service. postmark-rails gem, which integrates into standard rails mailers didn't work at all, and plain postmark gem (which uses postmark API instead of postmark SMTP server) works fine, but now my problem is producing the proper html for the email.
this is what I'm trying:
html = render_to_string(
partial: "transfer_mailer/transfer.html.erb",
locals: {
:#body => #body,
:#campaign => #campaign,
:#chat => #chat
}
)
but it returns empty string.
My setup involves Rails 5.0.1, ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux], Sidekiq 4.2.7, and in production im using nginx/1.10.2 and Phusion Passenger 5.1.1. Production environment is deployed in an azure virtual machine, and I added both inbound and outbound rules for allowing traffic through ports 25, 465, 2525, and 587.
Any help would be really appreciated.
Looking at the docs for render_to_string, it looks like the path doesn't need to include .html.erb, so maybe removing that will fix it.
You can see here for some example code:
In your case, it would be:
render_to_string(
partial: '/transfer_mailer/transfer',
locals: {
:#body => #body,
:#campaign => #campaign,
:#chat => #chat
},
layout: false
)
Also make sure the partial filename starts with an underscore, even though you don't include it with render_to_string or render calls.
There is the other way to use render_to_string for resolving your issue. Please see the code below.
#body = XXX
#campaign = YYY
#chat = ZZZ
html = render_to_string(
file: 'transfer_mailer/transfer.html.erb'
)
Hope it helps.

HTTParty GET to Fingercheck API gives 401

I am trying to use HTTParty in irb to test an API call, but I keep getting a 401. Attempts to do a get against the same URL with the same header info using the Postman Chrome add-on work fine -- any ideas?
irb> HTTParty.get("https://developer.fingercheck.com/api/v1/Employees/GetAllEmployees",
:headers => {"APIKEY" => "ABCD1234-1234-ABCD-EFGH-ABCD1234ABCD123",
"ClientSecretKey" => "ABCD1234-1234-ABCD-EFGH-ABCD1234ABCD123",
"Content-Type" => "application/json"})
=> <HTTParty::Response:0x8 parsed_response=nil, #response=#<Net::HTTPUnauthorized 401 Unauthorized readbody=true>,
#headers={"cache-control"=>["no-cache"], "pragma"=>["no-cache"],
"expires"=>["-1"], "server"=>["Microsoft-IIS/7.5"], "x-aspnet-version"=>["4.0.30319"],
"x-powered-by"=>["ASP.NET"], "date"=>["Mon, 01 Dec 2014 21:04:32 GMT"],
"connection"=>["close"], "content-length"=>["0"]}>
I have also tried to do the get call with :query=>..., :query => {:header..., and :basic_auth =>..., but none change the results. Any ideas?
I know a fair number of HTTParty questions have been asked and answered, but I didn't see anything that spoke to this particular issue.
The documentation I know of for the API is at http://developer.fingercheck.com/api/help
The error turned out to be a problem with the API, not with the code -- our headers were being read as 'Apikey' and 'Clientsecretkey' and therefore failing some equality on their side. A fix was pushed to production by them, code now functional.
Add 'Accept' => 'application/json' to your request headers.

Why can Gibbon Gem access API but can't listSubscribe()?

I'm trying to get mailchimp integrated with my ruby-on-rails app using the Gibbon gem.
I've successfully accessed the API. I tested it by getting a list of all my mailchimp lists. However, I'm running into problems with the listsubscribe method. I'm not getting any errors, it just isn't working at all.
I have the following code in the controller for the page where users sign up, after the user is made and their information can be accessed.
gb=Gibbon::API.new
gb.listSubscribe({:id => "the-id-for-list", :email_address => user.email, :update_existing => false, :double_optin => false, :send_welcome => true, :merge_vars => {'FNAME' => user.first_name, 'LNAME' => user.last_name, 'MERGE3' => user.subscription, 'MERGE4' => DateTime.now}})
It does nothing. I've tried playing around with the parameter phrasing (à la this post:How do you use the Gibbon Gem to automatically add subscribers to specific interest groups in MailChimp?) I've tried structuring it more like in this tutorial: http://www.leorodriguez.me/2011/08/subscribe-member-into-mailchimp-using.html
I have no idea what's going wrong. As I said before, other API calls are going through to MailChimp. Do you have any suggestions? Thank you in advance.
It turns out I had the code in the wrong place. I was not putting it where users were actually being created, but in the code to generate the view to ask users to sign up. Once I moved it to where the user was actually created, it worked fine.

Fetching signed_request in a Facebook App with Ruby/Sinatra and the Rest-Graph gem

I've built a Facebook app using Sinatra and the Rest-Graph gem. Now I would like to embed the app as an iframe tab in a Facebook Page.
To do that, I need to fetch data from the signed_request sent to my app by Facebook.
The Rest-Graph gem states the following feature on its Github page:
Utility to extract access_token and
check sig in cookies/signed_request
I couldn't find any documentation on how to use this "utility". Can you point me to some documentation or even better, give me an example on how this is used with Ruby/Sinatra?
Nearly all of the Graph API libraries that are available deal with signed_request in a similar way. Rest-Graph has a parse_signed_request method (Rest-Graph/lib/core.rb) that you can call in Sinatra.
I'm using Koala for this with Sinatra, and it works as advertised:
oauth = Koala::Facebook::OAuth.new(APP_ID, APP_CODE)
signed_request = oauth.parse_signed_request(params["signed_request"])
You get back a hash of the JSON object that Facebook posts:
{
"algorithm"=>"HMAC-SHA256",
"issued_at"=>1303883452,
"user"=>
{
"country"=>"us",
"locale"=>"en_US"
},
"user_id"=>"100002364226618"
}
rest-graph makes it pretty easy, too. Just tested this in a Sinatra app. Works perfectly:
rg = RestGraph.new( :app_id => APP_ID, :secret => APP_SECRET)
parsed_request = rg.parse_signed_request!(params["signed_request"])
Lemme know if that doesn't work for you.
I just got a response to this question from "cardinalblue", the developer of the Rest-Graph gem. This little example was exactly what I was looking for:
require 'sinatra'
require 'rest-graph'
app_id = '123'
secret = 'abc'
config = {:app_id => app_id,
:secret => secret}
post '/' do
rg = RestGraph.new(config)
rg.parse_signed_request!(params['signed_request'])
"#{rg.get('me').inspect.gsub('<', '<')}\n"
end
run Sinatra::Application
Sidenote: In case you're building something similar, please note the post '/' do. Facebook Pages fetch your page using a POST request instead of a GET.

Where can I look to see why Paperclip is failing silently in Rails 3?

I have followed the simple example here.
I have performed the generation, run the migration, added the code to my model and view, and restarted the application.
This is on a company edit screen, where the user can upload a logo.
Running Rails 3.0.3 in dev mode. The only thing even close to Paperclip that I see in the log is:
Started GET "/logos/original/missing.png" for 127.0.0.1 at Tue Dec 14 15:27:42 -0500 2010
ActionController::RoutingError (No route matches "/logos/original/missing.png"):
I was under the impression that Paperclip was pretty easy to use, but I can't seem to even locate an error message. Can anyone help?
Please set your "default_url" path to a image which is displayed if there is no image.
For example,
has_attached_file :image,
:default_url => '/images/nopicture.jpeg',
:styles => {
:large => "300x300>",
:thumb => "160x120>"
}
Where "nopicture.jpeg" which is available in your "/images" folder under public is the default picture to be displayed if none is available.
This should solve your problem.
Fixed! The power of Google. Or Bing rather. My first problem was, I did not have my form_helper include:
:html => { :multipart => true }
That at least got the call to Paperclip going. But it was hanging.
I am using Passenger to serve up Rails. And it turns out that Passenger did not know where ImageMagick was installed on my machine. So I added an initialization file to config/initializers called "paperclip.rb" with one line:
Paperclip.options[:image_magick_path] = "/opt/local/bin"
Problem solved.

Resources