require 'uri'
require 'MrMurano/Config'
require 'MrMurano/http'
require 'MrMurano/verbosing'
require 'MrMurano/SyncUpDown'

module MrMurano
  class SolutionBase
    def initialize
      @sid = $cfg['project.id']
#      @sid = $cfg['solution.id']
      raise MrMurano::ConfigError.new("No solution!") if @sid.nil?
#      @uriparts = [:project, @sid]
      @uriparts = [:solution, @sid]
      @itemkey = :id
      @project_section = nil
    end

    include Http
    include Verbose

    ## Generate an endpoint in Murano
    # Uses the uriparts and path
    # @param path String: any additional parts for the URI
    # @return URI: The full URI for this enpoint.
    def endPoint(path='')
      parts = ['https:/', $cfg['net.host'], 'api:1'] + @uriparts
      s = parts.map{|v| v.to_s}.join('/')
      URI(s + path.to_s)
    end
    # …

    include SyncUpDown
  end

  class Solution < SolutionBase
    def version
      get('/version')
    end

    def info
      get()
    end

    def list
      get('/')
    end

    def usage
      get('/usage')
    end

    def log
      get('/logs')
    end

  end

end

#  vim: set ai et sw=2 ts=2 :

require 'uri'
require 'MrMurano/Config'
require 'MrMurano/http'
require 'MrMurano/verbosing'
require 'MrMurano/SyncUpDown'

module MrMurano
  class SolutionBase
    def initialize
      @sid = $cfg['project.id']
#      @sid = $cfg['solution.id']
      raise MrMurano::ConfigError.new("No solution!") if @sid.nil?
#      @uriparts = [:project, @sid]
      @uriparts = [:solution, @sid]
      @itemkey = :id
      @project_section = nil
    end

    include Http
    include Verbose

    ## Generate an endpoint in Murano
    # Uses the uriparts and path
    # @param path String: any additional parts for the URI
    # @return URI: The full URI for this enpoint.
    def endPoint(path='')
      parts = ['https:/', $cfg['net.host'], 'api:1'] + @uriparts
      s = parts.map{|v| v.to_s}.join('/')
      URI(s + path.to_s)
    end
    # …

    def get(*args)
      ret = super
      if ret.nil?
        warning "No solution with ID: #{@sid}"
        exit 1
      end
      ret
    end

    include SyncUpDown
  end

  class Solution < SolutionBase
    def version
      get('/version')
    end

    def info
      get()
    end

    def list
      get('/')
    end

    def usage
      get('/usage')
    end

    def log
      get('/logs')
    end

  end

end

#  vim: set ai et sw=2 ts=2 :

Add get() wrapper to catch when ret is nil and die.
Add get() wrapper to catch when ret is nil and die.

- ret is nil, e.g., if the solution ID being used is invalid.
