Module: Html2img

Defined in:
lib/html2img/configuration.rb,
lib/html2img/cli.rb,
lib/html2img/client.rb,
lib/html2img/errors.rb,
lib/html2img/railtie.rb,
lib/html2img/request.rb,
lib/html2img/version.rb,
lib/html2img/transport.rb,
lib/html2img/render_response.rb,
lib/generators/html2img/install/install_generator.rb

Overview

Official Ruby client for the html2img.com HTML to Image API.

See Client for the API surface, and Html2img.configure for process-wide defaults.

Defined Under Namespace

Modules: Generators, Request Classes: AuthenticationError, CLI, Client, Configuration, ConnectionError, Error, InsufficientCreditsError, NotFoundError, NotSubscribedError, Railtie, RateLimitError, RenderResponse, ServerError, TimeoutError, Transport, ValidationError

Constant Summary collapse

VERSION =

Single source of truth for the gem version.

"1.1.1"
DEFAULT_BASE_URL =

Base URL of the API. Override only for testing or a private deployment.

"https://app.html2img.com"
DEFAULT_TIMEOUT =

Request timeout in seconds, just over the 30 second synchronous render budget.

35.0

Class Method Summary collapse

Class Method Details

.clientObject

A memoised client built from configuration.



63
64
65
# File 'lib/html2img/configuration.rb', line 63

def client
  @client ||= Client.new
end

.configurationObject

The process-wide configuration.



46
47
48
# File 'lib/html2img/configuration.rb', line 46

def configuration
  @configuration ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Configure the defaults used by client.

Yield Parameters:



53
54
55
56
57
58
59
60
# File 'lib/html2img/configuration.rb', line 53

def configure
  yield(configuration) if block_given?

  # A reconfigured process should not keep handing out the old client.
  @client = nil

  configuration
end

.downloadObject

Download a render with the default client.



89
90
91
# File 'lib/html2img/configuration.rb', line 89

def download(...)
  client.download(...)
end

.htmlObject

Render an HTML document with the default client.



74
75
76
# File 'lib/html2img/configuration.rb', line 74

def html(...)
  client.html(...)
end

.reset!Object

Forget the configuration and the memoised client. Mostly for tests.



68
69
70
71
# File 'lib/html2img/configuration.rb', line 68

def reset!
  @configuration = nil
  @client = nil
end

.saveObject

Save a render to disk with the default client.



94
95
96
# File 'lib/html2img/configuration.rb', line 94

def save(...)
  client.save(...)
end

.screenshotObject

Capture a screenshot with the default client.



79
80
81
# File 'lib/html2img/configuration.rb', line 79

def screenshot(...)
  client.screenshot(...)
end

.templateObject

Render a named template with the default client.



84
85
86
# File 'lib/html2img/configuration.rb', line 84

def template(...)
  client.template(...)
end