Sha256: eb2cffefc6da55b3fb409ac43ebc2430388073c377caec591fc7d4b3f11c13ce
Contents?: true
Size: 861 Bytes
Versions: 4
Compression:
Stored size: 861 Bytes
Contents
module Labelary class Image def self.encode(*args) self.new(*args).encode end def initialize(path:nil, mime_type:, filename:nil, file_io:nil) if path.present? @file = Faraday::UploadIO.new path, mime_type elsif file_io.present? && filename.present? @file = Faraday::UploadIO.new file_io, mime_type, filename else raise 'Path to image and MIME type or an IO object, filename and MIME type must be specified.' end end # http://labelary.com/faq.html#image-conversion def encode response = Labelary::Client.connection.post '/v1/graphics', { file: @file }, { Accept: 'application/json' } image = response.body return '^GFA,' + image['totalBytes'].to_s + ',' + image['totalBytes'].to_s + ',' + image['rowBytes'].to_s + ',' + image['data'] + '^FS' end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
labelary-0.3.0 | lib/labelary/image.rb |
labelary-0.2.0 | lib/labelary/image.rb |
labelary-0.1.1 | lib/labelary/image.rb |
labelary-0.1.0 | lib/labelary/image.rb |