Class: OembedProviderEngine::OembedProvider

Inherits:
Object
  • Object
show all
Defined in:
app/models/oembed_provider_engine/oembed_provider.rb

Overview

set OembedProvider.provider_name, etc. in your config/initializers or somewhere

Class Method Summary collapse

Class Method Details

.base_attributesObject

every request has these, mostly required mostly site wide version is special case



38
39
40
41
42
43
44
# File 'app/models/oembed_provider_engine/oembed_provider.rb', line 38

def base_attributes
  [:provider_url,
   :provider_name,
   :cache_age,
   :type,
   :version]
end

.cache_ageObject



23
24
25
# File 'app/models/oembed_provider_engine/oembed_provider.rb', line 23

def cache_age
  @@cache_age ||= nil
end

.cache_age=(age) ⇒ Object



27
28
29
# File 'app/models/oembed_provider_engine/oembed_provider.rb', line 27

def cache_age=(age)
  @@cache_age = age
end

.controller_model_mapsObject



69
70
71
# File 'app/models/oembed_provider_engine/oembed_provider.rb', line 69

def controller_model_maps
  @@controller_model_maps ||= Hash.new
end

.controller_model_maps=(hash_map) ⇒ Object



73
74
75
# File 'app/models/oembed_provider_engine/oembed_provider.rb', line 73

def controller_model_maps=(hash_map)
  @@controller_model_maps = hash_map
end

.find_provided_from(url) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/oembed_provider_engine/oembed_provider.rb', line 77

def find_provided_from(url)
  url = Addressable::URI.parse(url)
  #TODO smell
   = Rails.application.routes.recognize_path(url.path, :method=>:get)

  controller = [:controller]
  id = [: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_attributesObject

optional attributes that are specific to an instance of the providable model



48
49
50
51
52
53
54
55
# File 'app/models/oembed_provider_engine/oembed_provider.rb', line 48

def optional_attributes
  [:title,
   :author_name,
   :author_url,
   :thumbnail_url,
   :thumbnail_width,
   :thumbnail_height]
end

.provider_nameObject



15
16
17
# File 'app/models/oembed_provider_engine/oembed_provider.rb', line 15

def provider_name
  @@provider_name ||= String.new
end

.provider_name=(name) ⇒ Object



19
20
21
# File 'app/models/oembed_provider_engine/oembed_provider.rb', line 19

def provider_name=(name)
  @@provider_name = name
end

.provider_urlObject



7
8
9
# File 'app/models/oembed_provider_engine/oembed_provider.rb', line 7

def provider_url
  @@provider_url ||= String.new
end

.provider_url=(url) ⇒ Object



11
12
13
# File 'app/models/oembed_provider_engine/oembed_provider.rb', line 11

def provider_url=(url)
  @@provider_url = url
end

.required_attributesObject

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



62
63
64
65
66
67
# File 'app/models/oembed_provider_engine/oembed_provider.rb', line 62

def required_attributes
  { :photo => [:url, :width, :height],
    :video => [:html, :width, :height],
    :link => [],
    :rich => [:html, :width, :height] }
end

.versionObject



31
32
33
# File 'app/models/oembed_provider_engine/oembed_provider.rb', line 31

def version
  "1.0"
end