thegengen / cloudprint Goto Github PK
View Code? Open in Web Editor NEWA Ruby library for interacting with Google's Cloud Print service
License: MIT License
A Ruby library for interacting with Google's Cloud Print service
License: MIT License
Google's documentation for cloudprint is really old now. Their API playground does not feature it any longer, rather they have a ...minimal... simulation tool here
Also, using this gem before the point of having a refresh_token is impossible, and understanding the flow of obtaining a refresh_token is complicated. Martin Fowler wrote an article about this, and he was using a well-documented API!
Hi.
I'm using your gem and it works perfect, almost...
I want to print a label for a product, I construct the PDF in my app, no problem, Initialize a CloudPrint instance and call print on it. The problem comes when the printer prints the label. The position of the label is totally wrong. It's not at the top of the page where I've expected it to be.
Can you have any control over the page settings, e.g. "Fit to page" or other options you have when printing directly to a printer in Google Chrome?
Here is my code:
client_id = file[Rails.env.downcase]["client_id"]
client_secret = file[Rails.env.downcase]["client_secret"]
client = CloudPrint::Client.new(
client_id: client_id,
client_secret: client_secret,
refresh_token: refresh_token
)
client.printers.find(default_printer_id).print(content: base64, content_type: "application/pdf", ticket: {"version": "1.0", "print": {}}, content_transfer_encoding: "base64")
Thank you.
could you create a example application, on how this should properly be implemented with oauth connecting to google.
I think we want a singleton class like CloudPrint::Auth
that supports the following methods:
generate_url
should generate a correct URL.process_code
should generate a refresh token (default) or single access token (optional)Hello,
Very recently, and out of nowhere, the following error keeps coming up when trying to use client.printers.find(<printer_id>):
SocketError: Failed to open TCP connection to www.google.com:443 (getaddrinfo: No address associated with hostname)
I wonder what could be causing this problem?
Hello,
This gem has been working properly in the past. Now the exception "Net::ReadTimeout:Net::ReadTimeout" is raised when a job is submitted.
What could be the reason for this? I saw a pull request that suggests to update the Net::HTTP to Faraday. Could it be that Net::HTTP is getting old?
p = CloudPrint::Client.new(refresh_token: "refresh", client_id: "id", client_secret: "secret", callback_url: "Valid callback url")
my_printer = p.printers.find("id")
my_printer.print(content: "html", content_type: "text/html")
So arguably this is likely a documentation issue more than a problem (I hope), but the docs mention that you just pass a File as the content (and presumably application/pdf as the content type), but I canntot get that to work (I get errors about "no implicit conversion of nil into String" from within net/http/generic_request).
I also see other issues where it looks like folks are encoding the PDF content into base64 ahead of time - not sure if that is a choice of a necessity.
So any chance of an example of what you need to minimally print a PDF file via the gem would be much appreciated!
Can't get pdf to correctly print when printing to google drive. pdf shows up fine on local but comes across blank in google drive.
File.open(Rails.root.join('public', "#{invoice_number}.pdf"), 'wb') do |file|
file.write(decoded_invoice_pdf)
end
printer.print(title: "#{invoice_number}_1.pdf", content: decoded_invoice_pdf, content_type: "application/pdf")
printer.print(title: "#{invoice_number}_2.pdf", content: File.read(Rails.root.join('public', "#{invoice_number}.pdf")), content_type: "application/pdf")
Is there anyway to change the paper size with this gem? I'm trying to print a 5x7 card and I can't find anywhere that the paper size is specified, so it's forcing a letter size on my print job.
How do I run an application in Ruby on Rails? is possible?
Why can't we access the auth
method when initialising CloudPrint::Client.new
?
The current latest published gem has a dependency on oauth2 0.8.0
. This is incompatible with the latest Rails.
It seems to work fine if I change the dependency to 1.1.0
. Could you update and publish a new gem version?
The Cloudprint API can do a lot more stuff than what is currently in this gem. A list of capabilities (most of which I don't understand) are here:
Google Cloud Print provides a UI State that includes a summary, progress of a job, and a cause for display use. Parsing that information into the print_job
would help us display errors correctly with the same terminology as Google's UI.
I am using gem version 0.3.2 which is also the latest version in the repo. The README says that I should call client.auth.generate_url method. However, I get the following error:
NoMethodError: undefined method `auth' for #CloudPrint::Client:0x007f9559098918
It seems like, either a new gem version needs to be pushed to rubygems.org or the documentation is out of date.
Calling client.printers.all
delegates to client.printers.search_all
, which in turn delegates to client.printers.search('all')
. This doesn't return any printers, except for the default "Save to Google Docs" (__google__docs
). I suggest changing method_missing
to exclude "all" from the regexp, and then change def all
to be an alias on search
Hello all,
me again ๐
I'm getting A refresh_token is not available
.
So, this happens once the OAuth has been authenticated, and we try to hit the endpoint on Google again.
I've debugged the code and tried to run client.refresh_token
, no luck here.
Any ideas?
I'm using this:
cp = CloudPrint::Client.new(refresh_token: "sent refresh token valid", client_id: "sent valid id", client_secret: "sent valid secret", callback_url: "Valid callback url")
my_printer = cp.printers.find("valid id printer") #get correctly the printer
my_printer.print(content: "<h1>Hello World</h1>", content_type: "text/html")
#this return nil and not print
what is my mistake ?
OAuth2 depends on Faraday which is a lot nicer to work with than Net::HTTP. Since that dependency is already a given, this gem might as well take advantage of Faraday too.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.