HNsearch 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rvmrc +53 -0
- data/Gemfile +4 -0
- data/HNsearch.gemspec +28 -0
- data/LICENSE.txt +22 -0
- data/README.md +4 -0
- data/Rakefile +7 -0
- data/bin/HNsearch +4 -0
- data/lib/HNsearch/HNsearch_api.rb +20 -0
- data/lib/HNsearch/cli.rb +20 -0
- data/lib/HNsearch/version.rb +3 -0
- data/lib/HNsearch.rb +53 -0
- metadata +161 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.3-p392@hnsearch"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.19.0 (stable)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
|
27
|
+
do
|
28
|
+
if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
|
29
|
+
then \. "${__hook}" || true
|
30
|
+
fi
|
31
|
+
done
|
32
|
+
unset __hook
|
33
|
+
else
|
34
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
35
|
+
rvm --create "$environment_id" || {
|
36
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
37
|
+
return 1
|
38
|
+
}
|
39
|
+
fi
|
40
|
+
|
41
|
+
# If you use bundler, this might be useful to you:
|
42
|
+
# if [[ -s Gemfile ]] && {
|
43
|
+
# ! builtin command -v bundle >/dev/null ||
|
44
|
+
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
45
|
+
# }
|
46
|
+
# then
|
47
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
48
|
+
# gem install bundler
|
49
|
+
# fi
|
50
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
51
|
+
# then
|
52
|
+
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
53
|
+
# fi
|
data/Gemfile
ADDED
data/HNsearch.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'HNsearch/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "HNsearch"
|
8
|
+
spec.version = HNsearch::VERSION
|
9
|
+
spec.authors = ["Aniket Pant"]
|
10
|
+
spec.email = ["me@aniketpant.com"]
|
11
|
+
spec.description = "A Ruby Gem for searching Hacker News via your terminal"
|
12
|
+
spec.summary = "HNsearch"
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "nestful"
|
26
|
+
spec.add_runtime_dependency "thor"
|
27
|
+
spec.add_runtime_dependency "json"
|
28
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Aniket Pant
|
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.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/HNsearch
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "nestful"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module HNsearch
|
5
|
+
class HNsearchAPI
|
6
|
+
def initialize
|
7
|
+
@client = "http://api.thriftdb.com/api.hnsearch.com/"
|
8
|
+
end
|
9
|
+
|
10
|
+
def query_users(query)
|
11
|
+
api_response = Nestful.get "#{@client}users/_search?q=#{query}"
|
12
|
+
return JSON.parse(api_response)
|
13
|
+
end
|
14
|
+
|
15
|
+
def query_items(query)
|
16
|
+
api_response = Nestful.get "#{@client}items/_search?q=#{query}"
|
17
|
+
return JSON.parse(api_response)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/HNsearch/cli.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "HNsearch"
|
2
|
+
require "thor"
|
3
|
+
|
4
|
+
module HNsearch
|
5
|
+
class CLI < Thor
|
6
|
+
package_name "HNsearch"
|
7
|
+
map "-u" => :users
|
8
|
+
map "-i" => :items
|
9
|
+
|
10
|
+
desc "users [QUERY]", "returns information of queried user"
|
11
|
+
def users(query="")
|
12
|
+
HNsearch::users(query)
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "items [QUERY]", "returns information of queried item"
|
16
|
+
def items(query="")
|
17
|
+
HNsearch::items(query)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/HNsearch.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require "HNsearch/version"
|
2
|
+
require "HNsearch/HNsearch_api"
|
3
|
+
|
4
|
+
module HNsearch
|
5
|
+
def self.users(query)
|
6
|
+
result = HNsearchAPI.new.query_users(query)
|
7
|
+
print_users filter(result)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.items(query)
|
11
|
+
result = HNsearchAPI.new.query_items(query)
|
12
|
+
print_items filter(result)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.filter(result)
|
16
|
+
return result.fetch("results")
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.print_users(result)
|
20
|
+
result.each {
|
21
|
+
|e|
|
22
|
+
e = e.fetch("item")
|
23
|
+
username = e.fetch("username")
|
24
|
+
karma = e.fetch("karma")
|
25
|
+
|
26
|
+
out = []
|
27
|
+
out.push "Username: " + e.fetch("username")
|
28
|
+
out.push "Karma: " + e.fetch("karma").to_s
|
29
|
+
out.push "Profile URL: https://news.ycombinator.com/user?id=#{username}"
|
30
|
+
|
31
|
+
puts out.join("\n")
|
32
|
+
puts("\n")
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.print_items(result)
|
37
|
+
result.each {
|
38
|
+
|e|
|
39
|
+
e = e.fetch("item")
|
40
|
+
title = e.fetch("title")
|
41
|
+
url = e.fetch("url")
|
42
|
+
username = e.fetch("username")
|
43
|
+
|
44
|
+
out = []
|
45
|
+
out.push "Title: " + title
|
46
|
+
out.push "URL: " + url
|
47
|
+
out.push "Posted by: https://news.ycombinator.com/user?id=#{username} (#{username})"
|
48
|
+
|
49
|
+
puts out.join("\n")
|
50
|
+
puts("\n")
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: HNsearch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Aniket Pant
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: nestful
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: thor
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: json
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: A Ruby Gem for searching Hacker News via your terminal
|
111
|
+
email:
|
112
|
+
- me@aniketpant.com
|
113
|
+
executables:
|
114
|
+
- HNsearch
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- .gitignore
|
119
|
+
- .rvmrc
|
120
|
+
- Gemfile
|
121
|
+
- HNsearch.gemspec
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- bin/HNsearch
|
126
|
+
- lib/HNsearch.rb
|
127
|
+
- lib/HNsearch/HNsearch_api.rb
|
128
|
+
- lib/HNsearch/cli.rb
|
129
|
+
- lib/HNsearch/version.rb
|
130
|
+
homepage: ''
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
hash: -4321139604156623722
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ! '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
segments:
|
153
|
+
- 0
|
154
|
+
hash: -4321139604156623722
|
155
|
+
requirements: []
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 1.8.25
|
158
|
+
signing_key:
|
159
|
+
specification_version: 3
|
160
|
+
summary: HNsearch
|
161
|
+
test_files: []
|