Class: ServiceKiosk::InternalService

Inherits:
Object
  • Object
show all
Defined in:
lib/internal_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(kiosk, service) ⇒ InternalService

Returns a new instance of InternalService.



6
7
8
# File 'lib/internal_service.rb', line 6

def initialize(kiosk, service)
  @service = connect(kiosk, service)
end

Instance Method Details

#call(action, input = {}) ⇒ Object



32
33
34
35
36
37
# File 'lib/internal_service.rb', line 32

def call(action, input={})
  input_json = input.to_json
  #puts ">>> kiosk call: #{action} -> #{input_json}" if ENV[LOGGER_LEVEL].to_i < 1
  response = @service.method(action.to_sym).call(JSON.parse input_json)
  JSON.parse response.to_json
end

#class_from_string(str) ⇒ Object



25
26
27
28
29
30
# File 'lib/internal_service.rb', line 25

def class_from_string(str)
  #puts ">>> internal kiosk: class from str: #{str}"
  str.split('::').inject(Object) do |mod, class_name|
    mod.const_get(class_name)
  end
end

#class_name_from_locator(kiosk_locator, service_name) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/internal_service.rb', line 15

def class_name_from_locator(kiosk_locator, service_name)
  #puts ">>> locator: #{kiosk_locator}, svc: #{service_name}"
  parts = /ruby:\/\/\/(?<kiosk_name>[\w\.]*)/.match(kiosk_locator)
  name = service_name
  if parts[:kiosk_name]
    kiosk_name = parts[:kiosk_name].gsub('.', '::')
    name = kiosk_name + '::' + name
  end
end

#connect(kiosk, service) ⇒ Object



10
11
12
13
# File 'lib/internal_service.rb', line 10

def connect(kiosk, service)
  kiosk_class = class_from_string(class_name_from_locator(kiosk, service))
  kiosk_class.new
end

#create(input = {}) ⇒ Object



47
48
49
# File 'lib/internal_service.rb', line 47

def create(input={})
  call('create', input)
end

#delete(input = {}) ⇒ Object



55
56
57
# File 'lib/internal_service.rb', line 55

def delete(input={})
  call('delete', input)
end

#list(input = {}) ⇒ Object



39
40
41
# File 'lib/internal_service.rb', line 39

def list(input={})
  call('list', input)
end

#read(input = {}) ⇒ Object



43
44
45
# File 'lib/internal_service.rb', line 43

def read(input={})
  call('read', input)
end

#update(input = {}) ⇒ Object



51
52
53
# File 'lib/internal_service.rb', line 51

def update(input={})
  call('update', input)
end