You need to sign in or sign up before continuing.
Commit d3b2d67e authored by Jose Ernesto Suarez's avatar Jose Ernesto Suarez

Se añaden los primeros componentes de la libreria

parent 7608d907
.DS_Store
......@@ -32,6 +32,12 @@ Gem::Specification.new do |spec|
spec.add_dependency 'http','~> 4.4.0'
spec.add_dependency 'logger','~> 1.4.2'
spec.add_dependency 'google/apis/gmail_v1'
spec.add_dependency "google/apis/reseller_v1"
spec.add_dependency 'google/apis/drive_v2'
spec.add_dependency 'googleauth'
spec.add_dependency 'googleauth/stores/file_token_store'
spec.add_development_dependency 'bundler', '~> 2.1.4'
spec.add_development_dependency 'rake', '~> 13.0.1'
spec.add_development_dependency 'rspec', '~> 3.0'
......
# frozen_string_literal: true
require 'google-wedoops/configuration'
require 'google-wedoops/version'
require 'google-wedoops/authenticator'
require 'google-wedoops/drive'
require 'google-wedoops/reseller'
##
# This library is used for access Zoho
......
require 'googleauth'
require 'googleauth/stores/file_token_store'
module Wedoops
module Google
class Authenticator
OOB_URI = 'urn:ietf:wg:oauth:2.0:oob'
attr_accessor :authorizer,:credentials,:scopes
def initialize(credentials,scopes='https://www.googleapis.com/auth/drive')
puts "Incilizalizando authenticator"
raise "Unable to initialize with credentials file #{credentials}" unless File.exists?(credentials)
@credentials_file_path = credentials
@scopes = scopes
@authenticate_by=nil
@credentials=nil
#'./creds/client_secret_368310260238-3eo8g5e3ui0f3b5cso041o8ps9k8ivfg.apps.googleusercontent.com.json'
end
def auth_by_console(user_id)
puts "Authenticating from console"
scope = @scopes
client_id = Google::Auth::ClientId.from_file(@credentials_file_path)
token_store = Google::Auth::Stores::FileTokenStore.new(
:file => './tokens/tokens.yaml')
authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)
credentials = authorizer.get_credentials(user_id)
if credentials.nil?
url = authorizer.get_authorization_url(base_url: OOB_URI )
puts "Open #{url} in your browser and enter the resulting code:"
code = gets
credentials = authorizer.get_and_store_credentials_from_code(
user_id: user_id, code: code, base_url: OOB_URI)
end
@authenticated_by = "console"
return credentials
end
def auth_by_sa(user_id)
@credentials = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: File.open(@credentials_file_path),
scope: @scopes)
@credentials.sub = user_id
Google::Apis::RequestOptions.default.authorization = @credentials
@authenticated_by="service_account"
return true
end
def auth_by_env
end
def token!
fetch_access_token!
end
def fetch_access_token!
raise "Only available if is authenticated by service account" unless @authenticated_by == "service_account"
@credentials.fetch_access_token!
end
end
end
end
\ No newline at end of file
require 'google/apis/drive_v2'
require 'pp'
module Wedoops
module Google
class Drive
Drive = Google::Apis::DriveV2 # Alias the module
def initialize(authorization)
puts "Wedoops Drive"
pp authorization.class
@drive = Drive::DriveService.new
@drive.authorization = authorization # See Googleauth or Signet libraries
end
def download_file(metadata,path='tmp/myfile.txt')
puts "Dowloading the file in tmp"
# Download a file
@drive.get_file(metadata.id, download_dest: path)
end
def list_files(term="Wedoops")
puts "Current uploaded files with the term #{term}"
query="title contains \'#{term}\'"
files = @drive.list_files(q: query)
files.items.each do |file|
puts file.title
end
return files
end
def upload_file(path,title="Wedoops test document #{DateTime.now.strftime('%x')}")
puts "Uploading new file"
# Upload a fileruby
metadata = Drive::File.new(title: title)
metadata = @drive.insert_file(metadata, upload_source: path, content_type: 'text/plain')
return metadata
end
end
end
end
\ No newline at end of file
require 'google/apis/gmail_v1'
require "google/apis/reseller_v1"
require 'googleauth'
require 'googleauth/stores/file_token_store'
module Wedoops
module Google
class Reseller
Reseller = Google::Apis::ResellerV1
def initialize(authorization)
puts "Wedoops Reseller"
pp authorization.class
@service = Reseller::ResellerService.new
@service.authorization = authorization
end
def read_suscriptions
puts "Suscriptions:"
# Print the first 10 subscriptions you manage.
response = @service.list_subscriptions max_results: 100
puts "No subscriptions found" if response.subscriptions.empty?
response.subscriptions.each do |subscription|
puts "- #{subscription.customer_id} (#{subscription.sku_id}, #{subscription.plan.plan_name})"
end
return response.subscriptions
end
end
end
end
\ No newline at end of file
# frozen_string_literal: true
module Wedoops
module Google
VERSION = '0.0.5b'
VERSION = '0.0.1b'
end
end
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment