Class: Rerout::Resources::Qr
- Inherits:
-
Object
- Object
- Rerout::Resources::Qr
- Defined in:
- lib/rerout/qr.rb
Overview
QR helpers.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(client) ⇒ Qr
constructor
A new instance of Qr.
-
#svg(code, options = nil) ⇒ String
Fetch the QR as an SVG string.
-
#url(code, options = nil) ⇒ String
Build the URL the API serves the QR SVG from.
Constructor Details
#initialize(client) ⇒ Qr
Returns a new instance of Qr.
11 12 13 |
# File 'lib/rerout/qr.rb', line 11 def initialize(client) @client = client end |
Class Method Details
.build_url(base_url:, code:, options: nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rerout/qr.rb', line 44 def self.build_url(base_url:, code:, options: nil) raise ArgumentError, 'code is required' if code.nil? || code.to_s.empty? qopts = () base = base_url.to_s.sub(%r{/+\z}, '') path = "/v1/links/#{ERB::Util.url_encode(code.to_s)}/qr" url = "#{base}#{path}" query = qopts.to_query_hash return url if query.empty? "#{url}?#{URI.encode_www_form(query)}" end |
.coerce_options(options) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
58 59 60 61 62 63 64 65 66 |
# File 'lib/rerout/qr.rb', line 58 def self.() case when nil then QrOptions.new when QrOptions then when Hash then QrOptions.new(**.transform_keys(&:to_sym)) else raise ArgumentError, 'options must be a Rerout::QrOptions, Hash, or nil' end end |
Instance Method Details
#svg(code, options = nil) ⇒ String
Fetch the QR as an SVG string. Attaches the bearer token.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rerout/qr.rb', line 30 def svg(code, = nil) raise ArgumentError, 'code is required' if code.nil? || code.to_s.empty? qopts = Qr.() path = "/v1/links/#{ERB::Util.url_encode(code.to_s)}/qr" @client.request( method: :get, path: path, query: qopts.to_query_hash, raw: true ) end |