embulk-input-sendgrid 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0a61cf98838cf332b0f512977615a787053174b00a1167448c1fb9e21bb90b4
4
- data.tar.gz: 463ed205a7d98d37ee15e309d9fa8a9ef263a39156f556da22e2b3af1913ea40
3
+ metadata.gz: 18a3021b808886f9a8e8396cea78f63b81fa53a710b8f3e5ee694c1009e948b1
4
+ data.tar.gz: 2a988676b09ff6ad7b8d72cd751c2a822884d3b737555c398db4bec44e5fdbc9
5
5
  SHA512:
6
- metadata.gz: 2286e1f3dc89579af6cbab18205648475538a52a4673d7199b258e19c91a40590f5854b47a05de8b0e45487431b81d4b488855b4c2879da0c5ce28f78642e8b2
7
- data.tar.gz: 63249f5a2ac47b7ff6b7ebd041806dc8fc8344a7ec094889e9dd871210a136cfd39377b794029f13930da372cdcf421623f088ce718ac4037d1919d5a7d20359
6
+ metadata.gz: d8bb1511ccb13c79d62f3be1ee11709495e17a34e2d80f8eb583b084b25c02f01479061626ed97ab7ba42021dd1056eda47dd7283581105a96ea0f7e6da82cb3
7
+ data.tar.gz: 9c465ad8be62329387be25f798cd558c711606ce35b45d029e487fe4715399f81ec69eb8bb131c9f99f146d1fbf1d981780dfb35845088d02e46430c6c101885
data/README.md CHANGED
@@ -1,32 +1,33 @@
1
1
  # Sendgrid input plugin for Embulk
2
2
 
3
- TODO: Write short description here and embulk-input-sendgrid.gemspec file.
3
+ Embulk input plugin for SendGrid stats
4
4
 
5
5
  ## Overview
6
6
 
7
7
  * **Plugin type**: input
8
- * **Resume supported**: yes
9
- * **Cleanup supported**: yes
8
+ * **Resume supported**: no
9
+ * **Cleanup supported**: no
10
10
  * **Guess supported**: no
11
11
 
12
12
  ## Configuration
13
13
 
14
- - **option1**: description (integer, required)
15
- - **option2**: description (string, default: `"myvalue"`)
16
- - **option3**: description (string, default: `null`)
14
+ - **api_key**: SendGrid API Key that requires Stats read permission (string, required)
15
+ - **start_date**: Start date for loading data, e.g. 2020-01-01(string, required)
16
+ - **end_date**: End date for loading data, e.g. 2020-02-01 (string, default: `today`)
17
17
 
18
18
  ## Example
19
19
 
20
20
  ```yaml
21
21
  in:
22
22
  type: sendgrid
23
- option1: example1
24
- option2: example2
23
+ api_key: YourAPIKey
24
+ start_date: 2020-01-01
25
+ end_date: 2020-02-01
25
26
  ```
26
27
 
27
28
 
28
29
  ## Build
29
30
 
30
31
  ```
31
- $ rake
32
+ $ rake build
32
33
  ```
@@ -1,13 +1,13 @@
1
1
 
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "embulk-input-sendgrid"
4
- spec.version = "0.1.1"
5
- spec.authors = [""]
4
+ spec.version = "0.1.2"
5
+ spec.authors = ["kaacun"]
6
6
  spec.summary = "Sendgrid input plugin for Embulk"
7
7
  spec.description = "Loads records from Sendgrid."
8
8
  spec.email = [""]
9
9
  spec.licenses = ["MIT"]
10
- # TODO set this: spec.homepage = "https://github.com//embulk-input-sendgrid"
10
+ spec.homepage = "https://github.com/kaacun/embulk-input-sendgrid"
11
11
 
12
12
  spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
13
13
  spec.test_files = spec.files.grep(%r{^(test|spec)/})
@@ -1,6 +1,5 @@
1
1
  module Embulk
2
2
  module Input
3
-
4
3
  require 'json'
5
4
  require 'rest-client'
6
5
 
@@ -11,7 +10,7 @@ module Embulk
11
10
  task = {
12
11
  api_key: config.param(:api_key, :string),
13
12
  start_date: config.param(:start_date, :string),
14
- end_date: config.param(:end_date, :string, default: '')
13
+ end_date: config.param(:end_date, :string, default: 'today')
15
14
  }
16
15
 
17
16
  columns = [
@@ -32,7 +31,7 @@ module Embulk
32
31
  Column.new(14, 'unique_clicks', :long),
33
32
  Column.new(15, 'unique_opens', :long),
34
33
  Column.new(16, 'unsubscribe_drops', :long),
35
- Column.new(17, 'unsubscribes', :long),
34
+ Column.new(17, 'unsubscribes', :long)
36
35
  ]
37
36
 
38
37
  resume(task, columns, 1, &control)
@@ -48,11 +47,12 @@ module Embulk
48
47
  def run
49
48
  max_category_limit = 100
50
49
 
51
- date = Date.parse(@task[:start_date])
52
- end_date = @task[:end_date] != "" ? Date.parse(@task[:end_date]) : Date.today
50
+ date = @task[:start_date] == 'today' ? Date.today : Date.parse(@task[:start_date])
51
+ end_date = @task[:end_date] == 'today' ? Date.today : Date.parse(@task[:end_date])
52
+ endpoint = 'https://api.sendgrid.com/v3/categories/stats/sums'
53
53
 
54
- while date <= end_date do
55
- json = RestClient.get("https://api.sendgrid.com/v3/categories/stats/sums?start_date=#{date.strftime("%Y-%m-%d")}&limit=#{max_category_limit}", {:Authorization => "Bearer #{@task[:api_key]}", :content_type => 'application/json'})
54
+ while date <= end_date
55
+ json = RestClient.get(endpoint, { params: { start_date: date.strftime("%Y-%m-%d"), limit: max_category_limit }, Authorization: "Bearer #{@task[:api_key]}", content_type: 'application/json' })
56
56
  results = JSON.parse(json)
57
57
 
58
58
  results["stats"].each do |metrics|
@@ -66,6 +66,5 @@ module Embulk
66
66
  {}
67
67
  end
68
68
  end
69
-
70
69
  end
71
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-sendgrid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
- - ''
7
+ - kaacun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-07 00:00:00.000000000 Z
11
+ date: 2020-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -85,7 +85,7 @@ files:
85
85
  - example/Gemfile.lock
86
86
  - example/example.yml
87
87
  - lib/embulk/input/sendgrid.rb
88
- homepage:
88
+ homepage: https://github.com/kaacun/embulk-input-sendgrid
89
89
  licenses:
90
90
  - MIT
91
91
  metadata: {}