rpw 0.0.4 → 1.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.
@@ -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
@@ -0,0 +1,57 @@
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 list_content
20
+ response = Excon.get(domain + "/contents", 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 download_content(content, folder:)
30
+ ::CLI::UI::Progress.progress do |bar|
31
+ downloaded_file = File.open("#{folder}/#{content["s3_key"]}.partial", "w")
32
+ streamer = lambda do |chunk, remaining_bytes, total_bytes|
33
+ downloaded_file.write(chunk)
34
+ bar.tick(set_percent: 1 - (remaining_bytes.to_f / total_bytes).round(2))
35
+ end
36
+ response = Excon.get(content["url"], response_block: streamer)
37
+ unless response.status == 200
38
+ puts response.inspect
39
+ raise Error.new("Server problem: #{response.status}")
40
+ end
41
+ downloaded_file.close
42
+ File.rename(downloaded_file, "#{folder}/#{content["s3_key"]}")
43
+ bar.tick(set_percent: 1)
44
+ end
45
+ end
46
+
47
+ def latest_version?
48
+ resp = Excon.get("https://rubygems.org/api/v1/gems/rpw.json")
49
+ data = JSON.parse resp.body
50
+ Gem::Version.new(RPW::VERSION) >= Gem::Version.new(data["version"])
51
+ end
52
+
53
+ def register_email(email)
54
+ Excon.put(domain + "/license?email=#{email}&key=#{@key}").status == 200
55
+ end
56
+ end
57
+ end
@@ -1,3 +1,3 @@
1
1
  module RPW
2
- VERSION = "0.0.4"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -26,5 +26,6 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_dependency "thor"
28
28
  spec.add_dependency "thor-hollaback"
29
- spec.add_dependency "typhoeus"
29
+ spec.add_dependency "excon"
30
+ spec.add_dependency "cli-ui"
30
31
  end
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: 0.0.4
4
+ version: 1.1.0
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-10-29 00:00:00.000000000 Z
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,21 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: typhoeus
42
+ name: excon
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: cli-ui
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
@@ -60,6 +74,7 @@ executables:
60
74
  extensions: []
61
75
  extra_rdoc_files: []
62
76
  files:
77
+ - ".github/workflows/test.yml"
63
78
  - ".gitignore"
64
79
  - ".ruby_version"
65
80
  - CODE_OF_CONDUCT.md
@@ -71,6 +86,17 @@ files:
71
86
  - Rakefile
72
87
  - exe/rpw
73
88
  - lib/rpw.rb
89
+ - lib/rpw/README.md
90
+ - lib/rpw/cli.rb
91
+ - lib/rpw/cli/bannerlord.rb
92
+ - lib/rpw/cli/key.rb
93
+ - lib/rpw/cli/lesson.rb
94
+ - lib/rpw/cli/progress.rb
95
+ - lib/rpw/cli/quiz.rb
96
+ - lib/rpw/cli/sub_command_base.rb
97
+ - lib/rpw/client.rb
98
+ - lib/rpw/client_data.rb
99
+ - lib/rpw/gateway.rb
74
100
  - lib/rpw/version.rb
75
101
  - rpw.gemspec
76
102
  homepage: https://speedshop.co