newline_hw 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e28e442adebc87b5de1d6baf8f7ebf3e1a5daf53
4
- data.tar.gz: 417115780717dac70f57b29dbfd538803b722164
3
+ metadata.gz: d46ce94918c8dc2f9531f7c099083d157572e3e6
4
+ data.tar.gz: 606c4c9232451b006937bbd1db6f74ead21750f4
5
5
  SHA512:
6
- metadata.gz: '018456c7304830fbecb8a768b40523c87a36941c04fdbcbb5ece218bcbdcda429863f93c33e7b4c9456dfd08d52733bc25e17ff490113bbe083edf35067c24b9'
7
- data.tar.gz: 0d3a8e7e97b468b9ae42f8c880c12e16df03f724682e67f1b2b0f71dc79513bcc47e87031722ae2431c5b622a9c948b4614666a12f4ce3ad5a71bde7a306fcdc
6
+ metadata.gz: 20fe34238d130e1cda2c2971fb3c7f28ce71d20f98d68b40555232b6bed0331b410b7adc0ac0737cea126f05ace629e5afb41fc7f19138d8a116b2985c210824
7
+ data.tar.gz: 502d10233ddc89a0ed940d3cfd32e4a6046e00b944d3094199b55b9f58028526ac0e21d8527f27c8aad888825f7c6a3b84f16386698e78d309d6e84b2a8203e0
data/README.md CHANGED
@@ -83,10 +83,9 @@ _Javascript_
83
83
 
84
84
  ## TIYO-Assistant Integration
85
85
 
86
- This provides a message bus to allow TIYO assistant to send json to our local binary. This is used to open a terminal window (Apple Terminal or iTerm2) using appleScript and start a `$ hw <submission-id>` command. We use the NewlineCli to backfill data required to run the remainder of the commands.
86
+ This provides a message bus to allow TIYO assistant to send json to our local binary. This is used to open a terminal window (Apple Terminal or iTerm2) using appleScript and start a `$ hw <submission-id>` command. We use the Newline Api to backfill data required to run the remainder of the commands.
87
87
 
88
88
  1. You MUST be on a MAC (hope to drop this in the future)
89
- 1. You MUST have `newline_cli` installed
90
89
  2. You MUST be running a ruby 2.3 or higher
91
90
  3. You MUST have that ruby either in the system loadpath or use, rbenv, rvm, or chruby.
92
91
  4. THIS IS ALPHA so please send logs.
@@ -7,11 +7,10 @@ require_relative "newline_hw/chrome_manifest"
7
7
  require_relative "newline_hw/gui_trigger"
8
8
  require_relative "newline_hw/stream_command_handler"
9
9
  require_relative "newline_hw/stream_processor"
10
- require "newline_cli"
11
- require "newline_cli/api"
12
- require "newline_cli/token"
13
- require "newline_cli/error"
14
- require "newline_cli/auth"
10
+ require_relative "newline_hw/api"
11
+ require_relative "newline_hw/token"
12
+ require_relative "newline_hw/errors"
13
+
15
14
  require "active_support/core_ext/string"
16
15
 
17
16
  module NewlineHw
@@ -0,0 +1,55 @@
1
+ require "json"
2
+ require "excon"
3
+ require "netrc"
4
+
5
+ module NewlineHw
6
+
7
+ class Api
8
+ DEFAULT_HOST = "https://newline.theironyard.com"
9
+
10
+ attr_reader :host
11
+
12
+ def initialize
13
+ @host = Api.host
14
+ token = NewlineHw::Token.get_for_user
15
+ @connection = Excon.new(@host, headers: {
16
+ "Authorization" => "token #{token}"
17
+ })
18
+ end
19
+
20
+ def post(path, data)
21
+ response = @connection.post(path: "/api/#{path}", body: data.to_json, headers: {
22
+ "Accept" => "application/json",
23
+ "Content-Type" => "application/json"
24
+ }, expects: [200, 201])
25
+ JSON.parse(response.body)
26
+ end
27
+
28
+ def put(path, data)
29
+ response = @connection.put(path: "/api/#{path}", body: data.to_json, headers: {
30
+ "Accept" => "application/json",
31
+ "Content-Type" => "application/json"
32
+ }, expects: [200, 201])
33
+ JSON.parse(response.body)
34
+ end
35
+
36
+ def get(path)
37
+ response = @connection.get(path: "/api/#{path}", expects: 200)
38
+ JSON.parse(response.body)
39
+ end
40
+
41
+ def self.auth(data)
42
+ response = Excon.post("#{host}/api/auth", headers: {
43
+ "Content-Type" => "application/json"
44
+ }, body: data)
45
+ raise NewlineHw::AuthenticationError, "Invalid email or password" if response.status != 200
46
+ JSON.parse(response.body)
47
+ end
48
+
49
+ private
50
+
51
+ def self.host
52
+ ENV["NEWLINE_API_HOST"] || DEFAULT_HOST
53
+ end
54
+ end
55
+ end
@@ -66,7 +66,7 @@ module NewlineHw
66
66
  option :editor
