aoj 0.0.4 → 0.0.5
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/aoj.gemspec +2 -2
- data/lib/aoj/cli.rb +5 -0
- data/lib/aoj/env.rb +34 -0
- data/lib/aoj/http.rb +5 -26
- data/lib/aoj/version.rb +1 -1
- data/spec/lib/aoj/env_spec.rb +72 -0
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 449266fb56333786a7e8ee152e4dfab57b245027
|
4
|
+
data.tar.gz: 3c74831e04c44d5d4af266bbb353cd45adf7a314
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3308c88f00e9a2a672836311754469a75be365719110e3f31aad85f5c4b73986dbf4637a8a0062aab9e24de3cd7d8b14cdf805c5ed10f13fae19ff813f29395d
|
7
|
+
data.tar.gz: ebe6e094de834312214e66b7f008e9df335552698669a3a9b22c8799377df7e39683d0a31662952fc2a742eca38440ab46cdb63c593aefb27e02043fb2eeda38
|
data/aoj.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = AOJ::VERSION
|
9
9
|
spec.authors = ["na-o-ys"]
|
10
10
|
spec.email = ["naoyoshi0511@gmail.com"]
|
11
|
-
spec.summary = %q{aoj
|
12
|
-
spec.description = %q{
|
11
|
+
spec.summary = %q{aoj command-line tool}
|
12
|
+
spec.description = %q{AOJ is a command-line tool for AOJ(Aizu Online Judge). You can submit your source to AOJ and check the result of judgement without opening browser or copy & paste..}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/lib/aoj/cli.rb
CHANGED
data/lib/aoj/env.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module AOJ
|
2
|
+
class Env
|
3
|
+
|
4
|
+
def initialize(env = ENV)
|
5
|
+
@env = env
|
6
|
+
end
|
7
|
+
|
8
|
+
# parse proxy from String
|
9
|
+
# param str : [http://][user:pass@]host[:port]
|
10
|
+
def parse_proxy_info
|
11
|
+
raw = @env["HTTP_PROXY"] || @env["http_proxy"]
|
12
|
+
return {} unless raw
|
13
|
+
|
14
|
+
main_str = raw
|
15
|
+
.strip
|
16
|
+
.sub(/^http:\/\//, "")
|
17
|
+
.sub(/\/+$/, "")
|
18
|
+
|
19
|
+
auth_str = main_str.match(/(.*)@/).to_a[1].to_s
|
20
|
+
host_str = main_str.sub(/^.*@/, "")
|
21
|
+
{
|
22
|
+
host: host_str.sub(/:.*$/, ""),
|
23
|
+
port: host_str.match(/:(.*)/).to_a[1].try(:to_i), # int or nil
|
24
|
+
user: auth_str.sub(/:.*$/, ""),
|
25
|
+
pass: auth_str.sub(/^.*:/, "")
|
26
|
+
}.select { |_, value| value.present? }
|
27
|
+
end
|
28
|
+
|
29
|
+
def proxy_specified?
|
30
|
+
parse_proxy_info != {}
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
data/lib/aoj/http.rb
CHANGED
@@ -3,33 +3,12 @@ require 'net/http'
|
|
3
3
|
module AOJ
|
4
4
|
|
5
5
|
HTTP = -> do
|
6
|
-
|
7
|
-
# [http://][user:pass@]host:port
|
8
|
-
env = ENV["HTTP_PROXY"] || ENV["http_proxy"]
|
9
|
-
break ::Net::HTTP unless env
|
10
|
-
|
11
|
-
info = parse_proxy_info(env)
|
6
|
+
proxy_info = Env.new.parse_proxy_info
|
12
7
|
::Net::HTTP::Proxy(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
8
|
+
proxy_info[:host],
|
9
|
+
proxy_info[:port],
|
10
|
+
proxy_info[:user],
|
11
|
+
proxy_info[:pass]
|
17
12
|
)
|
18
13
|
end.call
|
19
|
-
|
20
|
-
private
|
21
|
-
# TODO: test
|
22
|
-
def self.parse_proxy_info(str)
|
23
|
-
{}.tap do |i|
|
24
|
-
str.sub!(/http:\/\//, "")
|
25
|
-
str.sub!(/\/+$/, "")
|
26
|
-
if str.include?("@")
|
27
|
-
auth, str = str.split("@")
|
28
|
-
i[:user], i[:pass] = auth.split(":")
|
29
|
-
end
|
30
|
-
i[:host], port_str = str.split(":")
|
31
|
-
i[:port] = port_str.sub(/\//, "").to_i
|
32
|
-
i[:uri] = "http://" + str
|
33
|
-
end
|
34
|
-
end
|
35
14
|
end
|
data/lib/aoj/version.rb
CHANGED
@@ -0,0 +1,72 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe AOJ::Env do
|
4
|
+
describe 'parse_proxy_info' do
|
5
|
+
context 'when only host given' do
|
6
|
+
let(:env) { create_env("HTTP_PROXY" => "http://hoge.co.jp/") }
|
7
|
+
|
8
|
+
it { expect(env.parse_proxy_info).to eq(host: "hoge.co.jp") }
|
9
|
+
end
|
10
|
+
|
11
|
+
context 'when host and port given' do
|
12
|
+
let(:env) { create_env("HTTP_PROXY" => "http://hoge.co.jp:8080/") }
|
13
|
+
|
14
|
+
it {
|
15
|
+
expect(env.parse_proxy_info).to eq(
|
16
|
+
host: "hoge.co.jp",
|
17
|
+
port: 8080
|
18
|
+
)
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'when user, pass, host given' do
|
23
|
+
let(:env) { create_env("HTTP_PROXY" => "http://nao:secret@hoge.co.jp/") }
|
24
|
+
|
25
|
+
it {
|
26
|
+
expect(env.parse_proxy_info).to eq(
|
27
|
+
host: "hoge.co.jp",
|
28
|
+
user: "nao",
|
29
|
+
pass: "secret"
|
30
|
+
)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when user, pass, host and port given' do
|
35
|
+
let(:env) { create_env("HTTP_PROXY" => "http://nao:secret@hoge.co.jp:8080/") }
|
36
|
+
|
37
|
+
it {
|
38
|
+
expect(env.parse_proxy_info).to eq(
|
39
|
+
host: "hoge.co.jp",
|
40
|
+
port: 8080,
|
41
|
+
user: "nao",
|
42
|
+
pass: "secret"
|
43
|
+
)
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'when no proxy info given' do
|
48
|
+
let(:env) { AOJ::Env.new({}) }
|
49
|
+
|
50
|
+
it { expect(env.parse_proxy_info).to eq({}) }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'proxy_specified?' do
|
55
|
+
context 'when proxy info given' do
|
56
|
+
let(:env) { create_env("HTTP_PROXY" => "http://hoge.co.jp") }
|
57
|
+
|
58
|
+
it { expect(env.proxy_specified?).to be_truthy }
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when no proxy info given' do
|
62
|
+
let(:env) { AOJ::Env.new({}) }
|
63
|
+
|
64
|
+
it { expect(env.proxy_specified?).to be_falsy }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def create_env(hash)
|
69
|
+
hash.each { |key, value| value.freeze }
|
70
|
+
AOJ::Env.new(hash)
|
71
|
+
end
|
72
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aoj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- na-o-ys
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,8 +108,9 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '5.14'
|
111
|
-
description:
|
112
|
-
|
111
|
+
description: AOJ is a command-line tool for AOJ(Aizu Online Judge). You can submit
|
112
|
+
your source to AOJ and check the result of judgement without opening browser or
|
113
|
+
copy & paste..
|
113
114
|
email:
|
114
115
|
- naoyoshi0511@gmail.com
|
115
116
|
executables:
|
@@ -130,6 +131,7 @@ files:
|
|
130
131
|
- lib/aoj/cli/helper.rb
|
131
132
|
- lib/aoj/conf.rb
|
132
133
|
- lib/aoj/credential.rb
|
134
|
+
- lib/aoj/env.rb
|
133
135
|
- lib/aoj/error/api_error.rb
|
134
136
|
- lib/aoj/error/fetch_result_error.rb
|
135
137
|
- lib/aoj/error/file_open_error.rb
|
@@ -145,6 +147,7 @@ files:
|
|
145
147
|
- lib/aoj/version.rb
|
146
148
|
- spec/lib/aoj/api_spec.rb
|
147
149
|
- spec/lib/aoj/conf_spec.rb
|
150
|
+
- spec/lib/aoj/env_spec.rb
|
148
151
|
- spec/lib/aoj/language_spec.rb
|
149
152
|
- spec/spec_helper.rb
|
150
153
|
homepage: ''
|
@@ -170,9 +173,10 @@ rubyforge_project:
|
|
170
173
|
rubygems_version: 2.2.2
|
171
174
|
signing_key:
|
172
175
|
specification_version: 4
|
173
|
-
summary: aoj
|
176
|
+
summary: aoj command-line tool
|
174
177
|
test_files:
|
175
178
|
- spec/lib/aoj/api_spec.rb
|
176
179
|
- spec/lib/aoj/conf_spec.rb
|
180
|
+
- spec/lib/aoj/env_spec.rb
|
177
181
|
- spec/lib/aoj/language_spec.rb
|
178
182
|
- spec/spec_helper.rb
|