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
ee5bd026
Commit
ee5bd026
authored
Mar 07, 2022
by
Chantal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zoho environment migration
parent
4bf0e274
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
25 additions
and
25 deletions
+25
-25
authorization_request.rb
lib/zoholib/authorization_request.rb
+3
-3
grant_request.rb
lib/zoholib/grant_request.rb
+3
-3
refresh_request.rb
lib/zoholib/refresh_request.rb
+1
-1
zoho_basic_client.rb
lib/zoholib/zoho_basic_client.rb
+2
-2
zoho_client.rb
lib/zoholib/zoho_client.rb
+13
-13
zoho_request.rb
lib/zoholib/zoho_request.rb
+3
-3
No files found.
lib/zoholib/authorization_request.rb
View file @
ee5bd026
...
...
@@ -20,7 +20,7 @@ module Wedoops
@options
=
Hash
.
new
# environment specific settings
if
options
.
has_key?
(
:environment
)
&&
options
[
:environment
]
==
"sandbox"
self
.
class
.
base_uri
"https://accounts.zoho.
com
/oauth/v2/"
self
.
class
.
base_uri
"https://accounts.zoho.
eu
/oauth/v2/"
options
.
delete
(
:environment
)
@options
[
:environment
]
=
"sandbox"
end
...
...
@@ -90,7 +90,7 @@ module Wedoops
end
def
get_grant_token
# Ejecuta lo descrito en el paso 2 del ZOHO OAUTH https://www.zoho.
com
/crm/developer/docs/api/auth-request.html
# Ejecuta lo descrito en el paso 2 del ZOHO OAUTH https://www.zoho.
eu
/crm/developer/docs/api/auth-request.html
# Para recibir el codigo que nos permitira generar los tokens
# Atencion, este metodo abre un navegador para autorizar y un socket en el puerto 8000 para recibir el codigo tras
# la aceptacion de permisos
...
...
@@ -110,7 +110,7 @@ module Wedoops
end
def
get_grant_request
# Prepara la llamada descrita en el paso 3 del ZOHO OAUTH https://www.zoho.
com
/crm/developer/docs/api/access-refresh.html
# Prepara la llamada descrita en el paso 3 del ZOHO OAUTH https://www.zoho.
eu
/crm/developer/docs/api/access-refresh.html
# Para recibir access_token y refresh_token
raise
"Unable to get a grant request without grant token!"
if
@grant_token
.
nil?
options_grant_request
=
@options
.
dup
...
...
lib/zoholib/grant_request.rb
View file @
ee5bd026
...
...
@@ -3,11 +3,11 @@ module Wedoops
module
Zoholib
class
GrantRequest
<
ZohoRequest
#base_uri "https://accounts.zoho.
com
/oauth/v2/token"
#base_uri "https://accounts.zoho.
eu
/oauth/v2/token"
#headers: {"Authorization" => "Token token=\"111\""}
def
initialize
(
options
=
{})
if
options
.
has_key?
(
:environment
)
&&
options
[
:environment
]
==
"sandbox"
self
.
class
.
base_uri
"https://accounts.zoho.
com
/oauth/v2/"
self
.
class
.
base_uri
"https://accounts.zoho.
eu
/oauth/v2/"
options
.
delete
(
:environment
)
end
...
...
@@ -18,7 +18,7 @@ module Wedoops
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
# Ejecuta lo descrito en https://www.zoho.
eu
/crm/developer/docs/api/access-refresh.html
@options
[
:query
].
merge!
(
grant_type:
"authorization_code"
)
@options
.
merge!
(
:logger
=>
@logger
)
response
=
self
.
class
.
post
(
'/token'
,
@options
)
...
...
lib/zoholib/refresh_request.rb
View file @
ee5bd026
...
...
@@ -15,7 +15,7 @@ module Wedoops
def
initialize
(
options
=
{})
# environment specific settings
if
options
.
has_key?
(
:environment
)
&&
options
[
:environment
]
==
"sandbox"
self
.
class
.
base_uri
"https://accounts.zoho.
com
/oauth/v2/"
self
.
class
.
base_uri
"https://accounts.zoho.
eu
/oauth/v2/"
options
.
delete
(
:environment
)
end
...
...
lib/zoholib/zoho_basic_client.rb
View file @
ee5bd026
...
...
@@ -11,12 +11,12 @@ module Wedoops
module
Zoholib
class
ZohoBasicClient
include
HTTParty
base_uri
'https://www.zohoapis.
com
/crm/v2/'
base_uri
'https://www.zohoapis.
eu
/crm/v2/'
def
initialize
(
options
=
{})
# environment specific settings
if
options
.
has_key?
(
:environment
)
&&
options
[
:environment
]
==
"sandbox"
self
.
class
.
base_uri
"https://sandbox.zohoapis.
com
/crm/v2/"
self
.
class
.
base_uri
"https://sandbox.zohoapis.
eu
/crm/v2/"
end
#Es un cliennte basico que trabaja a partir de refresh_tokens
...
...
lib/zoholib/zoho_client.rb
View file @
ee5bd026
...
...
@@ -46,7 +46,7 @@ module Wedoops
end
def
get_code
url
=
"https://accounts.zoho.
com
/oauth/v2/auth?scope=
#{
@scope
}
&client_id=
#{
@client_id
}
&response_type=code&access_type=offline&redirect_uri=
#{
@redirect_uri
}
"
url
=
"https://accounts.zoho.
eu
/oauth/v2/auth?scope=
#{
@scope
}
&client_id=
#{
@client_id
}
&response_type=code&access_type=offline&redirect_uri=
#{
@redirect_uri
}
"
@logger
.
info
(
url
)
@logger
.
info
(
"#> Sending request...."
)
HTTP
.
follow
...
...
@@ -160,8 +160,8 @@ module Wedoops
execute_function
(
"https://www.zohoapis.com/crm/v2/functions/getjsonparams/actions/execute?auth_type=apikey&zapikey=1003.7fb3bae78b241ff68541181c3b699cf1.983d91325ef11808acdc31d225fdca60"
,
params
)
when
"call"
#just standard function
#https://crm.zoho.
com
/crm/v2/functions/{api_name_of_function}/actions/execute?auth_type=apikey&zapikey={zapikey}
execute_function
(
"https://crm.zoho.
com
/crm/v2/functions/{api_name_of_function}/actions/execute?auth_type=apikey&zapikey=1003.7fb3bae78b241ff68541181c3b699cf1.983d91325ef11808acdc31d225fdca60"
)
#https://crm.zoho.
eu
/crm/v2/functions/{api_name_of_function}/actions/execute?auth_type=apikey&zapikey={zapikey}
execute_function
(
"https://crm.zoho.
eu
/crm/v2/functions/{api_name_of_function}/actions/execute?auth_type=apikey&zapikey=1003.7fb3bae78b241ff68541181c3b699cf1.983d91325ef11808acdc31d225fdca60"
)
when
"read_api"
execute_function
(
"https://www.zohoapis.com/crm/v2/Modules/"
)
when
"adamo_address"
...
...
@@ -219,9 +219,9 @@ module Wedoops
@logger
.
info
(
"
#{
__method__
}
con @refresh_token =
#{
@refresh_token
}
y grant_token (@code) =
#{
@code
}
"
)
#Proceso OAUTH para recibir un nuevo refresh_token para poder refrescar el token
#url="https://accounts.zoho.
com
/oauth/v2/token?client_id=#{@client_id}&client_secret=#{@client_secret}&grant_type=authorization_code&code=#{@code}"
#url="https://accounts.zoho.
com
/oauth/v2/token?client_id=#{@client_id}&client_secret=#{@client_secret}&grant_type=refresh_token&code=#{@code}&redirect_uri=http://localhost:8000/auth/callback"
url
=
"https://accounts.zoho.
com
/oauth/v2/token?client_id=
#{
@client_id
}
&client_secret=
#{
@client_secret
}
&grant_type=authorization_code&code=
#{
@code
}
&redirect_uri=
#{
@redirect_uri
}
"
#url="https://accounts.zoho.
eu
/oauth/v2/token?client_id=#{@client_id}&client_secret=#{@client_secret}&grant_type=authorization_code&code=#{@code}"
#url="https://accounts.zoho.
eu
/oauth/v2/token?client_id=#{@client_id}&client_secret=#{@client_secret}&grant_type=refresh_token&code=#{@code}&redirect_uri=http://localhost:8000/auth/callback"
url
=
"https://accounts.zoho.
eu
/oauth/v2/token?client_id=
#{
@client_id
}
&client_secret=
#{
@client_secret
}
&grant_type=authorization_code&code=
#{
@code
}
&redirect_uri=
#{
@redirect_uri
}
"
res
=
post
(
url
)
resultado
=
JSON
.
parse
(
res
,
:symbolize_names
=>
true
)
if
resultado
.
has_key?
(
:error
)
...
...
@@ -245,9 +245,9 @@ module Wedoops
@logger
.
info
(
"
#{
__method__
}
con @refresh_token =
#{
@refresh_token
}
y grant_token (@code) =
#{
@code
}
"
)
#Proceso OAUTH para recibir un nuevo refresh_token para poder refrescar el token
#url="https://accounts.zoho.
com
/oauth/v2/token?client_id=#{@client_id}&client_secret=#{@client_secret}&grant_type=authorization_code&code=#{@code}"
#url="https://accounts.zoho.
com
/oauth/v2/token?client_id=#{@client_id}&client_secret=#{@client_secret}&grant_type=refresh_token&code=#{@code}&redirect_uri=http://localhost:8000/auth/callback"
url
=
"https://accounts.zoho.
com
/oauth/v2/token?client_id=
#{
@client_id
}
&client_secret=
#{
@client_secret
}
&grant_type=authorization_code&code=
#{
@code
}
&redirect_uri=
#{
@redirect_uri
}
"
#url="https://accounts.zoho.
eu
/oauth/v2/token?client_id=#{@client_id}&client_secret=#{@client_secret}&grant_type=authorization_code&code=#{@code}"
#url="https://accounts.zoho.
eu
/oauth/v2/token?client_id=#{@client_id}&client_secret=#{@client_secret}&grant_type=refresh_token&code=#{@code}&redirect_uri=http://localhost:8000/auth/callback"
url
=
"https://accounts.zoho.
eu
/oauth/v2/token?client_id=
#{
@client_id
}
&client_secret=
#{
@client_secret
}
&grant_type=authorization_code&code=
#{
@code
}
&redirect_uri=
#{
@redirect_uri
}
"
res
=
post
(
url
)
resultado
=
JSON
.
parse
(
res
,
:symbolize_names
=>
true
)
if
resultado
.
has_key?
(
:error
)
...
...
@@ -271,10 +271,10 @@ module Wedoops
def
refresh_oauth_token
#params=auth_params("refresh_token")
@logger
.
info
(
"Refrescando el token...."
)
url
=
"https://accounts.zoho.
com
/oauth/v2/token?refresh_token=
#{
@refresh_token
}
&client_id=
#{
@client_id
}
&client_secret=
#{
@client_secret
}
&grant_type=refresh_token"
url
=
"https://accounts.zoho.
eu
/oauth/v2/token?refresh_token=
#{
@refresh_token
}
&client_id=
#{
@client_id
}
&client_secret=
#{
@client_secret
}
&grant_type=refresh_token"
@logger
.
info
(
"URL REFRESCO:
#{
url
}
"
)
# Pruebo sin pasar el secret
#url="https://accounts.zoho.
com
/oauth/v2/token?refresh_token=#{@refresh_token}&client_id=#{@client_id}&grant_type=refresh_token"
#url="https://accounts.zoho.
eu
/oauth/v2/token?refresh_token=#{@refresh_token}&client_id=#{@client_id}&grant_type=refresh_token"
res
=
post
(
url
)
resultado
=
JSON
.
parse
(
res
,
:symbolize_names
=>
true
)
if
resultado
.
has_key?
(
:error
)
...
...
@@ -294,7 +294,7 @@ module Wedoops
def
update_life_token!
(
force
=
false
)
#Recogemos el token para toda la vida
token_url
=
"https://accounts.zoho.
com
/apiauthtoken/xml/create?SCOPE=
#{
@scope
}
&EMAIL_ID=
#{
@user
}
&PASSWORD=
#{
@pass
}
"
token_url
=
"https://accounts.zoho.
eu
/apiauthtoken/xml/create?SCOPE=
#{
@scope
}
&EMAIL_ID=
#{
@user
}
&PASSWORD=
#{
@pass
}
"
#A no ser que forcemos, devolvera true sin actualizar si el tokem es aun valido
unless
force
if
valid_token?
...
...
@@ -384,7 +384,7 @@ module Wedoops
def
authorization_request
raise
"Only available for OAuth"
unless
check_mode
==
"oauth"
#"https://accounts.zoho.
com
/oauth/v2/auth?scope=ZohoCRM.users.ALL&client_id={client_id}&response_type=code&access_type={"offline"or"online"}&redirect_uri={redirect_uri}"
#"https://accounts.zoho.
eu
/oauth/v2/auth?scope=ZohoCRM.users.ALL&client_id={client_id}&response_type=code&access_type={"offline"or"online"}&redirect_uri={redirect_uri}"
end
def
get
(
url
)
...
...
lib/zoholib/zoho_request.rb
View file @
ee5bd026
...
...
@@ -6,9 +6,9 @@ module Wedoops
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?
base_uri
"https://accounts.zoho.
eu
/oauth/v2/"
#https://accounts.zoho.
eu
/oauth/v2/auth?
#https://accounts.zoho.
eu
/oauth/v2/token?
headers
'Content-Type'
=>
'application/json'
attr_reader
:subdomain
,
:uri
...
...
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