embulk-input-mixpanel 0.5.10 → 0.5.11.alpha

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2db94c13e223960ee53abf712889a290728870d4
4
- data.tar.gz: bae22b3a844dd7b9a3e0aa61cbb7c2c06846137f
3
+ metadata.gz: 0c8f13b72e590889f06eb6f6db27cb0edb213853
4
+ data.tar.gz: c9406f58714adadca97e6d395050280bfb81ef35
5
5
  SHA512:
6
- metadata.gz: 72410d007e0d2035ecbeb1827d226c127fe62434f0e94cf3aa683ca4c1c6ba13c9107a1fdbc03d74dae00da7356034787f3da32417539a26efe0cf42f845278f
7
- data.tar.gz: 65c4d423bd208e80a9d72f17d6289cf2369c7b740ecbd7397fafa219672b48ff7bdd59a58953051a4919645bc8f2963c64445edad25ea29eb8b2e490130f491f
6
+ metadata.gz: 462b652b42397941d65ea31923e03d6f44d51610dbfaaa1159ee8cf793060dc84e08a7b91666516757e134368580949383a2ea89415c2149749c8377fbaba73c
7
+ data.tar.gz: c9d5a3b5c4d9753cb51421059577743dd8e5a9be41e9a142e647028c635621c6cf2ca43a03873aa24c90125b8972fc3bec09b6b8a7e56070e02c5c546582619c
data/README.md CHANGED
@@ -33,6 +33,7 @@ To get it, you should log in mixpanel website, and click gear icon at the lower
33
33
 
34
34
  - **api_key**: project API Key (string, required)
35
35
  - **api_secret**: project API Secret (string, required)
36
+ - **export_endpoint**: the Data Export API's endpoint (string, default to "http://data.mixpanel.com/api/2.0/export")
36
37
  - **timezone**: project timezone(string, required)
37
38
  - **from_date**: From date to export (string, optional, default: today - 2)
38
39
  - NOTE: Mixpanel API supports to export data from at least 2 days before to at most the previous day.
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "embulk-input-mixpanel"
3
- spec.version = "0.5.10"
3
+ spec.version = "0.5.11.alpha"
4
4
  spec.authors = ["yoshihara", "uu59"]
5
5
  spec.summary = "Mixpanel input plugin for Embulk"
6
6
  spec.description = "Loads records from Mixpanel."
@@ -60,6 +60,7 @@ module Embulk
60
60
  params: export_params(config),
61
61
  dates: range,
62
62
  timezone: timezone,
63
+ export_endpoint: export_endpoint(config),
63
64
  api_key: config.param(:api_key, :string),
64
65
  api_secret: config.param(:api_secret, :string),
65
66
  schema: config.param(:columns, :array),
@@ -122,14 +123,16 @@ module Embulk
122
123
  end
123
124
 
124
125
  def self.guess(config)
125
- giveup_when_mixpanel_is_down
126
+ giveup_when_mixpanel_is_down(export_endpoint(config))
126
127
 
127
128
  retryer = perfect_retry({
128
129
  retry_initial_wait_sec: config.param(:retry_initial_wait_sec, :integer, default: 1),
129
130
  retry_limit: config.param(:retry_limit, :integer, default: 5),
130
131
  })
131
-
132
- client = MixpanelApi::Client.new(config.param(:api_key, :string), config.param(:api_secret, :string), retryer)
132
+ client = MixpanelApi::Client.new(config.param(:api_key, :string),
133
+ config.param(:api_secret, :string),
134
+ retryer,
135
+ export_endpoint(config))
133
136
 
134
137
  range = guess_range(config)
135
138
  Embulk.logger.info "Guessing schema using #{range.first}..#{range.last} records"
@@ -153,7 +156,12 @@ module Embulk
153
156
  end
154
157
  end
155
158
 
159
+ def self.export_endpoint(config)
160
+ config.param(:export_endpoint, :string, default: Embulk::Input::MixpanelApi::Client::DEFAULT_EXPORT_ENDPOINT)
161
+ end
162
+
156
163
  def init
164
+ @export_endpoint = task[:export_endpoint]
157
165
  @api_key = task[:api_key]
158
166
  @api_secret = task[:api_secret]
159
167
  @params = task[:params]
@@ -167,7 +175,7 @@ module Embulk
167
175
 
168
176
  def run
169
177
  Embulk.logger.info "Job start time is #{task[:job_start_time]}"
170
- self.class.giveup_when_mixpanel_is_down
178
+ self.class.giveup_when_mixpanel_is_down(task[:export_endpoint])
171
179
  prev_latest_fetched_time = task[:latest_fetched_time] || 0
172
180
  prev_latest_fetched_time_format = Time.at(prev_latest_fetched_time).strftime("%F %T %z")
173
181
  current_latest_fetched_time = prev_latest_fetched_time
@@ -227,8 +235,8 @@ module Embulk
227
235
 
228
236
  private
229
237
 
230
- def self.giveup_when_mixpanel_is_down
231
- unless MixpanelApi::Client.mixpanel_available?
238
+ def self.giveup_when_mixpanel_is_down(export_endpoint)
239
+ unless MixpanelApi::Client.mixpanel_available?(export_endpoint)
232
240
  raise Embulk::DataError.new("Mixpanel service is down. Please retry later.")
233
241
  end
234
242
  end
