spohlenz-freshbooksrb 0.5 → 0.6
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.
- data/lib/freshbooks/base.rb +29 -6
- metadata +2 -2
data/lib/freshbooks/base.rb
CHANGED
@@ -46,14 +46,23 @@ module FreshBooks
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def self.list(params={})
|
49
|
-
|
49
|
+
params[:per_page] ||= 100
|
50
50
|
|
51
|
-
if
|
52
|
-
|
53
|
-
|
54
|
-
[new(result)]
|
51
|
+
if params[:per_page] < 100
|
52
|
+
# Listing less than one page
|
53
|
+
extract_list_result(call_api('list', params))
|
55
54
|
else
|
56
|
-
|
55
|
+
# Fetch all results by looping through pages
|
56
|
+
returning [] do |result|
|
57
|
+
params[:page] = 1
|
58
|
+
page = extract_list_result(call_api('list', params))
|
59
|
+
all << page
|
60
|
+
while page.size == 100
|
61
|
+
params[:page] += 1
|
62
|
+
page = extract_list_result(call_api('list', params))
|
63
|
+
all << page
|
64
|
+
end
|
65
|
+
end
|
57
66
|
end
|
58
67
|
end
|
59
68
|
|
@@ -106,5 +115,19 @@ module FreshBooks
|
|
106
115
|
def self.id_field
|
107
116
|
"#{prefix}_id"
|
108
117
|
end
|
118
|
+
|
119
|
+
def self.convert_to_array_of_objects(result)
|
120
|
+
if result && result.is_a?(Array)
|
121
|
+
result.map { |p| new(p) }
|
122
|
+
elsif list
|
123
|
+
[new(result)]
|
124
|
+
else
|
125
|
+
[]
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.extract_list_result(api_result)
|
131
|
+
convert_to_array_of_objects(api_result.andand[prefix.pluralize].andand[prefix])
|
109
132
|
end
|
110
133
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spohlenz-freshbooksrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: "0.
|
4
|
+
version: "0.6"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Pohlenz
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-09-10 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|