Commit ee5bd026 authored by Chantal's avatar Chantal

zoho environment migration

parent 4bf0e274
...@@ -20,7 +20,7 @@ module Wedoops ...@@ -20,7 +20,7 @@ module Wedoops
@options = Hash.new @options = Hash.new
# environment specific settings # environment specific settings
if options.has_key?(:environment) && options[:environment] == "sandbox" 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.delete(:environment)
@options[:environment] = "sandbox" @options[:environment] = "sandbox"
end end
...@@ -90,7 +90,7 @@ module Wedoops ...@@ -90,7 +90,7 @@ module Wedoops
end end
def get_grant_token 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 # 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 # Atencion, este metodo abre un navegador para autorizar y un socket en el puerto 8000 para recibir el codigo tras
# la aceptacion de permisos # la aceptacion de permisos
...@@ -110,7 +110,7 @@ module Wedoops ...@@ -110,7 +110,7 @@ module Wedoops
end end
def get_grant_request 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 # Para recibir access_token y refresh_token
raise "Unable to get a grant request without grant token!" if @grant_token.nil? raise "Unable to get a grant request without grant token!" if @grant_token.nil?
options_grant_request = @options.dup options_grant_request = @options.dup
......
...@@ -3,11 +3,11 @@ module Wedoops ...@@ -3,11 +3,11 @@ module Wedoops
module Zoholib module Zoholib
class GrantRequest < ZohoRequest 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\""} #headers: {"Authorization" => "Token token=\"111\""}
def initialize(options={}) def initialize(options={})
if options.has_key?(:environment) && options[:environment] == "sandbox" 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.delete(:environment)
end end
...@@ -18,7 +18,7 @@ module Wedoops ...@@ -18,7 +18,7 @@ module Wedoops
def token(options={}) def token(options={})
# Esta funcion se llama desde Zoholib::AuthorizationRequest # 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[:query].merge!(grant_type: "authorization_code")
@options.merge!(:logger => @logger) @options.merge!(:logger => @logger)
response=self.class.post('/token',@options) response=self.class.post('/token',@options)
......
...@@ -15,7 +15,7 @@ module Wedoops ...@@ -15,7 +15,7 @@ module Wedoops
def initialize(options={}) def initialize(options={})
# environment specific settings # environment specific settings
if options.has_key?(:environment) && options[:environment] == "sandbox" 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.delete(:environment)
end end
......
...@@ -11,12 +11,12 @@ module Wedoops ...@@ -11,12 +11,12 @@ module Wedoops
module Zoholib module Zoholib
class ZohoBasicClient class ZohoBasicClient
include HTTParty include HTTParty
base_uri 'https://www.zohoapis.com/crm/v2/' base_uri 'https://www.zohoapis.eu/crm/v2/'
def initialize(options={}) def initialize(options={})
# environment specific settings # environment specific settings
if options.has_key?(:environment) && options[:environment] == "sandbox" 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 end
#Es un cliennte basico que trabaja a partir de refresh_tokens #Es un cliennte basico que trabaja a partir de refresh_tokens
......
...@@ -46,7 +46,7 @@ module Wedoops ...@@ -46,7 +46,7 @@ module Wedoops
end end
def get_code 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(url)
@logger.info("#> Sending request....") @logger.info("#> Sending request....")
HTTP.follow HTTP.follow
...@@ -160,8 +160,8 @@ module Wedoops ...@@ -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) execute_function("https://www.zohoapis.com/crm/v2/functions/getjsonparams/actions/execute?auth_type=apikey&zapikey=1003.7fb3bae78b241ff68541181c3b699cf1.983d91325ef11808acdc31d225fdca60",params)
when "call" when "call"
#just standard function #just standard function
#https://crm.zoho.com/crm/v2/functions/{api_name_of_function}/actions/execute?auth_type=apikey&zapikey={zapikey} #https://crm.zoho.eu/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") 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" when "read_api"
execute_function("https://www.zohoapis.com/crm/v2/Modules/") execute_function("https://www.zohoapis.com/crm/v2/Modules/")
when "adamo_address" when "adamo_address"
...@@ -219,9 +219,9 @@ module Wedoops ...@@ -219,9 +219,9 @@ module Wedoops
@logger.info("#{__method__} con @refresh_token = #{@refresh_token} y grant_token (@code) = #{@code}") @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 #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.eu/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.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.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}&redirect_uri=#{@redirect_uri}"
res=post(url) res=post(url)
resultado = JSON.parse(res,:symbolize_names => true) resultado = JSON.parse(res,:symbolize_names => true)
if resultado.has_key?(:error) if resultado.has_key?(:error)
...@@ -245,9 +245,9 @@ module Wedoops ...@@ -245,9 +245,9 @@ module Wedoops
@logger.info("#{__method__} con @refresh_token = #{@refresh_token} y grant_token (@code) = #{@code}") @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 #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.eu/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.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.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}&redirect_uri=#{@redirect_uri}"
res=post(url) res=post(url)
resultado = JSON.parse(res,:symbolize_names => true) resultado = JSON.parse(res,:symbolize_names => true)
if resultado.has_key?(:error) if resultado.has_key?(:error)
...@@ -271,10 +271,10 @@ module Wedoops ...@@ -271,10 +271,10 @@ module Wedoops
def refresh_oauth_token def refresh_oauth_token
#params=auth_params("refresh_token") #params=auth_params("refresh_token")
@logger.info("Refrescando el 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}") @logger.info("URL REFRESCO: #{url}")
# Pruebo sin pasar el secret # 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) res=post(url)
resultado = JSON.parse(res,:symbolize_names => true) resultado = JSON.parse(res,:symbolize_names => true)
if resultado.has_key?(:error) if resultado.has_key?(:error)
...@@ -294,7 +294,7 @@ module Wedoops ...@@ -294,7 +294,7 @@ module Wedoops
def update_life_token!(force=false) def update_life_token!(force=false)
#Recogemos el token para toda la vida #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 #A no ser que forcemos, devolvera true sin actualizar si el tokem es aun valido
unless force unless force
if valid_token? if valid_token?
...@@ -384,7 +384,7 @@ module Wedoops ...@@ -384,7 +384,7 @@ module Wedoops
def authorization_request def authorization_request
raise "Only available for OAuth" unless check_mode == "oauth" 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 end
def get(url) def get(url)
......
...@@ -6,9 +6,9 @@ module Wedoops ...@@ -6,9 +6,9 @@ module Wedoops
include HTTParty include HTTParty
#debug_output $stdout #debug_output $stdout
base_uri "https://accounts.zoho.com/oauth/v2/" base_uri "https://accounts.zoho.eu/oauth/v2/"
#https://accounts.zoho.com/oauth/v2/auth? #https://accounts.zoho.eu/oauth/v2/auth?
#https://accounts.zoho.com/oauth/v2/token? #https://accounts.zoho.eu/oauth/v2/token?
headers 'Content-Type' => 'application/json' headers 'Content-Type' => 'application/json'
attr_reader :subdomain, :uri attr_reader :subdomain, :uri
......
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