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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14459fe606ed36868224523497ebfd8f84c9bd51
4
- data.tar.gz: 8a47696c781b80dc98c8135c2ee6856a84528d28
3
+ metadata.gz: d07143a587b4a627b335ae0cc19b4ea061eafb96
4
+ data.tar.gz: b61fcfed97d8a71e39ba01bf88069b5c47b17b22
5
5
  SHA512:
6
- metadata.gz: 7f64439fc4116fdf29f395d5eb3e1685068103709a7e61946b8ec3313c08b39035b8cdc43199cb3e9aca6623991672f5e6189687cd4428ef8511353c29766d6b
7
- data.tar.gz: 91f295000f852b390222aaaa0b5a40041e798ca62cea4029a895e37b274d7a92fa5cc27bc424031aceeb9d55787548b3da6b7f1fbaeeadbae64c0915e6741052
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
- def template_cards(template_deck_id=self.default_template_deck_id, offset: 0, limit: 100)
62
- puts template_deck_id
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
- result = JSON.parse(Sraas.api_resource(:get, "#{self.template_decks_endpoint}/#{template_deck_id}/template_cards", paging))
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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Sraas
2
- VERSION = '0.3.8'
2
+ VERSION = '0.3.9'
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.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Siegel