conred 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 223941e1f3b71677314d9743599bd7cc13e15aca
4
- data.tar.gz: 7b68bceef41a38dbb152288e2dca6e97d5795f55
3
+ metadata.gz: 52df766ea4e04c86a1a128f258afcfd1a98c0cdd
4
+ data.tar.gz: 2477890c39c4ff06dff211e80fc23fa055dc0bf4
5
5
  SHA512:
6
- metadata.gz: b2fd36b38ffbd85996e6d6a81bbd1ca7da0df09010ca6d45ef76c31cdb7ff322ae6f1141d2877ab7c1f1d5df031caefacefa9324aae39024e1d8f453fdd50607
7
- data.tar.gz: 5412338df0fc78541a46ad9d9c4473e658ff8835ff108ea5688f5ed84fbdd10ba30326016c61133032cbd7d7cec018603fc3416a85c4c2d312bd4da72db17b87
6
+ metadata.gz: 8450ca6de41b5981dd4fb478f7c70eb7a0c40d785f77e45b35af18563e8431ed86b024e18e6906ab672cf9ed7e1d5c8bb169b0f2c7d0480ce66cdb9f3b341d0f
7
+ data.tar.gz: af014e2a85ea64dde0e96dc8e88a0a13cb9cb1c44ce6f04e5335d51755b0baea1a2a513ac7d4dcd9763839a5a2184d5f46462492e32745a1371f4ed00ab68f8f
data/README.md CHANGED
@@ -3,10 +3,7 @@
3
3
 
4
4
  # Conred
5
5
 
6
- In every project we have common things like video
7
- embedding from url, user input displaying, formatting, trimming stripping,
8
- external url protocol adding and all that nasty stuff that we write in our apps.
9
- These are the cases where Conred saves the day.
6
+ Easily and safely embed YouTube and Vimeo videos in your applications.
10
7
 
11
8
  ## Installation
12
9
 
@@ -24,14 +21,12 @@ Or install it yourself as:
24
21
 
25
22
  ## Usage
26
23
 
27
- ### Iframe generator for Youtube and Vimeo videos:
28
-
29
24
  ```ruby
30
25
  c = Conred::Video.new(
31
- video_url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
32
- width: 285,
33
- height: 185,
34
- error_message: "Video url is invalid"
26
+ video_url: "http://www.youtube.com/watch?v=tNtW9pGFPTA&feature=plcp",
27
+ width: 285,
28
+ height: 185,
29
+ error_message: "Video url is invalid"
35
30
  )
36
31
  ```
37
32
 
@@ -4,15 +4,12 @@ require File.expand_path('../lib/conred/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Janis Miezitis"]
6
6
  gem.email = ["janjiss@gmail.com"]
7
- gem.description = %q{Gem to remove repetative tasks}
8
- gem.summary = %q{Comrades are for reusable code}
7
+ gem.description = %q{Safely and easily embed videos}
8
+ gem.summary = %q{Safely and easily embed YouTube and Vimeo videos}
9
9
  gem.homepage = "http://github.com/janjiss/conred"
10
10
 
11
- gem.add_dependency "haml", '>= 3.0'
12
- gem.add_dependency "typhoeus", '>= 0.6'
13
- gem.add_dependency "actionpack", '>= 3.0'
14
- gem.add_development_dependency "rspec", '>= 2.0'
15
- gem.add_development_dependency "rake", '>= 10.1'
11
+ gem.add_development_dependency "rspec", '~> 2.0'
12
+ gem.add_development_dependency "rake", '~> 10.1'
16
13
 
17
14
  gem.files = `git ls-files`.split($\)
18
15
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -1,3 +1,2 @@
1
1
  require "conred/version"
2
2
  require "conred/video"
3
- require "haml"
@@ -1,3 +1,3 @@
1
1
  module Conred
2
- VERSION = "0.4.3"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -1,17 +1,17 @@
1
1
  require "conred/version"
2
- require "action_view"
3
2
  require "net/http"
4
- require "typhoeus"
3
+ require "erb"
4
+
5
5
  module Conred
6
6
  module Video
7
- def initialize(arguments = {:width => 670, :height => 450, :error_message => "Video url you have provided is invalid"})
8
- @width = arguments[:width]
9
- @height = arguments[:height]
10
- @error_message = arguments[:error_message]
11
- @video_id = get_video_id_from arguments[:video_url]
7
+ def initialize(options = {})
8
+ @width = options.fetch(:width, 670)
9
+ @height = options.fetch(:height, 450)
10
+ @error_message = options.fetch(:error_message, "Invalid video url")
11
+ @video_id = get_video_id_from(options[:video_url])
12
12
  end
13
13
 
14
- def self.new arguments
14
+ def self.new(arguments)
15
15
  if Youtube.url_format_is_valid? arguments[:video_url]
16
16
  Youtube.new arguments
17
17
  elsif Video::Vimeo.url_format_is_valid? arguments[:video_url]
@@ -30,27 +30,22 @@ module Conred
30
30
  end
31
31
 
32
32
  def code
33
- render(
34
- :video_link => video_link,
35
- :height => @height,
36
- :width => @width
37
- ).html_safe
33
+ view_path = File.join(
34
+ File.dirname(__FILE__),
35
+ "../views/video/video_iframe.html.erb"
36
+ )
37
+ template = ERB.new(File.read(view_path))
38
+ template.result(binding)
38
39
  end
39
40
 
40
41
  def exist?
41
- response = Typhoeus.get("https:#{api_uri}")
42
- response.code == 200
42
+ response = Net::HTTP.get_response(URI("http:#{api_uri}"))
43
+ response.is_a?(Net::HTTPSuccess)
43
44
  end
44
45
 
45
- private
46
+ attr_reader :height, :width, :video_id, :error_message
46
47
 
47
- def render(locals = {})
48
- path = File.join(
49
- File.dirname(__FILE__),
50
- "../views/video/video_iframe".split("/")
51
- )
52
- Haml::Engine.new(File.read("#{path}.html.haml")).render(Object.new, locals)
53
- end
48
+ private
54
49
 
55
50
  class Youtube
56
51
  include Video
@@ -0,0 +1,2 @@
1
+ <iframe src="<%= video_link %>" frameborder="0" height="<%= height %>" width="<%= width %>" allowFullScreen mozallowfullscreen webkitAllowFullScreen >
2
+ </iframe>
@@ -20,65 +20,69 @@ describe Conred do
20
20
  }
