gaapi 0.2.0 → 0.2.1

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
  SHA256:
3
- metadata.gz: ffff326579e103303525b129d3befd2c26304126a20bb7c1f3f54b1aa6d0c7bd
4
- data.tar.gz: cef8c48c415155959499cb1c8faec0a422c8cb592ef4159fba906afcbeb47297
3
+ metadata.gz: 6c7d609f4d8f0c6c08af4d55afaf5f0b55f29f04ee94cd5d8b3acad4cbcbd8c2
4
+ data.tar.gz: d3c177187c100d3eeb148250be4369cfe1bcd93fc757f9549b6e25bc793a304f
5
5
  SHA512:
6
- metadata.gz: edf53d316f4c32fadddf748770779f6ab56dd26192b2a3683d42c938e63ae79f2310460cbc7aa87bae516d7ae8fe3166093c5933907ab786e7573cca476eef0d
7
- data.tar.gz: 5d67cb658c49b4b883cf75c09d0fb08089d1662ff40ed1a11adfa2e50c0a4bc79299f150f0876e1009a22fe9e8c4b5376db87c06dec7be02b7cd004567a74691
6
+ metadata.gz: e35b82cfa37eccb1381b79c074898311d2510e99afa6a19b57d83ff2a4c3e967eec516ada71c740afe8620113cfd54ee1b05910f921cdbb55cc58d2b6c3c08fd
7
+ data.tar.gz: 24806c984d60d18cec432a8f9858f6badf6882ea4ab08679256111abcbf082f83713de296662cf694237f2d8c95742d23366c834a24eacd213ece72ce676df16
data/bin/gaapi CHANGED
@@ -4,5 +4,4 @@
4
4
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")
5
5
  require "gaapi"
6
6
 
7
- GAAPI::Main.call
8
- # FIXME: This doesn't seem to return the status to the shell the way we want.
7
+ exit GAAPI::Main.call
@@ -4,12 +4,15 @@ module GAAPI
4
4
  # An access token generated from a credential file provided by Google Analystics.
5
5
  # The credential file is suitable for using in applications where humans aren't
6
6
  # involved, such as scheduled jobs. To obtain a credential file, follow the instructions
7
- # at https://developers.google.com/identity/protocols/OAuth2ServiceAccount.
7
+ # at https://developers.google.com/identity/protocols/OAuth2ServiceAccount.
8
8
  class AccessToken
9
9
  # Get a new access token. The actual token is lazily-generated, so no call is
10
- # made to Google Analytics until #token is called.
10
+ # made to Google Analytics until {#token} is called.
11
11
  # @param credential_file [String] File name of a credential file provided by
12
- # Google Analytics.
12
+ # Google Analytics. If `credential_file` is missing or `nil`, this method
13
+ # looks for credentials in `~/.gaapi/ga-api-key`.
14
+ # @raise [StandardError] Throws an exception if the credential file is readable
15
+ # or writable by other than the current user.
13
16
  def initialize(credential_file = nil)
14
17
  @credential_file = credential_file || File.expand_path("~/.gaapi/ga-api-key")
15
18
  stat = File::Stat.new(@credential_file)
data/lib/gaapi/main.rb CHANGED
@@ -7,7 +7,7 @@ module GAAPI
7
7
  class << self
8
8
  def call
9
9
  begin
10
- return 1 if (options = process_options).nil?
10
+ return false if (options = process_options).nil?
11
11
 
12
12
  puts "options: #{options.inspect}" if options[:debug]
13
13
 
@@ -20,10 +20,10 @@ module GAAPI
20
20
  puts "query: #{query.inspect}" if options[:debug]
21
21
  rescue StandardError => e
22
22
  $stderr.puts e.message # rubocop:disable Style/StderrPuts
23
- return 1
23
+ return false
24
24
  end
25
25
 
26
- return 0 if options[:dry_run]
26
+ return true if options[:dry_run]
27
27
 
28
28
  result = query.execute
29
29
  puts "result: #{result.inspect}" if options[:debug]
@@ -32,7 +32,7 @@ module GAAPI
32
32
  # Show the output unformatted, because we don't know what we're going
33
33
  # to get back.
34
34
  puts result.body
35
- return 1
35
+ return false
36
36
  end
37
37
 
38
38
  case options[:output_format]
@@ -42,7 +42,7 @@ module GAAPI
42
42
  puts result.pp
43
43
  end
44
44
 
45
- 0
45
+ true
46
46
  end
47
47
 
48
48
  def process_options
@@ -76,7 +76,7 @@ module GAAPI
76
76
  opts.on("-e",
77
77
  "--end-date END_DATE",
78
78
  Date,
79
- "Report including END_DATE.") do |end_date|
79
+ "Report including END_DATE (yyyy-mm-dd).") do |end_date|
80
80
  options[:end_date] = end_date
81
81
  end
82
82
 
@@ -93,7 +93,7 @@ module GAAPI
93
93
  opts.on("-s",
94
94
  "--start-date START_DATE",
95
95
  Date,
96
- "Report including START_DATE.") do |start_date|
96
+ "Report including START_DATE (yyyy-mm-dd).") do |start_date|
97
97
  options[:start_date] = start_date
98
98
  end
99
99
  end
data/lib/gaapi/query.rb CHANGED
@@ -14,7 +14,7 @@ module GAAPI
14
14
  # @param view_id [String] The view ID of the property for which to submit the
15
15
  # query.
16
16
  def initialize(query_string, view_id, access_token, start_date, end_date)
17
- @access_token = access_token
17
+ @access_token = access_token.to_s
18
18
  query_string = JSON.parse(query_string) unless query_string.is_a?(Hash)
19
19
  @query = {}
20
20
  @query["reportRequests"] = query_string["reportRequests"].map do |report_request|
@@ -29,7 +29,7 @@ module GAAPI
29
29
  end
30
30
 
31
31
  # Send the requested query to Google Analytics and return the response.
32
- # @return [HTTPResponse] The response from the request.
32
+ # @return [GAAPI::Response] The response from the request.
33
33
  def execute
34
34
  uri = URI.parse("https://analyticsreporting.googleapis.com/v4/reports:batchGet")
35
35
  https = Net::HTTP.new(uri.host, uri.port)
@@ -7,11 +7,13 @@ module GAAPI
7
7
  attr_reader :response
8
8
 
9
9
  # Raw body of the response. Typically only used for diagnostic purposes.
10
+ # @return [String] The unformatted body of the response.
10
11
  def body
11
12
  response.body
12
13
  end
13
14
 
14
- # Raw code of the response. Typically only used for diagnostic purposes.
15
+ # Raw HTTP status code of the response. Typically only used for diagnostic purposes.
16
+ # @return [String] The HTTP response code.
15
17
  def code
16
18
  response.code
17
19
  end
data/lib/gaapi/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GAAPI
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gaapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Larry Reid