Commit 2bc64d60 authored by Jose Ernesto Suarez's avatar Jose Ernesto Suarez

Se añaden nuevos metodos al control de reseller

parent 8f6fcf2b
...@@ -10,21 +10,68 @@ module Wedoops ...@@ -10,21 +10,68 @@ module Wedoops
Reseller = ::Google::Apis::ResellerV1 Reseller = ::Google::Apis::ResellerV1
def initialize(authorization) def initialize(authorization)
puts "Wedoops Reseller" @logger = Logger.new(STDOUT)
@logger.debug "Wedoops Reseller"
pp authorization.class pp authorization.class
@service = Reseller::ResellerService.new @service = Reseller::ResellerService.new
@service.authorization = authorization @service.authorization = authorization
end end
def read_suscriptions def read_suscriptions
puts "Suscriptions:" get_paginated_items(:list_subscriptions,:subscriptions)
# 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 end
return response.subscriptions
def get_suscription(customer,code,options={})
@logger.debug "#{__method__}: #{customer} #{code}"
response = @service.get_suscription(customer,code)
return response
end
def get_customer(customer,options={})
@logger.debug "#{__method__}: #{customer}"
response = @service.get_customer(customer)
return response
end end
def get_customer_subscriptions(customer,options={})
@logger.debug "#{__method__}:"
options.merge!(customer_id: customer)
return get_paginated_items(:list_subscriptions,:subscriptions,options)
end
private
def get_paginated_items(method,result_item,options={})
# Para todas las colecciones paginadas podemos usar este metodo
# Argumentos:
# method: Nombre de la llamada del servicio
# result_item: Nombre de la coleccion que devuelve method
# options: Opciones adicionales
#
# Resultado:
# Array con todos los elementos concatenados
@logger.debug "#{__method__}: #{method} #{result_item}"
page = 0
result = Array.new
options.merge!(max_results: 100)
options.merge!(page_token: nil)
begin
# Print the first 10 items you manage.
@logger.info "Page #{page}"
response = @service.public_send(method,options)
response_object = response.public_send(result_item)
@logger.error "No #{result_item} found" if response_object.empty?
options[:page_token]= response.next_page_token
result.concat(response_object)
page+=1
end while options[:page_token]
@logger.info("Returning #{result.size} results")
return result
end
end end
end end
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