Class: Lono::Pro::Importer::Service::Coder
- Inherits:
-
Object
- Object
- Lono::Pro::Importer::Service::Coder
- Defined in:
- lib/lono/pro/importer/service/coder.rb
Constant Summary collapse
- LONO_API =
ENV['LONO_API'] || 'https://api.lono.cloud/v1'
Instance Method Summary collapse
-
#initialize(template, options = {}) ⇒ Coder
constructor
A new instance of Coder.
- #translate ⇒ Object
Constructor Details
#initialize(template, options = {}) ⇒ Coder
Returns a new instance of Coder.
8 9 10 |
# File 'lib/lono/pro/importer/service/coder.rb', line 8 def initialize(template, ={}) @template, @options = template, end |
Instance Method Details
#translate ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/lono/pro/importer/service/coder.rb', line 12 def translate url = "#{LONO_API}/code" http = net_http_client(url) req = net_http_request(url, template: Base64.encode64(@template), # Base64 JSON for special chars that Rack::LintWrapper cannot process lono_version: Lono::VERSION, lono_pro_version: Lono::Pro::VERSION, lono_command: lono_command, ) res = http.request(req) # send request if res.code == "200" data = JSON.load(res.body) ruby_code = print(data) # returns data["ruby_code"] / passthrough ruby_code else puts "errored" puts "Unable to convert template to Ruby code." puts "The error has been reported." puts "Non-successful http response status code: #{res.code}" # puts "headers: #{res.each_header.to_h.inspect}" exit 1 end end |