Commit 38e7352b authored by Chantal's avatar Chantal

Merge branch 'fixes-uri' into 'master'

Fixes uri

See merge request !7
parents d73a4fb5 ee1f7241
.DS_Store
zoholib*.gem
.env
example_id | status | run_time |
----------------------------- | ------ | --------------- |
./spec/zoholib_spec.rb[1:1] | passed | 0.00155 seconds |
./spec/zoholib_spec.rb[1:2] | passed | 0.00156 seconds |
./spec/zoholib_spec.rb[1:3:1] | passed | 0.00096 seconds |
./spec/zoholib_spec.rb[1:3:2] | passed | 0.00039 seconds |
./spec/zoholib_spec.rb[1:3:3] | passed | 0.00039 seconds |
./spec/zoholib_spec.rb[1:3:4] | passed | 0.00029 seconds |
./spec/zoholib_spec.rb[1:3:5] | passed | 0.00045 seconds |
./spec/zoholib_spec.rb[1:1] | passed | 0.00071 seconds |
./spec/zoholib_spec.rb[1:2] | passed | 0.00047 seconds |
./spec/zoholib_spec.rb[1:3:1] | passed | 0.00044 seconds |
./spec/zoholib_spec.rb[1:3:2] | passed | 0.00006 seconds |
./spec/zoholib_spec.rb[1:3:3] | passed | 0.00006 seconds |
./spec/zoholib_spec.rb[1:3:4] | passed | 0.00004 seconds |
./spec/zoholib_spec.rb[1:3:5] | passed | 0.00004 seconds |
# Zoho Library
\ No newline at end of file
# Zoho Library
In case a new refresh_token is requested, is needed to generate it executing by hand a new authorization request.
This is becausee the ZOHO API opens a browser for manage the authorization, this can't be managed in the background
The AuthorizationRequest class also opens a server for receive the callback with the information.
```
irb> require './zoholib'
irb> options = {:client_id => '1000.W3UX1B57UxxxxxxxxxxxxxMDH',
:client_secret => '9axxxxxxxxxxxxxxdb3d18e',
:scope => "ZohoCRM.modules.ALL,ZohoCRM.coql.read",
:environment => "sandbox"}
irb> z=Wedoops::Zoholib::AuthorizationRequest.new(options)
irb> z.authorize
```
with this result
D, [2020-11-25T18:54:29.342094 #15899] DEBUG -- : grant token auth: {:environment=>"sandbox", :query=>{:client_id=>"1000.W3UX1B57UxxxxxxxxxxxxxMDH", :client_secret=>"9axxxxxxxxxxxxxxdb3d18e", :scope=>"ZohoCRM.modules.ALL,ZohoCRM.coql.read", :response_type=>"code", :access_type=>"offline", :redirect_uri=>"http://localhost:8000/auth/callback"}, :follow_redirects=>false} response
I, [2020-11-25T18:54:29.348050 #15899] INFO -- : Reading socket response
I, [2020-11-25T18:54:44.036801 #15899] INFO -- : GRANT TOKEN: 1000.70fec5d6a4dd2375df96616613d8205e.45603cb37cbd32987edb80d9a48dd38e
I, [2020-11-25T18:54:44.746596 #15899] INFO -- : [HTTParty] [2020-11-25 18:54:44 +0200] 200 "POST /token" 258
D, [2020-11-25T18:54:44.746711 #15899] DEBUG -- : grant request:{:query=>{:client_id=>"1000.W3UX1B57UxxxxxxxxxxxxxMDH", :client_secret=>"9axxxxxxxxxxxxxxdb3d18e", :redirect_uri=>"http://localhost:8000/auth/callback", :code=>"1000.70fec5d6a4dd2375df96616613d8205e.45603cb37cbd32987edb80d9a48dd38e", :grant_type=>"authorization_code"}, :logger=>#<Logger:0x00007f8e261545d0 @level=0, @progname=nil, @default_formatter=#<Logger::Formatter:0x00007f8e26154558 @datetime_format=nil>, @formatter=nil, @logdev=#<Logger::LogDevice:0x00007f8e261544e0 @shift_period_suffix=nil, @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x00007f8e26154490>>>} response: {"access_token":"1000.64686e79ebcd77a364bd28b906139d1b.453935f30b299d09087a2b2731543468","refresh_token":"1000.5c516d9e6caf86906bf7249101bxxxxxxxxxxxxxxxx380","api_domain":"https://www.zohoapis.com","token_type":"Bearer","expires_in":3600}
=> {:access_token=>"1000.64686e79ebcd7xxxxxxxxxb.453935f30b299d0908xxxxxxxxx8", :refresh_token=>"1000.5c516d9e6caf86906bf7249101bxxxxxxxxxxxxxxxx380", :api_domain=>"https://www.zohoapis.com", :token_type=>"Bearer", :expires_in=>3600}
now, we are able to initialize a new client with this token for accesing the sandbox
o={:refresh_token=>"1000.5c516d9e6caf86906bf7249101bxxxxxxxxxxxxxxxx380",
2.5.1 :009 > :client_id => '1000.W3UX1B57UxxxxxxxxxxxxxMDH',
2.5.1 :010 > :client_secret => '9axxxxxxxxxxxxxxdb3d18e',
2.5.1 :011 > :scope => "ZohoCRM.modules.ALL,ZohoCRM.coql.read",
2.5.1 :012 > :environment => "sandbox"}
z=Wedoops::Zoholib::ZohoBasicClient.new(o)
z.read("Contacts/4230509000000362013")
D, [2020-11-25T19:00:25.465606 #15899] DEBUG -- : Token is still valid
{"data"=>
[{"Owner"=>
{"name"=>"Zoho Admin",
"id"=>"4230509000000297001",
"email"=>"zoho.admin.ext@adamo.es"},
"Gis_Area"=>nil,
"B2B_Lead_Size"=>nil,
"Direcci_n_Cadmin"=>nil,
"$state"=>"save",
"$process_flow"=>false,
"Street"=>nil,
"id"=>"4230509000000362013",
"Coverage_Search_String"=>nil,
"$approval"=>
{"delegate"=>false, "approve"=>false, "reject"=>false, "resubmit"=>false},
"First_Visited_URL"=>nil,
"Created_Time"=>"2020-11-17T14:34:50+01:00",
"Estado_en_Cadmin"=>nil,
"response_B12"=>nil,
"Permanencia"=>nil,
"Longitude"=>nil,
"Nearest_Coverage"=>nil,
"Offline_Sent_Date"=>nil,
"Que_tiene_contratado"=>nil,
"Adamo_score"=>nil,
"Partner1"=>nil,
"LinkedIn"=>nil,
"Offline_Campaign"=>nil,
"Customer_ID"=>nil,
"Campa_a"=>nil,
"Last_Visited_Time"=>nil,
"Created_By"=>
{"name"=>"Zoho Admin",
"id"=>"4230509000000297001",
"email"=>"zoho.admin.ext@adamo.es"},
"UTM_Medium"=>nil,
"Description"=>nil,
"Customer_status"=>"WebSearch",
"Number_Of_Chats"=>nil,
"Vive_en_Poblaci_n"=>false,
"$review_process"=>{"approve"=>false, "reject"=>false, "resubmit"=>false},
"Average_Time_Spent_Minutes"=>nil,
"Salutation"=>nil,
"Full_Name"=>"Bo Bonnevie",
"RESPUESTA_IMP1"=>nil,
"Account_Name"=>nil,
"Email_Opt_Out"=>false,
"Tipo_accion"=>[],
"Last_Resoluci_n"=>nil,
"Fecha_Evento"=>nil,
"SMS_Campaign"=>nil,
"Mobile"=>nil,
"Territories"=>nil,
"smsmagic4__LeadIdCPY"=>nil,
"smsmagic4__Plain_Phone"=>"638737344",
"Form_URL"=>nil,
"Event_ID"=>nil,
"$orchestration"=>nil,
"Layout"=>{"name"=>"B2C", "id"=>"4230509000000091033"},
"Lead_Source"=>nil,
"CMS_Token"=>nil,
"Tag"=>[],
"Conoze_Adamo_por"=>nil,
"Email"=>"bo.bonnevie.ext@adamo.es",
"$currency_symbol"=>"EUR",
"Cargo_en_la_empresa"=>nil,
"Visitor_Score"=>nil,
"CallType_Sys02"=>nil,
"Latitude"=>nil,
"Accion"=>[],
"Last_Activity_Time"=>nil,
"Unsubscribed_Mode"=>nil,
"Adamo_Address"=>nil,
"Mailing_Date"=>nil,
"Zip_Code"=>nil,
"$approved"=>true,
"Reporting_To"=>nil,
"Not_For_Telesale"=>false,
"Fecha_de_carga"=>nil,
"Days_Visited"=>nil,
"Enlace_Cadmin"=>nil,
"Channel"=>nil,
"$editable"=>true,
"City"=>nil,
"Province"=>nil,
"Full_street"=>nil,
"Matching_Adamo_Appartment"=>nil,
"Lead_Created_Date"=>"2020-11-17T14:00:00+01:00",
"Previous_Distance"=>nil,
"Campaign"=>nil,
"UTM_Content"=>nil,
"ValidPhone"=>false,
"Embajador_Fiberhood"=>false,
"Operator"=>"Marketing",
"UTM_Campaign"=>nil,
"Poblaci_n_Evento"=>nil,
"First_Name"=>"Bo",
"Modified_By"=>
{"name"=>"Zoho Admin",
"id"=>"4230509000000297001",
"email"=>"zoho.admin.ext@adamo.es"},
"$review"=>nil,
"Phone"=>"638737344",
"Adamo_internal_ID"=>"NA",
"Modified_Time"=>"2020-11-17T14:34:50+01:00",
"Distance_nearest_Coverage"=>nil,
"Unsubscribed_Time"=>nil,
"Fiberhood"=>nil,
"First_Visited_Time"=>nil,
"Sabe_de_adamo"=>false,
"Last_Name"=>"Bonnevie",
"$in_merge"=>false,
"Referrer"=>nil,
"Distance_Updated"=>nil,
"UTM_Source"=>nil,
"$approval_state"=>"approved",
"SMS_Sent_Date"=>nil,
"DNI"=>nil}]}
\ No newline at end of file
......@@ -17,14 +17,16 @@ module Wedoops
}
def initialize(options={})
@options = Hash.new
# environment specific settings
if options.has_key?(:environment) && options[:environment] == "sandbox"
self.class.base_url "https://sandbox.zohoapis.com/oauth/v2/"
self.class.base_uri "https://accounts.zoho.com/oauth/v2/"
options.delete(:environment)
@options[:environment] = "sandbox"
end
#build_url(options)
@logger = ::Logger.new(STDOUT)
@options = Hash.new
options.merge!({response_type: 'code',access_type: 'offline',redirect_uri: 'http://localhost:8000/auth/callback'})
@grant_token = options[:grant_token]
#@options.merge!(grant_token: options[:grant_token] )
......@@ -94,6 +96,7 @@ module Wedoops
# la aceptacion de permisos
@options.merge!(follow_redirects: false)
response=self.class.get('/auth', @options)
@logger.debug("grant token auth: #{@options} response #{response}")
# puts "RESPONSE CODE:#{response.code}"
if response.code >= 300 && response.code < 400
redirect_url = response.headers['location']
......@@ -127,4 +130,4 @@ module Wedoops
end
end
end
\ No newline at end of file
end
......@@ -6,9 +6,9 @@ module Wedoops
#base_uri "https://accounts.zoho.com/oauth/v2/token"
#headers: {"Authorization" => "Token token=\"111\""}
def initialize(options={})
# environment specific settings
if options.has_key?(:environment) && options[:environment] == "sandbox"
self.class.base_url "https://sandbox.zohoapis.com/oauth/v2/"
self.class.base_uri "https://accounts.zoho.com/oauth/v2/"
options.delete(:environment)
end
@logger = ::Logger.new(STDOUT)
......@@ -22,6 +22,7 @@ module Wedoops
@options[:query].merge!(grant_type: "authorization_code")
@options.merge!(:logger => @logger)
response=self.class.post('/token',@options)
@logger.debug("grant request:#{@options} response: #{response}")
JSON.parse(response.body,symbolize_names: true)
end
......@@ -29,4 +30,4 @@ module Wedoops
end
end
end
\ No newline at end of file
end
......@@ -15,7 +15,8 @@ module Wedoops
def initialize(options={})
# environment specific settings
if options.has_key?(:environment) && options[:environment] == "sandbox"
self.class.base_url "https://sandbox.zohoapis.com/oauth/v2/"
self.class.base_uri "https://accounts.zoho.com/oauth/v2/"
options.delete(:environment)
end
options.merge!(grant_type: "refresh_token")
......@@ -29,4 +30,4 @@ module Wedoops
end
end
end
\ No newline at end of file
end
# frozen_string_literal: true
module Wedoops
module Zoholib
VERSION = '0.30' #introduces Sys02
VERSION = '0.31'
end
end
\ No newline at end of file
......@@ -16,7 +16,7 @@ module Wedoops
def initialize(options={})
# environment specific settings
if options.has_key?(:environment) && options[:environment] == "sandbox"
self.class.base_url "https://sandbox.zohoapis.com/crm/v2/"
self.class.base_uri "https://sandbox.zohoapis.com/crm/v2/"
end
#Es un cliennte basico que trabaja a partir de refresh_tokens
......@@ -50,6 +50,7 @@ module Wedoops
end
request= Zoholib::RefreshRequest.new(@options)
response=request.get_token
@logger.debug("Request: #{request.inspect} URI: #{request.class.base_uri}")
@logger.debug("#{__method__}:#{response.request.last_uri.to_s}")
response = JSON.parse(response.to_s, symbolize_names: true)
......@@ -126,6 +127,19 @@ module Wedoops
options[:body]=data
options.merge!(build_header)
response=self.class.put("/#{url}/upsert",options)
@logger.debug("#{__method__}:#{response.request.last_uri.to_s}")
return manage_response(response,{:method=>__method__,:parameters => method(__method__).parameters.map { |arg| arg[1].to_s }})
end
def upsert(url,data)
raise "Invalid JSON!" unless valid_json?(data)
self.login?
options = {}
#Ojo, aqui tal vez deberiamos coprobar que viene con la forma :data => [:coleccion]
options[:body]=data
options.merge!(build_header)
response=self.class.put("/#{url}",options)
@logger.debug("#{__method__}:#{response.request.last_uri.to_s}")
return manage_response(response,{:method=>__method__,:parameters => method(__method__).parameters.map { |arg| arg[1].to_s }})
......@@ -244,4 +258,4 @@ module Wedoops
end
end
end
\ No newline at end of file
end
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