htmlcsstoimage-api 0.1.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -3
- data/.ruby-version +1 -1
- data/Gemfile.lock +42 -35
- data/README.md +183 -11
- data/htmlcsstoimage.gemspec +4 -2
- data/lib/htmlcsstoimage/client.rb +36 -0
- data/lib/htmlcsstoimage/images.rb +173 -0
- data/lib/htmlcsstoimage/signed_urls.rb +130 -0
- data/lib/htmlcsstoimage/templates.rb +99 -0
- data/lib/htmlcsstoimage/version.rb +2 -1
- data/lib/htmlcsstoimage.rb +8 -151
- metadata +24 -30
- data/cassettes/HTMLCSSToImage/_create_image/accepts_additional_params.yml +0 -66
- data/cassettes/HTMLCSSToImage/_create_image/creates_an_image.yml +0 -64
- data/cassettes/HTMLCSSToImage/_create_template/creates_a_new_template.yml +0 -62
- data/cassettes/HTMLCSSToImage/_delete_image/deletes_an_image.yml +0 -60
- data/cassettes/HTMLCSSToImage/_templates/retrieves_templates.yml +0 -110
- data/cassettes/HTMLCSSToImage/_url_to_image/accepts_additional_params.yml +0 -64
- data/cassettes/HTMLCSSToImage/_url_to_image/creates_an_image_from_a_url.yml +0 -64
- data/docs/HTMLCSSToImage/ApiResponse.html +0 -124
- data/docs/HTMLCSSToImage.html +0 -1340
- data/docs/_config.yml +0 -1
- data/docs/_index.html +0 -122
- data/docs/class_list.html +0 -51
- data/docs/css/common.css +0 -1
- data/docs/css/full_list.css +0 -58
- data/docs/css/style.css +0 -496
- data/docs/file.README.html +0 -187
- data/docs/file_list.html +0 -56
- data/docs/frames.html +0 -17
- data/docs/index.html +0 -187
- data/docs/js/app.js +0 -314
- data/docs/js/full_list.js +0 -216
- data/docs/js/jquery.js +0 -4
- data/docs/method_list.html +0 -107
- data/docs/top-level-namespace.html +0 -110
data/docs/file.README.html
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>
|
|
7
|
-
File: README
|
|
8
|
-
|
|
9
|
-
— Documentation by YARD 0.9.25
|
|
10
|
-
|
|
11
|
-
</title>
|
|
12
|
-
|
|
13
|
-
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
|
14
|
-
|
|
15
|
-
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
|
16
|
-
|
|
17
|
-
<script type="text/javascript">
|
|
18
|
-
pathId = "README";
|
|
19
|
-
relpath = '';
|
|
20
|
-
</script>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
|
24
|
-
|
|
25
|
-
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
</head>
|
|
29
|
-
<body>
|
|
30
|
-
<div class="nav_wrap">
|
|
31
|
-
<iframe id="nav" src="file_list.html?1"></iframe>
|
|
32
|
-
<div id="resizer"></div>
|
|
33
|
-
</div>
|
|
34
|
-
|
|
35
|
-
<div id="main" tabindex="-1">
|
|
36
|
-
<div id="header">
|
|
37
|
-
<div id="menu">
|
|
38
|
-
|
|
39
|
-
<a href="_index.html">Index</a> »
|
|
40
|
-
<span class="title">File: README</span>
|
|
41
|
-
|
|
42
|
-
</div>
|
|
43
|
-
|
|
44
|
-
<div id="search">
|
|
45
|
-
|
|
46
|
-
<a class="full_list_link" id="class_list_link"
|
|
47
|
-
href="class_list.html">
|
|
48
|
-
|
|
49
|
-
<svg width="24" height="24">
|
|
50
|
-
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
|
51
|
-
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
|
52
|
-
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
|
53
|
-
</svg>
|
|
54
|
-
</a>
|
|
55
|
-
|
|
56
|
-
</div>
|
|
57
|
-
<div class="clear"></div>
|
|
58
|
-
</div>
|
|
59
|
-
|
|
60
|
-
<div id="content"><div id='filecontents'><h1 id="html-css-to-image-ruby">HTML/CSS to Image - Ruby</h1>
|
|
61
|
-
|
|
62
|
-
<p><img src="https://github.com/htmlcsstoimage/ruby-client/workflows/Test/badge.svg?branch=main" alt="Test"> <a href="https://badge.fury.io/rb/htmlcsstoimage-api"><img src="https://badge.fury.io/rb/htmlcsstoimage-api.svg" alt="Gem Version"></a></p>
|
|
63
|
-
|
|
64
|
-
<p>Ruby client for the <a href="https://htmlcsstoimage.com">HTML/CSS to Image API</a>.</p>
|
|
65
|
-
|
|
66
|
-
<p>Generate a png, jpg or webp images with Ruby. Renders exactly like Google Chrome.</p>
|
|
67
|
-
|
|
68
|
-
<h2 id="installation">Installation</h2>
|
|
69
|
-
|
|
70
|
-
<p>Add this line to your application's Gemfile:</p>
|
|
71
|
-
|
|
72
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>htmlcsstoimage-api</span><span class='tstring_end'>'</span></span>
|
|
73
|
-
</code></pre>
|
|
74
|
-
|
|
75
|
-
<p>And then execute:</p>
|
|
76
|
-
|
|
77
|
-
<pre class="code ruby"><code class="ruby">$ bundle
|
|
78
|
-
</code></pre>
|
|
79
|
-
|
|
80
|
-
<p>Or install it yourself as:</p>
|
|
81
|
-
|
|
82
|
-
<pre class="code ruby"><code class="ruby">$ gem install htmlcsstoimage-api
|
|
83
|
-
</code></pre>
|
|
84
|
-
|
|
85
|
-
<h2 id="usage">Usage</h2>
|
|
86
|
-
|
|
87
|
-
<p>Create a new instance of the API client.</p>
|
|
88
|
-
|
|
89
|
-
<pre class="code ruby"><code class="ruby"><span class='comment'># Retrieve your user id and api key from https://htmlcsstoimage.com/dashboard
|
|
90
|
-
</span><span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="HTMLCSSToImage.html" title="HTMLCSSToImage (class)">HTMLCSSToImage</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="HTMLCSSToImage.html#initialize-instance_method" title="HTMLCSSToImage#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>user_id:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>user-id</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>api_key:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>api-key</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
|
91
|
-
</code></pre>
|
|
92
|
-
|
|
93
|
-
<p><strong>Using Environment variables</strong></p>
|
|
94
|
-
|
|
95
|
-
<p>Alternatively, you can set <code>ENV["HCTI_USER_ID"]</code> and <code>ENV["HCTI_API_KEY"]</code>. These will be loaded automatically.</p>
|
|
96
|
-
|
|
97
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="HTMLCSSToImage.html" title="HTMLCSSToImage (class)">HTMLCSSToImage</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="HTMLCSSToImage.html#initialize-instance_method" title="HTMLCSSToImage#initialize (method)">new</a></span></span>
|
|
98
|
-
</code></pre>
|
|
99
|
-
|
|
100
|
-
<h3 id="create-an-image">Create an image</h3>
|
|
101
|
-
|
|
102
|
-
<p>Generate an image from HTML/CSS. Returns a URL to the image.</p>
|
|
103
|
-
|
|
104
|
-
<pre class="code ruby"><code class="ruby">image = client.create_image("<div>Hello, world</div>",
|
|
105
|
-
css: "div { background-color: red; font-family: Roboto; }",
|
|
106
|
-
google_fonts: "Roboto")
|
|
107
|
-
|
|
108
|
-
image
|
|
109
|
-
=> #<HTMLCSSToImage::ApiResponse url="https://hcti.io/v1/image/254b444c-dd82-4cc1-94ef-aa4b3a6870a6", id="254b444c-dd82-4cc1-94ef-aa4b3a6870a6">
|
|
110
|
-
image.url
|
|
111
|
-
=> "https://hcti.io/v1/image/254b444c-dd82-4cc1-94ef-aa4b3a6870a6"
|
|
112
|
-
</code></pre>
|
|
113
|
-
|
|
114
|
-
<h3 id="delete-an-image">Delete an image</h3>
|
|
115
|
-
|
|
116
|
-
<p>Delete an existing image. Removes the image from HCTI servers and clears the CDN.</p>
|
|
117
|
-
|
|
118
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_delete_image'>delete_image</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>254b444c-dd82-4cc1-94ef-aa4b3a6870a6</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
|
119
|
-
</code></pre>
|
|
120
|
-
|
|
121
|
-
<h3 id="url-to-image">URL to image</h3>
|
|
122
|
-
|
|
123
|
-
<p>Generate a screenshot of any public URL.</p>
|
|
124
|
-
|
|
125
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_image'>image</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_url_to_image'>url_to_image</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>https://github.com</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>viewport_width:</span> <span class='int'>800</span><span class='comma'>,</span> <span class='label'>viewport_height:</span> <span class='int'>1200</span><span class='rparen'>)</span>
|
|
126
|
-
</code></pre>
|
|
127
|
-
|
|
128
|
-
<h2 id="templates">Templates</h2>
|
|
129
|
-
|
|
130
|
-
<p>A template allows you to define HTML that includes variables to be substituted at the time of image creation. <a href="https://docs.htmlcsstoimage.com/getting-started/templates/">Learn more about templates</a>.</p>
|
|
131
|
-
|
|
132
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_template'>template</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_create_template'>create_template</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'><div>{{title}}</div></span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
|
133
|
-
<span class='comment'># => #<HTMLCSSToImage::ApiResponse template_id="t-56c64be5-5861-4148-acec-aaaca452027f", template_version=1596829374001>
|
|
134
|
-
</span>
|
|
135
|
-
<span class='comment'># Get templates
|
|
136
|
-
</span><span class='id identifier rubyid_all_templates'>all_templates</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_templates'>templates</span>
|
|
137
|
-
|
|
138
|
-
<span class='comment'># Create a signed URL for a templated image
|
|
139
|
-
</span><span class='id identifier rubyid_image'>image</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_create_image_from_template'>create_image_from_template</span><span class='lparen'>(</span><span class='id identifier rubyid_template'>template</span><span class='period'>.</span><span class='id identifier rubyid_template_id'>template_id</span><span class='comma'>,</span> <span class='lbrace'>{</span> <span class='label'>title:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Hello, world!</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span><span class='rparen'>)</span>
|
|
140
|
-
<span class='comment'># => #<HTMLCSSToImage::ApiResponse url="https://hcti.io/v1/image/t-56c64be5-5861-4148-acec-aaaca452027f/3aaa814dd998b302cc62b3550ddb35e8b9117c5ecea286da904eced0a3f44d9e?title=Hello%2C%20world%21">
|
|
141
|
-
</span>
|
|
142
|
-
<span class='id identifier rubyid_image'>image</span><span class='period'>.</span><span class='id identifier rubyid_url'>url</span>
|
|
143
|
-
<span class='comment'># => "https://hcti.io/v1/image/t-56c64be5-5861-4148-acec-aaaca452027f/3aaa814dd998b302cc62b3550ddb35e8b9117c5ecea286da904eced0a3f44d9e?title=Hello%2C%20world%21"
|
|
144
|
-
</span></code></pre>
|
|
145
|
-
|
|
146
|
-
<h3 id="additional-methods">Additional methods</h3>
|
|
147
|
-
|
|
148
|
-
<p>See the <a href="https://htmlcsstoimage.github.io/ruby-client/HTMLCSSToImage.html">ruby-client docs for all of the available methods</a>.</p>
|
|
149
|
-
|
|
150
|
-
<h2 id="available-parameters">Available parameters</h2>
|
|
151
|
-
|
|
152
|
-
<p>For detailed information on all the available parameters, visit the docs: <a href="https://docs.htmlcsstoimage.com/getting-started/using-the-api/">https://docs.htmlcsstoimage.com/getting-started/using-the-api/</a></p>
|
|
153
|
-
|
|
154
|
-
<h2 id="development">Development</h2>
|
|
155
|
-
|
|
156
|
-
<p>After checking out the repo, run <code>bin/setup</code> to install dependencies. Then, run <code>rake spec</code> to run the tests. You can also run <code>bin/console</code> for an interactive prompt that will allow you to experiment.</p>
|
|
157
|
-
|
|
158
|
-
<p>To install this gem onto your local machine, run <code>bundle exec rake install</code>. To release a new version, update the version number in <code>version.rb</code>, and then run <code>bundle exec rake release</code>, which will create a git tag for the version, push git commits and tags, and push the <code>.gem</code> file to <a href="https://rubygems.org">rubygems.org</a>.</p>
|
|
159
|
-
|
|
160
|
-
<p>To generate the Yard docs, run <code>yard doc -o docs</code> and commit the changes.</p>
|
|
161
|
-
|
|
162
|
-
<h2 id="support">Support</h2>
|
|
163
|
-
|
|
164
|
-
<p>For help with the API, you can also contact <code>support@htmlcsstoimage.com</code>.</p>
|
|
165
|
-
|
|
166
|
-
<h2 id="contributing">Contributing</h2>
|
|
167
|
-
|
|
168
|
-
<p>Bug reports and pull requests are welcome on GitHub at <a href="https://github.com/htmlcsstoimage/ruby-client">https://github.com/htmlcsstoimage/ruby-client</a>.</p>
|
|
169
|
-
|
|
170
|
-
<h2 id="license">License</h2>
|
|
171
|
-
|
|
172
|
-
<p>The gem is available as open source under the terms of the <a href="https://opensource.org/licenses/MIT">MIT License</a>.</p>
|
|
173
|
-
|
|
174
|
-
<h2 id="code-of-conduct">Code of Conduct</h2>
|
|
175
|
-
|
|
176
|
-
<p>Everyone interacting in the project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the <a href="https://github.com/htmlcsstoimage/ruby-client/blob/main/CODE_OF_CONDUCT.md">code of conduct</a>.</p>
|
|
177
|
-
</div></div>
|
|
178
|
-
|
|
179
|
-
<div id="footer">
|
|
180
|
-
Generated on Fri Aug 7 13:04:07 2020 by
|
|
181
|
-
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
182
|
-
0.9.25 (ruby-2.6.5).
|
|
183
|
-
</div>
|
|
184
|
-
|
|
185
|
-
</div>
|
|
186
|
-
</body>
|
|
187
|
-
</html>
|
data/docs/file_list.html
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
5
|
-
<meta charset="utf-8" />
|
|
6
|
-
|
|
7
|
-
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" />
|
|
8
|
-
|
|
9
|
-
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" />
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
|
14
|
-
|
|
15
|
-
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
<title>File List</title>
|
|
19
|
-
<base id="base_target" target="_parent" />
|
|
20
|
-
</head>
|
|
21
|
-
<body>
|
|
22
|
-
<div id="content">
|
|
23
|
-
<div class="fixed_header">
|
|
24
|
-
<h1 id="full_list_header">File List</h1>
|
|
25
|
-
<div id="full_list_nav">
|
|
26
|
-
|
|
27
|
-
<span><a target="_self" href="class_list.html">
|
|
28
|
-
Classes
|
|
29
|
-
</a></span>
|
|
30
|
-
|
|
31
|
-
<span><a target="_self" href="method_list.html">
|
|
32
|
-
Methods
|
|
33
|
-
</a></span>
|
|
34
|
-
|
|
35
|
-
<span><a target="_self" href="file_list.html">
|
|
36
|
-
Files
|
|
37
|
-
</a></span>
|
|
38
|
-
|
|
39
|
-
</div>
|
|
40
|
-
|
|
41
|
-
<div id="search">Search: <input type="text" /></div>
|
|
42
|
-
</div>
|
|
43
|
-
|
|
44
|
-
<ul id="full_list" class="file">
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
<li id="object_README" class="odd">
|
|
48
|
-
<div class="item"><span class="object_link"><a href="index.html" title="README">README</a></span></div>
|
|
49
|
-
</li>
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
</ul>
|
|
54
|
-
</div>
|
|
55
|
-
</body>
|
|
56
|
-
</html>
|
data/docs/frames.html
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<title>Documentation by YARD 0.9.25</title>
|
|
6
|
-
</head>
|
|
7
|
-
<script type="text/javascript">
|
|
8
|
-
var match = unescape(window.location.hash).match(/^#!(.+)/);
|
|
9
|
-
var name = match ? match[1] : 'index.html';
|
|
10
|
-
name = name.replace(/^(\w+):\/\//, '').replace(/^\/\//, '');
|
|
11
|
-
window.top.location = name;
|
|
12
|
-
</script>
|
|
13
|
-
<noscript>
|
|
14
|
-
<h1>Oops!</h1>
|
|
15
|
-
<h2>YARD requires JavaScript!</h2>
|
|
16
|
-
</noscript>
|
|
17
|
-
</html>
|
data/docs/index.html
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8">
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>
|
|
7
|
-
File: README
|
|
8
|
-
|
|
9
|
-
— Documentation by YARD 0.9.25
|
|
10
|
-
|
|
11
|
-
</title>
|
|
12
|
-
|
|
13
|
-
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
|
14
|
-
|
|
15
|
-
<link rel="stylesheet" href="css/common.css" type="text/css" />
|
|
16
|
-
|
|
17
|
-
<script type="text/javascript">
|
|
18
|
-
pathId = "README";
|
|
19
|
-
relpath = '';
|
|
20
|
-
</script>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
|
24
|
-
|
|
25
|
-
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
</head>
|
|
29
|
-
<body>
|
|
30
|
-
<div class="nav_wrap">
|
|
31
|
-
<iframe id="nav" src="class_list.html?1"></iframe>
|
|
32
|
-
<div id="resizer"></div>
|
|
33
|
-
</div>
|
|
34
|
-
|
|
35
|
-
<div id="main" tabindex="-1">
|
|
36
|
-
<div id="header">
|
|
37
|
-
<div id="menu">
|
|
38
|
-
|
|
39
|
-
<a href="_index.html">Index</a> »
|
|
40
|
-
<span class="title">File: README</span>
|
|
41
|
-
|
|
42
|
-
</div>
|
|
43
|
-
|
|
44
|
-
<div id="search">
|
|
45
|
-
|
|
46
|
-
<a class="full_list_link" id="class_list_link"
|
|
47
|
-
href="class_list.html">
|
|
48
|
-
|
|
49
|
-
<svg width="24" height="24">
|
|
50
|
-
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
|
|
51
|
-
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
|
|
52
|
-
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
|
|
53
|
-
</svg>
|
|
54
|
-
</a>
|
|
55
|
-
|
|
56
|
-
</div>
|
|
57
|
-
<div class="clear"></div>
|
|
58
|
-
</div>
|
|
59
|
-
|
|
60
|
-
<div id="content"><div id='filecontents'><h1 id="html-css-to-image-ruby">HTML/CSS to Image - Ruby</h1>
|
|
61
|
-
|
|
62
|
-
<p><img src="https://github.com/htmlcsstoimage/ruby-client/workflows/Test/badge.svg?branch=main" alt="Test"> <a href="https://badge.fury.io/rb/htmlcsstoimage-api"><img src="https://badge.fury.io/rb/htmlcsstoimage-api.svg" alt="Gem Version"></a></p>
|
|
63
|
-
|
|
64
|
-
<p>Ruby client for the <a href="https://htmlcsstoimage.com">HTML/CSS to Image API</a>.</p>
|
|
65
|
-
|
|
66
|
-
<p>Generate a png, jpg or webp images with Ruby. Renders exactly like Google Chrome.</p>
|
|
67
|
-
|
|
68
|
-
<h2 id="installation">Installation</h2>
|
|
69
|
-
|
|
70
|
-
<p>Add this line to your application's Gemfile:</p>
|
|
71
|
-
|
|
72
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>htmlcsstoimage-api</span><span class='tstring_end'>'</span></span>
|
|
73
|
-
</code></pre>
|
|
74
|
-
|
|
75
|
-
<p>And then execute:</p>
|
|
76
|
-
|
|
77
|
-
<pre class="code ruby"><code class="ruby">$ bundle
|
|
78
|
-
</code></pre>
|
|
79
|
-
|
|
80
|
-
<p>Or install it yourself as:</p>
|
|
81
|
-
|
|
82
|
-
<pre class="code ruby"><code class="ruby">$ gem install htmlcsstoimage-api
|
|
83
|
-
</code></pre>
|
|
84
|
-
|
|
85
|
-
<h2 id="usage">Usage</h2>
|
|
86
|
-
|
|
87
|
-
<p>Create a new instance of the API client.</p>
|
|
88
|
-
|
|
89
|
-
<pre class="code ruby"><code class="ruby"><span class='comment'># Retrieve your user id and api key from https://htmlcsstoimage.com/dashboard
|
|
90
|
-
</span><span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="HTMLCSSToImage.html" title="HTMLCSSToImage (class)">HTMLCSSToImage</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="HTMLCSSToImage.html#initialize-instance_method" title="HTMLCSSToImage#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='label'>user_id:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>user-id</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>api_key:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>api-key</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
|
91
|
-
</code></pre>
|
|
92
|
-
|
|
93
|
-
<p><strong>Using Environment variables</strong></p>
|
|
94
|
-
|
|
95
|
-
<p>Alternatively, you can set <code>ENV["HCTI_USER_ID"]</code> and <code>ENV["HCTI_API_KEY"]</code>. These will be loaded automatically.</p>
|
|
96
|
-
|
|
97
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="HTMLCSSToImage.html" title="HTMLCSSToImage (class)">HTMLCSSToImage</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="HTMLCSSToImage.html#initialize-instance_method" title="HTMLCSSToImage#initialize (method)">new</a></span></span>
|
|
98
|
-
</code></pre>
|
|
99
|
-
|
|
100
|
-
<h3 id="create-an-image">Create an image</h3>
|
|
101
|
-
|
|
102
|
-
<p>Generate an image from HTML/CSS. Returns a URL to the image.</p>
|
|
103
|
-
|
|
104
|
-
<pre class="code ruby"><code class="ruby">image = client.create_image("<div>Hello, world</div>",
|
|
105
|
-
css: "div { background-color: red; font-family: Roboto; }",
|
|
106
|
-
google_fonts: "Roboto")
|
|
107
|
-
|
|
108
|
-
image
|
|
109
|
-
=> #<HTMLCSSToImage::ApiResponse url="https://hcti.io/v1/image/254b444c-dd82-4cc1-94ef-aa4b3a6870a6", id="254b444c-dd82-4cc1-94ef-aa4b3a6870a6">
|
|
110
|
-
image.url
|
|
111
|
-
=> "https://hcti.io/v1/image/254b444c-dd82-4cc1-94ef-aa4b3a6870a6"
|
|
112
|
-
</code></pre>
|
|
113
|
-
|
|
114
|
-
<h3 id="delete-an-image">Delete an image</h3>
|
|
115
|
-
|
|
116
|
-
<p>Delete an existing image. Removes the image from HCTI servers and clears the CDN.</p>
|
|
117
|
-
|
|
118
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_delete_image'>delete_image</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>254b444c-dd82-4cc1-94ef-aa4b3a6870a6</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
|
119
|
-
</code></pre>
|
|
120
|
-
|
|
121
|
-
<h3 id="url-to-image">URL to image</h3>
|
|
122
|
-
|
|
123
|
-
<p>Generate a screenshot of any public URL.</p>
|
|
124
|
-
|
|
125
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_image'>image</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_url_to_image'>url_to_image</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>https://github.com</span><span class='tstring_end'>"</span></span><span class='comma'>,</span> <span class='label'>viewport_width:</span> <span class='int'>800</span><span class='comma'>,</span> <span class='label'>viewport_height:</span> <span class='int'>1200</span><span class='rparen'>)</span>
|
|
126
|
-
</code></pre>
|
|
127
|
-
|
|
128
|
-
<h2 id="templates">Templates</h2>
|
|
129
|
-
|
|
130
|
-
<p>A template allows you to define HTML that includes variables to be substituted at the time of image creation. <a href="https://docs.htmlcsstoimage.com/getting-started/templates/">Learn more about templates</a>.</p>
|
|
131
|
-
|
|
132
|
-
<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_template'>template</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_create_template'>create_template</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'><div>{{title}}</div></span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
|
|
133
|
-
<span class='comment'># => #<HTMLCSSToImage::ApiResponse template_id="t-56c64be5-5861-4148-acec-aaaca452027f", template_version=1596829374001>
|
|
134
|
-
</span>
|
|
135
|
-
<span class='comment'># Get templates
|
|
136
|
-
</span><span class='id identifier rubyid_all_templates'>all_templates</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_templates'>templates</span>
|
|
137
|
-
|
|
138
|
-
<span class='comment'># Create a signed URL for a templated image
|
|
139
|
-
</span><span class='id identifier rubyid_image'>image</span> <span class='op'>=</span> <span class='id identifier rubyid_client'>client</span><span class='period'>.</span><span class='id identifier rubyid_create_image_from_template'>create_image_from_template</span><span class='lparen'>(</span><span class='id identifier rubyid_template'>template</span><span class='period'>.</span><span class='id identifier rubyid_template_id'>template_id</span><span class='comma'>,</span> <span class='lbrace'>{</span> <span class='label'>title:</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Hello, world!</span><span class='tstring_end'>"</span></span> <span class='rbrace'>}</span><span class='rparen'>)</span>
|
|
140
|
-
<span class='comment'># => #<HTMLCSSToImage::ApiResponse url="https://hcti.io/v1/image/t-56c64be5-5861-4148-acec-aaaca452027f/3aaa814dd998b302cc62b3550ddb35e8b9117c5ecea286da904eced0a3f44d9e?title=Hello%2C%20world%21">
|
|
141
|
-
</span>
|
|
142
|
-
<span class='id identifier rubyid_image'>image</span><span class='period'>.</span><span class='id identifier rubyid_url'>url</span>
|
|
143
|
-
<span class='comment'># => "https://hcti.io/v1/image/t-56c64be5-5861-4148-acec-aaaca452027f/3aaa814dd998b302cc62b3550ddb35e8b9117c5ecea286da904eced0a3f44d9e?title=Hello%2C%20world%21"
|
|
144
|
-
</span></code></pre>
|
|
145
|
-
|
|
146
|
-
<h3 id="additional-methods">Additional methods</h3>
|
|
147
|
-
|
|
148
|
-
<p>See the <a href="https://htmlcsstoimage.github.io/ruby-client/HTMLCSSToImage.html">ruby-client docs for all of the available methods</a>.</p>
|
|
149
|
-
|
|
150
|
-
<h2 id="available-parameters">Available parameters</h2>
|
|
151
|
-
|
|
152
|
-
<p>For detailed information on all the available parameters, visit the docs: <a href="https://docs.htmlcsstoimage.com/getting-started/using-the-api/">https://docs.htmlcsstoimage.com/getting-started/using-the-api/</a></p>
|
|
153
|
-
|
|
154
|
-
<h2 id="development">Development</h2>
|
|
155
|
-
|
|
156
|
-
<p>After checking out the repo, run <code>bin/setup</code> to install dependencies. Then, run <code>rake spec</code> to run the tests. You can also run <code>bin/console</code> for an interactive prompt that will allow you to experiment.</p>
|
|
157
|
-
|
|
158
|
-
<p>To install this gem onto your local machine, run <code>bundle exec rake install</code>. To release a new version, update the version number in <code>version.rb</code>, and then run <code>bundle exec rake release</code>, which will create a git tag for the version, push git commits and tags, and push the <code>.gem</code> file to <a href="https://rubygems.org">rubygems.org</a>.</p>
|
|
159
|
-
|
|
160
|
-
<p>To generate the Yard docs, run <code>yard doc -o docs</code> and commit the changes.</p>
|
|
161
|
-
|
|
162
|
-
<h2 id="support">Support</h2>
|
|
163
|
-
|
|
164
|
-
<p>For help with the API, you can also contact <code>support@htmlcsstoimage.com</code>.</p>
|
|
165
|
-
|
|
166
|
-
<h2 id="contributing">Contributing</h2>
|
|
167
|
-
|
|
168
|
-
<p>Bug reports and pull requests are welcome on GitHub at <a href="https://github.com/htmlcsstoimage/ruby-client">https://github.com/htmlcsstoimage/ruby-client</a>.</p>
|
|
169
|
-
|
|
170
|
-
<h2 id="license">License</h2>
|
|
171
|
-
|
|
172
|
-
<p>The gem is available as open source under the terms of the <a href="https://opensource.org/licenses/MIT">MIT License</a>.</p>
|
|
173
|
-
|
|
174
|
-
<h2 id="code-of-conduct">Code of Conduct</h2>
|
|
175
|
-
|
|
176
|
-
<p>Everyone interacting in the project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the <a href="https://github.com/htmlcsstoimage/ruby-client/blob/main/CODE_OF_CONDUCT.md">code of conduct</a>.</p>
|
|
177
|
-
</div></div>
|
|
178
|
-
|
|
179
|
-
<div id="footer">
|
|
180
|
-
Generated on Fri Aug 7 13:04:07 2020 by
|
|
181
|
-
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
|
182
|
-
0.9.25 (ruby-2.6.5).
|
|
183
|
-
</div>
|
|
184
|
-
|
|
185
|
-
</div>
|
|
186
|
-
</body>
|
|
187
|
-
</html>
|