Commit e580b7a8 authored by Jose Ernesto Suarez's avatar Jose Ernesto Suarez

Merge branch 'fix/submodule' into 'master'

Fix/submodule

See merge request wedoops/zoholib!1
parents 0e4138c5 ed7c5be6
example_id | status | run_time | example_id | status | run_time |
----------------------------- | ------ | --------------- | ----------------------------- | ------ | --------------- |
./spec/zoholib_spec.rb[1:1] | passed | 0.00183 seconds | ./spec/zoholib_spec.rb[1:1] | passed | 0.00155 seconds |
./spec/zoholib_spec.rb[1:2] | passed | 0.00144 seconds | ./spec/zoholib_spec.rb[1:2] | passed | 0.00156 seconds |
./spec/zoholib_spec.rb[1:3:1] | passed | 0.00112 seconds | ./spec/zoholib_spec.rb[1:3:1] | passed | 0.00096 seconds |
./spec/zoholib_spec.rb[1:3:2] | passed | 0.0012 seconds | ./spec/zoholib_spec.rb[1:3:2] | passed | 0.00039 seconds |
./spec/zoholib_spec.rb[1:3:3] | passed | 0.00009 seconds | ./spec/zoholib_spec.rb[1:3:3] | passed | 0.00039 seconds |
./spec/zoholib_spec.rb[1:3:4] | passed | 0.0002 seconds | ./spec/zoholib_spec.rb[1:3:4] | passed | 0.00029 seconds |
./spec/zoholib_spec.rb[1:3:5] | passed | 0.00022 seconds | ./spec/zoholib_spec.rb[1:3:5] | passed | 0.00045 seconds |
...@@ -14,20 +14,22 @@ require 'zoholib/zoho_client' ...@@ -14,20 +14,22 @@ require 'zoholib/zoho_client'
## ##
# This library is used for access Zoho # This library is used for access Zoho
module Zoholib module Wedoops
class << self module Zoholib
attr_accessor :configuration class << self
end attr_accessor :configuration
end
def self.configuration
@configuration ||= Configuration.new def self.configuration
end @configuration ||= Configuration.new
end
def self.reset
@configuration = Configuration.new def self.reset
end @configuration = Configuration.new
end
def self.configure
yield(configuration) def self.configure
yield(configuration)
end
end end
end end
...@@ -4,93 +4,94 @@ require 'json' ...@@ -4,93 +4,94 @@ require 'json'
require 'logger' require 'logger'
require 'date' require 'date'
module Wedoops
module Zoholib
class AdamoClient
module Zoholib def initialize(options={})
class AdamoClient @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={}) def cobertura_project
@logger = Logger.new(STDOUT) count=2
@http = HTTP url = "https://coverage-dump.adamo.es/v1/cobertura-project/#{count}?limit=500"
.use(logging: {logger: @logger}) return HTTP.use(logging: {logger: @logger})
.timeout(connect: 15, read: 30) .timeout(connect: 15, read: 30)
.headers("cache-control" => "no-cache", .headers("cache-control" => "no-cache",
"accept" => "application/json", "accept" => "application/json",
"postman-token" => "8b126eb1-0de6-4a10-d78d-1fb417fb23b0", "postman-token" => "8b126eb1-0de6-4a10-d78d-1fb417fb23b0",
"x-apikey" => "Af8cbSpgkAReYqBs66DHJUkf2MJW3d9JDFVJhWe4U5haD") "x-apikey" => "Af8cbSpgkAReYqBs66DHJUkf2MJW3d9JDFVJhWe4U5haD").get(url)
end end
def cobertura_project def cobertura
count=2 page=1
url = "https://coverage-dump.adamo.es/v1/cobertura-project/#{count}?limit=500" limit=50000
return HTTP.use(logging: {logger: @logger}) #date=Date.parse("06-04-2020").strftime("%Y%m%d")
.timeout(connect: 15, read: 30) date=Date.today.prev_day.strftime("%Y%m%d")
.headers("cache-control" => "no-cache", resultado_final=Array.new
"accept" => "application/json", r=Array.new
"postman-token" => "8b126eb1-0de6-4a10-d78d-1fb417fb23b0", loop do
"x-apikey" => "Af8cbSpgkAReYqBs66DHJUkf2MJW3d9JDFVJhWe4U5haD").get(url) print "#{page} "
end
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 def projects
page=1 page=1
limit=50000 limit=50000
#date=Date.parse("06-04-2020").strftime("%Y%m%d") #date=Date.today.prev_day.strftime("%Y%m%d")
date=Date.today.prev_day.strftime("%Y%m%d") date=Date.parse("01-01-2011").strftime("%Y%m%d")
resultado_final=Array.new resultado_final=Array.new
r=Array.new r=Array.new
loop do loop do
print "#{page} " print "#{page} "
url= "https://coverage-dump.adamo.es/v1/cobertura-project/#{page}?limit=#{limit}&date=#{date}"
url= "https://coverage-dump.adamo.es/v1/cobertura/#{page}?limit=#{limit}&date=#{date}" #.use(logging: {logger: @logger})
#.use(logging: {logger: @logger}) resultado= HTTP.timeout(connect: 15, read: 30)
resultado= HTTP.timeout(connect: 15, read: 30) .headers("cache-control" => "no-cache",
.headers("cache-control" => "no-cache", "accept" => "application/json",
"accept" => "application/json", "postman-token" => "8b126eb1-0de6-4a10-d78d-1fb417fb23b0",
"postman-token" => "8b126eb1-0de6-4a10-d78d-1fb417fb23b0", "x-apikey" => "zYkWN38SYH6hr2Ixq75xvDENl6hrYOvxx0FxLvPD7BUe6").get(url)
"x-apikey" => "zYkWN38SYH6hr2Ixq75xvDENl6hrYOvxx0FxLvPD7BUe6").get(url) r= JSON.parse(resultado, symbolize_names: true)
r= JSON.parse(resultado, symbolize_names: true) resultado_final.concat(r)
resultado_final.concat(r) page+=1
page+=1 print "(#{r.size}/#{resultado_final.size}),"
print "(#{r.size}/#{resultado_final.size})," break if r.size < limit || page >2
break if r.size < limit || page >2 end
end puts resultado_final.size
puts resultado_final.size return resultado_final
return resultado_final end
end
def projects private
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 def get_params(url,payload)
@http.get(url, :params => payload)
end
def get_params(url,payload) def get(url)
@http.get(url, :params => payload) @http.get(url)
end end
end
def get(url) end
@http.get(url)
end
end
end end
\ No newline at end of file
This diff is collapsed.
...@@ -5,53 +5,54 @@ require 'logger' ...@@ -5,53 +5,54 @@ require 'logger'
require 'date' require 'date'
require 'savon' require 'savon'
module Wedoops
module Zoholib module Zoholib
class B12Client class B12Client
def initialize(options={}) def initialize(options={})
@logger = Logger.new(STDOUT) @logger = Logger.new(STDOUT)
initialize_client initialize_client
@client.call(:lead) @client.call(:lead)
end end
def send_lead(lead) def send_lead(lead)
@logger.info("Sending lead: #{lead[:idvar]} tlf:#{lead[:Telefono]}") @logger.info("Sending lead: #{lead[:idvar]} tlf:#{lead[:Telefono]}")
#pp lead #pp lead
#puts ":.................:" #puts ":.................:"
begin begin
response = @client.call(:lead) do response = @client.call(:lead) do
message(lead) message(lead)
end
rescue Exception => e
@logger.error("Error sending the lead: #{e.message}")
return nil
end end
rescue Exception => e begin
@logger.error("Error sending the lead: #{e.message}") b12_id = response.body[:lead_response][:return]
return nil unless b12_id.match(/^\d*$/)
end raise "Error de B12, envio #{lead[:idvar]} tlf:#{lead[:Telefono]} duplicado (#{b12_id})" if b12_id == "-1"
begin raise "Error interno de B12, error #{b12_id} recibido"
b12_id = response.body[:lead_response][:return] end
unless b12_id.match(/^\d*$/) rescue Exception => e
raise "Error de B12, envio #{lead[:idvar]} tlf:#{lead[:Telefono]} duplicado (#{b12_id})" if b12_id == "-1" @logger.error("Error getting the LEAD ID: #{e.message}")
raise "Error interno de B12, error #{b12_id} recibido" return nil
end end
rescue Exception => e return b12_id
@logger.error("Error getting the LEAD ID: #{e.message}")
return nil
end end
return b12_id
end
private private
def initialize_client def initialize_client
@client = Savon.client do @client = Savon.client do
wsdl 'http://panel.digitalion.com/wss/cobalt.lead.php?wsdl' wsdl 'http://panel.digitalion.com/wss/cobalt.lead.php?wsdl'
pretty_print_xml true pretty_print_xml true
#convert_request_keys_to :camelcase #convert_request_keys_to :camelcase
log false log false
log_level :info log_level :info
end
end end
end
end
end end
end end
\ No newline at end of file
# frozen_string_literal: true # 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 def initialize
## @client_id = nil
# This class permits the configuration of the Valenciaport Access. @client_secret = nil
# Is neccesary the WDSL URLs for the login and transport endpoint @scope = nil
# as well the array with the different credentials wich will be used @refresh_token = nil
class Configuration end
attr_accessor :client_id, :client_secret, :scope, :refresh_token
def initialize
@client_id = nil
@client_secret = nil
@scope = nil
@refresh_token = nil
end
end
end end
end end
\ No newline at end of file
#require './lib/zoho_request' #require './lib/zoho_request'
module Zoholib module Wedoops
class GrantRequest < ZohoRequest module Zoholib
class GrantRequest < ZohoRequest
#base_uri "https://accounts.zoho.com/oauth/v2/token" #base_uri "https://accounts.zoho.com/oauth/v2/token"
#headers: {"Authorization" => "Token token=\"111\""} #headers: {"Authorization" => "Token token=\"111\""}
def initialize(options={}) def initialize(options={})
@logger = ::Logger.new(STDOUT) @logger = ::Logger.new(STDOUT)
@logged_in = false @logged_in = false
@options = options @options = options
end end
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.com/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)
JSON.parse(response.body,symbolize_names: true) JSON.parse(response.body,symbolize_names: true)
end end
end
end end
end end
\ No newline at end of file
#require './lib/zoho_request' #require './lib/zoho_request'
module Zoholib module Wedoops
class RefreshRequest < ZohoRequest module Zoholib
class RefreshRequest < ZohoRequest
# Sin en algun momento se quiere evitar el encode de URL # Sin en algun momento se quiere evitar el encode de URL
# he aqui un truco # he aqui un truco
#query_string_normalizer proc { |query|
# query.map do |key, value|
# [value].flatten.map {|v| "#{key}=#{v}"}.join('&')
# end.join('&')
# }
def initialize(options={}) #query_string_normalizer proc { |query|
options.merge!(grant_type: "refresh_token") # query.map do |key, value|
@options={:query => options} # [value].flatten.map {|v| "#{key}=#{v}"}.join('&')
end # 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 end
end end
\ No newline at end of file
module Zoholib module Wedoops
module Zoho module Zoholib
class Response class Response
......
# frozen_string_literal: true # frozen_string_literal: true
module Wedoops
module Zoholib module Zoholib
VERSION = '0.0.1b' VERSION = '0.0.1b'
end end
end
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
require 'httparty' require 'httparty'
require 'json' require 'json'
module Wedoops
module Zoholib module Zoholib
class ZohoRequest class ZohoRequest
include HTTParty include HTTParty
#debug_output $stdout #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
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
end end
\ No newline at end of file
...@@ -5,7 +5,7 @@ require 'zoholib' ...@@ -5,7 +5,7 @@ require 'zoholib'
RSpec.configure do |conf| RSpec.configure do |conf|
conf.before(:all) do conf.before(:all) do
Zoholib.configure do |config| Wedoops::Zoholib.configure do |config|
puts "Trying to config" puts "Trying to config"
config.client_id = "client_id" config.client_id = "client_id"
config.client_secret = "client_secret" config.client_secret = "client_secret"
......
require 'spec_helper' require 'spec_helper'
require 'stringio' require 'stringio'
RSpec.describe Zoholib do RSpec.describe Wedoops::Zoholib do
it 'has a version number' do it 'has a version number' do
expect(Zoholib::VERSION).not_to be nil expect(Wedoops::Zoholib::VERSION).not_to be nil
end end
it 'does something useful' do it 'does something useful' do
...@@ -12,23 +12,23 @@ RSpec.describe Zoholib do ...@@ -12,23 +12,23 @@ RSpec.describe Zoholib do
describe 'Configuration' do describe 'Configuration' do
it 'The configuration shuld be a Zoholib::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 end
it 'The client_id is a string' do 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 end
it 'The client_secret is a string' do 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 end
it 'The scopes is a string' do 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 end
it 'The refresh_token is a string' do 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 end
end end
\ No newline at end of file
...@@ -6,7 +6,7 @@ require 'zoholib/version' ...@@ -6,7 +6,7 @@ require 'zoholib/version'
Gem::Specification.new do |spec| Gem::Specification.new do |spec|
spec.name = 'zoholib' spec.name = 'zoholib'
spec.version = Zoholib::VERSION spec.version = Wedoops::Zoholib::VERSION
spec.date = '2020-04-25' spec.date = '2020-04-25'
spec.authors = ['Wedoops.io'] spec.authors = ['Wedoops.io']
spec.email = 'wedoops@wedoops.io' spec.email = 'wedoops@wedoops.io'
......
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