sraas 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sraas.rb +25 -2
  3. data/lib/sraas/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 39ad93470422e16143d61148fa58b2af9463aa94
4
- data.tar.gz: baa83e2a3e5d63e271b930ec06cd0c19d8b8d05f
3
+ metadata.gz: af79a1b3cdc77cf6ea26c5ce968562ca573867d2
4
+ data.tar.gz: 2d000227d9c4c79cb5076e6349021a6874536695
5
5
  SHA512:
6
- metadata.gz: dcb278d65cda7a20f3d0e84404fd65c134f144b15309d4047edc2ceeedc762f1ab2902cc17e1d579793c32604df7eeaace59aebb5291a0eb76ca8155b35c1509
7
- data.tar.gz: c6162f0d68df9409ffbf7da97c89fe3f230097c9a83521f60682dadcf127a9c31abae15497df305b0118a88d855c6f1209440670643da6c64dd93a6d70fe95eb
6
+ metadata.gz: db4cb29c28282f4cc4ca12638867191d3e16b872ae0ceed73f48fcc0b67cf556980048e3f3cddd76f61879bf840dc3792ad167867ab0334e8ab4e74a30160349
7
+ data.tar.gz: 803a4c99a0c1a1237ccc30a9ca311b4bb733e7f7a03f6316fe8c134474c5cab0fbc5255c112dc5e035a1900f7d6096b9409ec34a104774d1213d85029132e100
data/lib/sraas.rb CHANGED
@@ -51,9 +51,32 @@ module Sraas
51
51
  end
52
52
 
53
53
  # This returns template cards "index" json
54
+ # if limit is > 100, do paging here.
54
55
  def template_cards(template_deck_id, offset: 0, limit: 100)
55
- paging = { limit: limit, offset: offset }.to_query
56
- JSON.parse(Sraas.api_resource(:get, "#{self.template_decks_endpoint}/#{template_deck_id}/template_cards", paging))
56
+ if limit <= 100
57
+ paging = { limit: limit, offset: offset }.to_query
58
+ JSON.parse(Sraas.api_resource(:get, "#{self.template_decks_endpoint}/#{template_deck_id}/template_cards", paging))
59
+ else
60
+ template_cards = []
61
+ q, r = limit.divmod(100)
62
+
63
+ # if remainder > 0, request for it first.
64
+ if r > 0
65
+ paging = { limit: r, offset: offset }.to_query
66
+ template_cards << JSON.parse(Sraas.api_resource(:get, "#{self.template_decks_endpoint}/#{template_deck_id}/template_cards", paging))
67
+ offset += r
68
+ end
69
+ q.times do
70
+ paging = { limit: 100, offset: offset }.to_query
71
+ result = JSON.parse(Sraas.api_resource(:get, "#{self.template_decks_endpoint}/#{template_deck_id}/template_cards", paging))
72
+ # If limit is bigger than number of template_cards, break once result is empty
73
+ # e.g. limit = 10000
74
+ break if result.empty?
75
+ template_cards << result
76
+ offset += result.count
77
+ end
78
+ template_cards.flatten
79
+ end
57
80
  end
58
81
 
59
82
  # This returns template card "full" json
data/lib/sraas/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sraas
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
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.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Siegel