21
21
 
22
22
  it "should match youtube video" do
23
- short_youtube_url.should be_youtube_video
24
- https_youtube_url.should be_youtube_video
25
- short_youtube_url_with_www.should be_youtube_video
26
- long_youtube_url_with_features.should be_youtube_video
27
- short_youtube_url_without_http_and_www.should be_youtube_video
23
+ expect(short_youtube_url).to be_youtube_video
24
+ expect(https_youtube_url).to be_youtube_video
25
+ expect(short_youtube_url_with_www).to be_youtube_video
26
+ expect(long_youtube_url_with_features).to be_youtube_video
27
+ expect(short_youtube_url_without_http_and_www).to be_youtube_video
28
28
  end
29
29
 
30
30
  it "should check for corner cases" do
31
- evil_vimeo.should_not be_youtube_video
32
- evil_vimeo.should_not be_vimeo_video
31
+ expect(evil_vimeo).to_not be_youtube_video
32
+ expect(evil_vimeo).to_not be_vimeo_video
33
33
  end
34
34
 
35
35
  it "should match vimeo video" do
36
- vimeo_url.should_not be_youtube_video
37
- vimeo_without_http.should be_vimeo_video
38
- https_vimeo_url.should be_vimeo_video
39
- vimeo_url.should be_vimeo_video
36
+ expect(vimeo_url).to_not be_youtube_video
37
+ expect(vimeo_without_http).to be_vimeo_video
38
+ expect(https_vimeo_url).to be_vimeo_video
39
+ expect(vimeo_url).to be_vimeo_video
40
40
  end
41
41
 
42
42
  describe "youtube embed code" do
43
43
  subject {Conred::Video.new(:video_url=>"http://www.youtube.com/watch?v=Lrj5Kxdzouc", :width=>450,:height=> 300).code }
44
- it { should match(/Lrj5Kxdzouc/)}
45
- it { should match(/width='450'/)}
46
- it {should match(/height='300'/)}
44
+ it "matches to correct html" do
45
+ expect(subject).to match(/Lrj5Kxdzouc/)
46
+ expect(subject).to match(/width="450"/)
47
+ expect(subject).to match(/height="300"/)
48
+ end
47
49
  end
48
50
 
49
51
  describe "vimeo embed code" do
50
52
  subject { Conred::Video.new(:video_url=>"http://vimeo.com/49556689", :width=>450, :height=>300).code }
51
- it {should match(/49556689/)}
52
- it {should match(/width='450'/)}
53
- it {should match(/height='300'/)}
53
+ it "matches to correct html" do
54
+ expect(subject).to match(/49556689/)
55
+ expect(subject).to match(/width="450"/)
56
+ expect(subject).to match(/height="300"/)
57
+ end
54
58
  end
55
59
 
56
60
  it "should render error message when url is invalid" do
57
- error_video.code.should == "Some mistake in url"
61
+ expect(error_video.code).to eq("Some mistake in url")
58
62
  end
59
63
 
