inbox 2.0.0 → 2.0.1

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: 0eed0e8c05ccc5058757a802114677ef14f3d290
4
- data.tar.gz: d8561281e5cac7dc75c2d940f602a05b3b022fd5
3
+ metadata.gz: e4c45defbc44bf103f5b3dc5e96f48d29e640299
4
+ data.tar.gz: f02c604694341f461eea4b746eacccfd5c2888c4
5
5
  SHA512:
6
- metadata.gz: 1520cdba3b742d01486e28820830ed6db74748c9f35146c254bdf4e17167286acece7fb9da28ab44e7f17f05e6d5c4a2166129cda211d6764492146fa424411e
7
- data.tar.gz: 3ffd9f2218a91713f9011de687dd79de1ce852f32c9b3fbe2505dace03ef3b95cc65f258308236584719c104fac1dcf6f72fb84b23d2df7bd2b1ad2ca98d281c
6
+ metadata.gz: 1c3eb310a357ddb279efff8ae524f7c1a94a2e8970363682380b0f820a2ca7527581e2f37231a41d729b81c05ceefbf2fd8ed52ecef0e5c3054b3a24cfba92f3
7
+ data.tar.gz: 0e0931047cd3c10b64c6c8eb3a1f1f636cc8de647c424bb185c5263026b62cda70fbca3b7fd80f4208ace9a59c636490400dab2d912b742bc01681ad47d868bd
@@ -34,7 +34,7 @@ module Inbox
34
34
  label
35
35
  end
36
36
 
37
- if not folder.nil?
37
+ if not folder.nil? and folder.is_a?(Hash)
38
38
  folder = Folder.new(@_api)
39
39
  folder.inflate(@folder)
40
40
  @folder = folder
@@ -52,14 +52,22 @@ module Inbox
52
52
  def as_json(options = {})
53
53
  hash = {}
54
54
 
55
+ if not @unread.nil?
56
+ hash["unread"] = @unread
57
+ end
58
+
59
+ if not @starred.nil?
60
+ hash["starred"] = @starred
61
+ end
62
+
55
63
  if not @labels.nil? and @labels != []
56
- hash["labels"] = @labels.map do |label|
64
+ hash["label_ids"] = @labels.map do |label|
57
65
  label.id
58
66
  end
59
67
  end
60
68
 
61
69
  if not @folder.nil?
62
- hash["folder"] = @folder.id
70
+ hash["folder_id"] = @folder.id
63
71
  end
64
72
 
65
73
  hash
@@ -38,7 +38,7 @@ module Inbox
38
38
  label
39
39
  end
40
40
 
41
- if not folder.nil?
41
+ if not folder.nil? and folder.is_a?(Hash)
42
42
  folder = Folder.new(@_api)
43
43
  folder.inflate(@folder)
44
44
  @folder = folder
@@ -59,13 +59,13 @@ module Inbox
59
59
  end
60
60
 
61
61
  if not @labels.nil? and @labels != []
62
- hash["labels"] = @labels.map do |label|
62
+ hash["label_ids"] = @labels.map do |label|
63
63
  label.id
64
64
  end
65
65
  end
66
66
 
67
67
  if not @folder.nil?
68
- hash["folder"] = @folder.id
68
+ hash["folder_id"] = @folder.id
69
69
  end
70
70
 
71
71
  hash
@@ -15,17 +15,16 @@ module Inbox
15
15
  def each
16
16
  return enum_for(:each) unless block_given?
17
17
 
18
- @filters[:offset] = 0 unless @filters.key?(:offset)
19
- @filters[:limit] = 100 unless @filters.key?(:limit)
20
-
18
+ offset = 0
19
+ chunk_size = 100
21
20
  finished = false
22
21
  while (!finished) do
23
- results = get_model_collection()
22
+ results = get_model_collection(offset, chunk_size)
24
23
  results.each { |item|
25
24
  yield item
26
25
  }
27
- @filters[:offset] += results.length
28
- finished = results.length < @filters[:limit]
26
+ offset += results.length
27
+ finished = results.length < chunk_size
29
28
  end
30
29
  end
31
30
 
@@ -65,17 +64,12 @@ module Inbox
65
64
  finished = false
66
65
  chunk_size = 100
67
66
 
68
- while (!finished && accumulated.length < limit) do
69
- @filters[:offset] = offset + accumulated.length
70
-
71
- # if the total items we want, minus how many we already have, is fewer than we plan to grab...
72
- remaining = limit - accumulated.length
73
- if remaining < chunk_size
74
- chunk_size = remaining
75
- end
76
- @filters[:limit] = chunk_size
67
+ if limit < chunk_size
68
+ chunk_size = limit
69
+ end
77
70
 
78
- results = get_model_collection()
71
+ while (!finished && accumulated.length < limit) do
72
+ results = get_model_collection(offset + accumulated.length, chunk_size)
79
73
  accumulated = accumulated.concat(results)
80
74
 
81
75
  # we're done if we have more than 'limit' items, or if we asked for 50 and got less than 50...
@@ -142,8 +136,10 @@ module Inbox
142
136
  model
143
137
  end
144
138
 
145
- def get_model_collection
139
+ def get_model_collection(offset = 0, limit = 100)
146
140
  filters = @filters.clone
141
+ filters[:offset] = offset
142
+ filters[:limit] = limit
147
143
  models = []
148
144
 
149
145
  RestClient.get(url, :params => filters){ |response,request,result|
@@ -1,3 +1,3 @@
1
1
  module Inbox
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Gotow
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-02-06 00:00:00.000000000 Z
13
+ date: 2016-02-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client