Sha256: f3a62cf465ebe56b142af1b2fc81df5a317f31d81b63e550aceb2da9eef630f1

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

# encoding: UTF-8

require 'addressable/uri'
require 'rubygems/package'
require 'zlib'
require 'open-uri'
require 'fileutils'

require_relative '../errors.rb'

module Factor
  module Connector
    class Instance
      attr_accessor :definition, :callback, :instance_id

      def initialize(options = {})
        @definition = options[:definition] if options[:definition]
      end

      def callback=(block)
        @callback = block if block
      end

      def respond(params)
        @callback.call(params) if @callback
      end

      def id
        @definition.id
      end

      def info(message)
        log 'info', message
      end

      def error(message)
        log 'error', message
      end

      def warn(message)
        log 'warn', message
      end

      def debug(message)
        log 'debug', message
      end

      def log(status, message)
        respond type: 'log', status: status, message: message
      end

      protected

      def exception(ex, parameters = {})
        debug "exception: #{ex.message}"
        debug 'backtrace:'
        ex.backtrace.each do |line|
          debug "  #{line}"
        end
        debug "parameters: #{parameters}"
      end

      private

      def targz_to_zip(file)
        stringio = Zip::ZipOutputStream.write_buffer do |zipio|
          Gem::Package::TarReader.new(Zlib::GzipReader.open(file.path)) do |tar|
            tar.each do |entry|
              zipio.put_next_entry entry.full_name
              zipio.write entry.read
            end
          end

        end
        stringio.rewind
        file = File.new(file.path.gsub(/.gz/, '.zip').gsub(/.tar/, ''), 'w+')
        file.write stringio.read
        file.rewind
        file
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
factor-connector-api-0.0.5 ./lib/instances/instance.rb
factor-connector-api-0.0.4 ./lib/instances/instance.rb