sraas 0.2.11 → 0.2.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '092789958c810fe7c467e3b9ce2a4ff36cd1de69'
4
- data.tar.gz: abad1f249f610b9509efcfb1b74b380745b34bd8
3
+ metadata.gz: d407823833658ffe8b28c0f49a259741e6b9cc37
4
+ data.tar.gz: 5ee3444513c052742d5e517899a62857776d4b7b
5
5
  SHA512:
6
- metadata.gz: 836b106e41b9d4a3d4f4dbd733b409dbeac680025dfab55491c5711b0457d1a0ce2d1e53bcb3b49d434563efaecb7d9ee1960ed92a57b709a1ba67fb7260861d
7
- data.tar.gz: 4ffb93cbd3783734260826cca06f28a62a4c1f379299b6261d7f2c792b1033bbe0187ccee10e1d4a0b2d3b566a21106937834b15a1f96d9c19e2dacf6c135cda
6
+ metadata.gz: 5fcd44f675dc9064afaf963a25ce5a9ddcb339a39123bf3dca2bd7a5080ea160c0261cd9c46b36f9ce371f7478296b09c3e3c863453c64e6cd6fecf366d4cab2
7
+ data.tar.gz: b0d4f0dcbb5bb172641e3cb9b9abeb799d03aa50ca82283ac20d62c0db88ab9a813d1402c07a515014594e4762a6a256272cd44e55d45151efb97c6c0386023c
data/README.md CHANGED
@@ -46,8 +46,47 @@ end
46
46
  ```
47
47
  This will create polymorphic association `sraas_consumer` which provides interface for using SRAAS API
48
48
 
49
+ ## CLI new features
50
+ - Get template cards specified by template_deck id
51
+ ```bash
52
+ $ sraas template_card template_cards xxxx
53
+ ```
54
+ - Get template card specified by template_card id
55
+ ```bash
56
+ $ sraas template_card info xxxx
57
+ ```
58
+ - Get template card's children specified by template_card id
59
+ ```bash
60
+ $ sraas template_card children xxxx
61
+ ```
62
+ - Get template card's parents specified by template_card id
63
+ ```bash
64
+ $ sraas template_card parents xxxx
65
+ ```
66
+ - Get lesson cards specified by consumer id and lessons id
67
+ ```bash
68
+ $ sraas cards lesson --consumer_id=xxxx --lesson_id=x
69
+ ```
70
+ - Get card specified by card id
71
+ ```bash
72
+ $ sraas cards info xxxx
73
+ ```
74
+ - Get card's children specified by card id
75
+ ```bash
76
+ $ sraas cards children xxxx
77
+ ```
78
+ - Get card's parents specified by card id
79
+ ```bash
80
+ $ sraas cards parents xxxx
81
+ ```
82
+
49
83
  ## Tests
50
- To run tests use
84
+ #### Preparation
85
+ ```bash
86
+ $ cd specs/dummy/
87
+ $ rake db:migrate
88
+ ```
89
+ #### Runing
51
90
  ```bash
52
91
  $ rake spec
