slapshot 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/slapshot +1 -1
- data/lib/slapshot/main.rb +53 -0
- data/lib/slapshot/version.rb +1 -1
- metadata +2 -1
data/bin/slapshot
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
require 'formatador'
|
4
|
+
require 'spreadsheet'
|
5
|
+
|
6
|
+
class SlapshotConnection
|
7
|
+
|
8
|
+
def initialize(url, instance, username, password)
|
9
|
+
@app = "Portfolio"
|
10
|
+
@instance = instance
|
11
|
+
@api = RestClient::Resource.new url, :user => username, :password => password, :timeout => -1
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_app(app)
|
15
|
+
@app = app
|
16
|
+
end
|
17
|
+
|
18
|
+
def search(query, count)
|
19
|
+
|
20
|
+
response = @api["search"].get :params => { :i => @instance, :app => @app, :q => query, :c => count }, :content_type => :json, :accept => :json
|
21
|
+
|
22
|
+
json_response = JSON.parse(response.body)
|
23
|
+
puts "Found #{json_response['count']} total results, retrieving #{count} results in #{json_response['search_time']} ms."
|
24
|
+
|
25
|
+
json_response['docs']
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_table(result)
|
29
|
+
Formatador.display_table(result)
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_xls(result, out)
|
33
|
+
|
34
|
+
book = Spreadsheet::Workbook.new
|
35
|
+
sheet1 = book.create_worksheet :name => 'Search Results'
|
36
|
+
|
37
|
+
columns = ['name', 'entity_type', 'highlight']
|
38
|
+
|
39
|
+
rownum = 0
|
40
|
+
for column in columns
|
41
|
+
sheet1.row(rownum).push column
|
42
|
+
end
|
43
|
+
for row in result
|
44
|
+
rownum += 1
|
45
|
+
for column in columns
|
46
|
+
sheet1.row(rownum).push row[column].nil? ? 'N/A' : row[column]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
book.write(out)
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
data/lib/slapshot/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slapshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -153,6 +153,7 @@ extra_rdoc_files:
|
|
153
153
|
files:
|
154
154
|
- bin/slapshot
|
155
155
|
- lib/slapshot/version.rb
|
156
|
+
- lib/slapshot/main.rb
|
156
157
|
- lib/slapshot.rb
|
157
158
|
- README.rdoc
|
158
159
|
- slapshot.rdoc
|