google-wrapper 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fcef374be7f72c30ba09c7116c746b18ca46e44c
4
+ data.tar.gz: 38fbc0e690203169f8f327cee5d63f4a1a919a4e
5
+ SHA512:
6
+ metadata.gz: 617bcd5537a30c319651f3f83591bfbee04bd5f243e687b2be2c448d28af497e24d103a5b1962f9cf93818970cf3a34b04c250a17f7931fa36eb0928528c0211
7
+ data.tar.gz: f6f7180ab7d7c4bb23a0c0c6b693d527c0a92ab18dc6d39539bfa07dfdeecc8f9e858046b8a76d2ab951945a083055f86c8c7d686786ba0d260ce31684ec88e2
data/.env ADDED
@@ -0,0 +1,4 @@
1
+ GOOGLE_ADMIN_USER_EMAIL=user@hosteddomain.com
2
+ GOOGLE_ADMIN_CUSTOMER_ID=12345
3
+ GOOGLE_API_PRIVATE_KEY=-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCQd2IvKv+fmJO0\njB4bd8mr3Pg8fsVemz/uOsxWf7PZIHkZOqv9IEv0Pf2Cq3ZRLQfW5F7Z9NLDBC05\nm/vSTtVocmzooHcc+ks4n4gDkfHSBDKmvT+C1gHBsIXn7gl4NR0q/EXMPmMhY0Ez\nK3skPD+SGa88KSANguThqdI2dah61XdzCaRfJfGFOZPWdenZh2165uDKaRgK4mmp\nxT/7EFdvMh9l0C9B+nD3VBYZrVakMLdtXwaH6PT5LCzjOM4Gu5ACs9txwskx1znB\nZpj5x6JnKDz2gEjoxJn5WMJv4U6E//HhHdNIZyeNx6F5hBkNpmNtmpR2b2TFojgo\n+5R7WL9JAgMBAAECggEAZzEvrBudvoWBNF1GAD7fimjr1GKFXx+sWeIcJclQUU81\n0USsp8HTH2LMW/NYL4Hn8KLt8ehESFMKbvUxurbfD510l/JPQx6ybn7d7Bbq0iZ3\ne80AuddeJ9mMvO+2Sew+qn7K6KrDqoy4fPGZI3f5vMWl+2Yw5BXUojDo3EfNEfek\nEvy5eLIKma+GVfmazVpKReD8fI5pzBRaUtltv5i8gCALtabRIR97LDDgFcmjmxqH\nyha0WAnVRejz/ygmQtthNvyGWfdkgMZR0pnfBSI9ahm/Dew1pX3ZXSUVw0X6u1SD\nOnGxm2emP+jCuV1weNsTrpxyIFCP68d+ouJcHcqj0QKBgQDmDP8eMRURIJv+PECD\nfvFmGu6kD8SuSi/wZk5WRFDI1n1FdsSpJ+rBciCYPArWMM/Hmul/p4pm7wdeQFm/\nIkH9e8eLlpkk0dcEDHRh2qR4zKlxnjSFo3oyrA6rmfTaUD/3MXPBJf3gMVnLEr7C\nzLPjS5BXix5EYmIWrLWAitS/DQKBgQCgwwebXOVbJySJnM/cVqG7zGHxTyF6Lt23\nhwvg/zAOSzPz33Ie7Ttqh9pm2E3vBsnhEetKQkAQ3ZRGAkqiLszWHG393mEsPZla\njfDHduPYLh5M9QulbMP4daaDkhZl1qPYi9F87I4uukI3fVxQYmJx0WZaGGbGeL7D\nnYzMIYVSLQKBgQCbvvbFKPObSdlyULZYkAu8VcV0mxxL5vv3pDuq2ctbfSMIcTUJ\nVHXxi2OXzSaFBjzVZQJqIzJnJ7J0U9qutPG6PB/HWCjMLaiFHC16xjyNb/nTawkh\n5KBpR+UStkN3vdbgcsFsZV0weBjTjBhL56xt2I2bRxsxru27biffI56OzQKBgGUg\nikZ3N2gRxXAzjqYicPb76JitmHeNx7dNYnGU1ZwIPpQoeVdvEDNBZmfPpaa49IF6\njjJWXoq9eCpaAqznF7+Qfrh2DVaRIUjPhSlUZpt012a9tyfGtbgz+h1F5oUFcmgj\n/BHDlOVcEY9qcom2egrzGJmQRAaRqh7PmuRGKeG5AoGADqZ6rI1ihMZ2t6vsjwsa\n/PeO/taSlLTSarXShznE14GbeNYwjxFlOduuBjK/bU6Nm4qnL64Z2O7gOfQuFyII\neWRDUVHELmZVbvpbQJeTJcaB6NrrdIUc+vCWkxQuxKL/53iOgU5rtof+rKA2AKV8\nUJc7Af2/rnvbdZUxin/pU1I=\n-----END PRIVATE KEY-----\n
4
+ GOOGLE_API_SERVICE_ACCOUNT=fake@fake.iam.gserviceaccount.com
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in google-wrapper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 John Bohn
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Google::Wrapper
2
+
3
+ Small gem to wrap google-api-client
4
+
5
+ google-api-client can be a bit gnarly to work with sometimes. This makes things easier for us.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'google-wrapper'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install google-wrapper
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/alphasights/google-wrapper/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
9
+ rescue LoadError
10
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'google/wrapper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "google-wrapper"
8
+ spec.version = Google::Wrapper::VERSION
9
+ spec.authors = ["John Bohn"]
10
+ spec.email = ["jjbohn@gmail.com"]
11
+ spec.summary = %q{Small gem to wrap google-api-client}
12
+ spec.description = %q{google-api-client can be a bit gnarly to work with sometimes. This makes things easier for us}
13
+ spec.homepage = "https://engineering.alphasights.com/"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(spec)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "google-api-client", "~> 0.8.6"
22
+ spec.add_development_dependency "dotenv", "~> 2.0"
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.4.0"
26
+ end
@@ -0,0 +1,42 @@
1
+ require "google/api_client"
2
+ require "google/client_builder/construction_helper"
3
+
4
+ module Google
5
+ class ClientBuilder
6
+ extend ConstructionHelper
7
+
8
+ PRIVATE_KEY = ENV.fetch("GOOGLE_API_PRIVATE_KEY").gsub("\\n", "\n")
9
+ PRIVATE_KEY_SECRET = "notasecret" # static default for Google P12 auth
10
+ SERVICE_ACCOUNT_EMAIL = ENV.fetch("GOOGLE_API_SERVICE_ACCOUNT")
11
+
12
+ attr_accessor :user_email, :scopes, :authorize
13
+
14
+ def self.key
15
+ OpenSSL::PKey::RSA.new(PRIVATE_KEY, PRIVATE_KEY_SECRET)
16
+ end
17
+
18
+ def initialize
19
+ yield(self) if block_given?
20
+ end
21
+
22
+ def authorize!
23
+ @authorize = true
24
+ end
25
+
26
+ def build
27
+ Google::APIClient.new(application_name: "google-wrapper", application_version: Google::Wrapper::VERSION).tap do |client|
28
+ client.authorization = asserter.authorize(user_email) if authorize?
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def asserter
35
+ Google::APIClient::JWTAsserter.new(SERVICE_ACCOUNT_EMAIL, scopes, self.class.key)
36
+ end
37
+
38
+ def authorize?
39
+ @authorize === true
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,23 @@
1
+ require "google/client_builder/scopes_helper"
2
+
3
+ module Google
4
+ class ClientBuilder
5
+ module ConstructionHelper
6
+ def calendar_client(user_email)
7
+ Google::ClientBuilder.new do |c|
8
+ c.user_email = user_email
9
+ c.scopes = ScopesHelper.calendar
10
+ c.authorize!
11
+ end.build
12
+ end
13
+
14
+ def directory_client
15
+ ClientBuilder.new do |c|
16
+ c.user_email = ENV.fetch("GOOGLE_ADMIN_USER_EMAIL")
17
+ c.scopes = ScopesHelper.directory
18
+ c.authorize!
19
+ end.build
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ module Google
2
+ class ClientBuilder
3
+ class ScopesHelper
4
+ def self.calendar
5
+ ["https://www.googleapis.com/auth/calendar"]
6
+ end
7
+
8
+ def self.directory
9
+ ["https://www.googleapis.com/auth/admin.directory.user",
10
+ "https://www.googleapis.com/auth/admin.directory.userschema"]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ module Google
2
+ module Directory
3
+ end
4
+ end
5
+
6
+ require "google/directory/base_api"
7
+
8
+ require "google/directory/schema"
9
+ require "google/directory/schema/field"
10
+ require "google/directory/schema/field_type"
11
+
12
+ require "google/directory/user"
@@ -0,0 +1,23 @@
1
+ module Google
2
+ module Directory
3
+ class BaseApi
4
+ def initialize(client = nil)
5
+ @client = client
6
+ end
7
+
8
+ private
9
+
10
+ def default_query
11
+ { customer: "my_customer", customerId: ENV.fetch("GOOGLE_ADMIN_CUSTOMER_ID") }
12
+ end
13
+
14
+ def directory_api
15
+ @directory_api ||= client.discovered_api("admin", "directory_v1")
16
+ end
17
+
18
+ def client
19
+ @client ||= Google::ClientBuilder.directory_client
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,34 @@
1
+ require "google/directory/schema/field"
2
+ require "google/directory/schema/field_type"
3
+
4
+ module Google
5
+ module Directory
6
+ class Schema < BaseApi
7
+ def insert(key, fields)
8
+ body = schema_api.insert.request_schema.new
9
+ body.fields = fields.map(&:to_google_field)
10
+ body.schema_name = key
11
+
12
+ client.execute!(api_method: schema_api.insert,
13
+ body_object: body,
14
+ parameters: default_query)
15
+ end
16
+
17
+ def update(key, fields)
18
+ body = schema_api.update.request_schema.new
19
+ body.fields = fields.map(&:to_google_field)
20
+ body.schema_name = key
21
+
22
+ client.execute!(api_method: schema_api.update,
23
+ body_object: body,
24
+ parameters: default_query.merge(schemaKey: key))
25
+ end
26
+
27
+ private
28
+
29
+ def schema_api
30
+ @schema ||= directory_api.discovered_resources.find { |resource| resource.name == "schemas" }
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,11 @@
1
+ module Google
2
+ module Directory
3
+ class Schema < BaseApi
4
+ Field = Struct.new(:name, :type) do
5
+ def to_google_field
6
+ { fieldName: name, fieldType: type.to_s }
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Google
2
+ module Directory
3
+ class Schema < BaseApi
4
+ module FieldType
5
+ class Boolean; def self.to_s; "BOOL"; end; end
6
+ class String; def self.to_s; "STRING"; end; end
7
+ class Integer; def self.to_s; "INT64"; end; end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ require "google/directory/user/badges"
2
+
3
+ module Google
4
+ module Directory
5
+ module User
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,20 @@
1
+ module Google
2
+ module Directory
3
+ module User
4
+ class Badges < BaseApi
5
+ # Update a users badges
6
+ #
7
+ # @param user_key [String] Can be the user's primary email address, alias email address, or unique user ID.
8
+ # @param badges [Array] An array of the badges (as Symbols or Strings)
9
+ def update(user_key, badges)
10
+ body = directory_api.users.patch.request_schema.new
11
+ body.custom_schemas = { badges: badges.map { |badge| [badge, true] }.to_h }
12
+
13
+ client.execute!(api_method: directory_api.users.patch,
14
+ body_object: body,
15
+ parameters: default_query.merge(userKey: user_key))
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,70 @@
1
+ require "ostruct"
2
+
3
+ module Google
4
+ class DummyClient
5
+ class UndefinedAPIError < RuntimeError; end
6
+
7
+ APIS = {
8
+ "directory_v1" => {
9
+ "admin" => {
10
+ "schemas" => %W(insert patch update delete get),
11
+ "users" => %W(insert patch delete get),
12
+ },
13
+ },
14
+ "v3" => {
15
+ "calendar" => {
16
+ "events" => %W(insert update delete get),
17
+ },
18
+ },
19
+ }.freeze
20
+
21
+ def initialize
22
+ @class_cache = {}
23
+ APIS.each do |version, stubs|
24
+ stubs.each do |api, resources|
25
+ cache_key = "#{api}::#{version}"
26
+
27
+ @class_cache[cache_key] = DummyAPIFactory.new(api, version, APIS.fetch(version).fetch(api))
28
+ end
29
+ end
30
+ end
31
+
32
+ def discovered_api(api, version)
33
+ cache_key = "#{api}::#{version}"
34
+ @class_cache.fetch(cache_key)
35
+ rescue KeyError
36
+ raise UndefinedAPIError, <<-MSG
37
+ The #{api} API for version #{version} is not stubbed out.
38
+ See Google::DummyClient::APIS to see available API stubs.
39
+ MSG
40
+ end
41
+
42
+ def execute(params)
43
+ OpenStruct.new(data: OpenStruct.new(params))
44
+ end
45
+
46
+ alias_method :execute!, :execute
47
+ end
48
+
49
+ class DummyAPIFactory
50
+ # Creates a new class for the API. This anonymous class should be garbage collected
51
+ # in ruby > 2.1 so there's no need to worry about garbage collection.
52
+ def self.new(name, version, method_chains)
53
+ Class.new {
54
+ method_chains.each do |method, child_methods|
55
+ define_method method do
56
+ methods = Hash[child_methods.map do |m|
57
+ [m, OpenStruct.new(request_schema: OpenStruct, name: "#{name}.#{method}.#{m}")]
58
+ end]
59
+
60
+ OpenStruct.new(methods.merge(name: method))
61
+ end
62
+ end
63
+
64
+ define_method "discovered_resources" do
65
+ method_chains.map { |method, _| public_send(method) }
66
+ end
67
+ }.new
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,8 @@
1
+ module Google
2
+ module Wrapper
3
+ end
4
+ end
5
+
6
+ require "google/wrapper/version"
7
+ require "google/client_builder"
8
+ require "google/directory"
@@ -0,0 +1,5 @@
1
+ module Google
2
+ module Wrapper
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ describe Google::ClientBuilder::ScopesHelper do
4
+ it "can give you sane default scopes for different uses" do
5
+ expect(described_class.calendar).to eql(["https://www.googleapis.com/auth/calendar"])
6
+ expect(described_class.directory).to eql(["https://www.googleapis.com/auth/admin.directory.user",
7
+ "https://www.googleapis.com/auth/admin.directory.userschema"])
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe Google::ClientBuilder do
4
+ it "can take a user email (for when you're acting on behalf of a user)" do
5
+ scopes = Google::ClientBuilder::ScopesHelper.directory
6
+
7
+ asserter = double("Google::APIClient::JWTAsserter")
8
+ authorization = double(generate_authenticated_request: double)
9
+ key = Google::ClientBuilder.key
10
+
11
+ allow_any_instance_of(Google::ClientBuilder).to receive(:asserter).and_return(asserter)
12
+ expect(asserter).to receive(:authorize).with("jjbohn@gmail.com").and_return(authorization)
13
+
14
+ client = described_class.new do |c|
15
+ c.user_email = "jjbohn@gmail.com"
16
+ c.scopes = Google::ClientBuilder::ScopesHelper.directory
17
+ c.authorize!
18
+ end.build
19
+
20
+ expect(client).to be_instance_of(Google::APIClient)
21
+ expect(client.authorization).to equal(authorization)
22
+ end
23
+ end
@@ -0,0 +1,74 @@
1
+ require "spec_helper"
2
+
3
+ module Google::Directory
4
+ describe Schema do
5
+ subject(:schema_api) { described_class.new(client_spy) }
6
+ let(:client_spy) { Google::DummyClient.new }
7
+ let(:badge_fields) do
8
+ [Schema::Field.new("corporate_portal", Schema::FieldType::Boolean),
9
+ Schema::Field.new("compliance", Schema::FieldType::Boolean)]
10
+ end
11
+
12
+ before do
13
+ allow(ENV).to receive(:fetch).with("GOOGLE_ADMIN_CUSTOMER_ID").and_return("1234")
14
+ end
15
+
16
+ it "proxies update to a google api client" do
17
+ result = schema_api.update("badges", badge_fields)
18
+ api_method = result.data.api_method
19
+ body_object = result.data.body_object
20
+ parameters = result.data.parameters
21
+
22
+ expect(api_method.name).to eql("admin.schemas.update")
23
+ expect(body_object.schema_name).to eql("badges")
24
+ expect(body_object.fields).to match_array([
25
+ { fieldName: "corporate_portal", fieldType: "BOOL" },
26
+ { fieldName: "compliance", fieldType: "BOOL" }
27
+ ])
28
+ expect(parameters).to eql({ customer: "my_customer", customerId: "1234", schemaKey: "badges" })
29
+ end
30
+
31
+ it "proxies insert to a google api client" do
32
+ result = schema_api.insert("badges", badge_fields)
33
+ api_method = result.data.api_method
34
+ body_object = result.data.body_object
35
+ parameters = result.data.parameters
36
+
37
+ expect(api_method.name).to eql("admin.schemas.insert")
38
+ expect(body_object.schema_name).to eql("badges")
39
+ expect(body_object.fields).to match_array([
40
+ { fieldName: "corporate_portal", fieldType: "BOOL" },
41
+ { fieldName: "compliance", fieldType: "BOOL" }
42
+ ])
43
+ expect(parameters).to eql({ customer: "my_customer", customerId: "1234" })
44
+ end
45
+ end
46
+
47
+ describe Schema::Field do
48
+ it "takes a field key name and a type (as a class)" do
49
+ field = described_class.new("test", Schema::FieldType::String)
50
+ expect(field.name).to eql("test")
51
+ expect(field.type).to eql(Schema::FieldType::String)
52
+ end
53
+
54
+ it "can be converted to google compatible argument" do
55
+ field = described_class.new("test", Schema::FieldType::String)
56
+
57
+ expect(field.to_google_field).to eql({
58
+ fieldName: "test",
59
+ fieldType: "STRING",
60
+ })
61
+ end
62
+
63
+ it "included type maps" do
64
+ field = described_class.new("test", Schema::FieldType::String)
65
+ expect(field.to_google_field[:fieldType]).to eql("STRING")
66
+
67
+ field = described_class.new("test", Schema::FieldType::Boolean)
68
+ expect(field.to_google_field[:fieldType]).to eql("BOOL")
69
+
70
+ field = described_class.new("test", Schema::FieldType::Integer)
71
+ expect(field.to_google_field[:fieldType]).to eql("INT64")
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+
3
+ module Google::Directory::User
4
+ describe Badges do
5
+ subject(:badges_api) { described_class.new(client_spy) }
6
+ let(:client_spy) { Google::DummyClient.new }
7
+
8
+ before do
9
+ allow(ENV).to receive(:fetch).with("GOOGLE_ADMIN_CUSTOMER_ID").and_return("1234")
10
+ end
11
+
12
+ it "proxies patch to a google api client" do
13
+ result = badges_api.update("john.bohn@alphasights.com", [:client_portal, :reporting_world])
14
+
15
+ api_method = result.data.api_method
16
+ body_object = result.data.body_object
17
+ parameters = result.data.parameters
18
+
19
+ expect(api_method.name).to eql("admin.users.patch")
20
+ expect(body_object.custom_schemas).to eql({
21
+ badges: {
22
+ client_portal: true,
23
+ reporting_world: true,
24
+ }
25
+ })
26
+
27
+ expect(parameters).to eql({
28
+ customer: "my_customer",
29
+ customerId: "1234",
30
+ userKey: "john.bohn@alphasights.com"
31
+ })
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ require "spec_helper"
2
+
3
+ describe Google::DummyClient do
4
+ subject(:client) { described_class.new }
5
+
6
+ it "can generate a calendar dummy api interface" do
7
+ calendar = client.discovered_api("calendar", "v3")
8
+ expect(calendar.events.insert.name).to eql("calendar.events.insert")
9
+ expect(calendar.events.update.name).to eql("calendar.events.update")
10
+ expect(calendar.events.delete.name).to eql("calendar.events.delete")
11
+ expect(calendar.events.get.name).to eql("calendar.events.get")
12
+ end
13
+
14
+ it "mimics google `discovered_resources` method" do
15
+ calendar = client.discovered_api("calendar", "v3")
16
+
17
+ events = calendar.discovered_resources.first
18
+ expect(events.name).to eql("events")
19
+ expect(events.insert.name).to eql("calendar.events.insert")
20
+ end
21
+
22
+ it "raises an error if it does not have that API defined" do
23
+ expect{ client.discovered_api("v3", "foo") }
24
+ .to raise_error(Google::DummyClient::UndefinedAPIError)
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ require "bundler/setup"
2
+ Bundler.setup
3
+
4
+ require "dotenv"
5
+ Dotenv.load
6
+
7
+ require "google/wrapper"
8
+ require "google/dummy_client"
9
+
10
+ RSpec.configure do |config|
11
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google-wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - John Bohn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: google-api-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.4.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.4.0
83
+ description: google-api-client can be a bit gnarly to work with sometimes. This makes
84
+ things easier for us
85
+ email:
86
+ - jjbohn@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".env"
92
+ - ".gitignore"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - google-wrapper.gemspec
98
+ - lib/google/client_builder.rb
99
+ - lib/google/client_builder/construction_helper.rb
100
+ - lib/google/client_builder/scopes_helper.rb
101
+ - lib/google/directory.rb
102
+ - lib/google/directory/base_api.rb
103
+ - lib/google/directory/schema.rb
104
+ - lib/google/directory/schema/field.rb
105
+ - lib/google/directory/schema/field_type.rb
106
+ - lib/google/directory/user.rb
107
+ - lib/google/directory/user/badges.rb
108
+ - lib/google/dummy_client.rb
109
+ - lib/google/wrapper.rb
110
+ - lib/google/wrapper/version.rb
111
+ - spec/google/client_builder/scopes_helper_spec.rb
112
+ - spec/google/client_builder_spec.rb
113
+ - spec/google/directory/schema_spec.rb
114
+ - spec/google/directory/user/badges_spec.rb
115
+ - spec/google/dummy_client_spec.rb
116
+ - spec/spec_helper.rb
117
+ homepage: https://engineering.alphasights.com/
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.4.5
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Small gem to wrap google-api-client
141
+ test_files:
142
+ - spec/google/client_builder/scopes_helper_spec.rb
143
+ - spec/google/client_builder_spec.rb
144
+ - spec/google/directory/schema_spec.rb
145
+ - spec/google/directory/user/badges_spec.rb
146
+ - spec/google/dummy_client_spec.rb
147
+ - spec/spec_helper.rb