eloqua_api 0.0.9 → 0.0.11
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 +8 -8
- data/lib/eloqua_api/bulk/export.rb +23 -0
- data/lib/eloqua_api/bulk/query.rb +224 -0
- data/lib/eloqua_api/bulk/sync.rb +11 -0
- data/lib/eloqua_api/bulk_client.rb +5 -0
- data/lib/eloqua_api/client.rb +1 -1
- data/lib/eloqua_api/rest/landing_page.rb +1 -1
- data/lib/eloqua_api/rest/segment.rb +4 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTNmYzc1MDdlMzdjMWY2ZmY4Yjc5NjRjN2NkYzQ4MzYyNjYwYTk1ZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDg5ZjU1ZDhjNTg5NzY1YWI5MmNlM2I4NjNlMTQzYTYxNmQ2NDAwYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MjgxMzZhYzIzOTRkZmRiZDRkNmQ4NjE4NGZjZDZmNGRiMzRkMzJhMWYyMjc3
|
10
|
+
MTIxYjU2NDQyMThmNjkwNmI0NjNjNmI5Y2E5ZjhmNzNhMzBjOGI3MWUwMDAz
|
11
|
+
ZTcxZjM0ZjJlNjA2M2I3Yjk3ZGJkNjQxMjhhNTZjZWRjNmJkZjk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Y2VmNDZiMGYzMjkxZDg0OWE5YzA3MGZiMDkyYzA3NmY4NDRjNmY2OTdlYjQx
|
14
|
+
Y2RhYjFiMzE2NmMxNmM1MjYxZGUwMWI0ZjA4NTFiZTZlNzFlNGE3MmQ1YTVm
|
15
|
+
ODE1NDc5M2MxYzgwYWRjY2ExNTljZmM4Mzg3NTJjZjM0MmE1OTM=
|
@@ -10,5 +10,28 @@ module Eloqua
|
|
10
10
|
|
11
11
|
get("%s/data" % export_uri, options)
|
12
12
|
end
|
13
|
+
|
14
|
+
#
|
15
|
+
# Version 2.0 of the Bulk API
|
16
|
+
#
|
17
|
+
def define_activity_export(export)
|
18
|
+
post("activities/exports", export)
|
19
|
+
end
|
20
|
+
alias :define_activities_export :define_activity_export
|
21
|
+
|
22
|
+
def retrieve_activity_export(export_uri, options={})
|
23
|
+
options[:limit] ||= 50000
|
24
|
+
|
25
|
+
get("%s/data" % export_uri, options)
|
26
|
+
end
|
27
|
+
alias :retrieve_activities_export :retrieve_activity_export
|
28
|
+
|
29
|
+
def delete_export_definition(export_uri, options={})
|
30
|
+
delete(export_uri)
|
31
|
+
end
|
32
|
+
|
33
|
+
def delete_export(export_uri, options={})
|
34
|
+
delete("%s/data" % export_uri)
|
35
|
+
end
|
13
36
|
end
|
14
37
|
end
|
@@ -0,0 +1,224 @@
|
|
1
|
+
module Eloqua
|
2
|
+
#
|
3
|
+
# Usage:
|
4
|
+
#
|
5
|
+
# client = Eloqua::BulkClient.new({ ... })
|
6
|
+
# client.query("My Query/Export Name").
|
7
|
+
# select("Activity.Asset.Id AS AssetId", "Activity.Id AS ActivityId").
|
8
|
+
# from("activities").
|
9
|
+
# where("Activity.CreatedAt > 2014-08-01", "Activity.Type = EmailOpen").
|
10
|
+
# limit(3).
|
11
|
+
# retain(3600).
|
12
|
+
# execute().
|
13
|
+
# wait(30).each do |row|
|
14
|
+
# puts row
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# If anything goes wrong (at any stage of the chain) a Query::Error exception will be thrown
|
18
|
+
# with a human readable error message, accompanied by the full HTTP request response and code
|
19
|
+
# when appropriate.
|
20
|
+
#
|
21
|
+
|
22
|
+
class Query
|
23
|
+
class Error < StandardError
|
24
|
+
attr_reader :response
|
25
|
+
|
26
|
+
def initialize(message, response=nil)
|
27
|
+
@response = response
|
28
|
+
super(message)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize(name, client)
|
33
|
+
@name = name
|
34
|
+
@client = client
|
35
|
+
@fields = {}
|
36
|
+
@filter = []
|
37
|
+
@retain = 0
|
38
|
+
@resource = nil
|
39
|
+
@limit = 50000
|
40
|
+
@uri = nil
|
41
|
+
@sync = false
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete
|
45
|
+
raise Error, 'Execute must be called before calling delete.' if @uri.nil?
|
46
|
+
|
47
|
+
@client.delete_export(@uri)
|
48
|
+
@client.delete_export_definition(@uri)
|
49
|
+
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
def execute
|
54
|
+
raise Error, 'Execute cannot be called more than once.' unless @uri.nil?
|
55
|
+
raise Error, 'A valid resource must be defined before calling execute.' unless @resource and @client.respond_to?(define_export_method) and @client.respond_to?(retrieve_export_method)
|
56
|
+
|
57
|
+
response = @client.send(define_export_method, to_h)
|
58
|
+
if response.code == 201 and response.parsed_response['uri']
|
59
|
+
@uri = response.parsed_response['uri']
|
60
|
+
else
|
61
|
+
raise Error.new("Could not execute query.", response)
|
62
|
+
end
|
63
|
+
|
64
|
+
self
|
65
|
+
end
|
66
|
+
|
67
|
+
def wait(secs)
|
68
|
+
raise Error, 'Execute must be called before wait.' if @uri.nil?
|
69
|
+
|
70
|
+
response = nil
|
71
|
+
@sync_uri ||= nil
|
72
|
+
|
73
|
+
if @sync_uri.nil?
|
74
|
+
response = @client.syncs(@uri)
|
75
|
+
if response.code == 201 and response.parsed_response['status'] == 'pending'
|
76
|
+
@sync_uri = response.parsed_response['uri']
|
77
|
+
else
|
78
|
+
raise Error.new("Could not sync.", response)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
i = 0
|
83
|
+
while i < secs
|
84
|
+
i += 1
|
85
|
+
|
86
|
+
response = @client.syncs_status(@sync_uri)
|
87
|
+
if response.code == 200 and response.parsed_response['status'] == "success"
|
88
|
+
@sync = true
|
89
|
+
return self
|
90
|
+
end
|
91
|
+
|
92
|
+
sleep 1
|
93
|
+
end
|
94
|
+
|
95
|
+
raise Error.new("Could not sync in #{secs} seconds.", response)
|
96
|
+
|
97
|
+
self
|
98
|
+
end
|
99
|
+
|
100
|
+
def count
|
101
|
+
raise Error, 'Wait must be called before calling count.' unless @sync
|
102
|
+
|
103
|
+
response = @client.send(retrieve_export_method, @uri, :limit => @limit)
|
104
|
+
if response.code == 200 and response.parsed_response['totalResults']
|
105
|
+
response.parsed_response['totalResults'].to_i
|
106
|
+
else
|
107
|
+
raise Error.new("Failed to get count.", response)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def each
|
112
|
+
raise Error, 'No block provided.' unless block_given?
|
113
|
+
raise Error, 'Wait must be called before calling each.' unless @sync
|
114
|
+
|
115
|
+
offset = 0
|
116
|
+
while true
|
117
|
+
response = @client.send(retrieve_export_method, @uri, :offset => offset, :limit => @limit)
|
118
|
+
if response.code == 200 and response.parsed_response['totalResults']
|
119
|
+
response = response.parsed_response
|
120
|
+
|
121
|
+
response['items'].each do |item|
|
122
|
+
yield item
|
123
|
+
end if response['items'].is_a?(Array)
|
124
|
+
|
125
|
+
if response['hasMore']
|
126
|
+
offset += @limit
|
127
|
+
else
|
128
|
+
break
|
129
|
+
end
|
130
|
+
else
|
131
|
+
raise Error.new("Failed to get rows for each.", response)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
self
|
136
|
+
end
|
137
|
+
|
138
|
+
def to_h
|
139
|
+
hash = {}
|
140
|
+
hash['name'] = @name
|
141
|
+
hash['fields'] = @fields
|
142
|
+
hash['filter'] = @filter.join(' ')
|
143
|
+
hash['secondsToRetainData'] = @retain if @retain > 0
|
144
|
+
hash
|
145
|
+
end
|
146
|
+
|
147
|
+
def limit(n)
|
148
|
+
@limit = n.to_i
|
149
|
+
self
|
150
|
+
end
|
151
|
+
|
152
|
+
def from(resource)
|
153
|
+
@resource = resource.downcase if resource.is_a?(String)
|
154
|
+
self
|
155
|
+
end
|
156
|
+
|
157
|
+
def retain(secs)
|
158
|
+
@retain = secs.to_i
|
159
|
+
self
|
160
|
+
end
|
161
|
+
|
162
|
+
def select(*selectors)
|
163
|
+
fields = {}
|
164
|
+
|
165
|
+
selectors.each do |field|
|
166
|
+
l, op, r = expression(field)
|
167
|
+
if not op.nil? and op.upcase == 'AS'
|
168
|
+
fields[r] = "{{#{l}}}"
|
169
|
+
elsif op.nil?
|
170
|
+
fields[field.gsub('.', '')] = "{{#{field}}}"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
@fields.merge!(fields) if fields.any?
|
175
|
+
|
176
|
+
self
|
177
|
+
end
|
178
|
+
|
179
|
+
def where(*conditions)
|
180
|
+
filter = []
|
181
|
+
|
182
|
+
conditions.each do |condition|
|
183
|
+
l, op, r = expression(condition)
|
184
|
+
filter << "'{{#{l}}}'#{op.upcase}'#{r}'" if l
|
185
|
+
end
|
186
|
+
|
187
|
+
if filter.any?
|
188
|
+
if block_given?
|
189
|
+
@filter << yield(filter.join(" AND "))
|
190
|
+
else
|
191
|
+
@filter << filter.join(" AND ")
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
self
|
196
|
+
end
|
197
|
+
|
198
|
+
def or(*conditions)
|
199
|
+
where(*conditions) do |filter|
|
200
|
+
"OR ( #{filter} )"
|
201
|
+
end
|
202
|
+
|
203
|
+
self
|
204
|
+
end
|
205
|
+
|
206
|
+
protected
|
207
|
+
|
208
|
+
def define_export_method
|
209
|
+
@define_export_method ||= :"define_#{@resource}_export"
|
210
|
+
end
|
211
|
+
|
212
|
+
def retrieve_export_method
|
213
|
+
@retrieve_export_method ||= :"retrieve_#{@resource}_export"
|
214
|
+
end
|
215
|
+
|
216
|
+
def expression(condition)
|
217
|
+
if condition =~ /^(.*?)\s+(.*?)\s+(.*?)$/
|
218
|
+
[$1, $2, $3]
|
219
|
+
else
|
220
|
+
[nil, nil, nil]
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
data/lib/eloqua_api/bulk/sync.rb
CHANGED
@@ -8,5 +8,16 @@ module Eloqua
|
|
8
8
|
def sync_status(sync_uri, options={})
|
9
9
|
get(sync_uri, options)
|
10
10
|
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# Version 2.0 of the Bulk API changed this endpoint
|
14
|
+
# from sync to syncs.
|
15
|
+
#
|
16
|
+
def syncs(export_uri, options={})
|
17
|
+
options[:syncedInstanceUri] ||= export_uri
|
18
|
+
post("syncs", options)
|
19
|
+
end
|
20
|
+
|
21
|
+
alias :syncs_status :sync_status
|
11
22
|
end
|
12
23
|
end
|
@@ -1,11 +1,16 @@
|
|
1
1
|
require 'eloqua_api/bulk/export'
|
2
2
|
require 'eloqua_api/bulk/sync'
|
3
|
+
require 'eloqua_api/bulk/query'
|
3
4
|
|
4
5
|
module Eloqua
|
5
6
|
class BulkClient < Client
|
6
7
|
include Export
|
7
8
|
include Sync
|
8
9
|
|
10
|
+
def query(name)
|
11
|
+
Query.new(name, self)
|
12
|
+
end
|
13
|
+
|
9
14
|
def build_path(*segments)
|
10
15
|
super('/Bulk/', *segments)
|
11
16
|
end
|
data/lib/eloqua_api/client.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eloqua_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nader Akhnoukh
|
@@ -59,6 +59,7 @@ extensions: []
|
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
61
|
- lib/eloqua_api/bulk/export.rb
|
62
|
+
- lib/eloqua_api/bulk/query.rb
|
62
63
|
- lib/eloqua_api/bulk/sync.rb
|
63
64
|
- lib/eloqua_api/bulk_client.rb
|
64
65
|
- lib/eloqua_api/client.rb
|