Class: OembedProvider
- Inherits:
-
Object
- Object
- OembedProvider
- Defined in:
- lib/oembed_provider.rb
Overview
set OembedProvider.provide_name, etc. in your config/initializers or somewhere
Class Method Summary collapse
-
.base_attributes ⇒ Object
every request has these, mostly required mostly site wide version is special case.
- .cache_age ⇒ Object
- .cache_age=(age) ⇒ Object
- .controller_model_maps ⇒ Object
- .controller_model_maps=(hash_map) ⇒ Object
- .find_provided_from(url) ⇒ Object
-
.optional_attributes ⇒ Object
optional attributes that are specific to an instance of the providable model.
- .provider_name ⇒ Object
- .provider_name=(name) ⇒ Object
- .provider_url ⇒ Object
- .provider_url=(url) ⇒ Object
-
.required_attributes ⇒ Object
these may be required depending on type see 2.3.4.1 - 2.3.4.4 of spec type specific attributes all attributes listed for these types are required the empty link array shows that nothing is required.
- .version ⇒ Object
Class Method Details
.base_attributes ⇒ Object
every request has these, mostly required mostly site wide version is special case
37 38 39 40 41 42 |
# File 'lib/oembed_provider.rb', line 37 def base_attributes [:provider_url, :provider_name, :cache_age, :version] end |
.cache_age ⇒ Object
22 23 24 |
# File 'lib/oembed_provider.rb', line 22 def cache_age @@cache_age ||= nil end |
.cache_age=(age) ⇒ Object
26 27 28 |
# File 'lib/oembed_provider.rb', line 26 def cache_age=(age) @@cache_age = age end |
.controller_model_maps ⇒ Object
67 68 69 |
# File 'lib/oembed_provider.rb', line 67 def controller_model_maps @@controller_model_maps ||= Hash.new end |
.controller_model_maps=(hash_map) ⇒ Object
71 72 73 |
# File 'lib/oembed_provider.rb', line 71 def controller_model_maps=(hash_map) @@controller_model_maps = hash_map end |
.find_provided_from(url) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/oembed_provider.rb', line 75 def find_provided_from(url) url = Addressable::URI.parse(url) submitted_url_params = ActionController::Routing::Routes.recognize_path(url.path, :method=>:get) controller = submitted_url_params[:controller] id = submitted_url_params[:id] # handle special cases where controllers are directly configured to point at a specific model model = OembedProvider.controller_model_maps[controller] # otherwise we use convention over configuration to determine model model = controller.singularize.camelize unless model model.constantize.find(id) end |
.optional_attributes ⇒ Object
optional attributes that are specific to an instance of the providable model
46 47 48 49 50 51 52 53 |
# File 'lib/oembed_provider.rb', line 46 def optional_attributes [:title, :author_name, :author_url, :thumbnail_url, :thumbnail_width, :thumbnail_height] end |
.provider_name ⇒ Object
14 15 16 |
# File 'lib/oembed_provider.rb', line 14 def provider_name @@provider_name ||= String.new end |
.provider_name=(name) ⇒ Object
18 19 20 |
# File 'lib/oembed_provider.rb', line 18 def provider_name=(name) @@provider_name = name end |
.provider_url ⇒ Object
6 7 8 |
# File 'lib/oembed_provider.rb', line 6 def provider_url @@provider_url ||= String.new end |
.provider_url=(url) ⇒ Object
10 11 12 |
# File 'lib/oembed_provider.rb', line 10 def provider_url=(url) @@provider_url = url end |
.required_attributes ⇒ Object
these may be required depending on type see 2.3.4.1 - 2.3.4.4 of spec type specific attributes all attributes listed for these types are required the empty link array shows that nothing is required
60 61 62 63 64 65 |
# File 'lib/oembed_provider.rb', line 60 def required_attributes { :photo => [:url, :width, :height], :video => [:html, :width, :height], :link => [], :rich => [:html, :width, :height] } end |
.version ⇒ Object
30 31 32 |
# File 'lib/oembed_provider.rb', line 30 def version "1.0" end |