fb_video_url_converter 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/README.md CHANGED
@@ -66,14 +66,18 @@ or without migrations:
66
66
  ## Example
67
67
 
68
68
  url = 'http://www.facebook.com/home.php?#!/video/video.php?v=SOME_ID'
69
- p FacebookVideo.video_url(url)
69
+ p FacebookVideo.get(url).url
70
70
 
71
71
  => 'http://video.ak.fbcdn.net/cfs-ak-ash4/214...long_long_url'
72
72
 
73
- p FacebookVideo.video_name(url)
73
+ p FacebookVideo.get(url).name
74
74
 
75
75
  => 'video_name'
76
76
 
77
+ you can use also `working?` to determine if object you have got is a valid
78
+ Facebook movie object. If not - use `object.error` to determine what type of
79
+ error has occurred.
80
+
77
81
  ## Setup
78
82
 
79
83
  When you create table required by Facebook Video URL Converter, you need to do
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'echoe'
4
4
 
5
- Echoe.new('fb_video_url_converter', '0.1.2') do |p|
5
+ Echoe.new('fb_video_url_converter', '0.1.3') do |p|
6
6
  p.description = "Facebook Video URL Converter is intended as an easy alternative to changing video hosting from Facebook to a different one."
7
7
  p.url = "https://github.com/mensfeld/FB-Video-URL-Converter"
8
8
  p.author = "Maciej Mensfeld"
@@ -2,12 +2,12 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{fb_video_url_converter}
5
- s.version = "0.1.2"
5
+ s.version = "0.1.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Maciej Mensfeld"]
9
9
  s.cert_chain = ["/home/mencio/.cert_keys/gem-public_cert.pem"]
10
- s.date = %q{2011-05-03}
10
+ s.date = %q{2011-05-05}
11
11
  s.description = %q{Facebook Video URL Converter is intended as an easy alternative to changing video hosting from Facebook to a different one.}
12
12
  s.email = %q{maciej@mensfeld.pl}
13
13
  s.extra_rdoc_files = ["CHANGELOG.rdoc", "README.md", "lib/facebook_bot.rb", "lib/facebook_video.rb", "lib/fb_video_url_converter.rb"]
@@ -13,33 +13,50 @@ end
13
13
 
14
14
  class FacebookVideo < ActiveRecord::Base
15
15
 
16
+ attr_accessor :error
17
+
16
18
  class << self
17
19
  attr_accessor :cache
18
20
  end
19
21
 
20
- VIDEO_ERROR_MSG = 'video_id_error'
21
- FB_ERROR_MSG = 'fb_account_error'
22
+ VIDEO_ERROR_MSG = :video_id_error
23
+ FB_ERROR_MSG = :fb_account_error
22
24
 
23
- before_create :set_cached_at_time
25
+ # Dummy video object containing info about error
26
+ # We will not return (or raise) errors - it is not deseable
27
+ class NotWorkingVideo
24
28
 
25
- validates_uniqueness_of :video_id
26
- validate :working?
29
+ attr_accessor :error
27
30
 
28
- def self.video_url(v_id)
29
- v = self.video_data(v_id)
30
- case v
31
- when 'video_error' then VIDEO_ERROR_MSG
32
- when 'fb_error' then FB_ERROR_MSG
33
- else v.url
31
+ def initialize(error)
32
+ @error = error
33
+ end
34
+
35
+ def url
36
+ @error
37
+ end
38
+
39
+ def name
40
+ @error
34
41
  end
42
+
43
+ def working?
44
+ false
45
+ end
46
+
35
47
  end
36
48
 
37
- def self.video_name(v_id)
49
+ before_create :set_cached_at_time
50
+
51
+ validates_uniqueness_of :video_id
52
+ validate :working?
53
+
54
+ def self.get(v_id)
38
55
  v = self.video_data(v_id)
39
56
  case v
40
- when 'video_error' then VIDEO_ERROR_MSG
41
- when 'fb_error' then FB_ERROR_MSG
42
- else v.name
57
+ when 'video_error' then NotWorkingVideo.new(VIDEO_ERROR_MSG)
58
+ when 'fb_error' then NotWorkingVideo.new(FB_ERROR_MSG)
59
+ else v
43
60
  end
