not_so_fast 0.1.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 +7 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +33 -0
- data/exe/not_so_fast +5 -0
- data/lib/not_so_fast/version.rb +5 -0
- data/lib/not_so_fast.rb +79 -0
- metadata +47 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: db8dc735618a60586a6e32f994280bf0cffa7ae835a0f0e59471dadf89d94546
|
|
4
|
+
data.tar.gz: f7516173397209a6a7b66bb8f63fadc9a4ff72cbdc0aa3fca5248fc0529b6985
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 50630ee53bf9a7f605c3a4b14b2d46941bb07fd5c70fcd50ac71c39e8b9a60d01f5a17265361bdfa4458e232688a07ea783c3d482654df27e17d4240b620d148
|
|
7
|
+
data.tar.gz: bc4f22246c60543769a42bb76d9442d64b83ac152106bc51f55885a898f0068b093a24a101c7b031bcfc1c95120e382e577a29a2f19f0570138a8de81861f42b
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 ziggy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# NotSoFast
|
|
2
|
+
|
|
3
|
+
A simple fast.com client
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
8
|
+
|
|
9
|
+
$ bundle add not_so_fast
|
|
10
|
+
|
|
11
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
12
|
+
|
|
13
|
+
$ gem install not_so_fast
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
Running `not_so_fast` will run display your download speed. From ruby use `NotSoFast.run`. The speed is measured in bps.
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
## Development
|
|
22
|
+
|
|
23
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
24
|
+
|
|
25
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
26
|
+
|
|
27
|
+
## Contributing
|
|
28
|
+
|
|
29
|
+
Bug reports and pull requests are welcome at https://0xacab.org/calyx/gems/not_so_fast.git
|
|
30
|
+
|
|
31
|
+
## License
|
|
32
|
+
|
|
33
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/exe/not_so_fast
ADDED
data/lib/not_so_fast.rb
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'json'
|
|
4
|
+
|
|
5
|
+
require_relative "not_so_fast/version"
|
|
6
|
+
|
|
7
|
+
module NotSoFast
|
|
8
|
+
class Error < StandardError; end
|
|
9
|
+
|
|
10
|
+
def self.get(url)
|
|
11
|
+
uri = URI(url)
|
|
12
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
13
|
+
request = Net::HTTP::Get.new uri
|
|
14
|
+
request["user-agent"] = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/112.0"
|
|
15
|
+
response = http.request request
|
|
16
|
+
if response.is_a?(Net::HTTPSuccess)
|
|
17
|
+
return response.body
|
|
18
|
+
else
|
|
19
|
+
puts "FAILED to fetch #{url}, response '#{response.message}'"
|
|
20
|
+
puts "RESPONSE HEADERS:"
|
|
21
|
+
puts response.to_hash.inspect
|
|
22
|
+
puts "REQUEST HEADERS:"
|
|
23
|
+
puts request.to_hash.inspect
|
|
24
|
+
return nil
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
rescue Errno::ECONNRESET
|
|
28
|
+
puts "FAILED GET #{url}: Connection reset by peer"
|
|
29
|
+
return nil
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
#
|
|
33
|
+
# returns speed in bps
|
|
34
|
+
#
|
|
35
|
+
def self.fetch_payload(payload_url, seconds_to_run)
|
|
36
|
+
start_time = Time.now
|
|
37
|
+
uri = URI(payload_url)
|
|
38
|
+
speed = 0
|
|
39
|
+
size = 0
|
|
40
|
+
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
|
|
41
|
+
http.request_get(uri) do |resp|
|
|
42
|
+
resp.read_body do |segment|
|
|
43
|
+
time_spent = Time.now - start_time
|
|
44
|
+
size += segment.bytesize * 8
|
|
45
|
+
speed = size / time_spent
|
|
46
|
+
if time_spent >= seconds_to_run
|
|
47
|
+
return speed
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
return speed
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.run(seconds_to_run=10)
|
|
56
|
+
fast_dot_com = get("https://fast.com")
|
|
57
|
+
return 0 unless fast_dot_com
|
|
58
|
+
app_url = "https://fast.com" + /(\/app-[[:alnum:]]+\.js)/.match(fast_dot_com)[1]
|
|
59
|
+
app_javascript = get(app_url)
|
|
60
|
+
return 0 unless app_javascript
|
|
61
|
+
token = /token:"([[:alnum:]]*)"/.match(app_javascript)&.[](1)
|
|
62
|
+
unless token
|
|
63
|
+
puts "ERROR: failed to parse token from javascript"
|
|
64
|
+
return 0
|
|
65
|
+
end
|
|
66
|
+
api_json = get("https://api.fast.com/netflix/speedtest?https=true&token=#{token}&urlCount=1")
|
|
67
|
+
return 0 unless api_json
|
|
68
|
+
begin
|
|
69
|
+
payload_url = JSON.parse(api_json)[0]["url"]
|
|
70
|
+
rescue StandardError => exc
|
|
71
|
+
puts "ERROR: failed to parse JSON from fast.com"
|
|
72
|
+
puts api_json
|
|
73
|
+
puts exc.to_s
|
|
74
|
+
return 0
|
|
75
|
+
end
|
|
76
|
+
speed = fetch_payload(payload_url, seconds_to_run)
|
|
77
|
+
return speed.round
|
|
78
|
+
end
|
|
79
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: not_so_fast
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- ziggy
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
email:
|
|
13
|
+
- ziggy@calyx.org
|
|
14
|
+
executables:
|
|
15
|
+
- not_so_fast
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- Gemfile
|
|
20
|
+
- LICENSE.txt
|
|
21
|
+
- README.md
|
|
22
|
+
- exe/not_so_fast
|
|
23
|
+
- lib/not_so_fast.rb
|
|
24
|
+
- lib/not_so_fast/version.rb
|
|
25
|
+
homepage: https://github.com/aepyornis/not_so_fast.git
|
|
26
|
+
licenses:
|
|
27
|
+
- MIT
|
|
28
|
+
metadata:
|
|
29
|
+
source_code_uri: https://github.com/aepyornis/not_so_fast.git
|
|
30
|
+
rdoc_options: []
|
|
31
|
+
require_paths:
|
|
32
|
+
- lib
|
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '3.1'
|
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '0'
|
|
43
|
+
requirements: []
|
|
44
|
+
rubygems_version: 3.6.9
|
|
45
|
+
specification_version: 4
|
|
46
|
+
summary: A simple fast.com client
|
|
47
|
+
test_files: []
|