class Oembedder::Provider
Attributes
endpoint[R]
format_type[R]
schemes[R]
Public Class Methods
new(params = {})
click to toggle source
# File lib/oembedder/provider.rb, line 5 def initialize(params = {}) params[:format_type] ||= "url" # url or querystring @format_type = params[:format_type] end
Public Instance Methods
get(request)
click to toggle source
get content
# File lib/oembedder/provider.rb, line 30 def get(request) conn = Faraday.new(:url => "#{self.endpoint.scheme}://#{self.endpoint.host}") do |faraday| faraday.request :url_encoded # faraday.response :logger faraday.response :json, :content_type => /\bjson$/ faraday.response :xml, :content_type => /\bxml$/ faraday.adapter Faraday.default_adapter end params = request.urlparams params += "&format=#{request.format}" if self.format_type == "querystring" response = conn.get(create_request_path(request) + params) ProviderResponse.create(request.format, response) end
match_scheme?(target)
click to toggle source
# File lib/oembedder/provider.rb, line 18 def match_scheme?(target) target.gsub!(/\/$/, '') # delete trailing slash mc = self.schemes.count do |scheme| pattern = Regexp.escape(scheme).gsub('\\*', '[^/]+') match = target.match Regexp.new(pattern) target.size == match.to_s.size unless match.nil? end true if mc >= 1 end
set_endpoint(endpoint)
click to toggle source
# File lib/oembedder/provider.rb, line 10 def set_endpoint(endpoint) @endpoint = URI.parse(endpoint) end
set_schemes(schemes)
click to toggle source
# File lib/oembedder/provider.rb, line 14 def set_schemes(schemes) @schemes = schemes end
Private Instance Methods
create_request_path(request)
click to toggle source
# File lib/oembedder/provider.rb, line 48 def create_request_path(request) if self.format_type == "url" if endpoint.path.match /\.\w+$/ self.endpoint.path.gsub(/\.\w+$/, ".#{request.format}") else self.endpoint.path + ".#{request.format}" end else self.endpoint.path end end