60
64
  it "should return correct embed code when passing arguments in url" do
61
- Conred::Video.new(:video_url=>"http://www.youtube.com/watch?NR=1&feature=endscreen&v=Lrj5Kxdzouc",:width=> 450,:height=> 300).code.should match(/Lrj5Kxdzouc/)
65
+ expect(Conred::Video.new(:video_url=>"http://www.youtube.com/watch?NR=1&feature=endscreen&v=Lrj5Kxdzouc",:width=> 450,:height=> 300).code).to match(/Lrj5Kxdzouc/)
62
66
  end
63
67
 
64
68
  describe "check if a video exist" do
65
69
  it "should return false if request 404" do
66
70
  non_existing_video = Conred::Video.new(:video_url=>"http://www.youtube.com/watch?v=Lrj5Kxdzoux")
67
- non_existing_video.exist?.should be_false
71
+ expect(non_existing_video.exist?).to eq(false)
68
72
  end
69
73
 
70
74
  it "should make a request to the proper uri" do
71
75
  non_existing_video = Conred::Video.new(:video_url=>"http://www.youtube.com/watch?v=Lrj5Kxdzoux")
72
- non_existing_video.api_uri.should eq("//gdata.youtube.com/feeds/api/videos/Lrj5Kxdzoux")
76
+ expect(non_existing_video.api_uri).to eq("//gdata.youtube.com/feeds/api/videos/Lrj5Kxdzoux")
73
77
  end
74
78
 
75
79
  it "should be true if response is 200" do
76
80
  existing_video = Conred::Video.new(:video_url=>"http://www.youtube.com/watch?v=Lrj5Kxdzouc")
77
- existing_video.exist?.should be_true
81
+ expect(existing_video.exist?).to eq(true)
78
82
  end
79
83
 
80
84
  it "should be false if uri isn't recognized" do
81
- error_video.exist?.should be_false
85
+ expect(error_video.exist?).to eq(false)
82
86
  end
83
87
  end
84
88
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: conred
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janis Miezitis
@@ -10,77 +10,35 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: haml
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '3.0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '3.0'
27
- - !ruby/object:Gem::Dependency
28
- name: typhoeus
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0.6'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0.6'
41
- - !ruby/object:Gem::Dependency
42
- name: actionpack
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '3.0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '3.0'
55
13
  - !ruby/object:Gem::Dependency
56
14
  name: rspec
57
15
  requirement: !ruby/object:Gem::Requirement
58
16
  requirements:
59
- - - ">="
17
+ - - "~>"
60
18
  - !ruby/object:Gem::Version
61
19
  version: '2.0'
62
20
  type: :development
63
21
  prerelease: false
64
22
  version_requirements: !ruby/object:Gem::Requirement
65
23
  requirements:
66
- - - ">="
24
+ - - "~>"
67
25
  - !ruby/object:Gem::Version
68
26
  version: '2.0'
69
27
  - !ruby/object:Gem::Dependency
70
28
  name: rake
71
29
  requirement: !ruby/object:Gem::Requirement
72
30
  requirements:
73
- - - ">="
31
+ - - "~>"
74
32
  - !ruby/object:Gem::Version
75
33
  version: '10.1'
76
34
  type: :development
77
35
  prerelease: false
78
36
  version_requirements: !ruby/object:Gem::Requirement
79
37
  requirements:
80
- - - ">="
38
+ - - "~>"
81
39
  - !ruby/object:Gem::Version
82
40
  version: '10.1'
83
- description: Gem to remove repetative tasks
41
+ description: Safely and easily embed videos
84
42
  email:
85
43
  - janjiss@gmail.com
86
44
  executables: []
@@ -96,7 +54,7 @@ files:
96
54
  - lib/conred.rb
97
55
  - lib/conred/version.rb
98
56
  - lib/conred/video.rb
99
- - lib/views/video/video_iframe.html.haml
57
+ - lib/views/video/video_iframe.html.erb
100
58
  - spec/conred_spec.rb
101
59
  - spec/conred_spec/video_spec.rb
102
60
  homepage: http://github.com/janjiss/conred
@@ -121,7 +79,7 @@ rubyforge_project:
121
79
  rubygems_version: 2.2.0
122
80
  signing_key:
123
81
  specification_version: 4
124
- summary: Comrades are for reusable code
82
+ summary: Safely and easily embed YouTube and Vimeo videos
125
83
  test_files:
126
84
  - spec/conred_spec.rb
127
85
  - spec/conred_spec/video_spec.rb
@@ -1 +0,0 @@
1
- %iframe{:allowFullScreen => "", :frameborder => "0", :height => height, :mozallowfullscreen => "", :src => "#{video_link}", :webkitAllowFullScreen => "", :width => width}