67
67
  def setup_command(submission_id)
68
68
  puts Shell::Setup.new(submission_id, config).cmd
69
- rescue NewlineCli::AuthenticationError => e
69
+ rescue NewlineHw::AuthenticationError => e
70
70
  say "Could not log into Newline using NewlineCLI, have you logged in?"
71
71
  say "Error from NewlineCli #{e.message}"
72
72
  exit 3
@@ -0,0 +1,4 @@
1
+ module NewlineHw
2
+ class AuthenticationError < StandardError
3
+ end
4
+ end
@@ -2,7 +2,6 @@ require "uri"
2
2
  require "net/http"
3
3
  require "json"
4
4
  require "openssl"
5
- require "newline_cli/api"
6
5
 
7
6
  module NewlineHw
8
7
  class GuiTrigger
@@ -110,7 +110,7 @@ module NewlineHw
110
110
  end
111
111
 
112
112
  private def query_submission_info
113
- NewlineCli::Api.new.get("assignment_submissions/#{@newline_submission_id}")
113
+ NewlineHw::Api.new.get("assignment_submissions/#{@newline_submission_id}")
114
114
  end
115
115
  end
116
116
  end
@@ -35,7 +35,6 @@ module NewlineHw
35
35
  message_at: message_at,
36
36
  data: {
37
37
  newline_hw_version: NewlineHw::VERSION,
38
- newline_cli_version: NewlineCli::VERSION,
39
38
  ruby_version: RUBY_VERSION,
40
39
  newline_hw_config_path: Config::CONFIG_PATH,
41
40
  newline_hw_path: NewlineHw.root_path,
@@ -0,0 +1,33 @@
1
+ require "jwt"
2
+ require "yaml"
3
+
4
+ module NewlineHw
5
+ class Token
6
+ NETRC_KEY = "newline.theironyard.com"
7
+
8
+ def self.decode(token)
9
+ payload = JWT.decode(token, nil, false)
10
+ payload[0]
11
+ end
12
+
13
+ def self.get_for_path
14
+ path_config = YAML.load_file(".path.config")
15
+ path_config["token"]
16
+ end
17
+
18
+ def self.get_for_user
19
+ return ENV["NEWLINE_API_TOKEN"] if ENV["NEWLINE_API_TOKEN"]
20
+ if (netrc = netrc_file[NETRC_KEY])
21
+ netrc["password"]
22
+ else
23
+ raise NewlineHw::AuthenticationError, "No stored credentials or ENV[\"NEWLINE_API_TOKEN\"]"
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def self.netrc_file
30
+ Netrc.read("#{Netrc.home_path}/#{Netrc.netrc_filename}")
31
+ end
32
+ end
33
+ end
@@ -1,3 +1,3 @@
1
1
  module NewlineHw
2
- VERSION = "1.2.1".freeze
2
+ VERSION = "1.2.2".freeze
3
3
  end
@@ -30,7 +30,9 @@ Gem::Specification.new do |spec|
30
30
  spec.add_dependency "activesupport", ">= 5.0"
31
31
  spec.add_dependency "json", ">= 2.0.0"
32
32
  spec.add_dependency "thor", "~> 0.19.1"
33
- spec.add_dependency "newline_cli", ">= 0.2.5"
33
+ spec.add_dependency "excon", ">= 0.46.0"
34
+ spec.add_dependency "netrc", "~> 0.11.0"
35
+ spec.add_dependency "jwt", ">= 1.5.6"
34
36
 
35
37
  spec.add_development_dependency "bundler", "~> 1.11"
36
38
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: newline_hw
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Russell Osborne
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-17 00:00:00.000000000 Z
11
+ date: 2017-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -53,19 +53,47 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.19.1
55
55
  - !ruby/object:Gem::Dependency
56
- name: newline_cli
56
+ name: excon
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 0.2.5
61
+ version: 0.46.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 0.2.5
68
+ version: 0.46.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: netrc
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.11.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.11.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: jwt
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 1.5.6
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 1.5.6
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: bundler
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -147,9 +175,11 @@ files:
147
175
  - exe/newline_hw_stream
148
176
  - exe/newline_hw_stream_shim
149
177
  - lib/newline_hw.rb
178
+ - lib/newline_hw/api.rb
150
179
  - lib/newline_hw/chrome_manifest.rb
151
180
  - lib/newline_hw/cli.rb
152
181
  - lib/newline_hw/config.rb
182
+ - lib/newline_hw/errors.rb
153
183
  - lib/newline_hw/gui_trigger.rb
154
184
  - lib/newline_hw/shell/function.rb
155
185
  - lib/newline_hw/shell/run.rb
@@ -159,6 +189,7 @@ files:
159
189
  - lib/newline_hw/shell/setup.rb
160
190
  - lib/newline_hw/stream_command_handler.rb
161
191
  - lib/newline_hw/stream_processor.rb
192
+ - lib/newline_hw/token.rb
162
193
  - lib/newline_hw/version.rb
163
194
  - newline_hw.gemspec
164
195
  homepage: https://online.theironyard.com.