pipejump 0.4.2 → 0.4.3
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/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.3
|
@@ -27,6 +27,8 @@ module Pipejump
|
|
27
27
|
# * size
|
28
28
|
# * collect
|
29
29
|
# * reject
|
30
|
+
# * inject
|
31
|
+
# * map
|
30
32
|
# ===== Example:
|
31
33
|
# @session.sources.size
|
32
34
|
# @session.sources.each { |source| }
|
@@ -108,7 +110,7 @@ module Pipejump
|
|
108
110
|
all.inspect
|
109
111
|
end
|
110
112
|
|
111
|
-
['first', 'last', 'each', 'size', 'collect', 'reject', 'inject'].each do |method|
|
113
|
+
['first', 'last', 'each', 'size', 'collect', 'reject', 'inject', 'map'].each do |method|
|
112
114
|
class_eval <<-STR
|
113
115
|
def #{method}(*args, &block)
|
114
116
|
all.#{method}(*args, &block)
|
@@ -129,9 +129,56 @@ module Pipejump
|
|
129
129
|
end
|
130
130
|
|
131
131
|
def get(url) #:nodoc:
|
132
|
-
|
133
|
-
|
134
|
-
|
132
|
+
result = []
|
133
|
+
code = 0
|
134
|
+
page = 1
|
135
|
+
url = paginate(url, 1)
|
136
|
+
while (response = get_data(get_response(url)))[1] != []
|
137
|
+
data = response[1]
|
138
|
+
|
139
|
+
# If this is a single item, or this isn't a duplicate, continue.
|
140
|
+
if !data.is_a?(Array)
|
141
|
+
result = data
|
142
|
+
break
|
143
|
+
end
|
144
|
+
|
145
|
+
break if result == data
|
146
|
+
|
147
|
+
# Concatenate our result and data
|
148
|
+
result += data
|
149
|
+
page = page + 1
|
150
|
+
|
151
|
+
url = paginate(url, page)
|
152
|
+
|
153
|
+
end
|
154
|
+
code = response[0]
|
155
|
+
[code, result]
|
156
|
+
end
|
157
|
+
|
158
|
+
def paginate(url, num) #:nodoc:
|
159
|
+
# Convenience
|
160
|
+
num = num.to_s
|
161
|
+
|
162
|
+
# If the URL is a single object, don't paginate
|
163
|
+
return url if url.match("\w.json")
|
164
|
+
|
165
|
+
# If the URL has already been paginated.
|
166
|
+
return url.gsub(/(page=)(\d+)/, "page=#{num}") if url.match("page=")
|
167
|
+
|
168
|
+
# If the URL contains a ?
|
169
|
+
return url.gsub(/$/, "&page=#{num}") if url.match(/\?.*$/)
|
170
|
+
|
171
|
+
# If the URL hasn't been paginated, and has no ?
|
172
|
+
url.gsub(/$/, "?page=#{num}")
|
173
|
+
end
|
174
|
+
|
175
|
+
def get_response(url)
|
176
|
+
connection.get(url)
|
177
|
+
end
|
178
|
+
|
179
|
+
def get_data(response)
|
180
|
+
code = response.code.to_i
|
181
|
+
(code == 200) ? [200, JSON.parse(response.body)] : [code,'']
|
135
182
|
end
|
136
183
|
|
137
184
|
def post(url, data) #:nodoc:
|
@@ -183,4 +230,4 @@ module Pipejump
|
|
183
230
|
|
184
231
|
|
185
232
|
end
|
186
|
-
end
|
233
|
+
end
|
data/lib/pipejump/version.rb
CHANGED
@@ -40,14 +40,13 @@ describe Pipejump::Deal do
|
|
40
40
|
(@deal.attributes.keys - ['entity']).each do |attribute|
|
41
41
|
@deal.send(attribute).should == @deal.attributes[attribute]
|
42
42
|
end
|
43
|
-
@deal.entity.class.should == Pipejump::Contact
|
44
43
|
@deal.destroy
|
45
44
|
end
|
46
45
|
|
47
46
|
it "should return errors with invalid params" do
|
48
47
|
@deal = @session.deals.create({})
|
49
48
|
@deal.id.should == nil
|
50
|
-
@deal.errors['deal'].collect{ |e| e['error']['field'] }.sort.should == ['
|
49
|
+
@deal.errors['deal'].collect{ |e| e['error']['field'] }.sort.should == ['entity_id', 'name']
|
51
50
|
end
|
52
51
|
|
53
52
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pipejump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2013-01-23 00:00:00.000000000 Z
|
15
15
|
dependencies: []
|
16
16
|
description: Base API Ruby client
|
17
17
|
email: marcin@futuresimple.com
|
@@ -46,7 +46,6 @@ files:
|
|
46
46
|
- spec/connection.sample.yml
|
47
47
|
- spec/pipejump/resources/contact/note_spec.rb
|
48
48
|
- spec/pipejump/resources/contact/reminder_spec.rb
|
49
|
-
- spec/pipejump/resources/contact_custom_fields_spec.rb
|
50
49
|
- spec/pipejump/resources/contact_spec.rb
|
51
50
|
- spec/pipejump/resources/contact_validation_spec.rb
|
52
51
|
- spec/pipejump/resources/deal/note_spec.rb
|
@@ -84,7 +83,6 @@ test_files:
|
|
84
83
|
- spec/connection.sample.yml
|
85
84
|
- spec/pipejump/resources/contact/note_spec.rb
|
86
85
|
- spec/pipejump/resources/contact/reminder_spec.rb
|
87
|
-
- spec/pipejump/resources/contact_custom_fields_spec.rb
|
88
86
|
- spec/pipejump/resources/contact_spec.rb
|
89
87
|
- spec/pipejump/resources/contact_validation_spec.rb
|
90
88
|
- spec/pipejump/resources/deal/note_spec.rb
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Pipejump::Contact do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@session = PipejumpSpec.session
|
7
|
-
@contact = @session.contacts.create(:name => 'contact1'+uuid)
|
8
|
-
end
|
9
|
-
|
10
|
-
after do
|
11
|
-
@contact.destroy
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#custom_fields" do
|
15
|
-
|
16
|
-
it "returns a hash of custom fields" do
|
17
|
-
@contact.custom_fields['test_field'] = 'yaaay'
|
18
|
-
@contact.save.should == true
|
19
|
-
|
20
|
-
@session.contacts.find(@contact.id).custom_fields['test_field'].should =='yaaay'
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
|