labelary 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +100 -0
- data/Rakefile +1 -0
- data/bin/console +7 -0
- data/bin/setup +8 -0
- data/labelary.gemspec +28 -0
- data/lib/labelary.rb +9 -0
- data/lib/labelary/client.rb +23 -0
- data/lib/labelary/configuration.rb +36 -0
- data/lib/labelary/image.rb +26 -0
- data/lib/labelary/label.rb +33 -0
- data/lib/labelary/version.rb +3 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 29390c82c16e578804bd475ba6e6281bdc20fdeb
|
4
|
+
data.tar.gz: 3e684e1c454a745dbdaa88a88c131ca11e50ea66
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad081eb939b53d154d92932a9efe1ba7a7abb7324d2beda2ebb8451d15d0e5dad3a0e779e60b4203b4c1aa1ec0db80e1971f4774ed735b5f6e3c5d75dcb1a757
|
7
|
+
data.tar.gz: 9ffaeb7cd26fbb1e00eef7ff0df5669ceec78a7e4a02bbebcb4b910454f2f62d4ca09bf46dac14bfb99482e8164c43ddc49eb31bb134ce83279a739d4aad927c
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Robert Coleman
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# Labelary
|
2
|
+
|
3
|
+
Labelary ZPL (Zebra Printer Language) Web Service API Client for Ruby.
|
4
|
+
|
5
|
+
**Features:**
|
6
|
+
|
7
|
+
* Render ZPL strings as PNG or PDF.
|
8
|
+
* Encode images to ZPL.
|
9
|
+
* Global configuration or per-request.
|
10
|
+
|
11
|
+
Web service details and instructions: http://labelary.com/service.html
|
12
|
+
|
13
|
+
Supported ZPL commands: http://labelary.com/docs.html
|
14
|
+
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
gem 'labelary'
|
22
|
+
```
|
23
|
+
|
24
|
+
And then execute:
|
25
|
+
|
26
|
+
$ bundle
|
27
|
+
|
28
|
+
Or install it yourself as:
|
29
|
+
|
30
|
+
$ gem install labelary
|
31
|
+
|
32
|
+
## Configuration
|
33
|
+
|
34
|
+
Configuration is available, you can set this per request or in an initializer like so:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
# config/initializers/labelary.rb
|
38
|
+
Labelary.configure do |config|
|
39
|
+
config.dpmm = 8 # required
|
40
|
+
config.width = 3.98 # required (inches)
|
41
|
+
config.height = 6.85 # required (inches)
|
42
|
+
config.index = 0 # optional, for picking a label when multiple are present in the ZPL (usually 0)
|
43
|
+
config.content_type = 'image/png' # or 'application/pdf', specifies the content type of the returned label
|
44
|
+
config.url = 'http://api.labelary.com' # optional (for self hosted)
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
## Usage
|
49
|
+
|
50
|
+
### Rendering Labels
|
51
|
+
|
52
|
+
Pass in a width, height, dpmm (or set defaults in your configuration block) and a ZPL string to have it rendered as a PNG or PDF.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
Labelary::Label.render zpl: '^XA^FDHello World^FS^XZ', content_type: 'image/png', dpmm: 8, width: 6, height: 4
|
56
|
+
#> PNG blob
|
57
|
+
```
|
58
|
+
|
59
|
+
Or with configuration:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
# config/initializers/labelary.rb
|
63
|
+
Labelary.configure do |config|
|
64
|
+
config.dpmm = 8
|
65
|
+
config.width = 6
|
66
|
+
config.height = 4
|
67
|
+
config.content_type = 'application/pdf'
|
68
|
+
end
|
69
|
+
|
70
|
+
# elsewhere e.g. lib/label_render.rb
|
71
|
+
Labelary::Label.render zpl: '^XA^FDHello World^FS^XZ'
|
72
|
+
#> PDF blob
|
73
|
+
```
|
74
|
+
|
75
|
+
### ZPL Encoding Images
|
76
|
+
|
77
|
+
Pass in an image (or an IO object) and it's mime type and you'll get back a ZPL encoded version.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
Labelary::Image.encode path: '/path/to/image.png', mime_type: 'image/png'
|
81
|
+
#> "^GFA,6699,6699,87,,::lR01F,SNIP,:^FS"
|
82
|
+
|
83
|
+
Labelary::Image.encode file_io: IO.read('/path/to/image.png'), filename: 'image.png', mime_type: 'image/png'
|
84
|
+
#> "^GFA,6699,6699,87,,::lR01F,SNIP,:^FS"
|
85
|
+
```
|
86
|
+
|
87
|
+
## Development
|
88
|
+
|
89
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
90
|
+
|
91
|
+
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](https://rubygems.org).
|
92
|
+
|
93
|
+
## Contributing
|
94
|
+
|
95
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rjocoleman/labelary.
|
96
|
+
|
97
|
+
|
98
|
+
## License
|
99
|
+
|
100
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/labelary.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'labelary/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'labelary'
|
8
|
+
spec.version = Labelary::VERSION
|
9
|
+
spec.authors = ['Robert Coleman']
|
10
|
+
spec.email = ['github@robert.net.nz']
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby Gem to interact with the Labelary.com ZPL Web Service}
|
13
|
+
spec.description = %q{Ruby Gem to interact with the Labelary.com ZPL Web Service}
|
14
|
+
spec.homepage = 'https://github.com/rjocoleman/labelary'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
25
|
+
|
26
|
+
spec.add_dependency 'faraday', '~> 0.9'
|
27
|
+
spec.add_dependency 'faraday_middleware', '~> 0.10'
|
28
|
+
end
|
data/lib/labelary.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module Labelary
|
2
|
+
class Client
|
3
|
+
def self.connection(*args)
|
4
|
+
self.new(*args).connection
|
5
|
+
end
|
6
|
+
|
7
|
+
def connection
|
8
|
+
@connection ||= Faraday.new(url: config.url) do |faraday|
|
9
|
+
faraday.request :multipart
|
10
|
+
faraday.response :json, content_type: /\bjson$/
|
11
|
+
|
12
|
+
faraday.adapter config.http_adapter
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def config
|
19
|
+
@config ||= Labelary.configuration
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Labelary
|
2
|
+
class << self
|
3
|
+
attr_accessor :configuration
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.configuration
|
7
|
+
@configuration ||= Configuration.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.configure
|
11
|
+
yield configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
class Configuration
|
15
|
+
attr_accessor *[
|
16
|
+
:url,
|
17
|
+
:http_adapter,
|
18
|
+
:dpmm,
|
19
|
+
:width,
|
20
|
+
:height,
|
21
|
+
:index,
|
22
|
+
:content_type,
|
23
|
+
]
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@url = 'http://api.labelary.com'
|
27
|
+
@http_adapter = Faraday.default_adapter
|
28
|
+
@dpmm = nil
|
29
|
+
@width = nil
|
30
|
+
@height = nil
|
31
|
+
@index = 0
|
32
|
+
@content_type = 'image/png'
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Labelary
|
2
|
+
class Image
|
3
|
+
def self.encode(*args)
|
4
|
+
self.new(*args).encode
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(path:nil, mime_type:, filename:nil, file_io:nil)
|
8
|
+
if path.present?
|
9
|
+
@file = Faraday::UploadIO.new path, mime_type
|
10
|
+
elsif file_io.present? && filename.present?
|
11
|
+
@file = Faraday::UploadIO.new file_io, mime_type, filename
|
12
|
+
else
|
13
|
+
raise 'Path to image and MIME type or an IO object, filename and MIME type must be specified.'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# http://labelary.com/faq.html#image-conversion
|
18
|
+
def encode
|
19
|
+
response = Labelary::Client.connection.post '/v1/graphics', { file: @file }, { Accept: 'application/json' }
|
20
|
+
image = response.body
|
21
|
+
|
22
|
+
return '^GFA,' + image['totalBytes'].to_s + ',' + image['totalBytes'].to_s + ',' + image['rowBytes'].to_s + ',' + image['data'] + '^FS'
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Labelary
|
2
|
+
class Label
|
3
|
+
def self.render(*args)
|
4
|
+
self.new(*args).render
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(dpmm: nil, width: nil, height: nil, index: nil, zpl:, content_type: nil)
|
8
|
+
@zpl ||= zpl
|
9
|
+
@dpmm ||= dpmm || config.dpmm
|
10
|
+
@width ||= width || config.width
|
11
|
+
@height ||= height || config.height
|
12
|
+
@index ||= index || config.index
|
13
|
+
@content_type ||= content_type || config.content_type
|
14
|
+
|
15
|
+
raise 'Invalid dpmm' if @dpmm.nil?
|
16
|
+
raise 'Invalid width' if @width.nil?
|
17
|
+
raise 'Invalid height' if @height.nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
# http://labelary.com/service.html
|
21
|
+
def render
|
22
|
+
response = Labelary::Client.connection.post "/v1/printers/#{@dpmm}dpmm/labels/#{@width}x#{@height}/#{@index}/", @zpl, { Accept: @content_type }
|
23
|
+
return response.body
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def config
|
29
|
+
@config ||= Labelary.configuration
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: labelary
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Coleman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: faraday
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.9'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faraday_middleware
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
83
|
+
description: Ruby Gem to interact with the Labelary.com ZPL Web Service
|
84
|
+
email:
|
85
|
+
- github@robert.net.nz
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- labelary.gemspec
|
98
|
+
- lib/labelary.rb
|
99
|
+
- lib/labelary/client.rb
|
100
|
+
- lib/labelary/configuration.rb
|
101
|
+
- lib/labelary/image.rb
|
102
|
+
- lib/labelary/label.rb
|
103
|
+
- lib/labelary/version.rb
|
104
|
+
homepage: https://github.com/rjocoleman/labelary
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.5.1
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Ruby Gem to interact with the Labelary.com ZPL Web Service
|
128
|
+
test_files: []
|