Class: FacebookVideo
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- FacebookVideo
- Defined in:
- lib/facebook_video.rb
Defined Under Namespace
Classes: NotWorkingVideo
Constant Summary collapse
- VIDEO_ERROR_MSG =
:video_id_error
- FB_ERROR_MSG =
:fb_account_error
Class Attribute Summary collapse
-
.cache ⇒ Object
Returns the value of attribute cache.
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
Class Method Summary collapse
Instance Method Summary collapse
Class Attribute Details
.cache ⇒ Object
Returns the value of attribute cache.
19 20 21 |
# File 'lib/facebook_video.rb', line 19 def cache @cache end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
16 17 18 |
# File 'lib/facebook_video.rb', line 16 def error @error end |
Class Method Details
.get(v_id) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/facebook_video.rb', line 54 def self.get(v_id) v = self.video_data(v_id) case v when :video_error then NotWorkingVideo.new(VIDEO_ERROR_MSG) when :fb_error then NotWorkingVideo.new(FB_ERROR_MSG) else v end end |
Instance Method Details
#url=(new_url) ⇒ Object
63 64 65 66 67 |
# File 'lib/facebook_video.rb', line 63 def url=(new_url) self.errors.clear self.cached_at = Time.now super new_url end |
#url_working? ⇒ Boolean
81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/facebook_video.rb', line 81 def url_working? begin host = URI.parse(self.url).host http = Net::HTTP.new(host) headers = http.head(self.url) rescue return false end if headers.code == "200" true else false end end |
#working? ⇒ Boolean
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/facebook_video.rb', line 69 def working? v = false if self.cached_at >= Time.now - self.class.cache && self.url.length > 10 v = true else v = url_working? self.cached_at = Time.now end self.errors.add(:cached_at, 'Cache ulegl przedawnieniu') unless v v end |