module Api::UrlParser
Constants
- BASE_URL
- RELATIVE_AYAH_PATH
- RELATIVE_EDITION_PATH
- RELATIVE_PARAH_PATH
- RELATIVE_SURAH_PATH
Public Instance Methods
handle_ayah_urls(params)
click to toggle source
# File lib/api/url_parser.rb, line 38 def handle_ayah_urls(params) case params[:action] when :show relative_url = [BASE_URL, RELATIVE_AYAH_PATH, params[:number]].join('/') [relative_url, prepare_query_string(params[:extras])].join('?') when :sajdah then [BASE_URL, RELATIVE_AYAH_PATH, :sujood].join('/') end end
handle_edition_urls(params)
click to toggle source
# File lib/api/url_parser.rb, line 47 def handle_edition_urls(params) [BASE_URL, RELATIVE_EDITION_PATH, params[:number]].join('/') end
handle_parah_urls(params)
click to toggle source
# File lib/api/url_parser.rb, line 15 def handle_parah_urls(params) case params[:action] when :index then [BASE_URL, RELATIVE_PARAH_PATH].join('/') when :show then [BASE_URL, RELATIVE_PARAH_PATH, params[:number]].join('/') when :surahs then [BASE_URL, RELATIVE_PARAH_PATH, params[:number], params[:action]].join('/') when :ayahs relative_url = [BASE_URL, RELATIVE_PARAH_PATH, params[:number], params[:action]].join('/') [relative_url, prepare_query_string(params[:extras])].join('?') end end
handle_surah_urls(params)
click to toggle source
# File lib/api/url_parser.rb, line 26 def handle_surah_urls(params) case params[:action] when :index then [BASE_URL, RELATIVE_SURAH_PATH].join('/') when :show relative_url = [BASE_URL, RELATIVE_SURAH_PATH, params[:number]].join('/') [relative_url, prepare_query_string(params[:extras])].join('?') when :ayahs relative_url = [BASE_URL, RELATIVE_SURAH_PATH, params[:number], params[:action]].join('/') [relative_url, prepare_query_string(params[:extras])].join('?') end end
parse_url(params)
click to toggle source
# File lib/api/url_parser.rb, line 10 def parse_url(params) method_name = "handle_#{params[:entity]}_urls" self.send(method_name, **params) end
prepare_query_string(extras)
click to toggle source
# File lib/api/url_parser.rb, line 51 def prepare_query_string(extras) extras.to_a.map(&:join.with('=')).join('&') end