velocify 0.1.2 → 0.1.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -0
- data/README.md +47 -1
- data/lib/velocify/campaign.rb +12 -6
- data/lib/velocify/field.rb +12 -6
- data/lib/velocify/field_type.rb +12 -6
- data/lib/velocify/lead.rb +137 -57
- data/lib/velocify/model.rb +157 -46
- data/lib/velocify/status.rb +12 -6
- data/lib/velocify/version.rb +1 -1
- data/templates/add_leads.xml.erb +6 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb9807a174a61d5c269b5a6c8c82a70518b1c1fd
|
4
|
+
data.tar.gz: fd1f26749f639632e8e76140e23d72b6fbe79dd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6c4334483720f3e7e929b0fdd997b9a533b3000b7997377d1fdbcce9194240aba724c6fad3217f34ccdd8fe64020901269babcdf37f9314354622a0c2870bd1
|
7
|
+
data.tar.gz: 504b3bc13bbc1bffdce8be6d45f940846e0cb00f129112272aeb9364a1a431a46e0bc1f23ea88cb0be70c767b49c7a7989041b6ca78bc52a736ac22030938de2
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Changes in 0.1.3
|
2
|
+
|
3
|
+
* All model classes now support the optional keyword argument ```return_array:``` if you want to receive
|
4
|
+
a response that wraps the results in an array:
|
5
|
+
|
6
|
+
``` ruby
|
7
|
+
leads = Velocify::Lead.find_by_email 'hi@example.org', return_array: true
|
8
|
+
# Every element in the array would contain a lead
|
9
|
+
# => [{ ... }, ... ]
|
10
|
+
```
|
11
|
+
|
12
|
+
## Breaking Changes
|
13
|
+
|
14
|
+
* ```Velocify::Lead.find_all``` by default returns a response like so ```{leads=>{lead=> ... }```
|
15
|
+
instead of ```{get_leads_response=>{get_leads_result=>{leads=>lead=> ... }```.
|
16
|
+
|
data/README.md
CHANGED
@@ -21,14 +21,60 @@ Or install it yourself as:
|
|
21
21
|
## Usage
|
22
22
|
|
23
23
|
Before getting started, you must export two environment variables: ```VELOCIFY_USERNAME``` and ```VELOCIFY_PASSWORD```.
|
24
|
+
This gem uses Dotenv, so you can add these variables to your ```.env``` file in the root folder of your project.
|
24
25
|
|
25
26
|
``` ruby
|
26
27
|
require 'velocify'
|
27
28
|
|
28
29
|
statuses = Velocify::Status.find_all
|
29
|
-
|
30
|
+
# => {statuses=>status=>[{...}, ...]}
|
31
|
+
|
32
|
+
dormant_id = Velocify::ResponseReader.read(kind: :status, response: statuses).find_id_by_title 'Dormant'
|
33
|
+
# => 31
|
34
|
+
|
35
|
+
statuses_with_name = Velocify::ResponseReader.read(kind: :status, response: statuses).search_by_title 'Name'
|
36
|
+
# => [{...}, ...]
|
37
|
+
|
38
|
+
leads = Velocify::Lead.find_last_created
|
39
|
+
# => {leads=>lead=>{...}}
|
40
|
+
|
41
|
+
# There's also support for destructuring
|
42
|
+
|
43
|
+
success, leads = Velocify::Lead.find_all from: '2000-01-01T00:00:00', to: '2000-02-01T00:00:00', destruct: true
|
44
|
+
# => [true, {leads=>lead=>[{...}]}]
|
45
|
+
success
|
46
|
+
# => true
|
47
|
+
payload
|
48
|
+
# => {leads=>lead=>[{ ... }]}
|
49
|
+
|
50
|
+
# You can even have your results returned as an array
|
51
|
+
|
52
|
+
success, leads = Velocify::Lead.find_all from: '2000-01-01T00:00:00', to: '2000-02-01T00:00:00', destruct: true, return_array: true
|
53
|
+
# => [true, [{...}, ... }]
|
54
|
+
|
55
|
+
# Pushing leads to Velocify
|
56
|
+
campaign_id = Velocify::ResponseReader.read(kind: :campaign, response: Velocify::Campaign.find_all).find_id_by_title 'Test Campaign'
|
57
|
+
status_id = Velocify::ResponseReader.read(kind: :status, response: Velocify::Status.find_all).find_id_by_title 'Active'
|
58
|
+
last_name_id = Velocify::ResponseReader.read(kind: :field, response: Velocify::Field.find_all).find_id_by_title 'Last Name'
|
59
|
+
first_name_id = Velocify::ResponseReader.read(kind: :field, response: Velocify::Field.find_all).find_id_by_title 'First Name'
|
60
|
+
|
61
|
+
lead = Lead.new
|
62
|
+
lead.campaign_id = campaign_id
|
63
|
+
lead.status_id = status_id
|
64
|
+
lead.add_field id: first_name_id, value: "Joe"
|
65
|
+
lead.add_field id: last_name_id, value: "Bo"
|
66
|
+
|
67
|
+
list = Velocify::LeadList.new
|
68
|
+
list.add_lead lead
|
69
|
+
xml_payload = list.render # Renders xml output
|
70
|
+
|
71
|
+
Velocify::Lead.add leads: xml_payload
|
30
72
|
```
|
31
73
|
|
74
|
+
## Changes
|
75
|
+
|
76
|
+
For a list of changes in each release, read the CHANGELOG.
|
77
|
+
|
32
78
|
## Development
|
33
79
|
|
34
80
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/velocify/campaign.rb
CHANGED
@@ -2,14 +2,20 @@ module Velocify
|
|
2
2
|
class Campaign
|
3
3
|
include Model
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
def self.find_all destruct: false
|
5
|
+
def self.find_all destruct: false, return_array: false
|
8
6
|
verify_credentials!
|
9
7
|
|
10
|
-
request
|
11
|
-
|
12
|
-
|
8
|
+
request do
|
9
|
+
enable_destructuring destruct
|
10
|
+
operation :get_campaigns
|
11
|
+
authenticate true
|
12
|
+
transform do |resp|
|
13
|
+
if return_array
|
14
|
+
arrayify resp[:campaigns][:campaign]
|
15
|
+
else
|
16
|
+
resp
|
17
|
+
end
|
18
|
+
end
|
13
19
|
end
|
14
20
|
end
|
15
21
|
end
|
data/lib/velocify/field.rb
CHANGED
@@ -2,16 +2,22 @@ module Velocify
|
|
2
2
|
class Field
|
3
3
|
include Model
|
4
4
|
|
5
|
-
operations :get_fields
|
6
|
-
|
7
5
|
# @return [Hash] a list of fields
|
8
6
|
#
|
9
|
-
def self.find_all destruct: false
|
7
|
+
def self.find_all destruct: false, return_array: false
|
10
8
|
verify_credentials!
|
11
9
|
|
12
|
-
request
|
13
|
-
|
14
|
-
|
10
|
+
request do
|
11
|
+
enable_destructuring destruct
|
12
|
+
operation :get_fields
|
13
|
+
authenticate true
|
14
|
+
transform do |resp|
|
15
|
+
if return_array
|
16
|
+
arrayify resp[:fields][:field]
|
17
|
+
else
|
18
|
+
resp
|
19
|
+
end
|
20
|
+
end
|
15
21
|
end
|
16
22
|
end
|
17
23
|
end
|
data/lib/velocify/field_type.rb
CHANGED
@@ -2,15 +2,21 @@ module Velocify
|
|
2
2
|
class FieldType
|
3
3
|
include Model
|
4
4
|
|
5
|
-
operations :get_field_types
|
6
|
-
|
7
5
|
# @return [Hash] a list of fields
|
8
|
-
def self.find_all destruct: false
|
6
|
+
def self.find_all destruct: false, return_array: false
|
9
7
|
verify_credentials!
|
10
8
|
|
11
|
-
request
|
12
|
-
|
13
|
-
|
9
|
+
request do
|
10
|
+
enable_destructuring destruct
|
11
|
+
operation :get_field_types
|
12
|
+
authenticate true
|
13
|
+
transform do |resp|
|
14
|
+
if return_array
|
15
|
+
arrayify resp[:field_types][:field_type]
|
16
|
+
else
|
17
|
+
resp
|
18
|
+
end
|
19
|
+
end
|
14
20
|
end
|
15
21
|
end
|
16
22
|
end
|
data/lib/velocify/lead.rb
CHANGED
@@ -2,16 +2,6 @@ module Velocify
|
|
2
2
|
class Lead
|
3
3
|
include Model
|
4
4
|
|
5
|
-
operations :get_lead,
|
6
|
-
:get_leads,
|
7
|
-
:get_last_created_lead,
|
8
|
-
:get_leads_by_email,
|
9
|
-
:get_last_modified_lead,
|
10
|
-
:get_leads_by_phone,
|
11
|
-
:modify_lead_field,
|
12
|
-
:modify_lead_status,
|
13
|
-
:add_leads
|
14
|
-
|
15
5
|
attr :fields
|
16
6
|
attr_accessor :campaign_id, :agent_id, :status_id
|
17
7
|
|
@@ -36,12 +26,20 @@ module Velocify
|
|
36
26
|
# @param leads [String] The string representation of the XML document
|
37
27
|
# containing the new leads
|
38
28
|
#
|
39
|
-
def add leads:, destruct: false
|
29
|
+
def add leads:, destruct: false, return_array: false
|
40
30
|
verify_credentials!
|
41
31
|
|
42
|
-
request
|
43
|
-
|
44
|
-
|
32
|
+
request do
|
33
|
+
enable_destructuring destruct
|
34
|
+
operation :add_leads_response
|
35
|
+
message leads: leads
|
36
|
+
transform do |resp|
|
37
|
+
if return_array
|
38
|
+
arrayify resp[:leads][:lead]
|
39
|
+
else
|
40
|
+
resp
|
41
|
+
end
|
42
|
+
end
|
45
43
|
end
|
46
44
|
end
|
47
45
|
|
@@ -51,14 +49,21 @@ module Velocify
|
|
51
49
|
# @param to [String] The end date
|
52
50
|
# @return [Hash] The leads between the `from:` and `to:` dates
|
53
51
|
#
|
54
|
-
def find_all from:, to:, destruct: false
|
52
|
+
def find_all from:, to:, destruct: false, return_array: false
|
55
53
|
verify_credentials!
|
56
54
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
55
|
+
request do
|
56
|
+
enable_destructuring destruct
|
57
|
+
operation :get_leads
|
58
|
+
message from: from, to: to
|
59
|
+
authenticate true
|
60
|
+
transform do |resp|
|
61
|
+
if return_array
|
62
|
+
arrayify resp[:leads][:lead]
|
63
|
+
else
|
64
|
+
resp
|
65
|
+
end
|
66
|
+
end
|
62
67
|
end
|
63
68
|
end
|
64
69
|
|
@@ -67,12 +72,21 @@ module Velocify
|
|
67
72
|
# @param email [String] The email address used to search for a lead
|
68
73
|
# @return [Hash] The leads having the matching email address
|
69
74
|
#
|
70
|
-
def find_by_email email, destruct: false
|
75
|
+
def find_by_email email, destruct: false, return_array: false
|
71
76
|
verify_credentials!
|
72
77
|
|
73
|
-
request
|
74
|
-
|
75
|
-
|
78
|
+
request do
|
79
|
+
enable_destructuring destruct
|
80
|
+
operation :get_leads_by_email
|
81
|
+
authenticate true
|
82
|
+
message email: email
|
83
|
+
transform do |resp|
|
84
|
+
if return_array
|
85
|
+
arrayify resp[:leads][:lead]
|
86
|
+
else
|
87
|
+
resp
|
88
|
+
end
|
89
|
+
end
|
76
90
|
end
|
77
91
|
end
|
78
92
|
|
@@ -81,12 +95,21 @@ module Velocify
|
|
81
95
|
# @param phone [String] The phone number used to search for a lead
|
82
96
|
# @return [Hash] The leads having the matching phone number
|
83
97
|
#
|
84
|
-
def find_by_phone phone, destruct: false
|
98
|
+
def find_by_phone phone, destruct: false, return_array: false
|
85
99
|
verify_credentials!
|
86
|
-
|
87
|
-
request
|
88
|
-
|
89
|
-
|
100
|
+
|
101
|
+
request do
|
102
|
+
enable_destructuring destruct
|
103
|
+
operation :get_leads_by_phone
|
104
|
+
message phone: phone.gsub(/[()\- ]/, '')
|
105
|
+
authenticate true
|
106
|
+
transform do |resp|
|
107
|
+
if return_array
|
108
|
+
arrayify resp[:leads][:lead]
|
109
|
+
else
|
110
|
+
resp
|
111
|
+
end
|
112
|
+
end
|
90
113
|
end
|
91
114
|
end
|
92
115
|
|
@@ -95,30 +118,73 @@ module Velocify
|
|
95
118
|
# @param id [String] the id of the lead
|
96
119
|
# @return [Hash] The lead with the matching id
|
97
120
|
#
|
98
|
-
def find_by_id id, destruct: false
|
121
|
+
def find_by_id id, destruct: false, return_array: false
|
99
122
|
verify_credentials!
|
100
123
|
|
101
|
-
request
|
102
|
-
|
103
|
-
|
124
|
+
request do
|
125
|
+
enable_destructuring destruct
|
126
|
+
operation :get_lead
|
127
|
+
authenticate true
|
128
|
+
message lead_id: id
|
129
|
+
transform do |resp|
|
130
|
+
if return_array
|
131
|
+
arrayify resp[:leads][:lead]
|
132
|
+
else
|
133
|
+
resp
|
134
|
+
end
|
135
|
+
end
|
104
136
|
end
|
105
137
|
end
|
106
138
|
|
107
|
-
def find_last_created destruct: false
|
139
|
+
def find_last_created destruct: false, return_array: false
|
108
140
|
verify_credentials!
|
109
141
|
|
110
|
-
request
|
111
|
-
|
112
|
-
|
142
|
+
request do
|
143
|
+
enable_destructuring destruct
|
144
|
+
operation :get_last_created_lead
|
145
|
+
authenticate true
|
146
|
+
transform do |resp|
|
147
|
+
if return_array
|
148
|
+
arrayify resp[:leads][:lead]
|
149
|
+
else
|
150
|
+
resp
|
151
|
+
end
|
152
|
+
end
|
113
153
|
end
|
114
154
|
end
|
115
155
|
|
116
|
-
def find_last_modified destruct: false
|
156
|
+
def find_last_modified destruct: false, return_array: false
|
117
157
|
verify_credentials!
|
118
158
|
|
119
|
-
request
|
120
|
-
|
121
|
-
|
159
|
+
request do
|
160
|
+
enable_destructuring destruct
|
161
|
+
operation :get_last_modified_lead
|
162
|
+
authenticate true
|
163
|
+
transform do |resp|
|
164
|
+
if return_array
|
165
|
+
arrayify resp[:leads][:lead]
|
166
|
+
else
|
167
|
+
resp
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def remove id:, destruct: false, return_array: false
|
174
|
+
verify_credentials!
|
175
|
+
|
176
|
+
request do
|
177
|
+
enable_destructuring destruct
|
178
|
+
operation :remove_lead
|
179
|
+
authenticate true
|
180
|
+
message lead_id: id
|
181
|
+
transform do |resp|
|
182
|
+
if return_array
|
183
|
+
arrayify resp[:response][:removals] # also [:lead] ?
|
184
|
+
else
|
185
|
+
resp
|
186
|
+
end
|
187
|
+
end
|
122
188
|
end
|
123
189
|
end
|
124
190
|
|
@@ -132,15 +198,21 @@ module Velocify
|
|
132
198
|
# @param status_id [String] The id of the status
|
133
199
|
# @return [Hash] The response containing the updated lead
|
134
200
|
#
|
135
|
-
def update_status lead_id:, status_id:, destruct: false
|
201
|
+
def update_status lead_id:, status_id:, destruct: false, return_array: false
|
136
202
|
verify_credentials!
|
137
203
|
|
138
|
-
request
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
204
|
+
request do
|
205
|
+
enable_destructuring destruct
|
206
|
+
operation :modify_lead_status
|
207
|
+
authenticate true
|
208
|
+
message lead_id: lead_id, status_id: status_id
|
209
|
+
transform do |resp|
|
210
|
+
if return_array
|
211
|
+
arrayify resp[:leads][:lead]
|
212
|
+
else
|
213
|
+
resp
|
214
|
+
end
|
215
|
+
end
|
144
216
|
end
|
145
217
|
end
|
146
218
|
|
@@ -151,18 +223,26 @@ module Velocify
|
|
151
223
|
# @param new_value [String] The new value of the field
|
152
224
|
# @return [Hash] The response containing the updated lead
|
153
225
|
#
|
154
|
-
def update_field lead_id:, field_id:, new_value:, destruct: false
|
226
|
+
def update_field lead_id:, field_id:, new_value:, destruct: false, return_array: false
|
155
227
|
verify_credentials!
|
156
|
-
|
157
|
-
request
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
228
|
+
|
229
|
+
request do
|
230
|
+
enable_destructuring destruct
|
231
|
+
operation :modify_lead_field
|
232
|
+
authenticate true
|
233
|
+
message field_id: field_id, lead_id: lead_id, new_value: new_value
|
234
|
+
transform do |resp|
|
235
|
+
if return_array
|
236
|
+
arrayify resp[:leads][:lead]
|
237
|
+
else
|
238
|
+
resp
|
239
|
+
end
|
240
|
+
end
|
164
241
|
end
|
165
242
|
end
|
243
|
+
|
244
|
+
alias_method :last_created, :find_last_created
|
245
|
+
alias_method :last_modified, :find_last_modified
|
166
246
|
end
|
167
247
|
end
|
168
248
|
end
|
data/lib/velocify/model.rb
CHANGED
@@ -1,65 +1,176 @@
|
|
1
1
|
module Velocify
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
def authenticate!
|
6
|
-
@credentials = {
|
7
|
-
username: ENV['VELOCIFY_USERNAME'],
|
8
|
-
password: ENV['VELOCIFY_PASSWORD']
|
9
|
-
}
|
10
|
-
valid_credentials?
|
11
|
-
end
|
2
|
+
module Model
|
3
|
+
class Client
|
4
|
+
WSDL = 'http://service.leads360.com/ClientService.asmx?WSDL'
|
12
5
|
|
13
|
-
|
14
|
-
|
15
|
-
|
6
|
+
attr :spec, :client, :credentials
|
7
|
+
|
8
|
+
def initialize spec, credentials: nil
|
9
|
+
@spec = spec
|
10
|
+
@credentials = credentials
|
11
|
+
@client = Savon.client wsdl: WSDL
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
payload = {}
|
16
|
+
|
17
|
+
if spec.has_message?
|
18
|
+
payload = spec.__message
|
19
|
+
end
|
20
|
+
|
21
|
+
if spec.requires_auth?
|
22
|
+
payload.merge! credentials
|
23
|
+
end
|
16
24
|
|
17
|
-
|
25
|
+
raw_response = client.call(spec.__operation, { message: payload }).body
|
26
|
+
response_tag = "#{spec.__operation.to_s}_response".to_sym
|
27
|
+
result_tag = "#{spec.__operation.to_s}_result".to_sym
|
28
|
+
response = raw_response[response_tag][result_tag]
|
18
29
|
|
19
|
-
|
20
|
-
|
21
|
-
|
30
|
+
if spec.has_transform?
|
31
|
+
spec.__transform.call response
|
32
|
+
else
|
33
|
+
response
|
34
|
+
end
|
22
35
|
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def client; @client; end
|
40
|
+
|
41
|
+
def credentials; @credentials; end
|
23
42
|
end
|
24
43
|
|
25
|
-
|
26
|
-
|
44
|
+
module RequestHelpers
|
45
|
+
def arrayify data
|
46
|
+
if data.instance_of? Array
|
47
|
+
data
|
48
|
+
else
|
49
|
+
[data]
|
50
|
+
end
|
51
|
+
end
|
27
52
|
end
|
53
|
+
|
54
|
+
class RequestSpecification
|
55
|
+
include RequestHelpers
|
56
|
+
|
57
|
+
attr :destruct, :operation, :transform, :message, :credentials, :authenticate
|
58
|
+
|
59
|
+
def initialize
|
60
|
+
@destruct = false
|
61
|
+
end
|
62
|
+
|
63
|
+
def enable_destructuring is_on
|
64
|
+
@destruct = is_on
|
65
|
+
end
|
66
|
+
|
67
|
+
def destruct?
|
68
|
+
@destruct
|
69
|
+
end
|
70
|
+
|
71
|
+
def authenticate is_on
|
72
|
+
@authenticate = is_on
|
73
|
+
end
|
74
|
+
|
75
|
+
def message *msg
|
76
|
+
@message = Hash[ *msg ]
|
77
|
+
end
|
78
|
+
|
79
|
+
def operation op
|
80
|
+
@operation = op.to_sym
|
81
|
+
end
|
82
|
+
|
83
|
+
def transform &block
|
84
|
+
@transform = block
|
85
|
+
end
|
28
86
|
|
29
|
-
|
30
|
-
|
31
|
-
|
87
|
+
def has_message?
|
88
|
+
!@message.nil?
|
89
|
+
end
|
90
|
+
|
91
|
+
def requires_auth?
|
92
|
+
!@authenticate.nil?
|
93
|
+
end
|
94
|
+
|
95
|
+
def has_transform?
|
96
|
+
!@transform.nil?
|
97
|
+
end
|
98
|
+
|
99
|
+
def __message
|
100
|
+
@message
|
101
|
+
end
|
102
|
+
|
103
|
+
def __operation
|
104
|
+
@operation
|
105
|
+
end
|
106
|
+
|
107
|
+
def __transform
|
108
|
+
@transform
|
109
|
+
end
|
32
110
|
end
|
33
111
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
112
|
+
module ModelHelpers
|
113
|
+
attr :credentials
|
114
|
+
|
115
|
+
def authenticate!
|
116
|
+
@credentials = {
|
117
|
+
username: ENV['VELOCIFY_USERNAME'],
|
118
|
+
password: ENV['VELOCIFY_PASSWORD']
|
119
|
+
}
|
120
|
+
valid_credentials?
|
121
|
+
end
|
122
|
+
|
123
|
+
def authenticated?
|
124
|
+
valid_credentials?
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
|
129
|
+
def verify_credentials!
|
130
|
+
if @credentials.nil?
|
131
|
+
raise Velocify::AuthenticationException, "You must export your credentials to the environment"
|
47
132
|
end
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
133
|
+
end
|
134
|
+
|
135
|
+
def authenticated_message msg
|
136
|
+
@credentials.merge(msg) unless @credentials.nil?
|
137
|
+
end
|
138
|
+
|
139
|
+
def valid_credentials?
|
140
|
+
return false if @credentials.nil?
|
141
|
+
!@credentials[:username].empty? && !@credentials[:password].empty?
|
142
|
+
end
|
143
|
+
|
144
|
+
def request destruct: false, &block
|
145
|
+
begin
|
146
|
+
spec = RequestSpecification.new
|
147
|
+
spec.instance_eval(&block)
|
148
|
+
client = Client.new spec, credentials: @credentials
|
149
|
+
|
150
|
+
if destruct || spec.destruct?
|
151
|
+
result = client.call
|
152
|
+
[true, result]
|
153
|
+
else
|
154
|
+
client.call
|
155
|
+
end
|
156
|
+
rescue Savon::SOAPFault => ex
|
157
|
+
if destruct || spec.destruct?
|
158
|
+
[false, { message: ex.message }]
|
159
|
+
else
|
160
|
+
{ message: ex.message }
|
161
|
+
end
|
162
|
+
rescue Net::ReadTimeout => ex
|
163
|
+
if destruct || spec.destruct?
|
164
|
+
[false, { message: ex.message }]
|
165
|
+
else
|
166
|
+
{ message: ex.message }
|
167
|
+
end
|
53
168
|
end
|
54
169
|
end
|
55
170
|
end
|
56
|
-
|
57
|
-
|
58
|
-
module Model
|
171
|
+
|
59
172
|
def self.included mod
|
60
|
-
mod.extend
|
61
|
-
mod.client wsdl: 'http://service.leads360.com/ClientService.asmx?WSDL'
|
62
|
-
mod.extend Velocify::ModelHelpers
|
173
|
+
mod.extend ModelHelpers
|
63
174
|
mod.authenticate!
|
64
175
|
end
|
65
176
|
end
|
data/lib/velocify/status.rb
CHANGED
@@ -2,14 +2,20 @@ module Velocify
|
|
2
2
|
class Status
|
3
3
|
include Model
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
def self.find_all destruct: false
|
5
|
+
def self.find_all destruct: false, return_array: false
|
8
6
|
verify_credentials!
|
9
7
|
|
10
|
-
request
|
11
|
-
|
12
|
-
|
8
|
+
request do
|
9
|
+
enable_destructuring destruct
|
10
|
+
operation :get_statuses
|
11
|
+
authenticate true
|
12
|
+
transform do |resp|
|
13
|
+
if return_array
|
14
|
+
arrayify resp[:statuses][:status]
|
15
|
+
else
|
16
|
+
resp
|
17
|
+
end
|
18
|
+
end
|
13
19
|
end
|
14
20
|
end
|
15
21
|
end
|
data/lib/velocify/version.rb
CHANGED
data/templates/add_leads.xml.erb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
|
-
<!-- sample XML payload for AddLeads webmethod -->
|
2
1
|
<Leads>
|
3
2
|
<% @leads.each do |lead| %>
|
4
3
|
<Lead>
|
5
4
|
<% if lead.status_id? %>
|
6
|
-
<Status StatusId="<%= lead.status_id %>"
|
7
|
-
<% end %>
|
8
|
-
<% if lead.agent_id? %>
|
9
|
-
<Agent AgentId="<%= lead.agent_id %>"/>
|
5
|
+
<Status StatusId="<%= lead.status_id %>"></Status>
|
10
6
|
<% end %>
|
11
7
|
<% if lead.campaign_id? %>
|
12
|
-
<Campaign CampaignId="<%= lead.campaign_id %>"
|
8
|
+
<Campaign CampaignId="<%= lead.campaign_id %>"></Campaign>
|
9
|
+
<% end %>
|
10
|
+
<% if lead.agent_id? %>
|
11
|
+
<Agent AgentId="<%= lead.agent_id %>"></Agent>
|
13
12
|
<% end %>
|
14
13
|
<% unless lead.fields.empty? %>
|
15
14
|
<Fields>
|
16
15
|
<% lead.fields.each do |field| %>
|
17
|
-
<Field FieldId="<%= field[:id] %>" Value="<%= field[:value] %>"
|
16
|
+
<Field FieldId="<%= field[:id] %>" Value="<%= field[:value] %>"></Field>
|
18
17
|
<% end %>
|
19
18
|
</Fields>
|
20
19
|
<% end %>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: velocify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Dyba
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: savon
|
@@ -117,6 +117,7 @@ extra_rdoc_files: []
|
|
117
117
|
files:
|
118
118
|
- ".gitignore"
|
119
119
|
- ".travis.yml"
|
120
|
+
- CHANGELOG.md
|
120
121
|
- CODE_OF_CONDUCT.md
|
121
122
|
- Gemfile
|
122
123
|
- LICENSE.txt
|