Class: Labimotion::TemplateHub

Inherits:
Object
  • Object
show all
Defined in:
lib/labimotion/libs/template_hub.rb

Overview

TemplateHub

Constant Summary collapse

TARGET =
Rails.env.production? ? 'https://www.chemotion-repository.net/' : 'http://localhost:3000/'

Class Method Summary collapse

Class Method Details

.fetch_identifier(klass, identifier) ⇒ Object



50
51
52
53
54
55
# File 'lib/labimotion/libs/template_hub.rb', line 50

def self.fetch_identifier(klass, identifier)
  # body = { klass: klass, identifier: identifier }
  response = HTTParty.get("#{uri('fetch')}?klass=#{klass}&identifier=#{identifier}")
  # response.parsed_response if response.code == 200
  JSON.parse(response.body) if response.code == 200
end

.handle_response(oat, response) ⇒ Object

rubocop: disable Metrics/PerceivedComplexity



33
34
35
36
37
38
39
40
41
# File 'lib/labimotion/libs/template_hub.rb', line 33

def self.handle_response(oat, response) # rubocop: disable Metrics/PerceivedComplexity
  begin
    response&.success? ? 'OK' : 'ERROR'
  rescue StandardError => e
    raise e
  ensure
    ## oat.update(status: response&.success? ? 'done' : 'failure')
  end
end

.header(opt = {}) ⇒ Object



29
30
31
# File 'lib/labimotion/libs/template_hub.rb', line 29

def self.header(opt = {})
  opt || {}
end

.list(klass) ⇒ Object



43
44
45
46
47
48
# File 'lib/labimotion/libs/template_hub.rb', line 43

def self.list(klass)
  body = { klass: klass }
  response = HTTParty.get("#{uri('list')}?klass=#{klass}")
  # response.parsed_response if response.code == 200
  JSON.parse(response.body) if response.code == 200
end

.loggerObject



16
17
18
# File 'lib/labimotion/libs/template_hub.rb', line 16

def self.logger
  @@converter_logger ||= Logger.new(Rails.root.join('log/labimotion.log')) # rubocop:disable Style/ClassVars
end

.timeoutObject



25
26
27
# File 'lib/labimotion/libs/template_hub.rb', line 25

def self.timeout
  Rails.configuration.try(:converter).try(:timeout) || 30
end

.uri(api_name) ⇒ Object



20
21
22
23
# File 'lib/labimotion/libs/template_hub.rb', line 20

def self.uri(api_name)
  url = TARGET
  "#{url}api/v1/labimotion_hub/#{api_name}"
end