sraas 0.2.4 → 0.2.5
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 +4 -4
- data/bin/sraas +112 -2
- data/lib/sraas.rb +5 -0
- data/lib/sraas/has_sraas.rb +14 -1
- data/lib/sraas/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f7d1ea1fcf540c038fec64d167ca0ecb8a0532ee
|
4
|
+
data.tar.gz: 835571d14ca233c60a5a198169637ffa37a7759f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5527696865993c112540c5b18bb6f14623a956ca70f0392c49b85ed4cd7d8daf49bc18ad1139adb9edc8473955229dd79d70b5c7b0cd0c53c001bb4a4413c8c
|
7
|
+
data.tar.gz: 6632d5ef99f6983b806f5aed9ccb72319418a8615ddddad7569ee5a6260fa5e527894734f1d2a285047099a88e832d170f2920e907277a8fa879eb475a356c3e
|
data/bin/sraas
CHANGED
@@ -1,5 +1,115 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'hanami/cli'
|
4
|
+
require 'io/console'
|
3
5
|
require 'sraas'
|
4
|
-
|
6
|
+
require 'json'
|
7
|
+
require 'sdbm'
|
8
|
+
require 'pry'
|
9
|
+
|
10
|
+
module Sraas
|
11
|
+
module CLI
|
12
|
+
module Commands
|
13
|
+
extend Hanami::CLI::Registry
|
14
|
+
CRED = "#{ENV['HOME']}/.sraas".freeze
|
15
|
+
LOG = "#{ENV['HOME']}/.sraas.log".freeze
|
16
|
+
|
17
|
+
class Login < Hanami::CLI::Command
|
18
|
+
desc 'Stores login information'
|
19
|
+
|
20
|
+
def call(*)
|
21
|
+
puts 'Enter API Key'
|
22
|
+
api_key = STDIN.noecho(&:gets).chomp
|
23
|
+
File.write(CRED, api_key)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class SraasSectet < Hanami::CLI::Command
|
28
|
+
def use_credentials
|
29
|
+
Sraas.configuration.api_key = File.read(CRED)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Consumers < SraasSectet
|
34
|
+
desc 'Stores consumers UUIDs'
|
35
|
+
|
36
|
+
def call(*)
|
37
|
+
use_credentials
|
38
|
+
response = ::JSON.parse(Sraas.consumers)
|
39
|
+
ids = response.map do |consumer|
|
40
|
+
consumer['id']
|
41
|
+
end
|
42
|
+
File.write(LOG, ids.join("\n"))
|
43
|
+
puts ids.join("\n")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
module Info
|
48
|
+
class Consumer < SraasSectet
|
49
|
+
desc 'Fetches consumer information'
|
50
|
+
|
51
|
+
argument :uuid, desc: 'Consumer UUID'
|
52
|
+
|
53
|
+
example [SecureRandom.uuid]
|
54
|
+
|
55
|
+
def call(uuid: , **)
|
56
|
+
response = fetch_info(uuid)
|
57
|
+
text = "Info for Consumer #{uuid}. "
|
58
|
+
text += "Learns available: #{response['available_to_learn']} "
|
59
|
+
text += "Reviews available: #{response['available_to_review']}"
|
60
|
+
File.write(LOG, text)
|
61
|
+
puts text
|
62
|
+
end
|
63
|
+
|
64
|
+
def consumer_url(uuid)
|
65
|
+
"#{Sraas.consumers_endpoint}/#{uuid}"
|
66
|
+
end
|
67
|
+
|
68
|
+
def fetch_info(uuid)
|
69
|
+
use_credentials
|
70
|
+
url = consumer_url(uuid)
|
71
|
+
Sraas.sraas_consumer_info(url)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
module Review
|
77
|
+
class Consumer < Info::Consumer
|
78
|
+
argument :uuid, desc: 'Consumer UUID'
|
79
|
+
|
80
|
+
example [SecureRandom.uuid]
|
81
|
+
|
82
|
+
def call(uuid: , **)
|
83
|
+
response = fetch_info(uuid)
|
84
|
+
text = "[#{response['current_lesson']}/"
|
85
|
+
text += "#{response['lesson_count']}]"
|
86
|
+
File.write(LOG, text)
|
87
|
+
puts text
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Just for testing
|
93
|
+
class Version < Hanami::CLI::Command
|
94
|
+
desc 'Shows current version of the gem'
|
95
|
+
|
96
|
+
def call(*)
|
97
|
+
puts Sraas::VERSION
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
register 'version', Version, aliases: ['v', '-v', '--version']
|
102
|
+
register 'login', Login
|
103
|
+
register 'consumers', Consumers
|
104
|
+
|
105
|
+
register 'info', aliases: ['i', '-i'] do |prefix|
|
106
|
+
prefix.register 'consumer', Info::Consumer, aliases: ['c', '-c']
|
107
|
+
end
|
5
108
|
|
109
|
+
register 'review' do |prefix|
|
110
|
+
prefix.register 'consumer', Review::Consumer, aliases: ['c', '-c']
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
Hanami::CLI.new(Sraas::CLI::Commands).call
|
data/lib/sraas.rb
CHANGED
@@ -6,6 +6,7 @@ require 'sraas/configuration'
|
|
6
6
|
|
7
7
|
module Sraas
|
8
8
|
NoAPIKey = Class.new(StandardError)
|
9
|
+
DeckNotFound = Class.new(StandardError)
|
9
10
|
|
10
11
|
class << self
|
11
12
|
def configuration
|
@@ -36,6 +37,10 @@ module Sraas
|
|
36
37
|
@cache = consumers.inject({}) { |a, v| k = v['id']; a[k] = v; a }
|
37
38
|
end
|
38
39
|
|
40
|
+
def consumers
|
41
|
+
api_resource(:get, consumers_endpoint)
|
42
|
+
end
|
43
|
+
|
39
44
|
def consumers_endpoint
|
40
45
|
"#{configuration.url}/consumers"
|
41
46
|
end
|
data/lib/sraas/has_sraas.rb
CHANGED
@@ -18,7 +18,7 @@ module Sraas
|
|
18
18
|
|
19
19
|
def configure_sraas_consumer!
|
20
20
|
create_sraas(consumer_uuid: new_consumer['id'], sraas_consumerable: self)
|
21
|
-
|
21
|
+
add_deck || fail(Sraas::DeckNotFound)
|
22
22
|
end
|
23
23
|
|
24
24
|
def consumer_id
|
@@ -27,6 +27,19 @@ module Sraas
|
|
27
27
|
|
28
28
|
private
|
29
29
|
|
30
|
+
def add_deck
|
31
|
+
return true if specified_deck.nil?
|
32
|
+
specified_deck && add_default_deck
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_default_deck
|
36
|
+
sraas.add_template_deck_by_name(specified_deck)
|
37
|
+
end
|
38
|
+
|
39
|
+
def specified_deck
|
40
|
+
self.class.sraas_default_deck
|
41
|
+
end
|
42
|
+
|
30
43
|
def new_consumer
|
31
44
|
Sraas.sraas_consumer_create(email, tags)
|
32
45
|
end
|
data/lib/sraas/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sraas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Siegel
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 5.0.6
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: hanami-cli
|
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'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: sqlite3
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|