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
38e7352b
Commit
38e7352b
authored
Mar 08, 2021
by
Chantal
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fixes-uri' into 'master'
Fixes uri See merge request
!7
parents
d73a4fb5
ee1f7241
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
194 additions
and
19 deletions
+194
-19
.gitignore
.gitignore
+1
-0
.rspec_status
.rspec_status
+7
-7
README.md
README.md
+156
-1
authorization_request.rb
lib/zoholib/authorization_request.rb
+6
-3
grant_request.rb
lib/zoholib/grant_request.rb
+4
-3
refresh_request.rb
lib/zoholib/refresh_request.rb
+3
-2
version.rb
lib/zoholib/version.rb
+1
-1
zoho_basic_client.rb
lib/zoholib/zoho_basic_client.rb
+16
-2
No files found.
.gitignore
View file @
38e7352b
.DS_Store
zoholib*.gem
.env
.rspec_status
View file @
38e7352b
example_id | status | run_time |
----------------------------- | ------ | --------------- |
./spec/zoholib_spec.rb[1:1] | passed | 0.00
155
seconds |
./spec/zoholib_spec.rb[1:2] | passed | 0.00
156
seconds |
./spec/zoholib_spec.rb[1:3:1] | passed | 0.000
96
seconds |
./spec/zoholib_spec.rb[1:3:2] | passed | 0.000
39
seconds |
./spec/zoholib_spec.rb[1:3:3] | passed | 0.000
39
seconds |
./spec/zoholib_spec.rb[1:3:4] | passed | 0.000
29
seconds |
./spec/zoholib_spec.rb[1:3:5] | passed | 0.000
45
seconds |
./spec/zoholib_spec.rb[1:1] | passed | 0.00
071
seconds |
./spec/zoholib_spec.rb[1:2] | passed | 0.00
047
seconds |
./spec/zoholib_spec.rb[1:3:1] | passed | 0.000
44
seconds |
./spec/zoholib_spec.rb[1:3:2] | passed | 0.000
06
seconds |
./spec/zoholib_spec.rb[1:3:3] | passed | 0.000
06
seconds |
./spec/zoholib_spec.rb[1:3:4] | passed | 0.000
04
seconds |
./spec/zoholib_spec.rb[1:3:5] | passed | 0.000
04
seconds |
README.md
View file @
38e7352b
# 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
lib/zoholib/authorization_request.rb
View file @
38e7352b
...
...
@@ -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'
]
...
...
lib/zoholib/grant_request.rb
View file @
38e7352b
...
...
@@ -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
...
...
lib/zoholib/refresh_request.rb
View file @
38e7352b
...
...
@@ -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"
)
...
...
lib/zoholib/version.rb
View file @
38e7352b
# frozen_string_literal: true
module
Wedoops
module
Zoholib
VERSION
=
'0.3
0'
#introduces Sys02
VERSION
=
'0.3
1'
end
end
\ No newline at end of file
lib/zoholib/zoho_basic_client.rb
View file @
38e7352b
...
...
@@ -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
}})
...
...
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