goo 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7f550149c1346e71351e1b8956bd0758171d0112
4
+ data.tar.gz: 7696ef0ed7c08eb31aef0c48d8d379ee7a28549d
5
+ SHA512:
6
+ metadata.gz: 1b0d1dde91139e556dd5384d439d3a9561df2634a50f83e86b19d00fd16e8a11107febeb14b15f029c8e0f17f42636221cef5c9433a7836bea2677a664363ed9
7
+ data.tar.gz: dad192d94611f3ce567632adf4bd7ed5beedd545c376304e630c7f1d259dbc066071102b2347545772e7100fa8037e49c0d44e76cc232157a1c0ed185b61b192
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at shemusok@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in goo.gemspec
4
+ gemspec
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2016 shemusok@gmail.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # goo - tiny command line Google API client
2
+
3
+ ## Installation
4
+
5
+ ```bash
6
+ $ git clone git@github.com:shemusok/goo.git
7
+ $ cd ./goo && bundle install && rake install
8
+ ```
9
+
10
+ ## Usage
11
+
12
+ * Command line options help:
13
+
14
+ ```bash
15
+ $ goo help
16
+ ```
17
+
18
+ * Get api/resources/method description:
19
+
20
+ ```bash
21
+ $ goo info webmasters.sitemaps.get
22
+ ```
23
+
24
+ * Call method:
25
+
26
+ ```bash
27
+ $ goo call webmasters.sitemaps.get -p\
28
+ feedpath:'http://example.com'\
29
+ siteUrl: 'http://example.com/sitemap.xml'
30
+ ```
31
+
32
+ call **reply** will be printed as **YAML** to **STDOUT**
33
+
34
+ ## Environment
35
+ * **$GOO_EMAIL** or **-e** option - app service email
36
+ * **$GOO_P12KEYFILE** or **-k** option - P12 key file path
37
+
38
+ ## Development
39
+
40
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+
42
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/shemusok/goo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "goo"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/goo ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require 'goo/cli/exe'
5
+
6
+ Goo::CLI::Exe.start
data/goo ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require 'goo/cli/exe'
5
+
6
+ Goo::CLI::Exe.start
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'goo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "goo"
8
+ spec.version = Goo::VERSION
9
+ spec.authors = ["Shem Ming"]
10
+ spec.email = ["shemusok@gmail.com"]
11
+
12
+ spec.summary = %q{tiny command line Google API client.}
13
+ spec.description = %q{Just 4 fun.}
14
+ spec.homepage = "https://github.com/shemusok/goo"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ # if spec.respond_to?(:metadata)
19
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
20
+ # else
21
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ # end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.11"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+
33
+ spec.add_dependency "google-api-client", '>= 0.8', '<0.9'
34
+ spec.add_dependency "thor"
35
+ spec.add_dependency "dotenv"
36
+ end
@@ -0,0 +1,6 @@
1
+ require "goo/version"
2
+ require 'dotenv'
3
+ Dotenv.load
4
+ module Goo
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,112 @@
1
+ require 'goo/client'
2
+
3
+ require 'thor'
4
+ require 'yaml'
5
+
6
+ module Goo::CLI
7
+ class Exe < Thor
8
+ no_commands {
9
+ class_option :email, {
10
+ desc: 'service account email',
11
+ default: ENV['GOO_EMAIL'],
12
+ aliases: '-e'
13
+ }
14
+ class_option :key_file, {
15
+ desc: 'service account p12 key file',
16
+ default: ENV['GOO_P12KEYFILE'],
17
+ aliases: '-k'
18
+ }
19
+
20
+ DEFAULT_APIS = {
21
+ webmasters: {
22
+ version: 'v3',
23
+ scope: 'https://www.googleapis.com/auth/webmasters'
24
+ },
25
+ siteVerification: {
26
+ scope: 'https://www.googleapis.com/auth/siteverification'
27
+ }
28
+ }
29
+
30
+ def client
31
+ puts "email: #{options[:email]}"
32
+ puts "key_file: #{options[:key_file]}"
33
+ @client ||= Goo::Client.new(
34
+ options[:email],
35
+ options[:key_file],
36
+ DEFAULT_APIS
37
+ )
38
+ end
39
+
40
+ def say msg
41
+ puts msg
42
+ end
43
+
44
+ def show obj
45
+ puts obj.to_yaml
46
+ end
47
+ }
48
+
49
+ desc 'call [options] api.[resources.]method', 'Executes google api method'
50
+ method_option :parameters, {
51
+ type: :hash,
52
+ desc: 'api call parameters, ',
53
+ aliases: '-p'
54
+ }
55
+ def call api_method
56
+ result = client.execute api_method, options[:parameters]
57
+ show result
58
+ result
59
+ end
60
+
61
+ desc 'info [options] api.[resources.]method', 'show help for google api/resource/method'
62
+ def info string
63
+ obj = client.get_api_object string
64
+ case obj
65
+ when ::Google::APIClient::API
66
+ say "#{obj.title} #{obj.version}"
67
+ say obj.description
68
+ unless obj.discovered_resources.empty?
69
+ say "Resources:"
70
+ obj.discovered_resources.each do |r|
71
+ d = r.description
72
+ say " #{r.name}#{d ? " - #{d}" : ""}"
73
+ end
74
+ end
75
+ unless obj.discovered_methods.empty?
76
+ say "Methods:"
77
+ obj.discovered_methods.each do |m|
78
+ d = m.description
79
+ say " #{m.name}#{d ? " - #{d}" : ""}"
80
+ end
81
+ end
82
+ when ::Google::APIClient::Resource
83
+ say obj.description if obj.description
84
+ unless obj.discovered_resources.empty?
85
+ say "Resources:"
86
+ obj.discovered_resources.each do |r|
87
+ d = r.description
88
+ say " #{r.name}#{d ? " - #{d}" : ""}"
89
+ end
90
+ end
91
+ unless obj.discovered_methods.empty?
92
+ say "Methods:"
93
+ obj.discovered_methods.each do |m|
94
+ d = m.description
95
+ say " #{m.name}#{d ? " - #{d}" : ""}"
96
+ end
97
+ end
98
+ when ::Google::APIClient::Method
99
+ say obj.description if obj.description
100
+ unless obj.parameters.empty?
101
+ say "Parameters"
102
+ obj.parameter_descriptions.each do |n, p|
103
+ d = p['description']
104
+ r = p['required']
105
+ say " #{n}(#{p['type']})#{d ? " - #{d} " : " "}#{r ? "Required" : "Optional"}"
106
+ end
107
+ end
108
+ end
109
+ obj
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,81 @@
1
+ require 'goo'
2
+ require 'google/api_client'
3
+
4
+ class Goo::Client
5
+ NAME = ENV['GOO_APPNAME'] || 'goo'
6
+ VERSION = ENV['GOO_APPVERSION'] || Goo::VERSION
7
+
8
+ attr_reader :email
9
+ attr_reader :key_file
10
+ attr_reader :apis_config
11
+ def initialize email, key_file, apis_config
12
+ @email = email
13
+ @key_file = key_file
14
+ @apis_config = apis_config
15
+ end
16
+
17
+ def key
18
+ @key ||= ::Google::APIClient::KeyUtils.load_from_pkcs12 key_file, 'notasecret'
19
+ end
20
+
21
+ def auth
22
+ if @auth.nil?
23
+ @auth = Signet::OAuth2::Client.new(
24
+ :token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
25
+ :audience => 'https://accounts.google.com/o/oauth2/token',
26
+ :scope => scopes,
27
+ :issuer => email,
28
+ :signing_key => key
29
+ )
30
+ @auth.fetch_access_token!
31
+ end
32
+ @auth
33
+ end
34
+
35
+ def scopes
36
+ @scopes ||= apis_config.values.collect {|api_config| api_config[:scope]}
37
+ end
38
+
39
+ def driver
40
+ @driver ||= ::Google::APIClient.new(
41
+ application_name: NAME,
42
+ application_version: VERSION
43
+ )
44
+ end
45
+
46
+ def api name
47
+ api_config = apis_config[name.to_sym]
48
+ raise "unknown google api: #{name}" unless api_config
49
+ result = driver.discovered_api *[name, api_config[:version] ? api_config[:version] : 'v1']
50
+ unless respond_to? name
51
+ singleton_class.send :define_method, name.to_sym do
52
+ result
53
+ end
54
+ end
55
+ result
56
+ end
57
+
58
+ def get_api_object string
59
+ api_name, *other = string.split '.'
60
+ other.inject api(api_name) do |method, part|
61
+ method = method.send part.underscore
62
+ end
63
+ end
64
+
65
+ def execute string, parameters = nil
66
+ api_method = get_api_object string
67
+ options = {
68
+ api_method: api_method,
69
+ authorization: auth
70
+ }
71
+ options[:parameters] = parameters if parameters
72
+ res = driver.execute options
73
+ unless res.success?
74
+ puts "'#{string}' request failed (#{res.status})"
75
+ puts res.headers
76
+ puts res.body
77
+ return nil
78
+ end
79
+ res.data ? res.data.to_hash : nil
80
+ end
81
+ end
@@ -0,0 +1,3 @@
1
+ module Goo
2
+ VERSION = "0.1.2"
3
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: goo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Shem Ming
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: google-api-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '0.9'
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0.8'
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '0.9'
75
+ - !ruby/object:Gem::Dependency
76
+ name: thor
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: dotenv
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ description: Just 4 fun.
104
+ email:
105
+ - shemusok@gmail.com
106
+ executables:
107
+ - goo
108
+ extensions: []
109
+ extra_rdoc_files: []
110
+ files:
111
+ - ".gitignore"
112
+ - ".rspec"
113
+ - ".travis.yml"
114
+ - CODE_OF_CONDUCT.md
115
+ - Gemfile
116
+ - LICENSE.md
117
+ - README.md
118
+ - Rakefile
119
+ - bin/console
120
+ - bin/setup
121
+ - exe/goo
122
+ - goo
123
+ - goo.gemspec
124
+ - lib/goo.rb
125
+ - lib/goo/cli/exe.rb
126
+ - lib/goo/client.rb
127
+ - lib/goo/version.rb
128
+ homepage: https://github.com/shemusok/goo
129
+ licenses: []
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.4.8
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: tiny command line Google API client.
151
+ test_files: []