Whatsapp send and Zammad autologin fixes

This commit is contained in:
Darren Clarke 2023-09-08 16:34:13 +02:00
parent a3d6b786e1
commit 9e68be7225
15 changed files with 153 additions and 100 deletions

View file

@ -12,7 +12,7 @@ class CdrSignal
#
def self.check_token(api_url, token)
api = CdrSignalAPI.new(api_url, token)
api = CdrSignalApi.new(api_url, token)
begin
bot = api.fetch_self
rescue StandardError => e
@ -128,7 +128,7 @@ class CdrSignal
def initialize(api_url, token)
@token = token
@api_url = api_url
@api = CdrSignalAPI.new(api_url, token)
@api = CdrSignalApi.new(api_url, token)
end
#

View file

@ -4,13 +4,12 @@ require 'json'
require 'net/http'
require 'net/https'
require 'uri'
require 'rest-client'
class CdrSignalAPI
class CdrSignalApi
def initialize(api_url, token)
@token = token
@last_update = 0
@api = api_url
@api_url = api_url
end
def parse_hash(hash)
@ -22,13 +21,13 @@ class CdrSignalAPI
end
def get(api)
url = "#{@api}/bots/#{@token}/#{api}"
JSON.parse(RestClient.get(url, { accept: :json }).body)
url = "#{@api_url}/bots/#{@token}/#{api}"
JSON.parse(Faraday.get(url, { Accept: "application/json" }).body)
end
def post(api, params = {})
url = "#{@api}/bots/#{@token}/#{api}"
JSON.parse(RestClient.post(url, params, { accept: :json }).body)
url = "#{@api_url}/bots/#{@token}/#{api}"
JSON.parse(Faraday.post(url, params.to_json, { "Content-Type": "application/json", Accept: "application/json" }).body)
end
def fetch_self

View file

@ -12,7 +12,7 @@ class CdrWhatsapp
#
def self.check_token(api_url, token)
api = CdrWhatsappAPI.new(api_url, token)
api = CdrWhatsappApi.new(api_url, token)
begin
bot = api.fetch_self
rescue StandardError => e
@ -128,7 +128,7 @@ class CdrWhatsapp
def initialize(api_url, token)
@token = token
@api_url = api_url
@api = CdrWhatsappAPI.new(api_url, token)
@api = CdrWhatsappApi.new(api_url, token)
end
#

View file

@ -4,9 +4,8 @@ require 'json'
require 'net/http'
require 'net/https'
require 'uri'
require 'rest-client'
class CdrWhatsappAPI
class CdrWhatsappApi
def initialize(api_url, token)
@token = token
@last_update = 0
@ -20,15 +19,15 @@ class CdrWhatsappAPI
end
ret
end
def get(api)
url = "#{@api_url}/bots/#{@token}/#{api}"
JSON.parse(RestClient.get(url, { accept: :json }).body)
JSON.parse(Faraday.get(url, { Accept: "application/json" }).body)
end
def post(api, params = {})
url = "#{@api_url}/bots/#{@token}/#{api}"
JSON.parse(RestClient.post(url, params, { accept: :json }).body)
JSON.parse(Faraday.post(url, params.to_json, { "Content-Type": "application/json", Accept: "application/json" }).body)
end
def fetch_self