anything-hub 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ spec/cassettes
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in anything-hub.gemspec
4
+ gemspec
5
+
6
+ gem 'pry'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Takatoshi Matsumoto
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,102 @@
1
+ # AnythingHub
2
+
3
+ Anything interface for github.
4
+ Filter response of Github api with anything interface and open selected one in browser.
5
+
6
+ **This has not uploaded to rubygems yet**
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'anything-hub'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```sh
19
+ $ bundle
20
+ ```
21
+
22
+ Or install it yourself as:
23
+
24
+ ```sh
25
+ $ gem install anything-hub
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ Put config file.
31
+
32
+ ```ruby
33
+ # in ~/.anything-hubrc
34
+ AnythingHub.configure do |c|
35
+ c.login "username" # github username
36
+ c.token "token" # github oauth token. this is optional. (If you use in non-interactive env, I recommend to set this.)
37
+ end
38
+ ```
39
+
40
+ Now support starred and searching
41
+
42
+ ```sh
43
+ $ anything-hub starred:ToQoz
44
+ $ anything-hub search:rails
45
+ ```
46
+
47
+ If you want to ignore cache
48
+
49
+ ```sh
50
+ $ anything-hub starred:ToQoz --cache no
51
+ ```
52
+
53
+ If you machine don't have `open` command(OSX have it)
54
+
55
+ ```sh
56
+ $ anything-hub starred:ToQoz --system_command xdg-open
57
+ ```
58
+
59
+ If you want to do only cache
60
+
61
+ ```sh
62
+ $ anything-hub cache:starred:ToQoz
63
+ ```
64
+
65
+ If you get token for github api(e.g. for cron)
66
+
67
+ ```sh
68
+ $ anything-hub token
69
+ ```
70
+
71
+ ## Tips
72
+
73
+ Periodically cache. For example for the often searched keyword and your starred.
74
+ **If try it, I recommend to put token to your `~/anything-hubrc`. You can get token by `$ anything-hub token`**
75
+
76
+ ```sh
77
+ $ crontab -e
78
+ 05 12 * * * /Users/toqoz/.rbenv/shims/anything-hub cache:search:rails >> /tmp/anything-hub.cron.log 2>> /tmp/anything-hub.cron.error.log
79
+ 05 1 * * * /Users/toqoz/.rbenv/shims/anything-hub cache:starred:ToQoz >> /tmp/anything-hub.cron.log 2>> /tmp/anything-hub.cron.error.log
80
+ ```
81
+
82
+ ## Help
83
+ ```sh
84
+ ✘╹◡╹✘ $ anyting-hub --help
85
+ $ anything-hub COMMANDS [OPTIONS]
86
+
87
+ available COMMANDS are
88
+ starred:USER_NAME
89
+ search:SEARCH_KEYWORD
90
+
91
+ -s, --system_command system command name. eg. xdg-open, open (default is open)
92
+ -c, --cache use cache. yes or no. (default is yes)
93
+ -h, --help Display this help message.
94
+ ```
95
+
96
+ ## Contributing
97
+
98
+ 1. Fork it
99
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
100
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
101
+ 4. Push to the branch (`git push origin my-new-feature`)
102
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'anything-hub/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "anything-hub"
8
+ gem.version = AnythingHub::VERSION
9
+ gem.authors = ["Takatoshi Matsumoto"]
10
+ gem.email = ["toqoz403@gmail.com"]
11
+ gem.description = %q{Anything interface for github}
12
+ gem.summary = %q{Anything interface for github. Filter response of Github api with anything interface and open selected one in browser.}
13
+ gem.homepage = "http://github.com/ToQoz/anything-hub"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'ruby-anything'
21
+ gem.add_dependency 'slop'
22
+ gem.add_dependency 'octokit'
23
+ gem.add_dependency 'activesupport'
24
+ gem.add_development_dependency 'rspec'
25
+ gem.add_development_dependency 'vcr'
26
+ gem.add_development_dependency 'webmock'
27
+ end
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "slop"
4
+ argv = ARGV.dup
5
+ slop = Slop.new(:strict => true, :help => true)
6
+ slop.on :s, :system_command=, 'system command name. eg. xdg-open, open (default is open)'
7
+ slop.on :c, :cache=, 'use cache. yes or no. (default is yes)'
8
+ slop.banner <<-BANNER
9
+ $ anything-hub COMMANDS [OPTIONS]
10
+
11
+ available COMMANDS are
12
+ starred:USER_NAME
13
+ search:SEARCH_KEYWORD
14
+ BANNER
15
+
16
+ begin
17
+ slop.parse!(argv)
18
+ rescue => e
19
+ puts e
20
+ exit!
21
+ end
22
+
23
+ options = slop.to_hash
24
+ if options[:help]
25
+ exit!
26
+ end
27
+ options.delete(:help)
28
+ options[:s] ||= 'open'
29
+
30
+ root = File.expand_path('../..', __FILE__)
31
+ $LOAD_PATH.unshift root
32
+ $LOAD_PATH.unshift File.join(root, 'lib')
33
+
34
+ require 'anything-hub'
35
+
36
+ AnythingHub.run(ARGV[0], options)
@@ -0,0 +1,54 @@
1
+ require 'json'
2
+ require 'octokit'
3
+ require 'ruby-anything'
4
+ require 'active_support/cache'
5
+ require "anything-hub/version"
6
+
7
+ module AnythingHub
8
+ extend self
9
+
10
+ attr_accessor :options
11
+
12
+ HOME_RC_FILE = '~/.anything-hubrc'
13
+
14
+ def run(input, opts = {})
15
+ init
16
+ self.options = opts
17
+
18
+ if (results = command(input))
19
+ cache.write(input, results.to_json)
20
+ system("#{options[:s]} #{_anything_(results).gsub(/.*\[(.*)\]/, '\1')}")
21
+ end
22
+ end
23
+
24
+ def init
25
+ require "anything-hub/config"
26
+ load HOME_RC_FILE
27
+ require "anything-hub/github"
28
+ require "anything-hub/command_set"
29
+ require "anything-hub/commands"
30
+ end
31
+
32
+ def app_dir
33
+ dir = File.expand_path('~/.anything-hub')
34
+ Dir.mkdir(dir) unless Dir.exists? dir
35
+ @app_dir ||= dir
36
+ end
37
+
38
+ def token
39
+ unless (_token = cache.read('authorizations:token') || config.token)
40
+ res = `curl \
41
+ --data '{"scopes":["repo"]}' \
42
+ --request POST -u '#{config.login}' \
43
+ https://api.github.com/authorizations`
44
+ _token = (JSON.parse(res) rescue nil).try(:[], 'token')
45
+ raise StandardError, 'invalid password' if _token.blank?
46
+ cache.write 'authorizations:token', _token
47
+ end
48
+ @token ||= _token
49
+ end
50
+
51
+ def cache
52
+ @cache ||= ActiveSupport::Cache::FileStore.new(File.join(app_dir, 'cache'))
53
+ end
54
+ end
@@ -0,0 +1,33 @@
1
+ module AnythingHub
2
+ extend self
3
+
4
+ def command_set(&block)
5
+ class_eval(&block)
6
+ end
7
+
8
+ def command(name, &block)
9
+ if block
10
+ commands << {:pattern => /^#{name}(:.+)?/, :block => block}
11
+ else
12
+ cmd = commands.detect { |c| c[:pattern] =~ name }
13
+ cmd[:block].call(name)
14
+ end
15
+ end
16
+
17
+ def commands
18
+ @commands ||= []
19
+ end
20
+
21
+ def fetch_from_api_or_cache(cache_key, &api)
22
+ unless options[:cache] == "no"
23
+ cache_data = JSON.parse(cache.read(cache_key)) rescue nil
24
+ end
25
+ if cache_data
26
+ cache_data
27
+ else
28
+ response = api.call
29
+ cache.write cache_key, response.to_json
30
+ response
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,31 @@
1
+ AnythingHub.command_set do
2
+ command :starred do |input|
3
+ _, username = input.split(':')
4
+ fetch_from_api_or_cache(input) do
5
+ github.starred(username || github.client.login).map do |repo|
6
+ "(#{repo.full_name}) #{repo.description} [#{repo.html_url}]"
7
+ end
8
+ end
9
+ end
10
+
11
+ command :search do |input|
12
+ _, query = input.split(':')
13
+ fetch_from_api_or_cache(input) do
14
+ github.search_repositories(query).map do |repo|
15
+ "(#{repo.username}/#{repo.name}) #{repo.description} [http://github.com/#{repo.username}/#{repo.name}]"
16
+ end
17
+ end
18
+ end
19
+
20
+ command :token do |input|
21
+ puts token
22
+ nil
23
+ end
24
+
25
+ command :cache do |input|
26
+ _, target_cmd = input.split(':', 2)
27
+ cache.write target_cmd, nil
28
+ cache.write target_cmd, command(target_cmd).to_json
29
+ nil
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ module AnythingHub
2
+ extend self
3
+
4
+ class Config
5
+ def method_missing(action, *args)
6
+ if args.first
7
+ instance_variable_set("@#{action.to_s}", args.first)
8
+ else
9
+ instance_variable_get("@#{action.to_s}")
10
+ end
11
+ end
12
+ end
13
+
14
+ def configure
15
+ yield config
16
+ end
17
+
18
+ def config
19
+ @config ||= AnythingHub::Config.new
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ module AnythingHub
2
+ extend self
3
+
4
+ class Github
5
+ def initialize(login, oauth_token)
6
+ @login = login
7
+ @oauth_token = oauth_token
8
+ end
9
+
10
+ def client
11
+ @client ||= Octokit::Client.new :login => @login, :oauth_token => @oauth_token, :auto_traversal => true
12
+ end
13
+
14
+ def method_missing(action, *args)
15
+ if client.respond_to?(action.to_s)
16
+ client.send(action, *args)
17
+ else
18
+ super
19
+ end
20
+ end
21
+ end
22
+
23
+ def github
24
+ @github ||= Github.new(config.login, token)
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module AnythingHub
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe AnythingHub do
4
+ describe 'test loading rc files' do
5
+ before do
6
+ AnythingHub::HOME_RC_FILE.replace('spec/fixtures/testrc')
7
+ end
8
+ after do
9
+ AnythingHub::HOME_RC_FILE.replace('~/.anything-hubrc')
10
+ end
11
+
12
+ context 'when AnythingHub init' do
13
+ before do
14
+ AnythingHub.init
15
+ end
16
+
17
+ it 'should set login' do
18
+ AnythingHub.config.login.should eq('ToQoz')
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ AnythingHub.configure do |c|
2
+ c.login "ToQoz"
3
+ end
4
+
5
+ # vim:set ft=ruby:
@@ -0,0 +1,6 @@
1
+ root = File.expand_path("../..", __FILE__)
2
+ $LOAD_PATH.unshift File.join(root, 'lib')
3
+ require 'active_support/core_ext'
4
+ require 'anything-hub'
5
+
6
+ Dir[File.join(root, "spec/support/**/*.rb")].each { |f| require f }
@@ -0,0 +1,22 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |c|
4
+ c.cassette_library_dir = 'spec/cassettes'
5
+ c.hook_into :webmock
6
+ c.default_cassette_options = { :record => :new_episodes }
7
+ c.configure_rspec_metadata!
8
+ end
9
+
10
+ RSpec.configure do |c|
11
+ c.treat_symbols_as_metadata_keys_with_true_values = true
12
+
13
+ c.around(:each) do |example|
14
+ options = example.metadata[:vcr] || {}
15
+ if options[:record] == :skip
16
+ VCR.turned_off(&example)
17
+ else
18
+ name = example.metadata[:full_description].gsub(/\s*$/, '').split(/\s+/, 2).join("/").underscore.gsub(/[^\w\/]+/, "_")
19
+ VCR.use_cassette(name, options, &example)
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,182 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: anything-hub
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Takatoshi Matsumoto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ prerelease: false
16
+ type: :runtime
17
+ version_requirements: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ name: ruby-anything
24
+ requirement: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ prerelease: false
32
+ type: :runtime
33
+ version_requirements: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ name: slop
40
+ requirement: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ prerelease: false
48
+ type: :runtime
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ name: octokit
56
+ requirement: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ prerelease: false
64
+ type: :runtime
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ name: activesupport
72
+ requirement: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ prerelease: false
80
+ type: :development
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ name: rspec
88
+ requirement: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ prerelease: false
96
+ type: :development
97
+ version_requirements: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ name: vcr
104
+ requirement: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ prerelease: false
112
+ type: :development
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ name: webmock
120
+ requirement: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Anything interface for github
127
+ email:
128
+ - toqoz403@gmail.com
129
+ executables:
130
+ - anything-hub
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - .gitignore
135
+ - .rspec
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - anything-hub.gemspec
141
+ - bin/anything-hub
142
+ - lib/anything-hub.rb
143
+ - lib/anything-hub/command_set.rb
144
+ - lib/anything-hub/commands.rb
145
+ - lib/anything-hub/config.rb
146
+ - lib/anything-hub/github.rb
147
+ - lib/anything-hub/version.rb
148
+ - spec/anything-hub_spec.rb
149
+ - spec/fixtures/testrc
150
+ - spec/spec_helper.rb
151
+ - spec/support/vcr.rb
152
+ homepage: http://github.com/ToQoz/anything-hub
153
+ licenses: []
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ none: false
166
+ requirements:
167
+ - - ! '>='
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 1.8.24
173
+ signing_key:
174
+ specification_version: 3
175
+ summary: Anything interface for github. Filter response of Github api with anything
176
+ interface and open selected one in browser.
177
+ test_files:
178
+ - spec/anything-hub_spec.rb
179
+ - spec/fixtures/testrc
180
+ - spec/spec_helper.rb
181
+ - spec/support/vcr.rb
182
+ has_rdoc: