rpw 0.0.3 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +109 -0
- data/.gitignore +1 -0
- data/Gemfile.lock +12 -16
- data/HISTORY.md +21 -0
- data/exe/rpw +1 -252
- data/lib/rpw.rb +4 -374
- data/lib/rpw/README.md +58 -0
- data/lib/rpw/cli.rb +94 -0
- data/lib/rpw/cli/bannerlord.rb +59 -0
- data/lib/rpw/cli/key.rb +15 -0
- data/lib/rpw/cli/lesson.rb +101 -0
- data/lib/rpw/cli/progress.rb +34 -0
- data/lib/rpw/cli/quiz.rb +28 -0
- data/lib/rpw/cli/sub_command_base.rb +30 -0
- data/lib/rpw/client.rb +178 -0
- data/lib/rpw/client_data.rb +73 -0
- data/lib/rpw/gateway.rb +67 -0
- data/lib/rpw/version.rb +1 -1
- data/rpw.gemspec +1 -1
- metadata +15 -3
@@ -0,0 +1,73 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "yaml"
|
3
|
+
|
4
|
+
module RPW
|
5
|
+
class ClientData
|
6
|
+
DOTFILE_NAME = ".rpw_info"
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
data # access file to load
|
10
|
+
end
|
11
|
+
|
12
|
+
def [](key)
|
13
|
+
data[key]
|
14
|
+
end
|
15
|
+
|
16
|
+
def []=(key, value)
|
17
|
+
data
|
18
|
+
data[key] = value
|
19
|
+
|
20
|
+
begin
|
21
|
+
File.open(filestore_location, "w") { |f| f.write(YAML.dump(data)) }
|
22
|
+
rescue
|
23
|
+
raise Error, "The RPW data at #{filestore_location} is not writable. \
|
24
|
+
Check your file permissions."
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.create_in_pwd!
|
29
|
+
FileUtils.touch(File.expand_path("./" + DOTFILE_NAME))
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.create_in_home!
|
33
|
+
unless File.directory?(File.expand_path("~/.rpw/"))
|
34
|
+
FileUtils.mkdir(File.expand_path("~/.rpw/"))
|
35
|
+
end
|
36
|
+
|
37
|
+
FileUtils.touch(File.expand_path("~/.rpw/" + DOTFILE_NAME))
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.delete_filestore
|
41
|
+
return unless File.exist?(filestore_location)
|
42
|
+
FileUtils.remove(filestore_location)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.exists?
|
46
|
+
File.exist? filestore_location
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.filestore_location
|
50
|
+
if File.exist?(File.expand_path("./" + DOTFILE_NAME))
|
51
|
+
File.expand_path("./" + DOTFILE_NAME)
|
52
|
+
else
|
53
|
+
File.expand_path("~/.rpw/" + DOTFILE_NAME)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def filestore_location
|
60
|
+
self.class.filestore_location
|
61
|
+
end
|
62
|
+
|
63
|
+
def data
|
64
|
+
@data ||= begin
|
65
|
+
begin
|
66
|
+
YAML.safe_load(File.read(filestore_location), permitted_classes: [Time]) || {}
|
67
|
+
rescue Errno::ENOENT
|
68
|
+
{}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/rpw/gateway.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require "excon"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module RPW
|
5
|
+
class Gateway
|
6
|
+
attr_accessor :domain
|
7
|
+
|
8
|
+
def initialize(domain, key)
|
9
|
+
@domain = domain
|
10
|
+
@key = key
|
11
|
+
end
|
12
|
+
|
13
|
+
class Error < StandardError; end
|
14
|
+
|
15
|
+
def authenticate_key(key)
|
16
|
+
Excon.get(domain + "/license", user: key).status == 200
|
17
|
+
end
|
18
|
+
|
19
|
+
def get_content_by_position(position)
|
20
|
+
response = Excon.get(domain + "/contents/positional?position=#{position}", user: @key)
|
21
|
+
if response.status == 200
|
22
|
+
JSON.parse(response.body)
|
23
|
+
else
|
24
|
+
puts response.inspect
|
25
|
+
raise Error, "There was a problem fetching this content."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def list_content
|
30
|
+
response = Excon.get(domain + "/contents", user: @key)
|
31
|
+
if response.status == 200
|
32
|
+
JSON.parse(response.body)
|
33
|
+
else
|
34
|
+
puts response.inspect
|
35
|
+
raise Error, "There was a problem fetching this content."
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def download_content(content, folder:)
|
40
|
+
puts "Downloading #{content["title"]}..."
|
41
|
+
downloaded_file = File.open("#{folder}/#{content["s3_key"]}.partial", "w")
|
42
|
+
streamer = lambda do |chunk, remaining_bytes, total_bytes|
|
43
|
+
downloaded_file.write(chunk)
|
44
|
+
print 13.chr
|
45
|
+
print "Remaining: #{(remaining_bytes.to_f / total_bytes * 100).round(2).to_s.rjust(8)}%" if remaining_bytes
|
46
|
+
end
|
47
|
+
response = Excon.get(content["url"], response_block: streamer)
|
48
|
+
unless response.status == 200
|
49
|
+
puts response.inspect
|
50
|
+
raise Error.new("Server problem: #{response.status}")
|
51
|
+
end
|
52
|
+
downloaded_file.close
|
53
|
+
print "\n"
|
54
|
+
File.rename(downloaded_file, "#{folder}/#{content["s3_key"]}")
|
55
|
+
end
|
56
|
+
|
57
|
+
def latest_version?
|
58
|
+
resp = Excon.get("https://rubygems.org/api/v1/gems/rpw.json")
|
59
|
+
data = JSON.parse resp.body
|
60
|
+
Gem::Version.new(RPW::VERSION) >= Gem::Version.new(data["version"])
|
61
|
+
end
|
62
|
+
|
63
|
+
def register_email(email)
|
64
|
+
Excon.put(domain + "/license?email=#{email}&key=#{@key}").status == 200
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/rpw/version.rb
CHANGED
data/rpw.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rpw
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nate Berkopec
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: excon
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -60,6 +60,7 @@ executables:
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
+
- ".github/workflows/test.yml"
|
63
64
|
- ".gitignore"
|
64
65
|
- ".ruby_version"
|
65
66
|
- CODE_OF_CONDUCT.md
|
@@ -71,6 +72,17 @@ files:
|
|
71
72
|
- Rakefile
|
72
73
|
- exe/rpw
|
73
74
|
- lib/rpw.rb
|
75
|
+
- lib/rpw/README.md
|
76
|
+
- lib/rpw/cli.rb
|
77
|
+
- lib/rpw/cli/bannerlord.rb
|
78
|
+
- lib/rpw/cli/key.rb
|
79
|
+
- lib/rpw/cli/lesson.rb
|
80
|
+
- lib/rpw/cli/progress.rb
|
81
|
+
- lib/rpw/cli/quiz.rb
|
82
|
+
- lib/rpw/cli/sub_command_base.rb
|
83
|
+
- lib/rpw/client.rb
|
84
|
+
- lib/rpw/client_data.rb
|
85
|
+
- lib/rpw/gateway.rb
|
74
86
|
- lib/rpw/version.rb
|
75
87
|
- rpw.gemspec
|
76
88
|
homepage: https://speedshop.co
|