reddavis-oembed-with-ruby 0.0.1

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.
data/README ADDED
@@ -0,0 +1,29 @@
1
+ This is/will (be) a very simple oEmbed wrapper in Ruby and will be accompanied by a Rails plugin.
2
+
3
+ To Use
4
+
5
+ a = Oembed::Media('put the url here')
6
+
7
+ You are then given attributes such as...
8
+
9
+ a.title
10
+ a.media_url - link to the media
11
+ a.html - a flash player, (only for videos)
12
+ a.format - video/photo
13
+
14
+
15
+ Services Supported
16
+
17
+ Flickr
18
+
19
+ Vimeo
20
+
21
+ Viddler
22
+
23
+ Qik
24
+
25
+ Pownce
26
+
27
+ Revision3
28
+
29
+ Hulu - You may get problems if the server your using it on is not in the US
@@ -0,0 +1,50 @@
1
+ module Oembed
2
+
3
+ class Media < Providers
4
+
5
+ attr_accessor :title, :media_url, :html, :format
6
+
7
+ def initialize(url)
8
+ @format = 'json'
9
+ @url = url
10
+ @sites = Oembed::Providers.new.sites
11
+ get_info
12
+ end
13
+
14
+ def get_info
15
+ find_provider
16
+ url = URI.parse(@base_url + @url)
17
+ http_get = Net::HTTP.get(url)
18
+ set_attributes(http_get)
19
+ end
20
+
21
+ def set_attributes(att)
22
+ parsed_data = JSON.parse(att)
23
+ @title = parsed_data['title']
24
+ @media_url = parsed_data['url']
25
+ @format = parsed_data['type']
26
+ @html = parsed_data['html'] if @format == 'video'
27
+ end
28
+
29
+
30
+ private
31
+ #find Oembed provider - set in ../providers.yaml
32
+ def find_provider
33
+ @sites.keys.each do |key|
34
+ if @url.match(/#{key}/)
35
+ @base_url = prepare_url(@sites[key])
36
+ end
37
+ end
38
+ end
39
+ #some urls contain format in the middle of the url
40
+ def prepare_url(url)
41
+ if url.match(/format/)
42
+ @base_url = "#{url.gsub(/\{format\}/, @format)}" + '?url='
43
+ else
44
+ @url = @url + '&format=json'
45
+ @base_url = url + '?url='
46
+ end
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,21 @@
1
+ module Oembed
2
+ class Providers
3
+
4
+ attr_accessor :sites
5
+
6
+ def initialize
7
+ @sites = {}
8
+ add_default_providers
9
+ end
10
+
11
+ private
12
+ def add_default_providers
13
+ load_providers
14
+ end
15
+
16
+ def load_providers
17
+ providers = YAML.load_file("#{File.dirname(__FILE__)}/../providers.yaml")
18
+ providers.each {|d| @sites.merge!(d[0] => d[1])}
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'yaml'
6
+
7
+ #Files
8
+ require 'oembed/providers'
9
+ require 'oembed/media'
10
+
11
+
12
+ puts a = Oembed::Media.new('http://www.vimeo.com/1263763').title
13
+
14
+ #puts b = Oembed::Media.new('http://www.flickr.com/photos/davidgutierrez/2135724493/').title
15
+
16
+ #puts c = Oembed::Media.new('http://www.viddler.com/explore/winelibrarytv/videos/142/').title
17
+
18
+ #puts d = Oembed::Media.new('http://qik.com/video/141977').title
19
+
20
+ #puts e = Oembed::Media.new('http://pownce.com/dburka/notes/2951118/').title
21
+
22
+ #puts f = Oembed::Media.new('http://revision3.com/trs/blockoland/').html
@@ -0,0 +1,13 @@
1
+ flickr: http://www.flickr.com/services/oembed
2
+
3
+ vimeo: http://www.vimeo.com/api/oembed.{format}
4
+
5
+ viddler: http://lab.viddler.com/services/oembed/
6
+
7
+ qik: http://qik.com/api/oembed.{format}
8
+
9
+ pownce: http://api.pownce.com/2.1/oembed.{format}
10
+
11
+ revision3: http://revision3.com/api/oembed/
12
+
13
+ # hulu: http://www.hulu.com/api/oembed.{format} - No UK service
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reddavis-oembed-with-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Red Davis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-08-01 03:09:06 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: reddavis@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README
26
+ - lib/oembed-with-ruby.rb
27
+ - lib/providers.yaml
28
+ - lib/oembed/media.rb
29
+ - lib/oembed/providers.rb
30
+ has_rdoc: false
31
+ homepage: http://github.com/reddavis/oembed-with-ruby/
32
+ post_install_message:
33
+ rdoc_options: []
34
+
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project:
52
+ rubygems_version: 1.2.0
53
+ signing_key:
54
+ specification_version: 2
55
+ summary: Ruby interface for oEmbed
56
+ test_files: []
57
+