Class: Handwritingio::Client
- Inherits:
-
Object
- Object
- Handwritingio::Client
- Defined in:
- lib/handwritingio.rb
Overview
The Official Handwriting.io API Client
Constant Summary collapse
- DEFAULT_URI =
Production API URI
URI.parse('https://api.handwriting.io')
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
-
.with_credentials(key, secret) ⇒ Object
Initializes a new Client with just your key and secret.
Instance Method Summary collapse
-
#handwriting(id) ⇒ Object
Get a handwriting.
-
#handwritings(params = {}) ⇒ Object
Lists handwritings.
-
#initialize(uri) ⇒ Client
constructor
Creates a new
Clientgiven a complete uri. -
#render_pdf(params) ⇒ Object
Render text in the specified handwriting as a PDF file.
-
#render_png(params) ⇒ Object
Render text in the specified handwriting, as a PNG image.
Constructor Details
#initialize(uri) ⇒ Client
Creates a new Client given a complete uri.
Prefer Client.with_credentials unless you to control hostname.
20 21 22 |
# File 'lib/handwritingio.rb', line 20 def initialize(uri) @uri = uri.is_a?(URI) ? uri : URI.parse(uri) end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
14 15 16 |
# File 'lib/handwritingio.rb', line 14 def uri @uri end |
Class Method Details
.with_credentials(key, secret) ⇒ Object
Initializes a new Client with just your key and secret.
This will be the most common way to get a Client instance. If you need more control use Client.new.
171 172 173 174 175 176 |
# File 'lib/handwritingio.rb', line 171 def self.with_credentials(key, secret) uri = DEFAULT_URI uri.user = key uri.password = secret new(uri) end |
Instance Method Details
#handwriting(id) ⇒ Object
Get a handwriting
Parameters
- id
-
Handwriting ID required
31 32 33 |
# File 'lib/handwritingio.rb', line 31 def handwriting(id) Handwriting.new(JSON.parse(get("/handwritings/#{id}"))) end |
#handwritings(params = {}) ⇒ Object
Lists handwritings
Parameters
- limit
-
number of items to fetch defaults to 200, minimum is 1, maximum is 1000
- offset
-
starting point in data set defaults to 0
- order_dir
-
order direction defaults to asc, value must be one of: asc, desc
- order_by
-
order field defaults to id, value must be one of: id, title, date_created, date_modified, rating_neatness, rating_cursivity, rating_embellishment, rating_character_width
51 52 53 |
# File 'lib/handwritingio.rb', line 51 def handwritings(params = {}) Handwriting.initialize_many(JSON.parse(get("/handwritings", params))) end |
#render_pdf(params) ⇒ Object
Render text in the specified handwriting as a PDF file.
Parameters
- handwriting_id
-
requiredThe ID of the handwriting to use. - text
-
requiredmaximum length is 9000 characters - handwriting_size
-
The size of the handwriting, from baseline to cap height. defaults to 20pt, minimum is 0in, maximum is 100in
- handwriting_color
-
The color of the handwriting expressed as (C,M,Y,K). defaults to (0, 0, 0, 1)
- width
-
Width of the image. defaults to 7in, minimum is 0in, maximum is 100in
- height
-
Height of the image. May be set to auto to determine the height automatically based on the text. defaults to 5in, minimum is 0in, maximum is 100in
- min_padding
-
experimentalCenters the block of text within the image, preserving at least min_padding around all four edges of the image. - line_spacing
-
Amount of vertical space for each line, provided as a multiplier of handwriting_size. defaults to 1.5, minimum is 0.0, maximum is 5.0
- line_spacing_variance
-
Amount to randomize spacing between lines, provided as a multiplier. Example: 0.1 means the space between lines will vary by +/- 10%. defaults to 0.0, minimum is 0.0, maximum is 1.0
- word_spacing_variance
-
Amount to randomize spacing between words, provided as a multiplier. Example: 0.1 means the space between words will vary by +/- 10%. defaults to 0.0, minimum is 0.0, maximum is 1.0
- random_seed
-
Set this to a positive number to get a repeatable image. If this parameter is included and positive, the returned image should always be the same for the given set of parameters. defaults to -1
134 135 136 |
# File 'lib/handwritingio.rb', line 134 def render_pdf(params) get("/render/pdf", params) end |
#render_png(params) ⇒ Object
Render text in the specified handwriting, as a PNG image.
Parameters
- handwriting_id
-
requiredThe ID of the handwriting to use. - text
-
requiredmaximum length is 9000 characters - handwriting_size
-
The size of the handwriting, from baseline to cap height. defaults to 20px, minimum is 0px, maximum is 9000px
- handwriting_color
-
The color of the handwriting expressed as #RRGGBB. defaults to #000000
- width
-
Width of the image. defaults to 504px, minimum is 0px, maximum is 9000px
- height
-
Height of the image. May be set to ‘auto` to determine the height automatically based on the text. defaults to 360px, minimum is 0px, maximum is 9000px
- min_padding
-
experimentalCenters the block of text within the image, preserving at least min_padding around all four edges of the image. - line_spacing
-
Amount of vertical space for each line, provided as a multiplier of handwriting_size. defaults to 1.5, minimum is 0.0, maximum is 5.0
- line_spacing_variance
-
Amount to randomize spacing between lines, provided as a multiplier. Example: 0.1 means the space between lines will vary by +/- 10%. defaults to 0.0, minimum is 0.0, maximum is 1.0
- word_spacing_variance
-
Amount to randomize spacing between words, provided as a multiplier. Example: 0.1 means the space between words will vary by +/- 10%. defaults to 0.0, minimum is 0.0, maximum is 1.0
- random_seed
-
Set this to a positive number to get a repeatable image. If this parameter is included and positive, the returned image should always be the same for the given set of parameters. defaults to -1
93 94 95 |
# File 'lib/handwritingio.rb', line 93 def render_png(params) get("/render/png", params) end |