punndit_youtube 0.0.2 → 0.0.3

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/lib/.DS_Store ADDED
Binary file
Binary file
@@ -0,0 +1,39 @@
1
+ module PunnditYoutube
2
+ class Client
3
+
4
+ #
5
+ #
6
+ #
7
+ def get_playlists(username)
8
+
9
+ end
10
+
11
+ #
12
+ # Retrieves a single playlist
13
+ #
14
+ # === Parameters
15
+ # playlistID<String>:: The ID of the playlist that you'd like to retrieve.
16
+ #
17
+ # === Returns
18
+ # PunnditYoutube::Model::Playlist
19
+ #
20
+ def playlist(playlistID)
21
+ url = "/feeds/api/playlists/#{playlistID}?alt=json&v=2"
22
+ parser = PunnditYoutube::Parser::PlaylistFeedParser.new(url)
23
+ parser.parse
24
+ end
25
+
26
+ #
27
+ # Retrieves a single video
28
+ #
29
+ # === Parameters
30
+ # videoID<String>:: The ID of the video that you'd like to retrieve.
31
+ #
32
+ # === Returns
33
+ # PunnditYoutube::Model::Video
34
+ #
35
+ def single_video(videoID)
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,10 @@
1
+ module PunnditYoutube
2
+ class Model
3
+ class Playlist < PunnditYoutube::Record
4
+ attr_reader :title, :subtitle, :playlist_id, :author, :thumbnail, :updated_at, :videos
5
+ #def videos
6
+ #PunnditYoutube::Parser::VideosFeedParser.new("http://gdata.youtube.com/feeds/api/playlists/#{playlist_id}?v=2").parse
7
+ #end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module PunnditYoutube
2
+ class Model
3
+ class User < PunnditYoutube::Record
4
+ def playlists
5
+
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,47 @@
1
+ module PunnditYoutube
2
+ class Model
3
+ class Video < PunnditYoutube::Record
4
+ #TODO: Add support for categories
5
+
6
+ # Returns a string value for the ID of the video
7
+ attr_reader :id
8
+
9
+ # Returns a string value for the title of the video
10
+ attr_reader :title
11
+
12
+ # Returns a string value for the description of the video
13
+ attr_reader :description
14
+
15
+ # Returns a string containing the url for the API call to get all the comments for a video.
16
+ #TODO: Add a method that will parse and return a Comment object
17
+ attr_reader :comment_url
18
+
19
+ # Returns a string value of the url to view the video (For playlists this returns the video url and not the link to the playlist)
20
+ attr_reader :video_url
21
+
22
+ # Returns a comma seperated string of all keywords associated with the video
23
+ attr_reader :keywords
24
+
25
+ # Returns an array of arrays that contains all availiable thumbnails sizes for the video and their dimensions
26
+ attr_reader :thumbnails
27
+
28
+ # Returns a string value for the aspect ratio of the video ("standard", "widescreen")
29
+ attr_reader :aspect_ratio
30
+
31
+ # Returns the duration of the video in seconds
32
+ attr_reader :duration
33
+
34
+ # Returns the timestamp of when the video was uploaded to YouTube
35
+ attr_reader :uploaded
36
+
37
+ # Returns the YouTube User ID of the account that uploaded the video
38
+ attr_reader :uploader_id
39
+
40
+ # Returns a hash array {:favorites, :view_count, :likes, :dislikes, :average, :max, :min}
41
+ attr_reader :stats
42
+
43
+ # Returns the timestamp when the video was last updated
44
+ attr_reader :updated_at
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,78 @@
1
+ module PunnditYoutube
2
+ class Parser
3
+
4
+ class FeedParser #:nodoc:
5
+ def initialize(url)
6
+ @url = url
7
+ end
8
+
9
+ def parse
10
+ parse_content Net::HTTP.get_response("gdata.youtube.com", @url)
11
+ end
12
+ end
13
+
14
+ class VideoFeedParser < FeedParser #:nodoc:
15
+ def parse_content(response)
16
+ json_body = JSON.parse(response.body)
17
+
18
+
19
+ end
20
+ end
21
+ # END VideoFeedParser
22
+
23
+ class VideosFeedParser < FeedParser #:nodoc:
24
+ def parse_content(response)
25
+ json_body = JSON.parse(response.body)
26
+
27
+ end
28
+ end
29
+ # END VideosFeedParser
30
+
31
+ class PlaylistFeedParser < FeedParser #:nodoc:
32
+ def parse_content(response)
33
+ json_body = JSON.parse(response.body)
34
+
35
+ videos = []
36
+ json_body['feed']['entry'].each do |e|
37
+ video = PunnditYoutube::Model::Video.new(
38
+ :id => e['media$group']['yt$videoid']['$t'],
39
+ :title => e['title']['$t'],
40
+ :description => e['media$group']['media$description']['$t'],
41
+ :comment_url => e['gd$comments']['gd$feedLink']['href'],
42
+ :video_url => e['media$group']['media$player']['url'],
43
+ #:keywords => e['mediage$group']['media$keywords']['$t'], if e['mediage$group']['media$keywords']['$t']
44
+ :thumbnails => e['media$group']['media$thumbnail'],
45
+ #:aspect_ratio => e['media$group']['yt$aspectRatio']['$t'], if e['media$group']['yt$aspectRatio']['$t']
46
+ :duration => e['media$group']['yt$duration']['seconds'],
47
+ :uploaded => e['media$group']['yt$uploaded']['$t'],
48
+ :uploader_id => e['media$group']['yt$uploaderId']['$t'],
49
+ :stats => {:favorites => e['yt$statistics']['favoriteCount'], :view_count => e['yt$statistics']['viewCount'], :likes => e['yt$rating']['numLikes'], :dislikes => e['yt$rating']['numDislikes'], :average => e['gd$rating']['average'], :max => e['gd$rating']['max'], :min => e['gd$rating']['min'], :numRaters => e['gd$rating']['numRaters'], :rel => e['gd$rating']['rel']},
50
+ :updated_at => e['updated']['$t']
51
+ )
52
+ videos.push(video)
53
+ end
54
+
55
+ playlist = PunnditYoutube::Model::Playlist.new(
56
+ :playlist_id => json_body['feed']['yt$playlistId']['$t'],
57
+ :title => json_body['feed']['title']['$t'],
58
+ :subtitle => json_body['feed']['subtitle']['$t'],
59
+ :author => json_body['feed']['author'][0]['$t'],
60
+ :thumbnail => json_body['feed']['media$group']['media$thumbnail'][2]['url'],
61
+ :updated_at => json_body['feed']['updated']['$t'],
62
+ :videos => videos
63
+ )
64
+ end
65
+ end
66
+ # END PlaylistFeedParser
67
+
68
+ class ChannelFeedParser < FeedParser #:nodoc:
69
+ def parse_content(url)
70
+ response = Net::HTTP.get_response("gdata.youtube.com", url)
71
+ json_body = JSON.parse(response.body)
72
+
73
+
74
+ end
75
+ end
76
+ # END ChannelFeedParser
77
+ end
78
+ end
@@ -0,0 +1,12 @@
1
+ module PunnditYoutube
2
+ class Record #:nodoc:
3
+ def initialize (params)
4
+ return if params.nil?
5
+
6
+ params.each do |key, value|
7
+ name = key.to_s
8
+ instance_variable_set("@#{name}", value) if respond_to?(name)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module PunnditYoutube
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require "punndit_youtube/version"
2
+ require "punndit_youtube/record"
2
3
  require "punndit_youtube/model/playlist"
