ga-shikomi 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/ga_shikomi.gemspec +1 -1
- data/lib/ga_shikomi/api.rb +42 -11
- data/lib/ga_shikomi/env_store.rb +25 -0
- data/lib/ga_shikomi/version.rb +1 -1
- metadata +31 -24
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
Yjg2MDZlMjc5M2M3OTM3Y2YyZDEwY2VkMDYwZDA4NTc3ZmUyOWY2YQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aefa66eed695aeebed4c52f2aa4fcfb2ea7ba535
|
4
|
+
data.tar.gz: f67aabae92c5059be40011dc4b7c778ce89134ec
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MmJiNzY5MDYzNzRmMzk2MjY5NTAyZDEyNmM5YzhmNGJhMTA2YmZjMzBjZGI4
|
11
|
-
ZjY4YzYxODUwODVmZGMxYjA5ZjBmN2MxMWQ3ZjYxMWQ5NDI1MWE=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NWYxOTA2ZWFhM2UyYzIwM2Q5NjUxODEzMDM1ZmZiY2NmMmEzYzhhODk0MDFh
|
14
|
-
ODVkY2IwZTljZjc5NjkyN2E3YTJhMDgxMTYxOWY3YTAyOTZhZWJiMDU1OGJm
|
15
|
-
OTBhYWMxOTNiNDNkNWUyZTMzY2NhMmI4NGEwNDA4MTZlOGU2MzQ=
|
6
|
+
metadata.gz: f442d95ccac518787f6b235fc30c8ca596be7368c0a743af5f863615b14da616682d3afe97b33be9d21cbcbfcee4152a785cda5c8a5aa19cf13fcde832111ba0
|
7
|
+
data.tar.gz: f27d1ecde593533849ed0ff3db2128f2c3608fc9d54056bae7f07010e5d78df68a3b6630154be307577bed4a212ae5c74add467f33da536ad72a5943283e7124
|
data/ga_shikomi.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_runtime_dependency "google-api-client"
|
21
|
+
spec.add_runtime_dependency "google-api-client", ">= 0.8.6", "< 0.9"
|
22
22
|
spec.add_runtime_dependency "thor"
|
23
23
|
spec.add_runtime_dependency "hirb"
|
24
24
|
|
data/lib/ga_shikomi/api.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require 'google/api_client'
|
2
3
|
require 'google/api_client/client_secrets'
|
3
4
|
require 'google/api_client/auth/installed_app'
|
@@ -8,6 +9,8 @@ module GAShikomi
|
|
8
9
|
class Api
|
9
10
|
class InexpectantResponse < StandardError; end
|
10
11
|
|
12
|
+
GOOGLE_API_KEYS = %w(GOOGLE_API_CREDENTIAL GOOGLE_API_SECRETS)
|
13
|
+
|
11
14
|
#
|
12
15
|
# [param] String store
|
13
16
|
#
|
@@ -20,31 +23,59 @@ module GAShikomi
|
|
20
23
|
end
|
21
24
|
attr_reader :client, :analytics, :last_request
|
22
25
|
|
26
|
+
def init_and_auth_analytics(store)
|
27
|
+
init_client
|
28
|
+
|
29
|
+
if GOOGLE_API_KEYS.all? {|e| ENV.has_key? e}
|
30
|
+
init_and_auth_with_env
|
31
|
+
else
|
32
|
+
init_and_auth_with_file_storage(store)
|
33
|
+
end
|
34
|
+
|
35
|
+
@analytics = client.discovered_api('analytics', 'v3')
|
36
|
+
end
|
37
|
+
|
38
|
+
def init_and_auth_with_env
|
39
|
+
credential = ::Google::APIClient::Storage.new(EnvStore.new(ENV))
|
40
|
+
credential.authorize
|
41
|
+
secrets = ::Google::APIClient::ClientSecrets.new(JSON.parse(ENV['GOOGLE_API_SECRETS']))
|
42
|
+
|
43
|
+
client.authorization = credential.authorization
|
44
|
+
end
|
45
|
+
|
23
46
|
#
|
24
47
|
# [param] String store
|
25
48
|
#
|
26
|
-
def
|
27
|
-
@client = ::Google::APIClient.new(
|
28
|
-
:application_name => :gacli,
|
29
|
-
:application_version => VERSION)
|
30
|
-
|
49
|
+
def init_and_auth_with_file_storage(store)
|
31
50
|
credential = ::Google::APIClient::FileStorage.new(store)
|
32
51
|
secrets = ::Google::APIClient::ClientSecrets.load(File.dirname(store))
|
33
52
|
|
34
53
|
if credential.authorization.nil?
|
35
|
-
flow =
|
36
|
-
:client_id => secrets.client_id,
|
37
|
-
:client_secret => secrets.client_secret,
|
38
|
-
:scope => ['https://www.googleapis.com/auth/analytics',
|
39
|
-
'https://www.googleapis.com/auth/analytics.edit'])
|
54
|
+
flow = flow(secrets)
|
40
55
|
|
41
56
|
client.authorization = flow.authorize
|
42
57
|
credential.write_credentials(client.authorization)
|
43
58
|
else
|
44
59
|
client.authorization = credential.authorization
|
45
60
|
end
|
61
|
+
end
|
46
62
|
|
47
|
-
|
63
|
+
def init_client
|
64
|
+
@client = ::Google::APIClient.new(
|
65
|
+
:application_name => :gacli,
|
66
|
+
:application_version => VERSION)
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# [param] Google::APIClient::ClientSecrets
|
71
|
+
# [return] Google::APIClient::InstalledAppFlow
|
72
|
+
#
|
73
|
+
def flow(secrets)
|
74
|
+
::Google::APIClient::InstalledAppFlow.new(
|
75
|
+
:client_id => secrets.client_id,
|
76
|
+
:client_secret => secrets.client_secret,
|
77
|
+
:scope => ['https://www.googleapis.com/auth/analytics',
|
78
|
+
'https://www.googleapis.com/auth/analytics.edit'])
|
48
79
|
end
|
49
80
|
|
50
81
|
#
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
class EnvStore
|
4
|
+
#
|
5
|
+
# [param] Hash env
|
6
|
+
#
|
7
|
+
def initialize(env)
|
8
|
+
@env = env
|
9
|
+
end
|
10
|
+
|
11
|
+
#
|
12
|
+
# [return] Hash
|
13
|
+
#
|
14
|
+
def load_credentials
|
15
|
+
JSON.parse(@env['GOOGLE_API_CREDENTIAL'])
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# [param] Hash credentials_hash
|
20
|
+
# [return] Hash
|
21
|
+
#
|
22
|
+
def write_credentials(credentials_hash)
|
23
|
+
credentials_hash
|
24
|
+
end
|
25
|
+
end
|
data/lib/ga_shikomi/version.rb
CHANGED
metadata
CHANGED
@@ -1,125 +1,131 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ga-shikomi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wtnabe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-api-client
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.8.6
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0.9'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
29
|
+
version: 0.8.6
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.9'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: thor
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
|
-
- -
|
37
|
+
- - ">="
|
32
38
|
- !ruby/object:Gem::Version
|
33
39
|
version: '0'
|
34
40
|
type: :runtime
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
|
-
- -
|
44
|
+
- - ">="
|
39
45
|
- !ruby/object:Gem::Version
|
40
46
|
version: '0'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: hirb
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
|
-
- -
|
51
|
+
- - ">="
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '0'
|
48
54
|
type: :runtime
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
|
-
- -
|
58
|
+
- - ">="
|
53
59
|
- !ruby/object:Gem::Version
|
54
60
|
version: '0'
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: bundler
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
|
-
- - ~>
|
65
|
+
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
67
|
version: '1.7'
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
|
-
- - ~>
|
72
|
+
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
74
|
version: '1.7'
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
76
|
name: rake
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
72
78
|
requirements:
|
73
|
-
- - ~>
|
79
|
+
- - "~>"
|
74
80
|
- !ruby/object:Gem::Version
|
75
81
|
version: '10.0'
|
76
82
|
type: :development
|
77
83
|
prerelease: false
|
78
84
|
version_requirements: !ruby/object:Gem::Requirement
|
79
85
|
requirements:
|
80
|
-
- - ~>
|
86
|
+
- - "~>"
|
81
87
|
- !ruby/object:Gem::Version
|
82
88
|
version: '10.0'
|
83
89
|
- !ruby/object:Gem::Dependency
|
84
90
|
name: minitest
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
|
-
- -
|
93
|
+
- - ">"
|
88
94
|
- !ruby/object:Gem::Version
|
89
95
|
version: '5'
|
90
96
|
type: :development
|
91
97
|
prerelease: false
|
92
98
|
version_requirements: !ruby/object:Gem::Requirement
|
93
99
|
requirements:
|
94
|
-
- -
|
100
|
+
- - ">"
|
95
101
|
- !ruby/object:Gem::Version
|
96
102
|
version: '5'
|
97
103
|
- !ruby/object:Gem::Dependency
|
98
104
|
name: minitest-power_assert
|
99
105
|
requirement: !ruby/object:Gem::Requirement
|
100
106
|
requirements:
|
101
|
-
- -
|
107
|
+
- - ">="
|
102
108
|
- !ruby/object:Gem::Version
|
103
109
|
version: '0'
|
104
110
|
type: :development
|
105
111
|
prerelease: false
|
106
112
|
version_requirements: !ruby/object:Gem::Requirement
|
107
113
|
requirements:
|
108
|
-
- -
|
114
|
+
- - ">="
|
109
115
|
- !ruby/object:Gem::Version
|
110
116
|
version: '0'
|
111
117
|
- !ruby/object:Gem::Dependency
|
112
118
|
name: minitest-reporters
|
113
119
|
requirement: !ruby/object:Gem::Requirement
|
114
120
|
requirements:
|
115
|
-
- -
|
121
|
+
- - ">"
|
116
122
|
- !ruby/object:Gem::Version
|
117
123
|
version: '1'
|
118
124
|
type: :development
|
119
125
|
prerelease: false
|
120
126
|
version_requirements: !ruby/object:Gem::Requirement
|
121
127
|
requirements:
|
122
|
-
- -
|
128
|
+
- - ">"
|
123
129
|
- !ruby/object:Gem::Version
|
124
130
|
version: '1'
|
125
131
|
description: Now, You can fetch general ga data.
|
@@ -130,7 +136,7 @@ executables:
|
|
130
136
|
extensions: []
|
131
137
|
extra_rdoc_files: []
|
132
138
|
files:
|
133
|
-
- .gitignore
|
139
|
+
- ".gitignore"
|
134
140
|
- Gemfile
|
135
141
|
- README.md
|
136
142
|
- Rakefile
|
@@ -140,6 +146,7 @@ files:
|
|
140
146
|
- lib/ga_shikomi/api.rb
|
141
147
|
- lib/ga_shikomi/command.rb
|
142
148
|
- lib/ga_shikomi/config.rb
|
149
|
+
- lib/ga_shikomi/env_store.rb
|
143
150
|
- lib/ga_shikomi/renderer.rb
|
144
151
|
- lib/ga_shikomi/subcommand/accounts.rb
|
145
152
|
- lib/ga_shikomi/subcommand/base.rb
|
@@ -165,17 +172,17 @@ require_paths:
|
|
165
172
|
- lib
|
166
173
|
required_ruby_version: !ruby/object:Gem::Requirement
|
167
174
|
requirements:
|
168
|
-
- -
|
175
|
+
- - ">="
|
169
176
|
- !ruby/object:Gem::Version
|
170
177
|
version: '0'
|
171
178
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
172
179
|
requirements:
|
173
|
-
- -
|
180
|
+
- - ">="
|
174
181
|
- !ruby/object:Gem::Version
|
175
182
|
version: '0'
|
176
183
|
requirements: []
|
177
184
|
rubyforge_project:
|
178
|
-
rubygems_version: 2.
|
185
|
+
rubygems_version: 2.2.2
|
179
186
|
signing_key:
|
180
187
|
specification_version: 4
|
181
188
|
summary: Google Analytics API wrapper for CLI written in Ruby.
|