sraas 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sraas.rb +5 -4
- data/lib/sraas/consumer.rb +26 -0
- data/lib/sraas/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d07143a587b4a627b335ae0cc19b4ea061eafb96
|
4
|
+
data.tar.gz: b61fcfed97d8a71e39ba01bf88069b5c47b17b22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 317e59e68f52068cfeb47d1c9fd9a46be38a47e14986a58ccfb20bbfce841cdbde183905efc92d5975f1eb18ca1204cfae24dd6c46bf950c65ad6321eca880b8
|
7
|
+
data.tar.gz: 23a14c626edeff63f476f1a165764c5832735cc67aa0b0fe14686c789f228ac8a43fb771a1b8b39e67ea6d3d1f972da2ff136a6027f9c07ff73065b8187dbfc7
|
data/lib/sraas.rb
CHANGED
@@ -57,14 +57,15 @@ module Sraas
|
|
57
57
|
end
|
58
58
|
|
59
59
|
# This returns template cards "index" json
|
60
|
-
# if limit is > 100, do paging here.
|
61
|
-
|
62
|
-
|
60
|
+
# if limit is > 100, do paging here. filter_params can be by_kind and by_lesson
|
61
|
+
# e.g. Sraas.template_cards(1234, filter_params: {by_kind: "Radical", by_lesson: 1})
|
62
|
+
def template_cards(template_deck_id=self.default_template_deck_id, filter_params: {}, offset: 0, limit: 100)
|
63
63
|
template_cards = []
|
64
64
|
remainder = limit
|
65
65
|
while remainder > 0 do
|
66
66
|
paging = { limit: remainder, offset: offset} #even if limit(remainder) > 100, it will be 100 on sraas side.
|
67
|
-
|
67
|
+
params = filter_params.merge(paging)
|
68
|
+
result = JSON.parse(Sraas.api_resource(:get, "#{self.template_decks_endpoint}/#{template_deck_id}/template_cards", params))
|
68
69
|
break if result.empty?
|
69
70
|
template_cards << result
|
70
71
|
remainder -= 100
|
data/lib/sraas/consumer.rb
CHANGED
@@ -79,6 +79,24 @@ module Sraas
|
|
79
79
|
parse_json { get("#{Sraas.cards_endpoint}/bulk?#{{ids: card_uuids}.to_query}") }
|
80
80
|
end
|
81
81
|
|
82
|
+
# Card#index_with_accuracy accessor.
|
83
|
+
# filter_params can be by_kind and by_lesson
|
84
|
+
# e.g. current_user.sraas.cards_with_accuracy(filter_params: {by_kind: "Radical", by_lesson: 1})
|
85
|
+
def cards_with_accuracy(filter_params: {}, offset: 0, limit: 100)
|
86
|
+
cards = []
|
87
|
+
remainder = limit
|
88
|
+
while remainder > 0 do
|
89
|
+
paging = { limit: remainder, offset: offset} #even if limit(remainder) > 100, it will be 100 on sraas side.
|
90
|
+
params = filter_params.merge(paging)
|
91
|
+
result = JSON.parse(Sraas.api_resource(:get, "#{consumer_url}/cards/index_with_accuracy", params))
|
92
|
+
break if result.empty?
|
93
|
+
cards << result
|
94
|
+
remainder -= 100
|
95
|
+
offset += 100
|
96
|
+
end
|
97
|
+
cards.flatten
|
98
|
+
end
|
99
|
+
|
82
100
|
# One card accessor. This return card "full" json
|
83
101
|
# TODO: make this return OpenStruct.
|
84
102
|
def card(card_uuid)
|
@@ -117,6 +135,14 @@ module Sraas
|
|
117
135
|
Sraas.template_deck(template_deck_id)
|
118
136
|
end
|
119
137
|
|
138
|
+
# template_cards accessor spcified by consumer
|
139
|
+
# Assume consumers/:consumer_id/decks has only one deck
|
140
|
+
# current_user.sraas.template_cards(filter_params: {by_lesson: 1, by_kind: 'Radical'})
|
141
|
+
def template_cards(filter_params: {}, offset: 0, limit: 100)
|
142
|
+
template_deck_id = template_deck['id']
|
143
|
+
Sraas.template_cards(template_deck_id, filter_params: filter_params, offset: offset, limit: limit)
|
144
|
+
end
|
145
|
+
|
120
146
|
# This returns template_cards selected with lesson number.
|
121
147
|
# and progress: 0
|
122
148
|
def template_lesson(lesson)
|
data/lib/sraas/version.rb
CHANGED