Class: ServiceKiosk::RemoteService
- Inherits:
-
Object
- Object
- ServiceKiosk::RemoteService
- Defined in:
- lib/remote_service.rb
Instance Method Summary collapse
- #action_url(action) ⇒ Object
- #call(action, input = {}) ⇒ Object
- #create(input = {}) ⇒ Object
- #debug(message) ⇒ Object
- #delete(input = {}) ⇒ Object
- #external_host(id) ⇒ Object
-
#initialize(kiosk, service) ⇒ RemoteService
constructor
A new instance of RemoteService.
- #list(input = {}) ⇒ Object
- #read(input = {}) ⇒ Object
- #update(input = {}) ⇒ Object
- #url(id = nil, input = nil) ⇒ Object
Constructor Details
#initialize(kiosk, service) ⇒ RemoteService
Returns a new instance of RemoteService.
9 10 11 12 13 |
# File 'lib/remote_service.rb', line 9 def initialize(kiosk, service) @endpoint = external_host(kiosk + '/' + service) @logger = ServiceKiosk::Kiosk.open('logger').service('Logger') unless @logger debug "remote service wants to use a logger: " + @logger.inspect end |
Instance Method Details
#action_url(action) ⇒ Object
19 20 21 |
# File 'lib/remote_service.rb', line 19 def action_url(action) @endpoint + '/' + action end |
#call(action, input = {}) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/remote_service.rb', line 30 def call(action, input={}) input_json = input.to_json debug "kiosk call: #{action} -> #{input_json}" response = RestClient.post action_url(action), {data: Base64.encode64(input_json)} JSON.parse Base64.decode64(response) end |
#create(input = {}) ⇒ Object
45 46 47 |
# File 'lib/remote_service.rb', line 45 def create(input={}) call('create', input) end |
#debug(message) ⇒ Object
57 58 59 |
# File 'lib/remote_service.rb', line 57 def debug() @logger.call('log', {'debug' => }) end |
#delete(input = {}) ⇒ Object
53 54 55 |
# File 'lib/remote_service.rb', line 53 def delete(input={}) call('delete', input) end |
#external_host(id) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/remote_service.rb', line 23 def external_host(id) # TODO: this hack is to correct the fact that sinatra using jruby on vbox ubuntu won't # bind properly to all interfaces 0.0.0.0 host = /inet addr:(\S+)/m.match(`ifconfig eth0`)[1] id.sub('localhost', host) end |
#list(input = {}) ⇒ Object
37 38 39 |
# File 'lib/remote_service.rb', line 37 def list(input={}) call('list', input) end |
#read(input = {}) ⇒ Object
41 42 43 |
# File 'lib/remote_service.rb', line 41 def read(input={}) call('read', input) end |
#update(input = {}) ⇒ Object
49 50 51 |
# File 'lib/remote_service.rb', line 49 def update(input={}) call('update', input) end |
#url(id = nil, input = nil) ⇒ Object
15 16 17 |
# File 'lib/remote_service.rb', line 15 def url(id=nil, input=nil) @endpoint + (id ? ('/' + id) : '') + (input ? '?data=' + CGI::escape(input.to_json) : '') end |