slapshot 0.0.9 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/slapshot +15 -8
- data/lib/slapshot/main.rb +7 -9
- data/lib/slapshot/version.rb +1 -1
- metadata +1 -1
data/bin/slapshot
CHANGED
@@ -19,8 +19,13 @@ desc 'Search your instance of Appshot'
|
|
19
19
|
arg_name 'Pass in the query'
|
20
20
|
command :search do |c|
|
21
21
|
|
22
|
-
c.desc '
|
23
|
-
c.
|
22
|
+
c.desc 'Get all results'
|
23
|
+
c.default_value false
|
24
|
+
c.switch [:a, :all]
|
25
|
+
|
26
|
+
c.desc 'Return all fields of the results, including code snippets'
|
27
|
+
c.default_value false
|
28
|
+
c.switch [:f, :full]
|
24
29
|
|
25
30
|
c.desc 'Export the results to an Excel file with the given name'
|
26
31
|
c.flag [:x, :xls]
|
@@ -31,20 +36,22 @@ command :search do |c|
|
|
31
36
|
|
32
37
|
c.action do |global_options,options,args|
|
33
38
|
|
34
|
-
if options[:a]
|
35
|
-
@sc.set_app options[:a]
|
36
|
-
end
|
37
|
-
|
38
39
|
if args.length != 1
|
39
|
-
raise
|
40
|
+
raise "The search command takes exactly one argument: the query"
|
41
|
+
end
|
42
|
+
|
43
|
+
count = options[:c]
|
44
|
+
if options[:a]
|
45
|
+
count = 5000
|
40
46
|
end
|
41
47
|
|
42
|
-
r = @sc.search args[0], options[:
|
48
|
+
r = @sc.search args[0], count, options[:f]
|
43
49
|
|
44
50
|
if options[:x]
|
45
51
|
@sc.to_xls r, options[:x]
|
46
52
|
puts "Exported search results to #{options[:x]}"
|
47
53
|
else
|
54
|
+
puts
|
48
55
|
puts @sc.to_table r
|
49
56
|
end
|
50
57
|
end
|
data/lib/slapshot/main.rb
CHANGED
@@ -48,25 +48,23 @@ end
|
|
48
48
|
class Appshot
|
49
49
|
|
50
50
|
def initialize(url, token, instance)
|
51
|
-
@app = "Portfolio"
|
52
51
|
@instance = instance
|
53
|
-
|
54
52
|
@api = RestClient::Resource.new url, :timeout => -1, :headers => {'Appshot-AuthToken' => token, 'Appshot-Instance' => instance}
|
55
53
|
end
|
56
54
|
|
57
|
-
def
|
58
|
-
@app = app
|
59
|
-
end
|
60
|
-
|
61
|
-
def search(query, count)
|
55
|
+
def search(query, count, full)
|
62
56
|
|
63
|
-
response = @api["v1/search"].get :params => { :i => @instance, :
|
57
|
+
response = @api["v1/search"].get :params => { :i => @instance, :q => query, :c => count, :f => full }, :content_type => :json, :accept => :json
|
64
58
|
|
65
59
|
json_response = JSON.parse(response.body)
|
66
60
|
|
67
|
-
|
61
|
+
if (Integer(json_response['count']) < Integer(count))
|
62
|
+
count = json_response['count']
|
63
|
+
end
|
68
64
|
|
65
|
+
puts "Found #{json_response['count']} total results, retrieving #{count} results in #{json_response['search_time']} ms."
|
69
66
|
json_response['docs']
|
67
|
+
|
70
68
|
end
|
71
69
|
|
72
70
|
def to_table(result)
|
data/lib/slapshot/version.rb
CHANGED