Class: Eris::LunaRequest
- Inherits:
-
Object
- Object
- Eris::LunaRequest
- Defined in:
- lib/eris/lib/luna_request.rb
Instance Attribute Summary collapse
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(options) ⇒ LunaRequest
constructor
A new instance of LunaRequest.
- #log_bad_json ⇒ Object
- #log_request ⇒ Object
- #params ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(options) ⇒ LunaRequest
Returns a new instance of LunaRequest.
8 9 10 11 |
# File 'lib/eris/lib/luna_request.rb', line 8 def initialize() @service = ["url"] @body = JSON.generate(["body"]) end |
Instance Attribute Details
#service ⇒ Object (readonly)
Returns the value of attribute service.
6 7 8 |
# File 'lib/eris/lib/luna_request.rb', line 6 def service @service end |
Instance Method Details
#execute ⇒ Object
25 26 27 28 29 30 |
# File 'lib/eris/lib/luna_request.rb', line 25 def execute @luna_response = `#{url}` # log_request log_bad_json @luna_response end |
#log_bad_json ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/eris/lib/luna_request.rb', line 41 def log_bad_json begin JSON.parse(@luna_response) rescue puts "BAD JSON FROM LUNA" puts "Request: #{url}" puts "Respose: #{@luna_response}" end end |
#log_request ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/eris/lib/luna_request.rb', line 32 def log_request puts "\n\n====> BODY PARAMS <====" pp @body puts "\n\n====> NOVACOM REQUEST <====" puts "Sending #{url}" puts "\n\n====> NOVACOM RESPONSE <====" puts @luna_response end |
#params ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/eris/lib/luna_request.rb', line 13 def params param_str = @body.dup param_str.gsub!('\\n') { '\\\\\\n' } # Yes, this escapes NEWLINES (block form needed) param_str.gsub!(' ', '\\ ') # escape spaces param_str.gsub!(/'/) { %q('\\\\\'') } # escape single quotes (block form needed) param_str end |
#url ⇒ Object
21 22 23 |
# File 'lib/eris/lib/luna_request.rb', line 21 def url "novacom run file://usr/bin/luna-send -- -n 1 -a com.palm.configurator -i #{@service} '#{params}'" end |