44
61
  end
45
62
 
@@ -14,24 +14,24 @@ describe FacebookVideo do
14
14
 
15
15
  context "when we obtain valid video for the first time" do
16
16
  it "should fetch it and return url" do
17
- FacebookVideo.video_url('111449252268656').should_not eql 'video_id_error'
17
+ FacebookVideo.get('111449252268656').name.should_not eql :video_id_error
18
18
  url = 'http://www.facebook.com/video/video.php?v=119040278176220&comments'
19
- FacebookVideo.video_url(url).should_not eql 'video_id_error'
19
+ FacebookVideo.get(url).name.should_not eql :video_id_error
20
20
  end
21
21
 
22
22
  it "should fetch it and return name" do
23
- FacebookVideo.video_name('111449252268656').should eql 'Naruto Shippuuden #203 Part2 [HD]'
23
+ FacebookVideo.get('111449252268656').name.should eql 'Naruto Shippuuden #203 Part2 [HD]'
24
24
  url = 'http://www.facebook.com/video/video.php?v=111449252268656&comments'
25
- FacebookVideo.video_name(url).should eql 'Naruto Shippuuden #203 Part2 [HD]'
25
+ FacebookVideo.get(url).name.should eql 'Naruto Shippuuden #203 Part2 [HD]'
26
26
  end
27
27
  end
28
28
 
29
29
  context "when we obtain video for n times" do
30
30
  it "should increase views counter" do
31
- FacebookVideo.video_name('111449252268656')
31
+ FacebookVideo.get('111449252268656')
32
32
  v = FacebookVideo.find_by_video_id('111449252268656').views
33
33
  10.times do
34
- FacebookVideo.video_name('111449252268656')
34
+ FacebookVideo.get('111449252268656')
35
35
  end
36
36
  FacebookVideo.find_by_video_id('111449252268656').views.should == v+10
37
37
  end
@@ -40,11 +40,11 @@ describe FacebookVideo do
40
40
  context "when video is too old" do
41
41
  it "should rerequest it and refresh cache time" do
42
42
  t = Time.now
43
- FacebookVideo.video_name('111449252268656')
43
+ FacebookVideo.get('111449252268656')
44
44
  v = FacebookVideo.find_by_video_id('111449252268656')
45
45
  v.cached_at = Time.at(946702800)
46
46
  v.save!
47
- FacebookVideo.video_name('111449252268656')
47
+ FacebookVideo.get('111449252268656')
48
48
  v.reload
49
49
  v.cached_at.should > t
50
50
  end
@@ -52,8 +52,8 @@ describe FacebookVideo do
52
52
 
53
53
  context "when we obtain invalid video" do
54
54
  it "should return warning" do
55
- FacebookVideo.video_name('').should eql 'video_id_error'
56
- FacebookVideo.video_url('').should eql 'video_id_error'
55
+ FacebookVideo.get('').url.should eql :video_id_error
56
+ FacebookVideo.get('').name.should eql :video_id_error
57
57
  end
58
58
  end
59
59
 
@@ -61,7 +61,7 @@ describe FacebookVideo do
61
61
  it "should return incorrect video ID info" do
62
62
  l = FacebookBot.email
63
63
  FacebookBot.email = 'aaa@aaa.pl'
64
- FacebookVideo.video_url('120641554682759').should eql 'fb_account_error'
64
+ FacebookVideo.get('120641554682759').url.should eql :fb_account_error
65
65
  remove_cookie
66
66
  FacebookBot.email = l
67
67
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: fb_video_url_converter
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Maciej Mensfeld
@@ -31,7 +31,7 @@ cert_chain:
31
31
  BH3YFsdk
32
32
  -----END CERTIFICATE-----
33
33
 
34
- date: 2011-05-03 00:00:00 +02:00
34
+ date: 2011-05-05 00:00:00 +02:00
35
35
  default_executable:
36
36
  dependencies:
37
37
  - !ruby/object:Gem::Dependency
metadata.gz.sig CHANGED
Binary file