polleverywhere/url2png-plus

Name: url2png-plus

Owner: Poll Everywhere

Description: A minimalist URL2PNG Ruby client

Created: 2017-11-11 00:54:17.0

Updated: 2017-11-11 01:18:21.0

Pushed: 2017-11-11 01:14:22.0

Homepage:

Size: 8

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Url2png::Plus

Generates URL2PNG urls for Ruby projects and integrations with popular web frameworks, like Rails, Sinatra, etc.

Why url2png-plus and not url2png?

The url2png gem is way more complicated than it needs to be:

  1. It tries to be compatible with a bunch of different versions of the url2png HTTP APIs. The client shouldn't worry about this, at least I can't rationalize it.

  2. Its insecure out of the box by using the http protocol. Configuring the protocol is difficult because the base URL is a “magic string” inside the gem.

  3. The project has roughly 1,000 LOC. This project has 40 LOC. That doesn't mean much, but it is less stuff that can break.

This gem only attempts to integrate with the most recent version of URL2PNG, which is v6 at the time of this writing. If URL2PNG upgrades their APIs, this client will be updated to use the new API without any attempt to remain compatible with the old APIs. That burden will be put on using an older version of the gem.

Installation

Add this line to your application's Gemfile:

'url2png-plus'

And then execute:

$ bundle

Or install it yourself as:

$ gem install url2png-plus
Usage
png = Url2png::Plus::Client.new(api_key: "APIKEY", secret: "SECRET")
e `URL2PNG_API_KEY` and `URL2PNG_SECRET` environment variables are used as a default.
r web applications you'd set those and initialize via `Url2png::Plus::Client.new`.
png.url "https://www.example.com/rabit.png", viewport: "100x100", fullpage: true

That's it. Read URL2PNG docs at https://www.url2png.com/docs to know what parameters you can use.

If you'd like to use in Rails or other web applications, include the helper wherever you need it:

s ApplicationController
clude Url2png::Plus::Helper

Example implementation in a controller
f redirect_to_image
redirect_to url2png_url(request.url, viewport: "1024x768")
d

Configuration

If you need to configure in Rails, create ./config/initializers/url2png.rb and:

png::Plus.config do |c|
api_key = "APIKEY"
secret = "SECRET"
Why would you change this to `http`? Defaults to `https`
scheme = "http"

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/polleverywhere/url2png-plus. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Url2png::Plus project?s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.