Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
google-wedoops
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gems
google-wedoops
Commits
2bc64d60
Commit
2bc64d60
authored
May 03, 2020
by
Jose Ernesto Suarez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Se añaden nuevos metodos al control de reseller
parent
8f6fcf2b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
9 deletions
+56
-9
reseller.rb
lib/google-wedoops/reseller.rb
+56
-9
No files found.
lib/google-wedoops/reseller.rb
View file @
2bc64d60
...
...
@@ -10,21 +10,68 @@ module Wedoops
Reseller
=
::
Google
::
Apis
::
ResellerV1
def
initialize
(
authorization
)
puts
"Wedoops Reseller"
@logger
=
Logger
.
new
(
STDOUT
)
@logger
.
debug
"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
get_paginated_items
(
:list_subscriptions
,
:subscriptions
)
end
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
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
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment