embulk-input-search_analytics 0.1.0
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 +7 -0
- data/.gitignore +7 -0
- data/.ruby-version +1 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +3 -0
- data/embulk-input-search_analytics.gemspec +21 -0
- data/examples/query.yml +19 -0
- data/lib/embulk/input/search_analytics.rb +8 -0
- data/lib/embulk/input/search_analytics/client.rb +63 -0
- data/lib/embulk/input/search_analytics/plugin.rb +63 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 73e29aa45ba4083290b9c07f2d30e938878ead246c22ad51825c6379c74b8f39
|
4
|
+
data.tar.gz: 9f179b0334a8c9c03e5420ff799ab3776ea9a5f86356aa43de70557629818556
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3962974f98d526db4d4bc005b9fbf2a6deaed2bdfca093ba4efe6b00816a12743160c37a0cdc04a902c3bc81115d522eddcc2e08ce35fe1906491050675feb27
|
7
|
+
data.tar.gz: 6ffb2eb04c64b7b85645ad9246be23d41bd404d7b298c3fdc2dda0fa3815ac4b360bd5af5aabc1d682f8c61d46967d7cbafb29d9726d06b072f9bd9de72acc63
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jruby-9.1.13.0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
MIT License
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Search Analytics input plugin for Embulk
|
2
|
+
|
3
|
+
Embulk input plugin for Google Search Analytics.
|
4
|
+
|
5
|
+
## Overview
|
6
|
+
* **Plugin type**: input
|
7
|
+
* **Resume supported**: no
|
8
|
+
* **Cleanup supported**: no
|
9
|
+
* **Guess supported**: no
|
10
|
+
|
11
|
+
## Configuration
|
12
|
+
|
13
|
+
- **client_id**: authentication (string, required)
|
14
|
+
- **client_secret**: authentication (string, required)
|
15
|
+
- **refresh_token**: authentication (string, required)
|
16
|
+
- **site_url**: Site URL for target data
|
17
|
+
- **start_date**: Target report start date. Valid format is "YYYY-MM-DD" (string, required)
|
18
|
+
- **end_date**: Target report end date. Valid format is "YYYY-MM-DD" (string, required)
|
19
|
+
- **dimensions**: Target dimensions (array, required)
|
20
|
+
- **dimension_filter_groups**: Target dimension filter groups, see example. (array, default: nil)
|
21
|
+
- **search_type**: Target search type, (string, default: web)
|
22
|
+
- **row_limit**: Target row limit, (integer, default: 5000)
|
23
|
+
|
24
|
+
## Example
|
25
|
+
|
26
|
+
```yaml
|
27
|
+
in:
|
28
|
+
type: search_analytics
|
29
|
+
client_id: xxxxxxx.apps.googleusercontent.com
|
30
|
+
client_secret: xxxxxxxxxx
|
31
|
+
refresh_token: 1/xxxxxxxxxx
|
32
|
+
site_url: https://sem-technology.info/
|
33
|
+
start_date: 2017-12-01
|
34
|
+
end_date: 2017-12-01
|
35
|
+
dimensions:
|
36
|
+
- query
|
37
|
+
- device
|
38
|
+
dimension_filter_groups:
|
39
|
+
- group_type: and
|
40
|
+
filters:
|
41
|
+
- dimension: country
|
42
|
+
operator: equals
|
43
|
+
expression: jpn
|
44
|
+
```
|
45
|
+
|
46
|
+
|
47
|
+
## Build
|
48
|
+
|
49
|
+
```
|
50
|
+
$ rake
|
51
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
Gem::Specification.new do |spec|
|
3
|
+
spec.name = "embulk-input-search_analytics"
|
4
|
+
spec.version = "0.1.0"
|
5
|
+
spec.authors = ["ryota.yamada"]
|
6
|
+
spec.summary = "Search Analytics input plugin for Embulk"
|
7
|
+
spec.description = "Loads records from Search Analytics."
|
8
|
+
spec.email = ["1987yama3@gmail.com"]
|
9
|
+
spec.licenses = ["MIT"]
|
10
|
+
spec.homepage = "https://github.com/sem-technology/embulk-input-search_analytics"
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
|
13
|
+
spec.test_files = spec.files.grep(%r{^(test|spec)/})
|
14
|
+
spec.require_paths = ["lib"]
|
15
|
+
|
16
|
+
spec.add_dependency "signet"
|
17
|
+
spec.add_dependency "google-api-client", "~> 0.9.11"
|
18
|
+
spec.add_development_dependency 'embulk', ['>= 0.8.38']
|
19
|
+
spec.add_development_dependency 'bundler', ['>= 1.10.6']
|
20
|
+
spec.add_development_dependency 'rake', ['>= 10.0']
|
21
|
+
end
|
data/examples/query.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
in:
|
2
|
+
type: search_analytics
|
3
|
+
client_id: xxxxxxx.apps.googleusercontent.com
|
4
|
+
client_secret: xxxxxxxxxx
|
5
|
+
refresh_token: 1/xxxxxxxxxx
|
6
|
+
site_url: https://sem-technology.info/
|
7
|
+
start_date: 2017-12-01
|
8
|
+
end_date: 2017-12-01
|
9
|
+
dimensions:
|
10
|
+
- query
|
11
|
+
- device
|
12
|
+
dimension_filter_groups:
|
13
|
+
- group_type: and
|
14
|
+
filters:
|
15
|
+
- dimension: country
|
16
|
+
operator: equals
|
17
|
+
expression: jpn
|
18
|
+
out:
|
19
|
+
type: stdout
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'google/apis/webmasters_v3'
|
2
|
+
module Embulk
|
3
|
+
module Input
|
4
|
+
module SearchAnalytics
|
5
|
+
class Client
|
6
|
+
def initialize(task, is_preview = false)
|
7
|
+
@task = task
|
8
|
+
@is_preview = is_preview
|
9
|
+
end
|
10
|
+
|
11
|
+
def invoke
|
12
|
+
response = []
|
13
|
+
start_row = 0
|
14
|
+
loop do
|
15
|
+
response << self.query(@task["site_url"], {
|
16
|
+
:row_limit => @task["row_limit"],
|
17
|
+
:dimensions => @task["dimensions"],
|
18
|
+
:dimension_filter_groups => @task["dimension_filter_groups"],
|
19
|
+
:search_type => @task["search_type"],
|
20
|
+
:start_date => @task["start_date"],
|
21
|
+
:end_date => @task["end_date"],
|
22
|
+
:start_row => start_row,
|
23
|
+
})
|
24
|
+
break if response.last.length < @task["row_limit"]
|
25
|
+
start_row += @task["row_limit"]
|
26
|
+
end
|
27
|
+
response.flatten
|
28
|
+
end
|
29
|
+
|
30
|
+
def query(site_url, params)
|
31
|
+
unless params[:dimension_filter_groups].nil?
|
32
|
+
params[:dimension_filter_groups] = JSON.parse(params[:dimension_filter_groups].to_json, symbolize_names: true)
|
33
|
+
end
|
34
|
+
self.service.query_search_analytics(site_url, params, {}).rows.collect do |row|
|
35
|
+
item = {}
|
36
|
+
@task["dimensions"].each_with_index do |dim, idx|
|
37
|
+
item[dim] = row.keys[idx]
|
38
|
+
end
|
39
|
+
item["clicks"] = row.clicks.to_i
|
40
|
+
item["impressions"] = row.impressions.to_i
|
41
|
+
item["ctr"] = row.ctr.to_f
|
42
|
+
item["position"] = row.position.to_f
|
43
|
+
item
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def service
|
48
|
+
webmasters_service = ::Google::Apis::WebmastersV3::WebmastersService.new
|
49
|
+
webmasters_service.authorization = Signet::OAuth2::Client.new({
|
50
|
+
:token_credential_uri => @task["token_credential_uri"],
|
51
|
+
:audience => @task["audience"],
|
52
|
+
:client_id => @task["client_id"],
|
53
|
+
:client_secret => @task["client_secret"],
|
54
|
+
:refresh_token => @task["refresh_token"],
|
55
|
+
:scope => @task["scope"],
|
56
|
+
})
|
57
|
+
webmasters_service.authorization.fetch_access_token!
|
58
|
+
webmasters_service
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Embulk
|
2
|
+
module Input
|
3
|
+
module SearchAnalytics
|
4
|
+
class Plugin < InputPlugin
|
5
|
+
::Embulk::Plugin.register_input("search_analytics", self)
|
6
|
+
|
7
|
+
def self.transaction(config, &control)
|
8
|
+
task = {
|
9
|
+
# API Authorize Parameters
|
10
|
+
"token_credential_uri" => "https://accounts.google.com/o/oauth2/token",
|
11
|
+
"audience" => "https://accounts.google.com/o/oauth2/token",
|
12
|
+
"client_id" => config.param("client_id", :string),
|
13
|
+
"client_secret" => config.param("client_secret", :string),
|
14
|
+
"refresh_token" => config.param("refresh_token", :string),
|
15
|
+
"scope" => "https://www.googleapis.com/auth/webmasters.readonly",
|
16
|
+
|
17
|
+
# API Request Parameters
|
18
|
+
"site_url" => config.param("site_url", :string),
|
19
|
+
"start_date" => config.param("start_date", :string),
|
20
|
+
"end_date" => config.param("end_date", :string),
|
21
|
+
"dimensions" => config.param("dimensions", :array),
|
22
|
+
"dimension_filter_groups" => config.param("dimension_filter_groups", :array, default: nil),
|
23
|
+
"search_type" => config.param("search_type", :string, default: "web"),
|
24
|
+
"row_limit" => config.param("row_limit", :integer, default: 5000),
|
25
|
+
}
|
26
|
+
columns = columns_from_task(task)
|
27
|
+
resume(task, columns, 1, &control)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.resume(task, columns, count, &control)
|
31
|
+
task_reports = yield(task, columns, count)
|
32
|
+
|
33
|
+
next_config_diff = {}
|
34
|
+
return next_config_diff
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.columns_from_task(task)
|
38
|
+
columns = task["dimensions"].map{|dimension|
|
39
|
+
Column.new(nil, dimension, :string)
|
40
|
+
}
|
41
|
+
columns << Column.new(nil, "clicks", :long)
|
42
|
+
columns << Column.new(nil, "impressions", :long)
|
43
|
+
columns << Column.new(nil, "ctr", :double)
|
44
|
+
columns << Column.new(nil, "position", :double)
|
45
|
+
columns
|
46
|
+
end
|
47
|
+
|
48
|
+
def init
|
49
|
+
end
|
50
|
+
|
51
|
+
def run
|
52
|
+
columns = self.class.columns_from_task(task)
|
53
|
+
Client.new(task, @is_preview).invoke.each do |row|
|
54
|
+
@page_builder.add columns.map{|col| row[col.name]}
|
55
|
+
end
|
56
|
+
@page_builder.finish
|
57
|
+
task_report = {}
|
58
|
+
task_report
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: embulk-input-search_analytics
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ryota.yamada
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
name: signet
|
20
|
+
prerelease: false
|
21
|
+
type: :runtime
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.9.11
|
33
|
+
name: google-api-client
|
34
|
+
prerelease: false
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.11
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.8.38
|
47
|
+
name: embulk
|
48
|
+
prerelease: false
|
49
|
+
type: :development
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.8.38
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.10.6
|
61
|
+
name: bundler
|
62
|
+
prerelease: false
|
63
|
+
type: :development
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.10.6
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
name: rake
|
76
|
+
prerelease: false
|
77
|
+
type: :development
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description: Loads records from Search Analytics.
|
84
|
+
email:
|
85
|
+
- 1987yama3@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".ruby-version"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- embulk-input-search_analytics.gemspec
|
97
|
+
- examples/query.yml
|
98
|
+
- lib/embulk/input/search_analytics.rb
|
99
|
+
- lib/embulk/input/search_analytics/client.rb
|
100
|
+
- lib/embulk/input/search_analytics/plugin.rb
|
101
|
+
homepage: https://github.com/sem-technology/embulk-input-search_analytics
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.6.13
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Search Analytics input plugin for Embulk
|
125
|
+
test_files: []
|