53
92
  ```
data/bin/sraas CHANGED
@@ -79,6 +79,173 @@ module Sraas
79
79
  end
80
80
  end
81
81
 
82
+ module Cards
83
+ class Search < SraasSectet
84
+ desc 'Searches card by consumer uuid, title, and kind'
85
+
86
+ option :title
87
+ option :kind
88
+ option :customer, aliases: ['c']
89
+
90
+ def call(**options)
91
+ response = fetch(options.fetch(:customer), options.fetch(:kind), options.fetch(:title))
92
+ puts response
93
+ end
94
+
95
+ def fetch(consumer_uuid, kind, title)
96
+ use_credentials
97
+ Sraas.search_card(consumer_uuid, title, kind)
98
+ end
99
+ end
100
+
101
+ class Info < SraasSectet
102
+ desc 'Gets card by card uuid'
103
+ argument :card_uuid
104
+
105
+ def call(card_uuid:, **)
106
+ response = fetch(card_uuid)
107
+ puts response
108
+ end
109
+
110
+ def fetch(card_uuid)
111
+ use_credentials
112
+ url = card_url(card_uuid)
113
+ JSON.parse(Sraas.api_resource(:get, url))
114
+ end
115
+
116
+ def card_url(card_uuid)
117
+ "#{Sraas.cards_endpoint}/#{card_uuid}"
118
+ end
119
+ end
120
+
121
+ class Children < SraasSectet
122
+ desc 'Gets children cards by card uuid'
123
+ argument :card_uuid
124
+
125
+ def call(card_uuid:, **)
126
+ response = fetch(card_uuid)
127
+ puts response
128
+ end
129
+
130
+ def fetch(card_uuid)
131
+ use_credentials
132
+ url = card_children_url(card_uuid)
133
+ JSON.parse(Sraas.api_resource(:get, url))
134
+ end
135
+
136
+ def card_children_url(card_uuid)
137
+ "#{Sraas.cards_endpoint}/#{card_uuid}/children"
138
+ end
139
+ end
140
+
141
+ class Parents < SraasSectet
142
+ desc 'Gets card parents by card uuid'
143
+ argument :card_uuid
144
+
145
+ def call(card_uuid:, **)
146
+ response = fetch(card_uuid)
147
+ puts response
148
+ end
149
+
150
+ def fetch(card_uuid)
151
+ use_credentials
152
+ url = card_parents_url(card_uuid)
153
+ JSON.parse(Sraas.api_resource(:get, url))
154
+ end
155
+
156
+ def card_parents_url(card_uuid)
157
+ "#{Sraas.cards_endpoint}/#{card_uuid}/parents"
158
+ end
159
+ end
160
+
161
+ class Lesson < Sraas::CLI::Commands::Info::Consumer
162
+ desc 'Gets cards for the lesson'
163
+ option :consumer_uuid, aliases: ['c']
164
+ option :lesson_id, aliases: ['l','lesson']
165
+
166
+ def call(**options)
167
+ response = fetch(options.fetch(:consumer_uuid),options.fetch(:lesson_id))
168
+ puts response
169
+ end
170
+
171
+ def fetch(consumer_uuid, lesson_id)
172
+ use_credentials
173
+ url = lesson_url(consumer_uuid,lesson_id)
174
+ JSON.parse(Sraas.api_resource(:get, url))
175
+ end
176
+
177
+ def lesson_url(consumer_uuid,lesson_id)
178
+ "#{consumer_url(consumer_uuid)}/lessons/#{lesson_id}"
179
+ end
180
+ end
181
+
182
+ class Update < SraasSectet
183
+ desc 'Updates card'
184
+
185
+ option :uuid
186
+ option :srs_level
187
+ option :user_data
188
+ option :unlocked_at
189
+ option :learned_at
190
+ option :performance
191
+ option :review_available_at
192
+ option :deck_id
193
+ option :template_card_id
194
+
195
+ def call(**options)
196
+ use_credentials
197
+ result = Sraas.update_card(options.fetch(:uuid), {card: options.select {|key| key != :uuid}})
198
+ puts result
199
+ end
200
+ end
201
+ end
202
+
203
+ module TemplateCard
204
+ class TemplateCards < SraasSectet
205
+ desc 'Gets template cards by template deck id'
206
+ argument :template_deck_id
207
+
208
+ def call(template_deck_id:, **)
209
+ use_credentials
210
+ response = Sraas.template_cards(template_deck_id)
211
+ puts response
212
+ end
213
+ end
214
+
215
+ class Info < SraasSectet
216
+ desc 'Get template card by template card id'
217
+ argument :template_card_id
218
+
219
+ def call(template_card_id:, **)
220
+ use_credentials
221
+ response = Sraas.template_card(template_card_id)
222
+ puts response
223
+ end
224
+ end
225
+
226
+ class Children < SraasSectet
227
+ desc 'Get template card by template card id'
228
+ argument :template_card_id
229
+
230
+ def call(template_card_id:, **)
231
+ use_credentials
232
+ response = Sraas.template_card_children(template_card_id)
233
+ puts response
234
+ end
235
+ end
236
+
237
+ class Parents < SraasSectet
238
+ desc 'Get template card by template card id'
239
+ argument :template_card_id
240
+
241
+ def call(template_card_id:, **)
242
+ use_credentials
243
+ response = Sraas.template_card_parents(template_card_id)
244
+ puts response
245
+ end
246
+ end
247
+ end
248
+
82
249
  module Review
83
250
  class Consumer < Info::Consumer
84
251
  argument :uuid, desc: 'Consumer UUID'
@@ -250,6 +417,22 @@ module Sraas
250
417
  prefix.register 'consumer', Learn::Consumer, aliases: ['c', '-c']
251
418
  end
252
419
 
420
+ register 'cards' do |prefix|
421
+ prefix.register 'search', Cards::Search, aliases: ['s', '-s']
422
+ prefix.register 'info', Cards::Info, aliases: ['i', '-i']
423
+ prefix.register 'children', Cards::Children, aliases: ['c', '-c']
424
+ prefix.register 'parents', Cards::Parents, aliases: ['p', '-p']
425
+ prefix.register 'lesson', Cards::Lesson, aliases: ['l', '-l']
426
+ prefix.register 'update', Cards::Update
427
+ end
428
+
429
+ register 'template_card', aliases: ['tc', '-tc'] do |prefix|
430
+ prefix.register 'template_cards', TemplateCard::TemplateCards, aliases: ['tcs', '-tcs']
431
+ prefix.register 'info', TemplateCard::Info, aliases: ['i', '-i']
432
+ prefix.register 'children', TemplateCard::Children, aliases: ['c', '-c']
433
+ prefix.register 'parents', TemplateCard::Parents, aliases: ['p', '-p']
434
+ end
435
+
253
436
  register 'review' do |prefix|
254
437
  prefix.register 'consumer', Review::Consumer, aliases: ['c', '-c']
255
438
  end
@@ -42,10 +42,40 @@ module Sraas
42
42
  JSON.parse(api_resource(:get, template_decks_endpoint))
43
43
  end
44
44
 
45
+ # This returns template cards "index" json
46
+ def template_cards(template_deck_id)
47
+ JSON.parse(Sraas.api_resource(:get, "#{self.template_decks_endpoint}/#{template_deck_id}/template_cards"))
48
+ end
49
+
50
+ # This returns template card "full" json
51
+ def template_card(template_card_id)
52
+ JSON.parse(Sraas.api_resource(:get, "#{self.template_cards_endpoint}/#{template_card_id}"))
53
+ end
54
+
55
+ # This returns template card's children's "index" json
56
+ def template_card_children(template_card_id)
57
+ JSON.parse(Sraas.api_resource(:get, "#{self.template_cards_endpoint}/#{template_card_id}/children"))
58
+ end
59
+
60
+ # This returns template card's parent's "index" json
61
+ def template_card_parents(template_card_id)
62
+ JSON.parse(Sraas.api_resource(:get, "#{self.template_cards_endpoint}/#{template_card_id}/parents"))
63
+ end
64
+
45
65
  def consumers
46
66
  api_resource(:get, consumers_endpoint)
47
67
  end
48
68
 
69
+ def search_card(consumer_uuid, title, kind)
70
+ query = "?title=#{title}&kind=#{kind}"
71
+ JSON.parse(api_resource(:get, card_search_endpoint(consumer_uuid) + query))
72
+ end
73
+
74
+ def update_card(card_uuid, params = {})
75
+ response = api_resource(:patch, cards_endpoint + "/#{card_uuid}", params)
76
+ response.code == 200
77
+ end
78
+
49
79
  def consumers_endpoint
50
80
  "#{configuration.url}/consumers"
51
81
  end
@@ -58,14 +88,18 @@ module Sraas
58
88
  "#{configuration.url}/cards"
59
89
  end
60
90
 
61
- def card_search_endpoint(consumer_id)
62
- "#{configuration.url}/consumers/#{consumer_id}/cards/search"
91
+ def card_search_endpoint(consumer_uuid)
92
+ "#{configuration.url}/consumers/#{consumer_uuid}/cards/search"
63
93
  end
64
94
 
65
95
  def template_decks_endpoint
66
96
  "#{configuration.url}/template_decks"
67
97
  end
68
98
 
99
+ def template_cards_endpoint
100
+ "#{configuration.url}/template_cards"
101
+ end
102
+
69
103
  def api_resource(http_method, url, payload = {})
70
104
  RestClient::Request
71
105
  .execute(
@@ -68,6 +68,7 @@ module Sraas
68
68
  parse_json { get("#{consumer_url}/lessons") }
69
69
  end
70
70
 
71
+ # Get all cards "index" json for the lesson and progress
71
72
  def lesson(lesson_id)
72
73
  lesson = parse_json { get("#{consumer_url}/lessons/#{lesson_id}") }
73
74
  OpenStruct.new(progress: lesson['progress'], cards: lesson['cards'])
@@ -78,13 +79,27 @@ module Sraas
78
79
  parse_json { get("#{Sraas.cards_endpoint}/bulk?#{{ids: card_uuids}.to_query}") }
79
80
  end
80
81
 
81
- # One card accessor
82
+ # One card accessor. This return card "full" json
82
83
  def card(card_uuid)
83
84
  parse_json { get("#{Sraas.cards_endpoint}/#{card_uuid}") }
84
85
  end
85
86
 
86
- def search_card(consumer_id, title, kind)
87
- parse_json { get("#{Sraas.card_search_endpoint(consumer_id)}?title=#{title}&kind=#{kind}") }
87
+ # Children cards accessor. This returns card children "index" json
88
+ def card_children(card_uuid)
89
+ parse_json { get("#{Sraas.cards_endpoint}/#{card_uuid}/children") }
90
+ end
91
+
92
+ # Parents cards accessor. This returns card parents "index" json
93
+ def card_parents(card_uuid)
94
+ parse_json { get("#{Sraas.cards_endpoint}/#{card_uuid}/parents") }
95
+ end
96
+
97
+ def search_card(title, kind)
98
+ Sraas.search_card(self.consumer_uuid, title, kind)
99
+ end
100
+
101
+ def update_card(card_uuid, params = {})
102
+ Sraas.update_card(card_uuid, params)
88
103
  end
89
104
 
90
105
  def report(correct_ids, incorrect_ids)
@@ -105,7 +120,7 @@ module Sraas
105
120
  deck_uuid = detect_deck_by_name(deck_name).dig('id')
106
121
  return false unless deck_uuid
107
122
  url = "#{Sraas.template_decks_endpoint}/#{deck_uuid}/add_to_consumer"
108
- payload = { consumer_id: [consumer_uuid] }
123
+ payload = { consumer_id: [self.consumer_uuid] }
109
124
  # TODO: Handle a request for a deck that doesn't exist elegantly.
110
125
  # Right now this dies on the patch call:
111
126
  data = Sraas.api_resource(:patch, url, payload)
@@ -114,12 +129,7 @@ module Sraas
114
129
 
115
130
  # This is a public method to provide to views parsing JSON in JavaScript
116
131
  def consumer_url
117
- "#{Sraas.consumers_endpoint}/#{consumer_uuid}"
118
- end
119
-
120
- def update_card(card_uuid, params = {})
121
- data = patch("#{Sraas.cards_endpoint}/#{card_uuid}", params)
122
- data.code == 200
132
+ "#{Sraas.consumers_endpoint}/#{self.consumer_uuid}"
123
133
  end
124
134
 
125
135
  private
@@ -137,10 +147,6 @@ module Sraas
137
147
  Sraas.api_resource(:get, url)
138
148
  end
139
149
 
140
- def patch(url, payload)
141
- Sraas.api_resource(:patch, url, payload)
142
- end
143
-
144
150
  def parse_json(&block)
145
151
  JSON.parse(block.call) if block_given?
146
152
  end
@@ -1,7 +1,7 @@
1
1
  module Sraas
2
2
  class TemplateCard
3
3
  class << self
4
- def index(offset: 1, limit: 1)
4
+ def index(offset: 0, limit: 100)
5
5
  paging = { limit: limit, offset: offset }.to_query
6
6
  JSON.parse(Sraas.api_resource(:get, "#{template_cards_url}?#{paging}"))
7
7
  end
@@ -10,6 +10,14 @@ module Sraas
10
10
  JSON.parse(Sraas.api_resource(:get, "#{template_cards_url}/#{id}"))
11
11
  end
12
12
 
13
+ def children(id)
14
+ JSON.parse(Sraas.api_resource(:get, "#{self.template_cards_url}/#{id}/children"))
15
+ end
16
+
17
+ def parents(id)
18
+ JSON.parse(Sraas.api_resource(:get, "#{self.template_cards_url}/#{id}/parents"))
19
+ end
20
+
13
21
  private
14
22
 
15
23
  def template_cards_url
@@ -20,6 +28,7 @@ module Sraas
20
28
  @deck_uuid ||= detect_deck_by_name.dig('id')
21
29
  end
22
30
 
31
+ # TODO: This should have a Sraas.io/template_decks/search?name=xxx instead of this.
23
32
  def detect_deck_by_name
24
33
  deck_name = Sraas.configuration.default_deck
25
34
  Sraas.template_decks.detect { |deck| deck['name'] == deck_name } || {}
@@ -1,3 +1,3 @@
1
1
  module Sraas
2
- VERSION = '0.2.11'
2
+ VERSION = '0.2.14'
3
3
  end
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.11
4
+ version: 0.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Siegel