3
4
  require "punndit_youtube/model/video"
4
5
  require "punndit_youtube/model/user"
@@ -14,4 +14,6 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "punndit_youtube"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = PunnditYoutube::VERSION
17
+
18
+ gem.add_development_dependency "rspec", "~> 2.6"
17
19
  end
@@ -0,0 +1,6 @@
1
+ require 'punndit_youtube'
2
+
3
+ describe PunnditYoutube::Model::Video do
4
+ it "should have title"
5
+
6
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: punndit_youtube
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,23 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-08-28 00:00:00.000000000 Z
13
- dependencies: []
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.6'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.6'
14
30
  description: simple_youtube is a Ruby client for parsing the YouTube API v2 using
15
31
  JSON objects. This is a lot cleaner and simpler method than trying to use the XML
16
32
  data provided. As the name implies this is for simple tasks involving YouTube like
@@ -27,9 +43,18 @@ files:
27
43
  - LICENSE
28
44
  - README.md
29
45
  - Rakefile
46
+ - lib/.DS_Store
30
47
  - lib/punndit_youtube.rb
48
+ - lib/punndit_youtube/.DS_Store
49
+ - lib/punndit_youtube/client.rb
50
+ - lib/punndit_youtube/model/playlist.rb
51
+ - lib/punndit_youtube/model/user.rb
52
+ - lib/punndit_youtube/model/video.rb
53
+ - lib/punndit_youtube/parser.rb
54
+ - lib/punndit_youtube/record.rb
31
55
  - lib/punndit_youtube/version.rb
32
56
  - punndit_youtube.gemspec
57
+ - spec/punndit_youtube_spec.rb
33
58
  homepage: http://www.punndit.com
34
59
  licenses: []
35
60
  post_install_message:
@@ -54,4 +79,5 @@ rubygems_version: 1.8.24
54
79
  signing_key:
55
80
  specification_version: 3
56
81
  summary: Ruby client for the YouTube API v2
57
- test_files: []
82
+ test_files:
83
+ - spec/punndit_youtube_spec.rb