Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zoholib
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
zoholib
Commits
65175efc
Commit
65175efc
authored
Apr 25, 2020
by
Jose Ernesto Suarez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Se mueve todo el modulo Wedoops
parent
0e4138c5
Changes
16
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
1058 additions
and
1044 deletions
+1058
-1044
.rspec_status
.rspec_status
+7
-7
zoholib.rb
lib/zoholib.rb
+17
-15
adamo_client.rb
lib/zoholib/adamo_client.rb
+83
-82
authorization_request.rb
lib/zoholib/authorization_request.rb
+104
-103
b12_client.rb
lib/zoholib/b12_client.rb
+39
-38
configuration.rb
lib/zoholib/configuration.rb
+16
-15
grant_request.rb
lib/zoholib/grant_request.rb
+20
-18
refresh_request.rb
lib/zoholib/refresh_request.rb
+19
-17
response.rb
lib/zoholib/response.rb
+2
-2
version.rb
lib/zoholib/version.rb
+5
-4
zoho_basic_client.rb
lib/zoholib/zoho_basic_client.rb
+145
-144
zoho_client.rb
lib/zoholib/zoho_client.rb
+580
-579
zoho_request.rb
lib/zoholib/zoho_request.rb
+12
-11
spec_helper.rb
spec/spec_helper.rb
+1
-1
zoholib_spec.rb
spec/zoholib_spec.rb
+7
-7
zoholib.gemspec
zoholib.gemspec
+1
-1
No files found.
.rspec_status
View file @
65175efc
example_id | status | run_time |
----------------------------- | ------ | --------------- |
./spec/zoholib_spec.rb[1:1] | passed | 0.00
183
seconds |
./spec/zoholib_spec.rb[1:2] | passed | 0.0014
4
seconds |
./spec/zoholib_spec.rb[1:3:1] | passed | 0.001
12
seconds |
./spec/zoholib_spec.rb[1:3:2] | passed | 0.00
12 seconds
|
./spec/zoholib_spec.rb[1:3:3] | passed | 0.0000
9
seconds |
./spec/zoholib_spec.rb[1:3:4] | passed | 0.000
2 seconds
|
./spec/zoholib_spec.rb[1:3:5] | passed | 0.000
22
seconds |
./spec/zoholib_spec.rb[1:1] | passed | 0.00
261
seconds |
./spec/zoholib_spec.rb[1:2] | passed | 0.0014
1
seconds |
./spec/zoholib_spec.rb[1:3:1] | passed | 0.001
25
seconds |
./spec/zoholib_spec.rb[1:3:2] | passed | 0.00
011 seconds
|
./spec/zoholib_spec.rb[1:3:3] | passed | 0.0000
8
seconds |
./spec/zoholib_spec.rb[1:3:4] | passed | 0.000
16 seconds
|
./spec/zoholib_spec.rb[1:3:5] | passed | 0.000
17
seconds |
lib/zoholib.rb
View file @
65175efc
...
...
@@ -14,20 +14,22 @@ require 'zoholib/zoho_client'
##
# This library is used for access Zoho
module
Zoholib
class
<<
self
attr_accessor
:configuration
end
def
self
.
configuration
@configuration
||=
Configuration
.
new
end
def
self
.
reset
@configuration
=
Configuration
.
new
end
def
self
.
configure
yield
(
configuration
)
module
Wedoops
module
Zoholib
class
<<
self
attr_accessor
:configuration
end
def
self
.
configuration
@configuration
||=
Configuration
.
new
end
def
self
.
reset
@configuration
=
Configuration
.
new
end
def
self
.
configure
yield
(
configuration
)
end
end
end
lib/zoholib/adamo_client.rb
View file @
65175efc
...
...
@@ -4,93 +4,94 @@ require 'json'
require
'logger'
require
'date'
module
Wedoops
module
Zoholib
class
AdamoClient
module
Zoholib
class
AdamoClient
def
initialize
(
options
=
{})
@logger
=
Logger
.
new
(
STDOUT
)
@http
=
HTTP
.
use
(
logging:
{
logger:
@logger
})
.
timeout
(
connect:
15
,
read:
30
)
.
headers
(
"cache-control"
=>
"no-cache"
,
"accept"
=>
"application/json"
,
"postman-token"
=>
"8b126eb1-0de6-4a10-d78d-1fb417fb23b0"
,
"x-apikey"
=>
"Af8cbSpgkAReYqBs66DHJUkf2MJW3d9JDFVJhWe4U5haD"
)
end
def
initialize
(
options
=
{})
@logger
=
Logger
.
new
(
STDOUT
)
@http
=
HTTP
.
use
(
logging:
{
logger:
@logger
})
.
timeout
(
connect:
15
,
read:
30
)
.
headers
(
"cache-control"
=>
"no-cache"
,
"accept"
=>
"application/json"
,
"postman-token"
=>
"8b126eb1-0de6-4a10-d78d-1fb417fb23b0"
,
"x-apikey"
=>
"Af8cbSpgkAReYqBs66DHJUkf2MJW3d9JDFVJhWe4U5haD"
)
end
def
cobertura_project
count
=
2
url
=
"https://coverage-dump.adamo.es/v1/cobertura-project/
#{
count
}
?limit=500"
return
HTTP
.
use
(
logging:
{
logger:
@logger
})
.
timeout
(
connect:
15
,
read:
30
)
.
headers
(
"cache-control"
=>
"no-cache"
,
"accept"
=>
"application/json"
,
"postman-token"
=>
"8b126eb1-0de6-4a10-d78d-1fb417fb23b0"
,
"x-apikey"
=>
"Af8cbSpgkAReYqBs66DHJUkf2MJW3d9JDFVJhWe4U5haD"
).
get
(
url
)
end
def
cobertura_project
count
=
2
url
=
"https://coverage-dump.adamo.es/v1/cobertura-project/
#{
count
}
?limit=500"
return
HTTP
.
use
(
logging:
{
logger:
@logger
})
.
timeout
(
connect:
15
,
read:
30
)
.
headers
(
"cache-control"
=>
"no-cache"
,
"accept"
=>
"application/json"
,
"postman-token"
=>
"8b126eb1-0de6-4a10-d78d-1fb417fb23b0"
,
"x-apikey"
=>
"Af8cbSpgkAReYqBs66DHJUkf2MJW3d9JDFVJhWe4U5haD"
).
get
(
url
)
end
def
cobertura
page
=
1
limit
=
50000
#date=Date.parse("06-04-2020").strftime("%Y%m%d")
date
=
Date
.
today
.
prev_day
.
strftime
(
"%Y%m%d"
)
resultado_final
=
Array
.
new
r
=
Array
.
new
loop
do
print
"
#{
page
}
"
url
=
"https://coverage-dump.adamo.es/v1/cobertura/
#{
page
}
?limit=
#{
limit
}
&date=
#{
date
}
"
#.use(logging: {logger: @logger})
resultado
=
HTTP
.
timeout
(
connect:
15
,
read:
30
)
.
headers
(
"cache-control"
=>
"no-cache"
,
"accept"
=>
"application/json"
,
"postman-token"
=>
"8b126eb1-0de6-4a10-d78d-1fb417fb23b0"
,
"x-apikey"
=>
"zYkWN38SYH6hr2Ixq75xvDENl6hrYOvxx0FxLvPD7BUe6"
).
get
(
url
)
r
=
JSON
.
parse
(
resultado
,
symbolize_names:
true
)
resultado_final
.
concat
(
r
)
page
+=
1
print
"(
#{
r
.
size
}
/
#{
resultado_final
.
size
}
),"
break
if
r
.
size
<
limit
||
page
>
2
end
puts
resultado_final
.
size
return
resultado_final
end
def
cobertura
page
=
1
limit
=
50000
#date=Date.parse("06-04-2020").strftime("%Y%m%d")
date
=
Date
.
today
.
prev_day
.
strftime
(
"%Y%m%d"
)
resultado_final
=
Array
.
new
r
=
Array
.
new
loop
do
print
"
#{
page
}
"
url
=
"https://coverage-dump.adamo.es/v1/cobertura/
#{
page
}
?limit=
#{
limit
}
&date=
#{
date
}
"
#.use(logging: {logger: @logger})
resultado
=
HTTP
.
timeout
(
connect:
15
,
read:
30
)
.
headers
(
"cache-control"
=>
"no-cache"
,
"accept"
=>
"application/json"
,
"postman-token"
=>
"8b126eb1-0de6-4a10-d78d-1fb417fb23b0"
,
"x-apikey"
=>
"zYkWN38SYH6hr2Ixq75xvDENl6hrYOvxx0FxLvPD7BUe6"
).
get
(
url
)
r
=
JSON
.
parse
(
resultado
,
symbolize_names:
true
)
resultado_final
.
concat
(
r
)
page
+=
1
print
"(
#{
r
.
size
}
/
#{
resultado_final
.
size
}
),"
break
if
r
.
size
<
limit
||
page
>
2
end
puts
resultado_final
.
size
return
resultado_final
end
def
projects
page
=
1
limit
=
50000
#date=Date.today.prev_day.strftime("%Y%m%d")
date
=
Date
.
parse
(
"01-01-2011"
).
strftime
(
"%Y%m%d"
)
resultado_final
=
Array
.
new
r
=
Array
.
new
loop
do
print
"
#{
page
}
"
url
=
"https://coverage-dump.adamo.es/v1/cobertura-project/
#{
page
}
?limit=
#{
limit
}
&date=
#{
date
}
"
#.use(logging: {logger: @logger})
resultado
=
HTTP
.
timeout
(
connect:
15
,
read:
30
)
.
headers
(
"cache-control"
=>
"no-cache"
,
"accept"
=>
"application/json"
,
"postman-token"
=>
"8b126eb1-0de6-4a10-d78d-1fb417fb23b0"
,
"x-apikey"
=>
"zYkWN38SYH6hr2Ixq75xvDENl6hrYOvxx0FxLvPD7BUe6"
).
get
(
url
)
r
=
JSON
.
parse
(
resultado
,
symbolize_names:
true
)
resultado_final
.
concat
(
r
)
page
+=
1
print
"(
#{
r
.
size
}
/
#{
resultado_final
.
size
}
),"
break
if
r
.
size
<
limit
||
page
>
2
end
puts
resultado_final
.
size
return
resultado_final
end
def
projects
page
=
1
limit
=
50000
#date=Date.today.prev_day.strftime("%Y%m%d")
date
=
Date
.
parse
(
"01-01-2011"
).
strftime
(
"%Y%m%d"
)
resultado_final
=
Array
.
new
r
=
Array
.
new
loop
do
print
"
#{
page
}
"
url
=
"https://coverage-dump.adamo.es/v1/cobertura-project/
#{
page
}
?limit=
#{
limit
}
&date=
#{
date
}
"
#.use(logging: {logger: @logger})
resultado
=
HTTP
.
timeout
(
connect:
15
,
read:
30
)
.
headers
(
"cache-control"
=>
"no-cache"
,
"accept"
=>
"application/json"
,
"postman-token"
=>
"8b126eb1-0de6-4a10-d78d-1fb417fb23b0"
,
"x-apikey"
=>
"zYkWN38SYH6hr2Ixq75xvDENl6hrYOvxx0FxLvPD7BUe6"
).
get
(
url
)
r
=
JSON
.
parse
(
resultado
,
symbolize_names:
true
)
resultado_final
.
concat
(
r
)
page
+=
1
print
"(
#{
r
.
size
}
/
#{
resultado_final
.
size
}
),"
break
if
r
.
size
<
limit
||
page
>
2
end
puts
resultado_final
.
size
return
resultado_final
end
private
private
def
get_params
(
url
,
payload
)
@http
.
get
(
url
,
:params
=>
payload
)
end
def
get_params
(
url
,
payload
)
@http
.
get
(
url
,
:params
=>
payload
)
end
def
get
(
url
)
@http
.
get
(
url
)
end
end
def
get
(
url
)
@http
.
get
(
url
)
end
end
end
end
\ No newline at end of file
lib/zoholib/authorization_request.rb
View file @
65175efc
This diff is collapsed.
Click to expand it.
lib/zoholib/b12_client.rb
View file @
65175efc
...
...
@@ -5,53 +5,54 @@ require 'logger'
require
'date'
require
'savon'
module
Zoholib
class
B12Client
module
Wedoops
module
Zoholib
class
B12Client
def
initialize
(
options
=
{})
@logger
=
Logger
.
new
(
STDOUT
)
initialize_client
@client
.
call
(
:lead
)
end
def
initialize
(
options
=
{})
@logger
=
Logger
.
new
(
STDOUT
)
initialize_client
@client
.
call
(
:lead
)
end
def
send_lead
(
lead
)
@logger
.
info
(
"Sending lead:
#{
lead
[
:idvar
]
}
tlf:
#{
lead
[
:Telefono
]
}
"
)
#pp lead
#puts ":.................:"
begin
response
=
@client
.
call
(
:lead
)
do
message
(
lead
)
def
send_lead
(
lead
)
@logger
.
info
(
"Sending lead:
#{
lead
[
:idvar
]
}
tlf:
#{
lead
[
:Telefono
]
}
"
)
#pp lead
#puts ":.................:"
begin
response
=
@client
.
call
(
:lead
)
do
message
(
lead
)
end
rescue
Exception
=>
e
@logger
.
error
(
"Error sending the lead:
#{
e
.
message
}
"
)
return
nil
end
rescue
Exception
=>
e
@logger
.
error
(
"Error sending the lead:
#{
e
.
message
}
"
)
return
nil
end
begin
b12_id
=
response
.
body
[
:lead_response
][
:return
]
unless
b12_id
.
match
(
/^\d*$/
)
raise
"Error de B12, envio
#{
lead
[
:idvar
]
}
tlf:
#{
lead
[
:Telefono
]
}
duplicado (
#{
b12_id
}
)"
if
b12_id
==
"-1"
r
aise
"Error interno de B12, error
#{
b12_id
}
recibido"
begin
b12_id
=
response
.
body
[
:lead_response
][
:return
]
unless
b12_id
.
match
(
/^\d*$/
)
raise
"Error de B12, envio
#{
lead
[
:idvar
]
}
tlf:
#{
lead
[
:Telefono
]
}
duplicado (
#{
b12_id
}
)"
if
b12_id
==
"-1"
raise
"Error interno de B12, error
#{
b12_id
}
recibido"
end
rescue
Exception
=>
e
@logger
.
error
(
"Error getting the LEAD ID:
#{
e
.
message
}
"
)
r
eturn
nil
end
rescue
Exception
=>
e
@logger
.
error
(
"Error getting the LEAD ID:
#{
e
.
message
}
"
)
return
nil
return
b12_id
end
return
b12_id
end
private
private
def
initialize_client
@client
=
Savon
.
client
do
wsdl
'http://panel.digitalion.com/wss/cobalt.lead.php?wsdl'
pretty_print_xml
true
#convert_request_keys_to :camelcase
log
false
log_level
:info
def
initialize_client
@client
=
Savon
.
client
do
wsdl
'http://panel.digitalion.com/wss/cobalt.lead.php?wsdl'
pretty_print_xml
true
#convert_request_keys_to :camelcase
log
false
log_level
:info
end
end
end
end
end
end
\ No newline at end of file
lib/zoholib/configuration.rb
View file @
65175efc
# frozen_string_literal: true
module
Wedoops
module
Zoholib
##
# This class permits the configuration of the Valenciaport Access.
# Is neccesary the WDSL URLs for the login and transport endpoint
# as well the array with the different credentials wich will be used
class
Configuration
attr_accessor
:client_id
,
:client_secret
,
:scope
,
:refresh_token
module
Zoholib
##
# This class permits the configuration of the Valenciaport Access.
# Is neccesary the WDSL URLs for the login and transport endpoint
# as well the array with the different credentials wich will be used
class
Configuration
attr_accessor
:client_id
,
:client_secret
,
:scope
,
:refresh_token
def
initialize
@client_id
=
nil
@client_secret
=
nil
@scope
=
nil
@refresh_token
=
nil
end
def
initialize
@client_id
=
nil
@client_secret
=
nil
@scope
=
nil
@refresh_token
=
nil
end
end
end
end
end
\ No newline at end of file
lib/zoholib/grant_request.rb
View file @
65175efc
#require './lib/zoho_request'
module
Zoholib
class
GrantRequest
<
ZohoRequest
module
Wedoops
module
Zoholib
class
GrantRequest
<
ZohoRequest
#base_uri "https://accounts.zoho.com/oauth/v2/token"
#headers: {"Authorization" => "Token token=\"111\""}
def
initialize
(
options
=
{})
@logger
=
::
Logger
.
new
(
STDOUT
)
@logged_in
=
false
@options
=
options
end
#base_uri "https://accounts.zoho.com/oauth/v2/token"
#headers: {"Authorization" => "Token token=\"111\""}
def
initialize
(
options
=
{})
@logger
=
::
Logger
.
new
(
STDOUT
)
@logged_in
=
false
@options
=
options
end
def
token
(
options
=
{})
# Esta funcion se llama desde Zoholib::AuthorizationRequest
# Ejecuta lo descrito en https://www.zoho.com/crm/developer/docs/api/access-refresh.html
@options
[
:query
].
merge!
(
grant_type:
"authorization_code"
)
@options
.
merge!
(
:logger
=>
@logger
)
response
=
self
.
class
.
post
(
'/token'
,
@options
)
JSON
.
parse
(
response
.
body
,
symbolize_names:
true
)
end
def
token
(
options
=
{})
# Esta funcion se llama desde Zoholib::AuthorizationRequest
# Ejecuta lo descrito en https://www.zoho.com/crm/developer/docs/api/access-refresh.html
@options
[
:query
].
merge!
(
grant_type:
"authorization_code"
)
@options
.
merge!
(
:logger
=>
@logger
)
response
=
self
.
class
.
post
(
'/token'
,
@options
)
JSON
.
parse
(
response
.
body
,
symbolize_names:
true
)
end
end
end
end
\ No newline at end of file
lib/zoholib/refresh_request.rb
View file @
65175efc
#require './lib/zoho_request'
module
Zoholib
class
RefreshRequest
<
ZohoRequest
module
Wedoops
module
Zoholib
class
RefreshRequest
<
ZohoRequest
# Sin en algun momento se quiere evitar el encode de URL
# he aqui un truco
#query_string_normalizer proc { |query|
# query.map do |key, value|
# [value].flatten.map {|v| "#{key}=#{v}"}.join('&')
# end.join('&')
# }
# Sin en algun momento se quiere evitar el encode de URL
# he aqui un truco
def
initialize
(
options
=
{})
options
.
merge!
(
grant_type:
"refresh_token"
)
@options
=
{
:query
=>
options
}
end
#query_string_normalizer proc { |query|
# query.map do |key, value|
# [value].flatten.map {|v| "#{key}=#{v}"}.join('&')
# end.join('&')
# }
def
initialize
(
options
=
{})
options
.
merge!
(
grant_type:
"refresh_token"
)
@options
=
{
:query
=>
options
}
end
def
get_token
self
.
class
.
post
(
"/token"
,
@options
)
end
def
get_token
self
.
class
.
post
(
"/token"
,
@options
)
end
end
end
\ No newline at end of file
lib/zoholib/response.rb
View file @
65175efc
module
Zoholib
module
Zoho
module
Wedoops
module
Zoho
lib
class
Response
...
...
lib/zoholib/version.rb
View file @
65175efc
# frozen_string_literal: true
module
Zoholib
VERSION
=
'0.0.1b'
end
module
Wedoops
module
Zoholib
VERSION
=
'0.0.1b'
end
end
\ No newline at end of file
lib/zoholib/zoho_basic_client.rb
View file @
65175efc
This diff is collapsed.
Click to expand it.
lib/zoholib/zoho_client.rb
View file @
65175efc
This diff is collapsed.
Click to expand it.
lib/zoholib/zoho_request.rb
View file @
65175efc
require
'httparty'
require
'json'
module
Zoholib
class
ZohoRequest
include
HTTParty
#debug_output $stdout
base_uri
"https://accounts.zoho.com/oauth/v2/"
#https://accounts.zoho.com/oauth/v2/auth?
#https://accounts.zoho.com/oauth/v2/token?
headers
'Content-Type'
=>
'application/json'
attr_reader
:subdomain
,
:uri
module
Wedoops
module
Zoholib
class
ZohoRequest
include
HTTParty
#debug_output $stdout
base_uri
"https://accounts.zoho.com/oauth/v2/"
#https://accounts.zoho.com/oauth/v2/auth?
#https://accounts.zoho.com/oauth/v2/token?
headers
'Content-Type'
=>
'application/json'
attr_reader
:subdomain
,
:uri
end
end
end
\ No newline at end of file
spec/spec_helper.rb
View file @
65175efc
...
...
@@ -5,7 +5,7 @@ require 'zoholib'
RSpec
.
configure
do
|
conf
|
conf
.
before
(
:all
)
do
Zoholib
.
configure
do
|
config
|
Wedoops
::
Zoholib
.
configure
do
|
config
|
puts
"Trying to config"
config
.
client_id
=
"client_id"
config
.
client_secret
=
"client_secret"
...
...
spec/zoholib_spec.rb
View file @
65175efc
require
'spec_helper'
require
'stringio'
RSpec
.
describe
Zoholib
do
RSpec
.
describe
Wedoops
::
Zoholib
do
it
'has a version number'
do
expect
(
Zoholib
::
VERSION
).
not_to
be
nil
expect
(
Wedoops
::
Zoholib
::
VERSION
).
not_to
be
nil
end
it
'does something useful'
do
...
...
@@ -12,23 +12,23 @@ RSpec.describe Zoholib do
describe
'Configuration'
do
it
'The configuration shuld be a Zoholib::Configuration'
do
expect
(
Zoholib
.
configuration
).
to
be_a_kind_of
(
Zoholib
::
Configuration
)
expect
(
Wedoops
::
Zoholib
.
configuration
).
to
be_a_kind_of
(
Wedoops
::
Zoholib
::
Configuration
)
end
it
'The client_id is a string'
do
expect
(
Zoholib
.
configuration
.
client_id
).
to
be_an
(
String
)
expect
(
Wedoops
::
Zoholib
.
configuration
.
client_id
).
to
be_an
(
String
)
end
it
'The client_secret is a string'
do
expect
(
Zoholib
.
configuration
.
client_secret
).
to
be_an
(
String
)
expect
(
Wedoops
::
Zoholib
.
configuration
.
client_secret
).
to
be_an
(
String
)
end
it
'The scopes is a string'
do
expect
(
Zoholib
.
configuration
.
scope
).
to
be_an
(
String
)
expect
(
Wedoops
::
Zoholib
.
configuration
.
scope
).
to
be_an
(
String
)
end
it
'The refresh_token is a string'
do
expect
(
Zoholib
.
configuration
.
refresh_token
).
to
be_an
(
String
)
expect
(
Wedoops
::
Zoholib
.
configuration
.
refresh_token
).
to
be_an
(
String
)
end
end
end
\ No newline at end of file
zoholib.gemspec
View file @
65175efc
...
...
@@ -6,7 +6,7 @@ require 'zoholib/version'
Gem
::
Specification
.
new
do
|
spec
|
spec
.
name
=
'zoholib'
spec
.
version
=
Zoholib
::
VERSION
spec
.
version
=
Wedoops
::
Zoholib
::
VERSION
spec
.
date
=
'2020-04-25'
spec
.
authors
=
[
'Wedoops.io'
]
spec
.
email
=
'wedoops@wedoops.io'
...
...
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