eigen.vision 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/bin/ev +7 -0
- data/lib/ev/cli.rb +106 -0
- data/lib/ev.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 70b4f420c4521e422db7f22428fb850549b42e350e483cbc499a86fcac2f34e6
|
|
4
|
+
data.tar.gz: 27397d76c53c976e2a66505c25b979818545e4cdb784c0342dca95c217d14f97
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cc53be8ef13d02a0c9d347172e1f6d3e0f1731ecdf0ccf822fe1dfa3ca2a47e32faca060fecc341996695b3cc7ea4f279474809a1fe0e729bd32ecedf65572b5
|
|
7
|
+
data.tar.gz: 80cc5716847262aa2585910d52ff4955313d29c7f95acd20a0d2cd3804bd865656a50a1cb7729908c6c4a292e92e02e12512c25cac0f8e112f7228b8c79f11d3
|
data/bin/ev
ADDED
data/lib/ev/cli.rb
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
require "net/http"
|
|
2
|
+
require "json"
|
|
3
|
+
|
|
4
|
+
module EV
|
|
5
|
+
class CLI
|
|
6
|
+
attr_reader :output
|
|
7
|
+
|
|
8
|
+
def initialize(args = [])
|
|
9
|
+
@args = args
|
|
10
|
+
@output = ""
|
|
11
|
+
run if @args.any?
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def run
|
|
17
|
+
case @args[0]
|
|
18
|
+
when "push" then push
|
|
19
|
+
when "login" then login
|
|
20
|
+
when "logout" then logout
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def push
|
|
25
|
+
source = File.read(@args[1])
|
|
26
|
+
url = @args[2] || "http://localhost:8080"
|
|
27
|
+
uri = URI("#{url}/analyze")
|
|
28
|
+
req = Net::HTTP::Post.new(uri)
|
|
29
|
+
req["Accept"] = "application/json"
|
|
30
|
+
req.set_form_data("source" => source)
|
|
31
|
+
creds = load_credentials
|
|
32
|
+
if creds && creds[:url] == url
|
|
33
|
+
req["Cookie"] =
|
|
34
|
+
"session=#{creds[:token]}"
|
|
35
|
+
end
|
|
36
|
+
res = Net::HTTP.start(
|
|
37
|
+
uri.hostname, uri.port
|
|
38
|
+
) do |http|
|
|
39
|
+
http.request(req)
|
|
40
|
+
end
|
|
41
|
+
JSON.parse(res.body).each do |pin|
|
|
42
|
+
@output += "#{pin["name"]}: " \
|
|
43
|
+
"#{pin["direction"]}\n"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def login
|
|
48
|
+
email = @args[1]
|
|
49
|
+
password = @args[2]
|
|
50
|
+
url = @args[3] || "http://localhost:8080"
|
|
51
|
+
uri = URI("#{url}/login")
|
|
52
|
+
req = Net::HTTP::Post.new(uri)
|
|
53
|
+
req["Accept"] = "application/json"
|
|
54
|
+
req.set_form_data(
|
|
55
|
+
"email" => email,
|
|
56
|
+
"password" => password
|
|
57
|
+
)
|
|
58
|
+
res = Net::HTTP.start(
|
|
59
|
+
uri.hostname, uri.port
|
|
60
|
+
) do |http|
|
|
61
|
+
http.request(req)
|
|
62
|
+
end
|
|
63
|
+
data = JSON.parse(res.body)
|
|
64
|
+
if res.code == "200"
|
|
65
|
+
save_credentials(url, data["token"])
|
|
66
|
+
@output = "logged in as #{email}\n"
|
|
67
|
+
else
|
|
68
|
+
@output =
|
|
69
|
+
"error: #{data["error"]}\n"
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def logout
|
|
74
|
+
delete_credentials
|
|
75
|
+
@output = "logged out\n"
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def credentials_path
|
|
79
|
+
File.join(Dir.home, ".ev",
|
|
80
|
+
"credentials")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def save_credentials(url, token)
|
|
84
|
+
dir = File.dirname(credentials_path)
|
|
85
|
+
Dir.mkdir(dir) unless Dir.exist?(dir)
|
|
86
|
+
File.write(credentials_path,
|
|
87
|
+
"#{url}\n#{token}\n")
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def load_credentials
|
|
91
|
+
return nil unless File.exist?(
|
|
92
|
+
credentials_path
|
|
93
|
+
)
|
|
94
|
+
lines = File.read(
|
|
95
|
+
credentials_path
|
|
96
|
+
).lines.map(&:chomp)
|
|
97
|
+
{ url: lines[0], token: lines[1] }
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def delete_credentials
|
|
101
|
+
if File.exist?(credentials_path)
|
|
102
|
+
File.delete(credentials_path)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
data/lib/ev.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: eigen.vision
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- eigen.vision
|
|
@@ -9,11 +9,14 @@ bindir: bin
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
|
-
executables:
|
|
12
|
+
executables:
|
|
13
|
+
- ev
|
|
13
14
|
extensions: []
|
|
14
15
|
extra_rdoc_files: []
|
|
15
16
|
files:
|
|
17
|
+
- bin/ev
|
|
16
18
|
- lib/ev.rb
|
|
19
|
+
- lib/ev/cli.rb
|
|
17
20
|
- lib/ev/pin.rb
|
|
18
21
|
homepage: https://eigen.vision
|
|
19
22
|
licenses:
|