Commit 65175efc authored by Jose Ernesto Suarez's avatar Jose Ernesto Suarez

Se mueve todo el modulo Wedoops

parent 0e4138c5
example_id | status | run_time |
----------------------------- | ------ | --------------- |
./spec/zoholib_spec.rb[1:1] | passed | 0.00183 seconds |
./spec/zoholib_spec.rb[1:2] | passed | 0.00144 seconds |
./spec/zoholib_spec.rb[1:3:1] | passed | 0.00112 seconds |
./spec/zoholib_spec.rb[1:3:2] | passed | 0.0012 seconds |
./spec/zoholib_spec.rb[1:3:3] | passed | 0.00009 seconds |
./spec/zoholib_spec.rb[1:3:4] | passed | 0.0002 seconds |
./spec/zoholib_spec.rb[1:3:5] | passed | 0.00022 seconds |
./spec/zoholib_spec.rb[1:1] | passed | 0.00261 seconds |
./spec/zoholib_spec.rb[1:2] | passed | 0.00141 seconds |
./spec/zoholib_spec.rb[1:3:1] | passed | 0.00125 seconds |
./spec/zoholib_spec.rb[1:3:2] | passed | 0.00011 seconds |
./spec/zoholib_spec.rb[1:3:3] | passed | 0.00008 seconds |
./spec/zoholib_spec.rb[1:3:4] | passed | 0.00016 seconds |
./spec/zoholib_spec.rb[1:3:5] | passed | 0.00017 seconds |
......@@ -14,20 +14,22 @@ require 'zoholib/zoho_client'
##
# This library is used for access Zoho
module Zoholib
class << self
attr_accessor :configuration
end
def self.configuration
@configuration ||= Configuration.new
end
def self.reset
@configuration = Configuration.new
end
def self.configure
yield(configuration)
module Wedoops
module Zoholib
class << self
attr_accessor :configuration
end
def self.configuration
@configuration ||= Configuration.new
end
def self.reset
@configuration = Configuration.new
end
def self.configure
yield(configuration)
end
end
end
......@@ -4,93 +4,94 @@ require 'json'
require 'logger'
require 'date'
module Wedoops
module Zoholib
class AdamoClient
module Zoholib
class AdamoClient
def initialize(options={})
@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={})
@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 cobertura_project
count=2
url = "https://coverage-dump.adamo.es/v1/cobertura-project/#{count}?limit=500"
return 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").get(url)
end
def cobertura_project
count=2
url = "https://coverage-dump.adamo.es/v1/cobertura-project/#{count}?limit=500"
return 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").get(url)
end
def cobertura
page=1
limit=50000
#date=Date.parse("06-04-2020").strftime("%Y%m%d")
date=Date.today.prev_day.strftime("%Y%m%d")
resultado_final=Array.new
r=Array.new
loop do
print "#{page} "
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
page=1
limit=50000
#date=Date.parse("06-04-2020").strftime("%Y%m%d")
date=Date.today.prev_day.strftime("%Y%m%d")
resultado_final=Array.new
r=Array.new
loop do
print "#{page} "
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 projects
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
def projects
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
private
def get_params(url,payload)
@http.get(url, :params => payload)
end
def get_params(url,payload)
@http.get(url, :params => payload)
end
def get(url)
@http.get(url)
end
end
def get(url)
@http.get(url)
end
end
end
end
\ No newline at end of file
This diff is collapsed.
......@@ -5,53 +5,54 @@ require 'logger'
require 'date'
require 'savon'
module Zoholib
class B12Client
module Wedoops
module Zoholib
class B12Client
def initialize(options={})
@logger = Logger.new(STDOUT)
initialize_client
@client.call(:lead)
end
def initialize(options={})
@logger = Logger.new(STDOUT)
initialize_client
@client.call(:lead)
end
def send_lead(lead)
@logger.info("Sending lead: #{lead[:idvar]} tlf:#{lead[:Telefono]}")
#pp lead
#puts ":.................:"
begin
response = @client.call(:lead) do
message(lead)
def send_lead(lead)
@logger.info("Sending lead: #{lead[:idvar]} tlf:#{lead[:Telefono]}")
#pp lead
#puts ":.................:"
begin
response = @client.call(:lead) do
message(lead)
end
rescue Exception => e
@logger.error("Error sending the lead: #{e.message}")
return nil
end
rescue Exception => e
@logger.error("Error sending the lead: #{e.message}")
return nil
end
begin
b12_id = response.body[:lead_response][:return]
unless b12_id.match(/^\d*$/)
raise "Error de B12, envio #{lead[:idvar]} tlf:#{lead[:Telefono]} duplicado (#{b12_id})" if b12_id == "-1"
raise "Error interno de B12, error #{b12_id} recibido"
begin
b12_id = response.body[:lead_response][:return]
unless b12_id.match(/^\d*$/)
raise "Error de B12, envio #{lead[:idvar]} tlf:#{lead[:Telefono]} duplicado (#{b12_id})" if b12_id == "-1"
raise "Error interno de B12, error #{b12_id} recibido"
end
rescue Exception => e
@logger.error("Error getting the LEAD ID: #{e.message}")
return nil
end
rescue Exception => e
@logger.error("Error getting the LEAD ID: #{e.message}")
return nil
return b12_id
end
return b12_id
end
private
private
def initialize_client
@client = Savon.client do
wsdl 'http://panel.digitalion.com/wss/cobalt.lead.php?wsdl'
pretty_print_xml true
#convert_request_keys_to :camelcase
log false
log_level :info
def initialize_client
@client = Savon.client do
wsdl 'http://panel.digitalion.com/wss/cobalt.lead.php?wsdl'
pretty_print_xml true
#convert_request_keys_to :camelcase
log false
log_level :info
end
end
end
end
end
end
\ No newline at end of file
# 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
##
# 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
def initialize
@client_id = nil
@client_secret = nil
@scope = nil
@refresh_token = nil
end
def initialize
@client_id = nil
@client_secret = nil
@scope = nil
@refresh_token = nil
end
end
end
end
end
\ No newline at end of file
#require './lib/zoho_request'
module Zoholib
class GrantRequest < ZohoRequest
module Wedoops
module Zoholib
class GrantRequest < ZohoRequest
#base_uri "https://accounts.zoho.com/oauth/v2/token"
#headers: {"Authorization" => "Token token=\"111\""}
def initialize(options={})
@logger = ::Logger.new(STDOUT)
@logged_in = false
@options = options
end
#base_uri "https://accounts.zoho.com/oauth/v2/token"
#headers: {"Authorization" => "Token token=\"111\""}
def initialize(options={})
@logger = ::Logger.new(STDOUT)
@logged_in = false
@options = options
end
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
@options[:query].merge!(grant_type: "authorization_code")
@options.merge!(:logger => @logger)
response=self.class.post('/token',@options)
JSON.parse(response.body,symbolize_names: true)
end
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
@options[:query].merge!(grant_type: "authorization_code")
@options.merge!(:logger => @logger)
response=self.class.post('/token',@options)
JSON.parse(response.body,symbolize_names: true)
end
end
end
end
\ No newline at end of file
#require './lib/zoho_request'
module Zoholib
class RefreshRequest < ZohoRequest
module Wedoops
module Zoholib
class RefreshRequest < ZohoRequest
# Sin en algun momento se quiere evitar el encode de URL
# he aqui un truco
#query_string_normalizer proc { |query|
# query.map do |key, value|
# [value].flatten.map {|v| "#{key}=#{v}"}.join('&')
# end.join('&')
# }
# Sin en algun momento se quiere evitar el encode de URL
# he aqui un truco
def initialize(options={})
options.merge!(grant_type: "refresh_token")
@options={:query => options}
end
#query_string_normalizer proc { |query|
# query.map do |key, value|
# [value].flatten.map {|v| "#{key}=#{v}"}.join('&')
# 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
\ No newline at end of file
module Zoholib
module Zoho
module Wedoops
module Zoholib
class Response
......
# frozen_string_literal: true
module Zoholib
VERSION = '0.0.1b'
end
module Wedoops
module Zoholib
VERSION = '0.0.1b'
end
end
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
require 'httparty'
require 'json'
module Zoholib
class ZohoRequest
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?
headers 'Content-Type' => 'application/json'
attr_reader :subdomain, :uri
module Wedoops
module Zoholib
class ZohoRequest
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?
headers 'Content-Type' => 'application/json'
attr_reader :subdomain, :uri
end
end
end
\ No newline at end of file
......@@ -5,7 +5,7 @@ require 'zoholib'
RSpec.configure do |conf|
conf.before(:all) do
Zoholib.configure do |config|
Wedoops::Zoholib.configure do |config|
puts "Trying to config"
config.client_id = "client_id"
config.client_secret = "client_secret"
......
require 'spec_helper'
require 'stringio'
RSpec.describe Zoholib do
RSpec.describe Wedoops::Zoholib do
it 'has a version number' do
expect(Zoholib::VERSION).not_to be nil
expect(Wedoops::Zoholib::VERSION).not_to be nil
end
it 'does something useful' do
......@@ -12,23 +12,23 @@ RSpec.describe Zoholib do
describe '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
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
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
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
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
\ No newline at end of file
......@@ -6,7 +6,7 @@ require 'zoholib/version'
Gem::Specification.new do |spec|
spec.name = 'zoholib'
spec.version = Zoholib::VERSION
spec.version = Wedoops::Zoholib::VERSION
spec.date = '2020-04-25'
spec.authors = ['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