Skip to content

Commit b6f39f3

Browse files
committed
Update ameba version.
1 parent b331dc5 commit b6f39f3

File tree

4 files changed

+51
-42
lines changed

4 files changed

+51
-42
lines changed

.ameba.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# This configuration file was generated by `ameba --gen-config`
2+
# on 2023-03-07 14:14:39 UTC using Ameba version 1.4.2.
3+
# The point is for the user to remove these configuration records
4+
# one by one as the reported problems are removed from the code base.
5+
6+
# Problems found: 1
7+
# Run `ameba --only Lint/NotNil` for details
8+
Lint/NotNil:
9+
Description: Identifies usage of `not_nil!` calls
10+
Excluded:
11+
- src/myip.cr
12+
Enabled: false
13+
Severity: Warning

shard.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2.0
22
shards:
33
ameba:
44
git: https://github.com/crystal-ameba/ameba.git
5-
version: 1.1.0
5+
version: 1.4.2+git.commit.3fbbe3986eef7e0e22b9decc3e37c2110f2a10eb
66

77
lexbor:
88
git: https://github.com/kostya/lexbor.git

shard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies:
1515
development_dependencies:
1616
ameba:
1717
github: crystal-ameba/ameba
18-
version: ~> 1.1.0
18+
branch: master
1919

2020
crystal: 1.5.0
2121

src/myip.cr

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ require "json"
77
chan = Channel(Tuple(String, String)).new
88

99
def from_url(url : String, follow : Bool = false) : Lexbor::Parser
10-
begin
11-
response = HTTP::Client.get url
12-
if response.status_code == 200
13-
return Lexbor::Parser.new(response.body)
14-
elsif follow && response.status_code == 301
15-
from_url response.headers["Location"], follow: true
16-
else
17-
raise ArgumentError.new "Host returned #{response.status_code}"
18-
end
19-
rescue Socket::Error
20-
raise Socket::Error.new "Host #{url} cannot be fetched"
10+
response = HTTP::Client.get url
11+
if response.status_code == 200
12+
Lexbor::Parser.new(response.body)
13+
elsif follow && response.status_code == 301
14+
from_url response.headers["Location"], follow: true
15+
else
16+
raise ArgumentError.new "Host returned #{response.status_code}"
2117
end
18+
rescue Socket::Error
19+
raise Socket::Error.new "Host #{url} cannot be fetched"
2220
end
2321

2422
def get_ip_from_ib_sb(chan)
@@ -58,37 +56,35 @@ def get_ip_from_ip138(chan)
5856
end
5957

6058
def get_ip_from_ip111(chan)
61-
begin
62-
ip111_url = "http://www.ip111.cn"
63-
doc = from_url(ip111_url, follow: true)
64-
65-
iframe = doc.nodes("iframe").map do |node|
66-
spawn do
67-
url = node.attribute_by("src").not_nil!
68-
ip = from_url(url).body!.tag_text.strip
69-
title = node.parent!.parent!.parent!.css(".card-header").first.tag_text.strip
70-
71-
chan.send({"ip111.cn:#{title}", ip})
72-
rescue Socket::Error
73-
STDERR.puts "visit #{url} failed, please check internet connection."
74-
rescue ArgumentError
75-
STDERR.puts "#{url} return 500"
76-
rescue ex
77-
STDERR.puts ex.message
78-
end
59+
ip111_url = "http://www.ip111.cn"
60+
doc = from_url(ip111_url, follow: true)
61+
62+
iframe = doc.nodes("iframe").map do |node|
63+
spawn do
64+
url = node.attribute_by("src").not_nil!
65+
ip = from_url(url).body!.tag_text.strip
66+
title = node.parent!.parent!.parent!.css(".card-header").first.tag_text.strip
67+
68+
chan.send({"ip111.cn:#{title}", ip})
69+
rescue Socket::Error
70+
STDERR.puts "visit #{url} failed, please check internet connection."
71+
rescue ArgumentError
72+
STDERR.puts "#{url} return 500"
73+
rescue ex
74+
STDERR.puts ex.message
7975
end
80-
81-
{doc, iframe.size}
82-
rescue Socket::Error
83-
STDERR.puts "visit #{ip111_url} failed, please check internet connection."
84-
exit
85-
rescue ArgumentError
86-
STDERR.puts "#{ip111_url} return 500"
87-
exit
88-
rescue ex
89-
STDERR.puts ex.message
90-
exit
9176
end
77+
78+
{doc, iframe.size}
79+
rescue Socket::Error
80+
STDERR.puts "visit #{ip111_url} failed, please check internet connection."
81+
exit
82+
rescue ArgumentError
83+
STDERR.puts "#{ip111_url} return 500"
84+
exit
85+
rescue ex
86+
STDERR.puts ex.message
87+
exit
9288
end
9389

9490
at_exit do

0 commit comments

Comments
 (0)