rpw 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,63 @@
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)}%"
46
+ end
47
+ Excon.get(content["url"], response_block: streamer)
48
+ downloaded_file.close
49
+ print "\n"
50
+ File.rename(downloaded_file, "#{folder}/#{content["s3_key"]}")
51
+ end
52
+
53
+ def latest_version?
54
+ resp = Excon.get("https://rubygems.org/api/v1/gems/rpw.json")
55
+ data = JSON.parse resp.body
56
+ Gem::Version.new(RPW::VERSION) >= Gem::Version.new(data["version"])
57
+ end
58
+
59
+ def register_email(email)
60
+ Excon.put(domain + "/license?email=#{email}&key=#{@key}").status == 200
61
+ end
62
+ end
63
+ end
@@ -1,3 +1,3 @@
1
1
  module RPW
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -26,5 +26,5 @@ 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
30
  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.5
4
+ version: 0.0.6
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-17 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: typhoeus
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
@@ -70,8 +71,18 @@ files:
70
71
  - README.md
71
72
  - Rakefile
72
73
  - exe/rpw
73
- - lib/README.md
74
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
75
86
  - lib/rpw/version.rb
76
87
  - rpw.gemspec
77
88
  homepage: https://speedshop.co