@@ -289,7 +297,7 @@ module Embulk
289
297
  )
290
298
  end
291
299
  Embulk.logger.info "Where params is #{params["where"]}"
292
- client = MixpanelApi::Client.new(@api_key, @api_secret, self.class.perfect_retry(task))
300
+ client = MixpanelApi::Client.new(@api_key, @api_secret, self.class.perfect_retry(task), @export_endpoint)
293
301
 
294
302
  if preview?
295
303
  client.export_for_small_dataset(params)
@@ -8,16 +8,17 @@ module Embulk
8
8
  module Input
9
9
  module MixpanelApi
10
10
  class Client
11
- ENDPOINT_EXPORT = "https://data.mixpanel.com/api/2.0/export/".freeze
12
11
  TIMEOUT_SECONDS = 3600
13
12
  PING_TIMEOUT_SECONDS = 3
14
13
  PING_RETRY_LIMIT = 3
15
14
  PING_RETRY_WAIT = 2
16
15
  SMALLSET_BYTE_RANGE = "0-#{5 * 1024 * 1024}"
16
+ DEFAULT_EXPORT_ENDPOINT = "https://data.mixpanel.com/api/2.0/export/".freeze
17
17
 
18
18
  attr_reader :retryer
19
19
 
20
- def self.mixpanel_available?
20
+ def self.mixpanel_available?(endpoint = nil)
21
+ endpoint ||= DEFAULT_EXPORT_ENDPOINT
21
22
  retryer = PerfectRetry.new do |config|
22
23
  config.limit = PING_RETRY_LIMIT
23
24
  config.sleep = PING_RETRY_WAIT
@@ -29,7 +30,7 @@ module Embulk
29
30
  retryer.with_retry do
30
31
  client = HTTPClient.new
31
32
  client.connect_timeout = PING_TIMEOUT_SECONDS
32
- client.get("https://data.mixpanel.com")
33
+ client.get(URI.join(endpoint, '/'))
33
34
  end
34
35
  true
35
36
  rescue PerfectRetry::TooManyRetry
@@ -37,7 +38,8 @@ module Embulk
37
38
  end
38
39
  end
39
40
 
40
- def initialize(api_key, api_secret, retryer = nil)
41
+ def initialize(api_key, api_secret, retryer = nil, endpoint = DEFAULT_EXPORT_ENDPOINT)
42
+ @endpoint = endpoint
41
43
  @api_key = api_key
42
44
  @api_secret = api_secret
43
45
  @retryer = retryer || PerfectRetry.new do |config|
@@ -102,7 +104,8 @@ module Embulk
102
104
 
103
105
  buf = ""
104
106
  error_response = ''
105
- response = httpclient.get(ENDPOINT_EXPORT, params) do |response, chunk|
107
+ Embulk.logger.info "Sending request to #{@endpoint}"
108
+ response = httpclient.get(@endpoint, params) do |response, chunk|
106
109
  # Only process data if response status is 200..299
107
110
  if response.status/100 == 2
108
111
  chunk.each_line do |line|
@@ -130,10 +133,11 @@ module Embulk
130
133
  # guess/preview
131
134
  # Try to fetch first `range` bytes
132
135
  set_signatures(params)
133
- res = httpclient.get(ENDPOINT_EXPORT, params, {"Range" => "bytes=#{range}"})
136
+ Embulk.logger.info "Sending request to #{@endpoint}"
137
+ res = httpclient.get(@endpoint, params, {"Range" => "bytes=#{range}"})
134
138
  if res.code == 416
135
139
  # cannot satisfied requested Range, get full body
136
- res = httpclient.get(ENDPOINT_EXPORT, params)
140
+ res = httpclient.get(@endpoint, params)
137
141
  end
138
142
  handle_error(res,res.body)
139
143
  response_to_enum(res.body)
@@ -541,6 +541,7 @@ module Embulk
541
541
  {
542
542
  api_key: API_KEY,
543
543
  api_secret: API_SECRET,
544
+ export_endpoint: "https://data.mixpanel.com/api/2.0/export/",
544
545
  timezone: TIMEZONE,
545
546
  schema: schema,
546
547
  dates: DATES.to_a.map(&:to_s),
@@ -845,6 +846,7 @@ module Embulk
845
846
  {
846
847
  api_key: API_KEY,
847
848
  api_secret: API_SECRET,
849
+ export_endpoint: "https://data.mixpanel.com/api/2.0/export/",
848
850
  timezone: TIMEZONE,
849
851
  incremental: true,
850
852
  incremental_column: nil,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-mixpanel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.10
4
+ version: 0.5.11.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - yoshihara
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-12-03 00:00:00.000000000 Z
12
+ date: 2017-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  requirement: !ruby/object:Gem::Requirement
@@ -220,12 +220,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
220
220
  version: '0'
221
221
  required_rubygems_version: !ruby/object:Gem::Requirement
222
222
  requirements:
223
- - - ">="
223
+ - - ">"
224
224
  - !ruby/object:Gem::Version
225
- version: '0'
225
+ version: 1.3.1
226
226
  requirements: []
227
227
  rubyforge_project:
228
- rubygems_version: 2.6.6
228
+ rubygems_version: 2.4.8
229
229
  signing_key:
230
230
  specification_version: 4
231
231
  summary: Mixpanel input plugin for Embulk