Class: Nexmo::OAS::Renderer::API
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Nexmo::OAS::Renderer::API
- Defined in:
- lib/nexmo/oas/renderer/app.rb
Class Method Summary collapse
Instance Method Summary collapse
- #check_oas_constraints!(definition) ⇒ Object
- #check_redirect! ⇒ Object
- #parse_params(extension) ⇒ Object
- #set_code_language ⇒ Object
- #set_document ⇒ Object
- #set_theme ⇒ Object
Class Method Details
.load_business_yaml ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/nexmo/oas/renderer/app.rb', line 65 def self.load_business_yaml raise "Application requires a 'config/business_info.yml' file to be defined inside the documentation path." if defined?(NexmoDeveloper::Application) && !File.exist?("#{Rails.configuration.docs_base_path}/config/business_info.yml") if defined?(NexmoDeveloper::Application) && File.exist?("#{Rails.configuration.docs_base_path}/config/business_info.yml") @url ||= begin config = YAML.load_file("#{Rails.configuration.docs_base_path}/config/business_info.yml") config['oas_url'] end else 'https://www.github.com/nexmo/api-specification/blob/master/definitions' end end |
Instance Method Details
#check_oas_constraints!(definition) ⇒ Object
85 86 87 88 89 |
# File 'lib/nexmo/oas/renderer/app.rb', line 85 def check_oas_constraints!(definition) return unless defined?(NexmoDeveloper::Application) pass unless OpenApiConstraint.match?(definition) end |
#check_redirect! ⇒ Object
78 79 80 81 82 83 |
# File 'lib/nexmo/oas/renderer/app.rb', line 78 def check_redirect! return unless defined?(NexmoDeveloper::Application) redirect_path = Redirector.find(request) redirect(redirect_path) if redirect_path end |
#parse_params(extension) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/nexmo/oas/renderer/app.rb', line 47 def parse_params(extension) extensions = extension.split('.') case extensions.size when 1 { definition: extensions.first } when 2 if extensions.second.match?(/v\d+/) { definition: extensions.first, version: extensions.second } else { definition: extensions.first, format: extensions.second } end when 3 { definition: extensions.first, version: extensions.second, format: extensions.last } else {} end end |
#set_code_language ⇒ Object
112 113 114 115 116 |
# File 'lib/nexmo/oas/renderer/app.rb', line 112 def set_code_language return if params[:code_language] == 'templates' @code_language = params[:code_language] end |
#set_document ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/nexmo/oas/renderer/app.rb', line 165 def set_document @document = if params[:code_language] == 'templates' 'verify/templates' elsif params[:code_language] == 'ncco' 'voice/ncco' elsif ::Nexmo::Markdown::CodeLanguage.exists?(params[:code_language]) params[:document] else "#{params[:document]}/#{params[:code_language]}" end end |
#set_theme ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/nexmo/oas/renderer/app.rb', line 118 def set_theme persisted_theme = nil if defined?(NexmoDeveloper::Application) session[:persisted_theme] = params[:theme] if params[:theme] persisted_theme = session[:persisted_theme] end @theme = params[:theme] || persisted_theme @theme = 'light' unless %w[light dark].include?(@theme) @theme_light = @theme == 'light' alternate_theme = @theme == 'light' ? 'dark' : 'light' @theme_link = "#{request.path_info}?theme=#{alternate_theme}" @theme_link = "/api#{@theme_link}" if defined?(NexmoDeveloper::Application) end |