Sha256: 028f20c72e37a16eeb2e2fb027a4ce9e98a5b7f5759f1bca149a363854611a31
Contents?: true
Size: 1.28 KB
Versions: 1
Compression:
Stored size: 1.28 KB
Contents
require 'json' require 'octokit' require 'ruby-anything' require 'active_support/cache' require "anything-hub/version" module AnythingHub extend self attr_accessor :options HOME_RC_FILE = '~/.anything-hubrc' def run(input, opts = {}) init self.options = opts if (results = command(input)) cache.write(input, results.to_json) system("#{options[:s]} #{_anything_(results).gsub(/.*\[(.*)\]/, '\1')}") end end def init require "anything-hub/config" load HOME_RC_FILE require "anything-hub/github" require "anything-hub/command_set" require "anything-hub/commands" end def app_dir dir = File.expand_path('~/.anything-hub') Dir.mkdir(dir) unless Dir.exists? dir @app_dir ||= dir end def token unless (_token = cache.read('authorizations:token') || config.token) res = `curl \ --data '{"scopes":["repo"]}' \ --request POST -u '#{config.login}' \ https://api.github.com/authorizations` _token = (JSON.parse(res) rescue nil).try(:[], 'token') raise StandardError, 'invalid password' if _token.blank? cache.write 'authorizations:token', _token end @token ||= _token end def cache @cache ||= ActiveSupport::Cache::FileStore.new(File.join(app_dir, 'cache')) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
anything-hub-0.0.1 | lib/anything-hub.rb |