Class: Yext::Api::Utils::ApiFinder
- Inherits:
-
Object
- Object
- Yext::Api::Utils::ApiFinder
- Defined in:
- lib/yext/api/utils/api_finder.rb
Overview
This module add the ‘find_api` method to a class to allow the searching of the base api category module for a particular route.
Class Method Summary collapse
Instance Method Summary collapse
- #find_api ⇒ Object
- #find_class_name ⇒ Object
-
#initialize(uri_path, uri_method) ⇒ ApiFinder
constructor
A new instance of ApiFinder.
Constructor Details
#initialize(uri_path, uri_method) ⇒ ApiFinder
Returns a new instance of ApiFinder.
15 16 17 18 19 20 21 |
# File 'lib/yext/api/utils/api_finder.rb', line 15 def initialize(uri_path, uri_method) uri = URI.parse(uri_path.to_s) uri.query = nil @uri_path = uri.to_s @uri_method = uri_method.to_s end |
Class Method Details
Instance Method Details
#find_api ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/yext/api/utils/api_finder.rb', line 23 def find_api api = find_class_name.to_s.split("::") return nil if api.length < 3 "Yext::Api::#{api[2]}".constantize end |
#find_class_name ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/yext/api/utils/api_finder.rb', line 31 def find_class_name api_hash = Yext::Api::Utils::ApiFinder.api_hash return build_class_name("Yext::Api::LiveApi", api_hash[:live_api]) if uri_path.include?("//liveapi.") api_hash.each do |api_class, module_details| next if api_class == :webhooks found_class = build_class_name("Yext::Api::#{api_class.to_s.classify}", module_details) return found_class if found_class.present? end nil end |