Sha256: 17dbd5a40805fe95929ee1848d0e36c1a929dde737a936dd5589d22d49eb1a11

Contents?: true

Size: 697 Bytes

Versions: 4

Compression:

Stored size: 697 Bytes

Contents

# frozen_string_literal: true

require 'faraday'
require 'faraday_middleware'
require 'uri'

module Runa
  class RemoteCode < Response
    attr_accessor :url

    # response/success
    attr_accessor :amount, :barcode_format, :barcode_string, :code, :expiry_date,
      :pin, :type

    def get(ctx)
      conn = Faraday.new(url: url) do |c|
        c.adapter :net_http
        c.use FaradayMiddleware::FollowRedirects, limit: 5
      end
      parse(conn.get("#{url}?format=json") { |r| r.headers['Accept'] = 'application/json' })
    end

    def parse(response)
      super

      if is_successful?
        self.class.new(@payload['e_code'])
      else
        self
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
runa-ruby-client-0.3.1 lib/runa/models/remote_code.rb
runa-ruby-client-0.3.0 lib/runa/models/remote_code.rb
runa-ruby-client-0.2.1 lib/runa/models/remote_code.rb
runa-ruby-client-0.1.0 lib/runa/models/remote_code.rb