widgetify 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,24 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+
13
+ # Ignore all logfiles and tempfiles.
14
+ /log/*.log
15
+ /tmp
16
+
17
+ # OS generated files #
18
+ .DS_Store
19
+ ehthumbs.db
20
+ Icon?
21
+ Thumbs.db
22
+
23
+ *~
24
+
data/LICENCE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (C) 2012 Kreeti Technologies
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ Widgetify
2
+ =============
3
+
4
+ Description
5
+ ------------
6
+ Widgetify provides the functionality for dealing with parsing from a url. It can parse the Open Graph Protocol, Oembed URL and the HTML image tags.
7
+ For Open Graph you can read more about the specification at [http://ogp.me](http://ogp.me) and for Oembed URL read more about the specification at [http://oembed.com/](http://oembed.com/) .
8
+
9
+ Requirements
10
+ ------------
11
+ ```
12
+ * Ruby(tested with 1.9.3)
13
+ * Nokogiri
14
+ * Rspec(only if you want to run the tests)
15
+ ```
16
+ Installation
17
+ ------------
18
+ ```
19
+ gem install widgetify
20
+
21
+ Installing from the github, include this line in your Gemfile.
22
+
23
+ gem 'widgetify', :git => "git@github.com:funnyfarmsf/widgetify.git"
24
+ ```
25
+
26
+ Usage
27
+ ------------
28
+ require 'widgetify'
29
+
30
+ ### For Open Graph Parsing
31
+ ```
32
+ widgetify = Widgetify::Base.new(your_url, {}, :parse_open_graph)
33
+
34
+ widgetify.parse_result
35
+ ```
36
+
37
+ ### For Oembed URL Parsing
38
+ ```
39
+ widgetify = Widgetify::Base.new(url, {:format => 'json', :maxwidth => '150', :maxheight => '250', :provider => 'provider_name'}, :parse_oembed)
40
+
41
+ widgetify.parse_result
42
+ ```
43
+ ### For Html Parsing
44
+ ```
45
+ widgetify = Widgetify::Base.new(your_url, {}, :parse_html)
46
+
47
+ widgetify.parse_result
48
+ ```
49
+
50
+ ### You can parse more than one type
51
+ *****
52
+ ```
53
+ widgetify = Widgetify::Base.new(url, {:format => 'json', :maxwidth => '150', :maxheight => '250', :provider => 'provider_name'}, :parse_oembed, :parse_open_graph)
54
+
55
+ widgetify.parse_result
56
+ ```
57
+
58
+ ###### Provider Name List
59
+ *****
60
+
61
+ * youtube
62
+ * flickr
63
+ * viddler
64
+ * qik
65
+ * revision3
66
+ * hulu
67
+ * vimeo
68
+ * collegehumour
69
+ * oohembed
70
+ * polleverywhere
71
+ * opera
72
+ * embed
73
+ * ifixit
74
+ * smugmug
75
+ * slideshare
76
+ * wordpress
@@ -0,0 +1,40 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+
3
+ require 'nokogiri'
4
+ require 'open-uri'
5
+ require_relative 'parser'
6
+ require_relative 'image_parser'
7
+
8
+ module Widgetify
9
+
10
+ class HTMLParser < Parser
11
+
12
+ def initialize(html_doc)
13
+ super(html_doc)
14
+ @html_doc = html_doc
15
+ html_parser
16
+ end
17
+
18
+ def html_parser
19
+ self['title'] = @html_doc.xpath('//title').text
20
+ self['canonical_url'] = canonical_url
21
+ self['description'] = description
22
+ self['images'] = images
23
+ end
24
+
25
+ private
26
+
27
+ def description
28
+ look_for_attribute('name', 'description')
29
+ end
30
+
31
+ def canonical_url
32
+ look_for_href('rel', 'canonical')
33
+ end
34
+
35
+ def images
36
+ image = Widgetify::ImageInfo.new(@html_doc)
37
+ image.look_for_images
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,33 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ module Widgetify
6
+
7
+ class ImageInfo
8
+
9
+ def initialize(html_doc)
10
+ @img_doc = html_doc.xpath("//img")
11
+ @image = []
12
+ end
13
+
14
+ def look_for_images
15
+ image = []
16
+ @img_doc.each do |attr|
17
+ img_hash = { }
18
+ img_hash["src"] = attr.get_attribute("src")
19
+ img_hash["width"] = attr.get_attribute("width")
20
+ img_hash["height"] = attr.get_attribute("height")
21
+ img_hash["alt"] = attr.get_attribute("alt")
22
+ img_hash["align"] = attr.get_attribute("align")
23
+ img_hash["class"] = attr.get_attribute("class")
24
+ img_hash["id"] = attr.get_attribute("id")
25
+ img_hash["lang"] = attr.get_attribute("lang")
26
+ img_hash["style"] = attr.get_attribute("style")
27
+ img_hash["title"] = attr.get_attribute("title")
28
+ image << img_hash
29
+ end
30
+ image
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,83 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+
3
+ require 'open-uri'
4
+ require 'json'
5
+ require_relative 'parser'
6
+ module Widgetify
7
+ API_END_POINTS = {
8
+ :youtube => 'http://www.youtube.com/oembed',
9
+ :flickr => 'http://flickr.com/services/oembed',
10
+ :viddler => 'http://lab.viddler.com/services/oembed/',
11
+ :qik => 'http://qik.com/api/oembed.',
12
+ :revision3 => 'http://revision3.com/api/oembed/',
13
+ :hulu => 'http://www.hulu.com/api/oembed.',
14
+ :vimeo => 'http://vimeo.com/api/oembed.',
15
+ :collegehumor => 'http://www.collegehumor.com/oembed.',
16
+ :oohembed => 'http://oohembed.com/oohembed/',
17
+ :polleverywhere => 'http://polleverywhere.com/services/oembed',
18
+ :opera => 'http://my.opera.com/service/oembed/',
19
+ :embed => 'http://api.embed.ly/1/oembed',
20
+ :ifixit => 'http://www.ifixit.com/Embed',
21
+ :smugmug => 'http://api.smugmug.com/services/oembed/',
22
+ :slideshare => 'http://www.slideshare.net/api/oembed/2',
23
+ :wordpress => 'http://public-api.wordpress.com/oembed/1.0/'
24
+ }
25
+ class OembedParser < Parser
26
+ def initialize(html_doc, options = {})
27
+ super(html_doc)
28
+ @html_doc = html_doc
29
+ @options = options
30
+ @options[:format] = 'json' if !@options[:format]
31
+ oembed_parse
32
+ end
33
+
34
+ protected
35
+
36
+ def oembed_parse
37
+ @link, type = look_for_type
38
+ if type
39
+ if type.scan('json').length > 0
40
+ @type = 'json'
41
+ elsif type.scan('xml').length > 0
42
+ @type = 'xml'
43
+ end
44
+ get_proper_response(type)
45
+ else
46
+ response_type_not_present
47
+ end
48
+ end
49
+
50
+ def response_type_not_present
51
+ api = API_END_POINTS[@options[:provider].to_sym]
52
+ @link = api[api.length - 1] == '.' ? api.to_s+@options[:format] : api.to_s+"?url="+@options[:url]
53
+ @link += "?url="+@options[:url] if @link.include?('json') || @link.include?('xml')
54
+ @link += "&maxwidth=" + @options[:maxwidth] if @options[:maxwidth]
55
+ @link += "&maxheight=" + @options[:maxheight] if @options[:maxheight]
56
+ @link += "&format=" + @options[:format] if @options[:format] && api.scan(@options[:format])
57
+ get_proper_response(@options[:format])
58
+ end
59
+
60
+ def get_proper_response(type)
61
+ case type
62
+ when /json/ then get_json
63
+ when /xml/ then get_xml
64
+ end
65
+ end
66
+
67
+ #### here the json response will be parsed
68
+
69
+ def get_json
70
+ obj = open(@link){ |f| f.read}
71
+ JSON.parse(obj).each{ |key, val| self[key] = val} if JSON.parse(obj)
72
+ end
73
+
74
+ ########### here the xml response will be parsed.
75
+ def get_xml
76
+ xml = Nokogiri::XML(open(@link))
77
+ xml.xpath('/oembed').children.each do |row|
78
+ self[row.name] = row.text
79
+ end
80
+ end
81
+ end #eof OembedParser
82
+
83
+ end
@@ -0,0 +1,53 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'json'
5
+ require_relative 'parser'
6
+
7
+ module Widgetify
8
+
9
+ class OpenGraphParser < Parser
10
+
11
+ def initialize(html_doc)
12
+ super(html_doc)
13
+ @html_doc = html_doc
14
+ @key_arr = ['og:image','og:video','og:audio']
15
+ open_graph_parser
16
+ end
17
+
18
+ protected
19
+
20
+ def open_graph_parser
21
+ self["images"] = look_for_metadata(@key_arr[0])
22
+ self["videos"] = look_for_metadata(@key_arr[1])
23
+ self["audios"] = look_for_metadata(@key_arr[2])
24
+ basic_meta_data
25
+ end
26
+
27
+ def look_for_metadata(attribute)
28
+ final_arr = []
29
+ img_hash = { }
30
+ @html_doc.xpath("//meta[starts-with(@property, '#{attribute}')]").each do |meta|
31
+ image = meta.get_attribute("property")
32
+ content = meta.get_attribute("content")
33
+ if image == attribute
34
+ img_hash = { }
35
+ final_arr << img_hash
36
+ img_hash["url"] = content
37
+ else
38
+ key = image.split(':').last
39
+ img_hash[key] = content
40
+ end
41
+ end
42
+ final_arr
43
+ end
44
+
45
+ def basic_meta_data
46
+ @html_doc.xpath("//meta[starts-with(@property, 'og:')]").each do |meta|
47
+ property = meta.get_attribute("property")
48
+ self[property.split(':').last] = meta.get_attribute("content") if property.split(':').length <= 2 && !@key_arr.include?(property)
49
+ end
50
+ end
51
+
52
+ end # eof OpenGraph class
53
+ end
@@ -0,0 +1,32 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ module Widgetify
6
+ class Parser < Hash ### this will be the base class
7
+ def initialize(html_doc)
8
+ @html_doc = html_doc
9
+ end
10
+
11
+ protected
12
+
13
+ def look_for_attribute(attr, attr_value)
14
+ meta_obj = @html_doc.xpath("//meta[@#{attr} = '#{attr_value}']")
15
+ meta_obj.first.get_attribute('content') unless meta_obj.first.nil?
16
+ end
17
+
18
+ def look_for_href(attr, attr_value)
19
+ meta_obj = @html_doc.xpath("//link[@#{attr} = '#{attr_value}']")
20
+ meta_obj.first.get_attribute('href') unless meta_obj.empty?
21
+ end
22
+
23
+ def look_for_type
24
+ oembed_type = @html_doc.xpath("//link[@type='application/json+oembed']")
25
+ oembed_type = !oembed_type.empty? ? oembed_type : @html_doc.xpath("//link[@type='text/xml+oembed']")
26
+ oembed_link = oembed_type.first.get_attribute('href') unless oembed_type.empty?
27
+ type = oembed_type.first.get_attribute('type') unless oembed_type.empty?
28
+ [oembed_link, type]
29
+ end
30
+ end
31
+ end
32
+
data/lib/widgetify.rb ADDED
@@ -0,0 +1,40 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+ require 'parser/oembed_parser'
5
+ require 'parser/open_graph_parser'
6
+ require 'parser/html_parser'
7
+
8
+ module Widgetify
9
+
10
+ class Base
11
+ attr_reader :parse_result
12
+
13
+ def initialize(url, options = {}, *args)
14
+ @html_doc = Nokogiri::HTML(open(url))
15
+ @parse_result = { }
16
+ @options = options
17
+ @options[:url] = url
18
+ parse_all if args.length == 0
19
+ args.each{ |arg| send(arg.to_sym)} if args.length > 0
20
+ end
21
+
22
+ def parse_open_graph
23
+ @parse_result['open_graph'] = Widgetify::OpenGraphParser.new(@html_doc)
24
+ end
25
+
26
+ def parse_oembed
27
+ @parse_result['oembed'] = Widgetify::OembedParser.new(@html_doc, @options)
28
+ end
29
+
30
+ def parse_html
31
+ @parse_result['html'] = Widgetify::HTMLParser.new(@html_doc)
32
+ end
33
+
34
+ def parse_all
35
+ parse_open_graph
36
+ parse_oembed
37
+ parse_html
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,34 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+ require 'spec_helper'
3
+
4
+ describe Widgetify::Base do
5
+ before :each do
6
+ @widgetify = Widgetify::Base.new('http://flickr.com/photos/bees/2362225867/',{ :provider => 'flickr', :format => 'json'}, :parse_oembed)
7
+ end
8
+
9
+ it "checking the thumbnail height" do
10
+ thumbnail_height = @widgetify.parse_result["oembed"]["thumbnail_height"]
11
+ thumbnail_height.should == 75
12
+ end
13
+
14
+ it "checking the title" do
15
+ title = @widgetify.parse_result["oembed"]["title"]
16
+ title.should == "Bacon Lollys"
17
+ end
18
+
19
+ it "checking the width" do
20
+ width = @widgetify.parse_result["oembed"]["width"]
21
+ width.should == "1024"
22
+ end
23
+
24
+ it "checking the height" do
25
+ height = @widgetify.parse_result["oembed"]["height"]
26
+ height.should == "768"
27
+ end
28
+
29
+ it "checking the provider name" do
30
+ provider = @widgetify.parse_result["oembed"]["provider_name"]
31
+ provider.should == "Flickr"
32
+ end
33
+
34
+ end
data/spec/html_spec.rb ADDED
@@ -0,0 +1,25 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+ require 'spec_helper'
3
+
4
+ describe Widgetify::Base do
5
+ before :each do
6
+ @widgetify = Widgetify::Base.new('http://vimeo.com/7100571',{ },:parse_html)
7
+ end
8
+
9
+
10
+ it "checking the title of the url" do
11
+ title = @widgetify.parse_result["html"]["title"]
12
+ title.should == "Ron Young Graduation on Vimeo"
13
+ end
14
+
15
+ it "checking the canonical_url of the url" do
16
+ canonical_url = @widgetify.parse_result["html"]["canonical_url"]
17
+ canonical_url.should == "/7100571"
18
+ end
19
+
20
+ it "checking the description of the url" do
21
+ description = @widgetify.parse_result["html"]["description"]
22
+ description.should == "Ron speaking in chapel and accepting his diploma."
23
+ end
24
+
25
+ end
data/spec/hulu_spec.rb ADDED
@@ -0,0 +1,39 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+ require 'spec_helper'
3
+
4
+ describe Widgetify::Base do
5
+ before :each do
6
+ @widgetify = Widgetify::Base.new('http://www.hulu.com/watch/160617',{ :provider => 'hulu', :format => 'json'}, :parse_oembed)
7
+ end
8
+
9
+ it "checking the thumbnail height" do
10
+ thumbnail_height = @widgetify.parse_result["oembed"]["thumbnail_height"]
11
+ thumbnail_height.should == 80
12
+ end
13
+
14
+ it "checking the title" do
15
+ title = @widgetify.parse_result["oembed"]["title"]
16
+ title.should == "What Is Hulu Plus? (Hulu Walkthrough)"
17
+ end
18
+
19
+ it "checking the width" do
20
+ width = @widgetify.parse_result["oembed"]["width"]
21
+ width.should == 512
22
+ end
23
+
24
+ it "checking the height" do
25
+ height = @widgetify.parse_result["oembed"]["height"]
26
+ height.should == 296
27
+ end
28
+
29
+ it "checking the author name" do
30
+ author = @widgetify.parse_result["oembed"]["author_name"]
31
+ author.should == "Hulu"
32
+ end
33
+
34
+ it "checking the provider name" do
35
+ provider = @widgetify.parse_result["oembed"]["provider_name"]
36
+ provider.should == "Hulu"
37
+ end
38
+
39
+ end
@@ -0,0 +1,30 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+ require 'spec_helper'
3
+
4
+ describe Widgetify::Base do
5
+
6
+ before :each do
7
+ @widgetify = Widgetify::Base.new('http://ogp.me',{ },:parse_open_graph)
8
+ end
9
+
10
+ it "checking the width of the open graph image protocol" do
11
+ width = @widgetify.parse_result["open_graph"]["images"].first["width"]
12
+ width.should == "300"
13
+ end
14
+
15
+ it "checking the height of the open graph image protocol" do
16
+ height = @widgetify.parse_result["open_graph"]["images"].first["height"]
17
+ height.should == "300"
18
+ end
19
+
20
+ it "checking the type of the open graph image protocol" do
21
+ type = @widgetify.parse_result["open_graph"]["images"].first["type"]
22
+ type.should == "image/png"
23
+ end
24
+
25
+ it "checking the url of the open graph image protocol" do
26
+ url = @widgetify.parse_result["open_graph"]["images"].first["url"]
27
+ url.should == "http://ogp.me/logo.png"
28
+ end
29
+
30
+ end
@@ -0,0 +1,48 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+ require 'spec_helper'
3
+
4
+ describe Widgetify::Base do
5
+
6
+ before :each do
7
+ @widgetify = Widgetify::Base.new('http://vimeo.com/7100571')
8
+ end
9
+
10
+ it "checking the json response of the url" do
11
+ type = @widgetify.parse_result["oembed"]["type"]
12
+ version = @widgetify.parse_result["oembed"]["version"]
13
+ provider_name = @widgetify.parse_result["oembed"]["provider_name"]
14
+ provider_url = @widgetify.parse_result["oembed"]["provider_url"]
15
+ title = @widgetify.parse_result["oembed"]["title"]
16
+ author_name = @widgetify.parse_result["oembed"]["author_name"]
17
+ author_url = @widgetify.parse_result["oembed"]["author_url"]
18
+ is_plus = @widgetify.parse_result["oembed"]["is_plus"]
19
+ width = @widgetify.parse_result["oembed"]["width"]
20
+ height = @widgetify.parse_result["oembed"]["height"]
21
+ duration = @widgetify.parse_result["oembed"]["duration"]
22
+ description = @widgetify.parse_result["oembed"]["description"]
23
+ thumbnail_url = @widgetify.parse_result["oembed"]["thumbnail_url"]
24
+ thumbnail_width = @widgetify.parse_result["oembed"]["thumbnail_width"]
25
+ thumbnail_height = @widgetify.parse_result["oembed"]["thumbnail_height"]
26
+ video_id = @widgetify.parse_result["oembed"]["video_id"]
27
+
28
+ type.should == "video"
29
+ version.should == "1.0"
30
+ provider_name.should == "Vimeo"
31
+ provider_url.should == "http:\/\/vimeo.com\/"
32
+ title.should == "Ron Young Graduation"
33
+ author_name.should == "Jeff Selph"
34
+ author_url.should == "http:\/\/vimeo.com\/jeffselph"
35
+ is_plus.should == "0"
36
+ width.should == 640
37
+ height.should == 432
38
+ duration.should == 1494
39
+ description.should == "Ron speaking in chapel and accepting his diploma."
40
+ thumbnail_url.should == "http:\/\/b.vimeocdn.com\/ts\/294\/142\/29414297_640.jpg"
41
+ thumbnail_width.should == 640
42
+ thumbnail_height.should == 432
43
+ video_id.should == 7100571
44
+ end
45
+
46
+
47
+
48
+ end
data/spec/qik_spec.rb ADDED
@@ -0,0 +1,34 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+ require 'spec_helper'
3
+
4
+ describe Widgetify::Base do
5
+ before :each do
6
+ @widgetify = Widgetify::Base.new('http://qik.com/video/49565',{ :provider => 'qik', :format => 'json'}, :parse_oembed)
7
+ end
8
+
9
+ it "checking the title" do
10
+ title = @widgetify.parse_result["oembed"]["title"]
11
+ title.should == "Alex and i having breakfast"
12
+ end
13
+
14
+ it "checking the width" do
15
+ width = @widgetify.parse_result["oembed"]["width"]
16
+ width.should == "425"
17
+ end
18
+
19
+ it "checking the height" do
20
+ height = @widgetify.parse_result["oembed"]["height"]
21
+ height.should == "319"
22
+ end
23
+
24
+ it "checking the author url" do
25
+ author = @widgetify.parse_result["oembed"]["author_url"]
26
+ author.should == "http://qik.com/kevin"
27
+ end
28
+
29
+ it "checking the provider name" do
30
+ provider = @widgetify.parse_result["oembed"]["provider_name"]
31
+ provider.should == "qik"
32
+ end
33
+
34
+ end
@@ -0,0 +1,29 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+ require 'spec_helper'
3
+
4
+ describe Widgetify::Base do
5
+ before :each do
6
+ @widgetify = Widgetify::Base.new('http://www.slideshare.net/haraldf/business-quotes-for-2011',{ :provider => 'slideshare', :format => 'json'}, :parse_oembed)
7
+ end
8
+
9
+ it "checking the title" do
10
+ title = @widgetify.parse_result["oembed"]["title"]
11
+ title.should == "Business Quotes for 2011"
12
+ end
13
+
14
+ it "checking the width" do
15
+ width = @widgetify.parse_result["oembed"]["width"]
16
+ width.to_s.should == "425"
17
+ end
18
+
19
+ it "checking the height" do
20
+ height = @widgetify.parse_result["oembed"]["height"]
21
+ height.to_s.should == "355"
22
+ end
23
+
24
+ it "checking the author name" do
25
+ author = @widgetify.parse_result["oembed"]["author_name"]
26
+ author.should == "Harald Felgner"
27
+ end
28
+
29
+ end
@@ -0,0 +1,29 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+ require 'spec_helper'
3
+
4
+ describe Widgetify::Base do
5
+ before :each do
6
+ @widgetify = Widgetify::Base.new('http://www.smugmug.com/popular/all%23125787395_hQSj9',{ :provider => 'smugmug', :format => 'json'}, :parse_oembed)
7
+ end
8
+
9
+ it "checking the title" do
10
+ title = @widgetify.parse_result["oembed"]["title"]
11
+ title.should == "Great Egret at dusk"
12
+ end
13
+
14
+ it "checking the width" do
15
+ width = @widgetify.parse_result["oembed"]["width"]
16
+ width.to_s.should == "600"
17
+ end
18
+
19
+ it "checking the height" do
20
+ height = @widgetify.parse_result["oembed"]["height"]
21
+ height.to_s.should == "400"
22
+ end
23
+
24
+ it "checking the author name" do
25
+ author = @widgetify.parse_result["oembed"]["author_name"]
26
+ author.should == "Jean-Luc Vaillant"
27
+ end
28
+
29
+ end
@@ -0,0 +1,7 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+ require 'rubygems'
3
+ require 'widgetify'
4
+
5
+ RSpec.configure do |config|
6
+ # some (optional) config here
7
+ end
@@ -0,0 +1,39 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+ require 'spec_helper'
3
+
4
+ describe Widgetify::Base do
5
+ before :each do
6
+ @widgetify = Widgetify::Base.new('http://www.viddler.com/explore/cdevroe/videos/424/',{ :provider => 'viddler', :format => 'json'}, :parse_oembed)
7
+ end
8
+
9
+ it "checking the thumbnail height" do
10
+ thumbnail_height = @widgetify.parse_result["oembed"]["thumbnail_height"]
11
+ thumbnail_height.should == 349
12
+ end
13
+
14
+ it "checking the title" do
15
+ title = @widgetify.parse_result["oembed"]["title"]
16
+ title.should == "iPhone macro lens demonstration"
17
+ end
18
+
19
+ it "checking the width" do
20
+ width = @widgetify.parse_result["oembed"]["width"]
21
+ width.should == 620
22
+ end
23
+
24
+ it "checking the height" do
25
+ height = @widgetify.parse_result["oembed"]["height"]
26
+ height.should == 349
27
+ end
28
+
29
+ it "checking the author name" do
30
+ author = @widgetify.parse_result["oembed"]["author_name "]
31
+ author.should == "cdevroe"
32
+ end
33
+
34
+ it "checking the provider name" do
35
+ provider = @widgetify.parse_result["oembed"]["provider_name"]
36
+ provider.should == "Viddler"
37
+ end
38
+
39
+ end
@@ -0,0 +1,30 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+ require 'spec_helper'
3
+
4
+ describe Widgetify::Base do
5
+
6
+ before :each do
7
+ @widgetify = Widgetify::Base.new('http://www.youtube.com/watch?v=IOYyCHGWJq4&feature=g-all-esi',{ },:parse_open_graph)
8
+ end
9
+
10
+ it "checking the width of the open graph video protocol" do
11
+ width = @widgetify.parse_result["open_graph"]["videos"].first["width"]
12
+ width.should == "1280"
13
+ end
14
+
15
+ it "checking the height of the open graph video protocol" do
16
+ height = @widgetify.parse_result["open_graph"]["videos"].first["height"]
17
+ height.should == "720"
18
+ end
19
+
20
+ it "checking the type of the open grpah video protocol" do
21
+ type = @widgetify.parse_result["open_graph"]["videos"].first["type"]
22
+ type.should == "application/x-shockwave-flash"
23
+ end
24
+
25
+ it "checking the url of the open graph video protocol" do
26
+ url = @widgetify.parse_result["open_graph"]["videos"].first["url"]
27
+ url.should == "http://www.youtube.com/v/IOYyCHGWJq4?version=3&autohide=1"
28
+ end
29
+
30
+ end
@@ -0,0 +1,34 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+ require 'spec_helper'
3
+
4
+ describe Widgetify::Base do
5
+ before :each do
6
+ @widgetify = Widgetify::Base.new('http://vimeo.com/7100569',{ :provider => 'vimeo', :format => 'json'}, :parse_oembed)
7
+ end
8
+
9
+ it "checking the title" do
10
+ title = @widgetify.parse_result["oembed"]["title"]
11
+ title.should == "Brad!"
12
+ end
13
+
14
+ it "checking the width" do
15
+ width = @widgetify.parse_result["oembed"]["width"]
16
+ width.to_s.should == "1280"
17
+ end
18
+
19
+ it "checking the height" do
20
+ height = @widgetify.parse_result["oembed"]["height"]
21
+ height.to_s.should == "720"
22
+ end
23
+
24
+ it "checking the author url" do
25
+ author = @widgetify.parse_result["oembed"]["author_name"]
26
+ author.should == "Casey Donahue"
27
+ end
28
+
29
+ it "checking the provider name" do
30
+ provider = @widgetify.parse_result["oembed"]["provider_name"]
31
+ provider.should == "Vimeo"
32
+ end
33
+
34
+ end
@@ -0,0 +1,29 @@
1
+ #Copyright (c) 2012, Kreeti Technologies All Rights Reserved.
2
+ require 'spec_helper'
3
+
4
+ describe Widgetify::Base do
5
+ before :each do
6
+ @widgetify = Widgetify::Base.new('http://matt.wordpress.com/2011/07/14/clouds-over-new-york/',{ :provider => 'wordpress', :format => 'json'}, :parse_oembed)
7
+ end
8
+
9
+ it "checking the thumbnail height" do
10
+ thumbnail_height = @widgetify.parse_result["oembed"]["thumbnail_height"]
11
+ thumbnail_height.should == 330
12
+ end
13
+
14
+ it "checking the title" do
15
+ title = @widgetify.parse_result["oembed"]["title"]
16
+ title.should == "Clouds over New York"
17
+ end
18
+
19
+ it "checking the author name" do
20
+ author = @widgetify.parse_result["oembed"]["author_name"]
21
+ author.should == "Matt"
22
+ end
23
+
24
+ it "checking the provider name" do
25
+ provider = @widgetify.parse_result["oembed"]["provider_name"]
26
+ provider.should == "Matt on Not-WordPress"
27
+ end
28
+
29
+ end
data/widgetify.gemspec ADDED
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'widgetify'
4
+ s.version = '0.0.1'
5
+ s.date = '2012-08-10'
6
+ s.summary = 'open graph and oembed data parsing '
7
+ s.add_runtime_dependency "nokogiri",["= 1.5.4"]
8
+ s.description = 'An alternative to embed.ly, it allows an HTML page to be parsed for various meta HTML and open graph details'
9
+ s.authors = ['santanu bhattacharya']
10
+ s.email = 'eng@kreeti.com'
11
+ s.files = `git ls-files`.split("\n")
12
+ s.homepage = 'https://github.com/kreetitech/widgetify'
13
+ s.license = 'MIT'
14
+
15
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: widgetify
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - santanu bhattacharya
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-08-10 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nokogiri
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.5.4
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ description: An alternative to embed.ly, it allows an HTML page to be parsed for various meta HTML and open graph details
27
+ email: eng@kreeti.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files: []
33
+
34
+ files:
35
+ - .gitignore
36
+ - LICENCE.txt
37
+ - README.md
38
+ - lib/parser/html_parser.rb
39
+ - lib/parser/image_parser.rb
40
+ - lib/parser/oembed_parser.rb
41
+ - lib/parser/open_graph_parser.rb
42
+ - lib/parser/parser.rb
43
+ - lib/widgetify.rb
44
+ - spec/flickr_spec.rb
45
+ - spec/html_spec.rb
46
+ - spec/hulu_spec.rb
47
+ - spec/image_spec.rb
48
+ - spec/oembed_spec.rb
49
+ - spec/qik_spec.rb
50
+ - spec/slide_share_spec.rb
51
+ - spec/smug_mug_spec.rb
52
+ - spec/spec_helper.rb
53
+ - spec/viddler_spec.rb
54
+ - spec/video_spec.rb
55
+ - spec/vimeo_spec.rb
56
+ - spec/wordpress_spec.rb
57
+ - widgetify.gemspec
58
+ homepage: https://github.com/kreetitech/widgetify
59
+ licenses:
60
+ - MIT
61
+ post_install_message:
62
+ rdoc_options: []
63
+
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.21
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: open graph and oembed data parsing
85
+ test_files: []
86
+