Sha256: 0bc9ed170c53c379b5c7891be815fbda28ce771322396578bce48dca8a159be6

Contents?: true

Size: 1.99 KB

Versions: 5

Compression:

Stored size: 1.99 KB

Contents

# encoding: utf-8

require 'thor'
require 'logger'
require 'yaml'
require 'rest-client'
require 'json'
require 'securerandom'
require 'fileutils'
require 'cfpropertylist'
require 'tempfile'

# TODO: remove rescue when https://github.com/tajchert/ruby_apk/pull/4 merged
begin
  require 'ruby_android'
rescue LoadError
  require 'ruby_apk'
end

require 'fir/patches'
require 'fir/util'
require 'fir/version'
require 'fir/cli'

module FIR
  CONFIG_PATH   = "#{ENV['HOME']}/.fir-cli"
  API_YML_PATH  = "#{File.dirname(__FILE__)}/fir/api.yml"
  APP_FILE_TYPE = %w(.ipa .apk).freeze

  include Util

  class << self
    attr_accessor :logger, :api, :config

    def api
      @api ||= YAML.load_file(API_YML_PATH).symbolize_keys
    end

    def config
      @config ||= YAML.load_file(CONFIG_PATH).symbolize_keys if File.exist?(CONFIG_PATH)
    end

    def reload_config
      @config = YAML.load_file(CONFIG_PATH).symbolize_keys
    end

    def write_config hash
      File.open(CONFIG_PATH, 'w+') { |f| f << YAML.dump(hash) }
    end

    def current_token
      @token ||= config[:token] if config
    end

    def get url, params = {}
      begin
        res = RestClient.get(url, params: params)
      rescue RestClient::Exception => e
        logger.error e.response
        exit 1
      end
      JSON.parse(res.body.force_encoding("UTF-8"), symbolize_names: true)
    end

    def post url, query, content_type = :json
      begin
        res = RestClient.post(url, query, { content_type: content_type })
      rescue RestClient::Exception => e
        logger.error e.response
        exit 1
      end
      JSON.parse(res.body.force_encoding("UTF-8"), symbolize_names: true)
    end

    def put url, query, content_type = :json
      begin
        res = RestClient.put(url, query, { content_type: content_type })
      rescue RestClient::Exception => e
        logger.error e.response
        exit 1
      end
      JSON.parse(res.body.force_encoding("UTF-8"), symbolize_names: true)
    end

    alias_method :☠, :exit
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fir-cli-1.0.8 lib/fir.rb
fir-cli-1.0.7 lib/fir.rb
fir-cli-1.0.6 lib/fir.rb
fir-cli-1.0.5 lib/fir.rb
fir-cli-1.0.4 lib/fir.rb