chalkers-Revver4R 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/CHANGELOG +0 -0
  2. data/README.rdoc +42 -0
  3. data/Rakefile +14 -0
  4. data/Revver4R.gemspec +34 -0
  5. data/init.rb +1 -0
  6. data/lib/revver4r.rb +144 -0
  7. metadata +74 -0
data/CHANGELOG ADDED
File without changes
data/README.rdoc ADDED
@@ -0,0 +1,42 @@
1
+ == Revver4R
2
+
3
+ Revver4R is a simple Ruby interface for Revver's api.
4
+
5
+ == Install
6
+
7
+ gem install chalkers-Revver4R --source http://gems.github.com
8
+
9
+ == Usage
10
+ Here's how to pull 1 quicktime video with the tag ruby
11
+
12
+ require 'Revver4R'
13
+ video_search = Revver4R::VideoSearch.new("qt","tag","ruby",{"limit" => 1})
14
+ videos = video_search.search
15
+ videos.each do |video|
16
+ puts video.to_yaml
17
+ end
18
+
19
+ For more information at http://developer.revver.com/feeds/mrss
20
+
21
+ == License
22
+ THE MIT LICENSE
23
+
24
+ Copyright (c) 2008 Andrew Chalkley
25
+
26
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
27
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation
28
+ the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
29
+ permit persons to whom the Software is
30
+ furnished to do so, subject to the following conditions:
31
+
32
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
33
+ Software.
34
+
35
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
36
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
37
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
38
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39
+
40
+ http://creativecommons.org/licenses/MIT/
41
+
42
+
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('Revver4R', '0.1.0') do |p|
6
+ p.description = "A simple Ruby interface for Revver's api."
7
+ p.url = "http://github.com/chalkers/revver4r"
8
+ p.author = "Andrew Chalkley"
9
+ p.email = "andrew@chalkely.org"
10
+ p.ignore_pattern = ["tmp/*", "scripts/*"]
11
+ p.development_dependencies = ["hpricot"]
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
data/Revver4R.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{Revver4R}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Andrew Chalkley"]
9
+ s.date = %q{2008-11-24}
10
+ s.description = %q{A simple Ruby interface for Revver's api.}
11
+ s.email = %q{andrew@chalkely.org}
12
+ s.extra_rdoc_files = ["CHANGELOG", "lib/revver4r.rb", "README.rdoc"]
13
+ s.files = ["CHANGELOG", "init.rb", "lib/revver4r.rb", "Manifest", "Rakefile", "README.rdoc", "Revver4R.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/chalkers/revver4r}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Revver4R", "--main", "README.rdoc"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{revver4r}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{A simple Ruby interface for Revver's api.}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_development_dependency(%q<hpricot>, [">= 0"])
28
+ else
29
+ s.add_dependency(%q<hpricot>, [">= 0"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<hpricot>, [">= 0"])
33
+ end
34
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'Revver4R'
data/lib/revver4r.rb ADDED
@@ -0,0 +1,144 @@
1
+ # Revver4R - Revver for Ruby Library
2
+ # Author: Andrew Chalkley (andrew@chalkley.org)
3
+ # Copyright: 2008 Andrew Chalkley
4
+ # License: MIT
5
+ # http://creativecommons.org/licenses/MIT/
6
+
7
+ require 'rubygems'
8
+ require 'open-uri'
9
+ require 'hpricot'
10
+
11
+ #== About
12
+ #
13
+ # This is module for searching Revver and returning video information from it.
14
+ #
15
+ #== Usage Example
16
+ #
17
+ # Here's how to pull 1 quicktime video with the tag ruby
18
+ #
19
+ # require 'Revver4R'
20
+ # video_search = Revver4R::VideoSearch.new("qt","tag","ruby",{"limit" => 1})
21
+ # videos = video_search.search
22
+ # videos.each do |video|
23
+ # puts video.to_yaml
24
+ # end
25
+ #
26
+ # For more information at http://developer.revver.com/feeds/mrss
27
+ module Revver4R
28
+
29
+ POSSIBLE_MEDIA_TYPES = ["flash", "qt"]
30
+ POSSIBLE_CONTENTS = ["user","collection","search","tag","latest","full","top10","top20","offline"]
31
+ POSSIBLE_OPTIONS = ["affiliate","orderBy","order","offset","limit","minAgeRestriction","maxAgeRestriction"]
32
+
33
+ POSSIBLE_ORDER_BYS = ["publicationDate","modifiedDate","createdDate","title","author","views","duration","size"]
34
+ POSSIBLE_ORDERS = ["asc","desc"]
35
+ RESTRICTION_RANGE = (1..5)
36
+
37
+ # http://feeds.revver.com/2.0/mrss/MEDIA/FEEDCONTENTS/FEEDCRITERIA?OPTIONS
38
+ REVVER_RSS_START = "http://feeds.revver.com/2.0/mrss/"
39
+
40
+ class SearchBase
41
+
42
+ attr_accessor :media, :feed_contents, :criteria
43
+ def initialize(media="flash", feed_contents="tag", criteria="rails", options = {"affiliate" => "chalkers"})
44
+ if POSSIBLE_MEDIA_TYPES.include? media
45
+ @media = media
46
+ else
47
+ raise "Invalid 'media' type. Choose from " + POSSIBLE_MEDIA_TYPES.join[", "]
48
+ end
49
+
50
+ if POSSIBLE_CONTENTS.include? feed_contents
51
+ @feed_contents = feed_contents
52
+ else
53
+ raise "Invalid 'feed_content' type. Choose from " + POSSIBLE_CONTENTS.join[", "]
54
+ end
55
+
56
+ @criteria = criteria
57
+
58
+ options.delete("affiliate") if options["affiliate"] == ""
59
+ raise "Invalid 'offset' must be an Integer" if (options.has_key?"offset" && options["offset"].is_a?(Integer))
60
+ raise "Invalid 'order'. Choose from "+ POSSIBLE_ORDERS.join[", "] if (options.has_key?"order" && !POSSIBLE_ORDERS.include?(options["order"]))
61
+ raise "Invalid 'orderBy'. Choose from "+ POSSIBLE_ORDER_BYS.join[", "] if (options.has_key?"orderBy" && !POSSIBLE_ORDER_BYS.include?(options["order"]))
62
+
63
+ ["minAgeRestriction","maxAgeRestriction"].each do |restriction|
64
+ raise "Invalid '#{restriction}'. It must be between " + RESTRICTION_RANGE.first + " - " + RESTRICTION_RANGE.last if (options.has_key?restriction && !RESTRICTION_RANGE.include?(options[restriction]))
65
+ end
66
+
67
+ @options = options
68
+ end
69
+
70
+ def search
71
+ raise "'search' method not implemented"
72
+ end
73
+
74
+ private
75
+
76
+ def download_feed(url)
77
+ Hpricot.XML(open(url, { "User-Agent" => "Ruby/#{RUBY_VERSION} (Revver4R)" }))
78
+ end
79
+
80
+ def generate_url
81
+ options = []
82
+ @options.each do |k,v|
83
+ options << (k + "=" + v.to_s)
84
+ end
85
+ REVVER_RSS_START + [@media,@feed_contents,@criteria].join("/") + "?" + options.join("&")
86
+ end
87
+
88
+ end
89
+
90
+ class VideoSearch < SearchBase
91
+ def search
92
+ doc = download_feed(generate_url)
93
+ feed_to_videos(doc)
94
+ end
95
+ private
96
+ def feed_to_videos(doc)
97
+ videos = []
98
+ (doc/"item").each do |item|
99
+ videos << Video.new(item)
100
+ end
101
+ videos
102
+ end
103
+ end
104
+
105
+ class Video
106
+ attr_accessor :title, :description, :credit, :content, :categories, :thumbnail, :rating, :license, :revver_url
107
+ alias :user :credit
108
+ def initialize(item)
109
+ @title = (item/"media:title").first.to_plain_text
110
+ @description = (item/"media:description").first.to_plain_text
111
+ @credit = (item/"media:credit").first.to_plain_text
112
+ @categories = (item/"media:category").first.to_plain_text.split(" ")
113
+ content_node = (item/"media:content").first
114
+ @content = VideoContent.new( content_node.attributes["type"],
115
+ content_node.attributes["url"],
116
+ content_node.attributes["duration"].to_i)
117
+ thumnail_node = (item/"media:thumbnail").first
118
+ @thumbnail = Thumbnail.new( thumnail_node.attributes["url"],
119
+ thumnail_node.attributes["width"].to_i,
120
+ thumnail_node.attributes["height"].to_i)
121
+ @revver_url = (item/"media:player").first.attributes["url"]
122
+ @rating = (item/"media:rating").first.to_plain_text
123
+ @license = (item/"creativeCommons:license").first.to_plain_text
124
+ end
125
+ end
126
+
127
+ class VideoContent
128
+ attr_accessor :type, :url, :duration
129
+ def initialize(type, url, duration)
130
+ @type = type
131
+ @url = url
132
+ @duration = duration
133
+ end
134
+ end
135
+
136
+ class Thumbnail
137
+ attr_accessor :url, :width, :height
138
+ def initialize(url, width, height)
139
+ @url = url
140
+ @width = width
141
+ @height = height
142
+ end
143
+ end
144
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: chalkers-Revver4R
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Chalkley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-11-24 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hpricot
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ description: A simple Ruby interface for Revver's api.
25
+ email: andrew@chalkely.org
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - CHANGELOG
32
+ - lib/revver4r.rb
33
+ - README.rdoc
34
+ files:
35
+ - CHANGELOG
36
+ - init.rb
37
+ - lib/revver4r.rb
38
+ - Manifest
39
+ - Rakefile
40
+ - README.rdoc
41
+ - Revver4R.gemspec
42
+ has_rdoc: true
43
+ homepage: http://github.com/chalkers/revver4r
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --line-numbers
47
+ - --inline-source
48
+ - --title
49
+ - Revver4R
50
+ - --main
51
+ - README.rdoc
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "1.2"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project: revver4r
69
+ rubygems_version: 1.2.0
70
+ signing_key:
71
+ specification_version: 2
72
+ summary: A simple Ruby interface for Revver's api.
73
+ test_files: []
74
+