qa_cube 0.0.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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -0
  3. data/lib/.gitignore +1 -0
  4. data/lib/appender.rb +55 -0
  5. metadata +47 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f9479a987207443d81225908394762ebc83f4b4b
4
+ data.tar.gz: af94890d6bfb8e5774f14168bb27cf92df966199
5
+ SHA512:
6
+ metadata.gz: 24b04b352c9fb7649e54dfc6cc22f0c87880acb4c3d75a608fd0737259e2905a43b7d7a0298c1c18ed102be67de00882dc04d3c0a7052895bc1df9cd319c2ff9
7
+ data.tar.gz: d264715d6e7a66c45837bb6bdcc228dad4f7bd5349fc7daea8876a5939d56fab6b8bd526da564f559020761488a47c2ca9cae206976c02082078af049323dc21
data/LICENSE ADDED
@@ -0,0 +1 @@
1
+ Since this code is mostly from Google's developer examples, it falls under https://opensource.google.com/docs/thirdparty/licenses/#GoogleAuthoredCode . Anything I've added on top of it is "public domain/free for any use".
data/lib/.gitignore ADDED
@@ -0,0 +1 @@
1
+ client_secret.json
data/lib/appender.rb ADDED
@@ -0,0 +1,55 @@
1
+ require "qa_cube/version"
2
+ require 'google/apis/sheets_v4'
3
+ require 'googleauth'
4
+ require 'googleauth/stores/file_token_store'
5
+
6
+ require 'fileutils'
7
+
8
+
9
+ module QACube
10
+ class SheetsAppender
11
+
12
+ OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'
13
+ APPLICATION_NAME = 'Google Sheets API Test Result Appender'
14
+ CREDENTIALS_PATH = File.join(Dir.home, '.credentials','sheetsappender.yaml')
15
+ SCOPE = Google::Apis::SheetsV4::AUTH_SPREADSHEETS
16
+
17
+ def initialize(sheet_name:, spreadsheet_id:, range:, verbose: nil, client_secrets_path:)
18
+ @verbose ||= verbose
19
+ if @verbose.nil?
20
+ @verbose = false
21
+ end
22
+ @client_secrets_path = client_secrets_path
23
+ @service = Google::Apis::SheetsV4::SheetsService.new
24
+ @service.authorization = authorize
25
+ @spreadsheet_id = spreadsheet_id
26
+ @sheet_name = sheet_name
27
+ @range = "\'#{sheet_name}\'!#{range}"
28
+ end
29
+
30
+ def append(values:)
31
+ request_body = Google::Apis::SheetsV4::ValueRange.new({values: values})
32
+ response = @service.append_spreadsheet_value(@spreadsheet_id, @range, request_body, value_input_option: "USER_ENTERED")
33
+ if @verbose
34
+ puts response.to_json
35
+ end
36
+ end
37
+
38
+ def authorize
39
+ FileUtils.mkdir_p(File.dirname(CREDENTIALS_PATH))
40
+ client_id = Google::Auth::ClientId.from_file(@client_secrets_path)
41
+ token_store = Google::Auth::Stores::FileTokenStore.new(file: CREDENTIALS_PATH)
42
+ authorizer = Google::Auth::UserAuthorizer.new(client_id, SCOPE, token_store)
43
+ user_id = 'default'
44
+ credentials = authorizer.get_credentials(user_id)
45
+ if credentials.nil?
46
+ url = authorizer.get_authorization_url(base_url: OOB_URI)
47
+ puts "First time auth URL"
48
+ puts url
49
+ code = gets
50
+ credentials = authorizer.get_and_store_credentials_from_code(user_id: user_id, code: code, base_url: OOB_URI)
51
+ end
52
+ credentials
53
+ end
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qa_cube
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bennett Talpers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Allows a user to easily append data to a Google Sheets sheet.
14
+ email:
15
+ - bennett.talpers@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE
21
+ - lib/.gitignore
22
+ - lib/appender.rb
23
+ homepage: ''
24
+ licenses: []
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.5.1
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Code taken from the examples found on https://developers.google.com/sheets/api/samples
46
+ and parameterized, so it can be plugged-in easily to automated QA projects.
47
+ test_files: []