punndit_youtube 0.0.4 → 0.0.5

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.
@@ -33,7 +33,9 @@ module PunnditYoutube
33
33
  # PunnditYoutube::Model::Video
34
34
  #
35
35
  def single_video(videoID)
36
-
36
+ url = "/feeds/api/videos/#{videoID}?alt=json&v=2"
37
+ parser = PunnditYoutube::Parser::VideoFeedParser.new(url)
38
+ parser.parse
37
39
  end
38
40
  end
39
41
  end
@@ -14,16 +14,46 @@ module PunnditYoutube
14
14
  class VideoFeedParser < FeedParser #:nodoc:
15
15
  def parse_content(response)
16
16
  json_body = JSON.parse(response.body)
17
+ e = json_body['entry']
17
18
 
18
-
19
+ video = PunnditYoutube::Model::Video.new(
20
+ :id => e['media$group']['yt$videoid']['$t'],
21
+ :title => e['title']['$t'],
22
+ :description => e['media$group']['media$description']['$t'],
23
+ :comment_url => e['gd$comments']['gd$feedLink']['href'],
24
+ :video_url => e['media$group']['media$player']['url'],
25
+ #:keywords => e['mediage$group']['media$keywords']['$t'], if e['mediage$group']['media$keywords']['$t']
26
+ :thumbnails => e['media$group']['media$thumbnail'],
27
+ #:aspect_ratio => e['media$group']['yt$aspectRatio']['$t'], if e['media$group']['yt$aspectRatio']['$t']
28
+ :duration => e['media$group']['yt$duration']['seconds'],
29
+ :uploaded => e['media$group']['yt$uploaded']['$t'],
30
+ :uploader_id => e['media$group']['yt$uploaderId']['$t'],
31
+ :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']},
32
+ :updated_at => e['updated']['$t']
33
+ )
19
34
  end
20
35
  end
21
36
  # END VideoFeedParser
22
37
 
23
38
  class VideosFeedParser < FeedParser #:nodoc:
24
39
  def parse_content(response)
25
- json_body = JSON.parse(response.body)
26
-
40
+ e = JSON.parse(response.body)
41
+
42
+ video = PunnditYoutube::Model::Video.new(
43
+ :id => e['media$group']['yt$videoid']['$t'],
44
+ :title => e['title']['$t'],
45
+ :description => e['media$group']['media$description']['$t'],
46
+ :comment_url => e['gd$comments']['gd$feedLink']['href'],
47
+ :video_url => e['media$group']['media$player']['url'],
48
+ #:keywords => e['mediage$group']['media$keywords']['$t'], if e['mediage$group']['media$keywords']['$t']
49
+ :thumbnails => e['media$group']['media$thumbnail'],
50
+ #:aspect_ratio => e['media$group']['yt$aspectRatio']['$t'], if e['media$group']['yt$aspectRatio']['$t']
51
+ :duration => e['media$group']['yt$duration']['seconds'],
52
+ :uploaded => e['media$group']['yt$uploaded']['$t'],
53
+ :uploader_id => e['media$group']['yt$uploaderId']['$t'],
54
+ :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']},
55
+ :updated_at => e['updated']['$t']
56
+ )
27
57
  end
28
58
  end
29
59
  # END VideosFeedParser
@@ -1,3 +1,3 @@
1
1
  module PunnditYoutube
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -4,7 +4,7 @@ require File.expand_path('../lib/punndit_youtube/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["David Slone"]
6
6
  gem.email = ["dbslone@gmail.com"]
7
- gem.description = %q{simple_youtube is a Ruby client for parsing the YouTube API v2 using JSON objects. This is a lot cleaner and simpler method than trying to use the XML data provided. As the name implies this is for simple tasks involving YouTube like getting a Playlist, Channel, or single video information. This version does not currently support advances searches on the YouTube API.}
7
+ gem.description = %q{punndit_youtube is a Ruby client for parsing the YouTube API v2 using JSON objects. This is a lot cleaner and simpler method than trying to use the XML data provided. This is for simple tasks involving YouTube like getting a Playlist(s), Channel, or single video information. This version does not currently support advances searches on the YouTube API.}
8
8
  gem.summary = %q{Ruby client for the YouTube API v2}
9
9
  gem.homepage = "http://www.punndit.com"
10
10
 
@@ -0,0 +1,18 @@
1
+ require 'punndit_youtube'
2
+
3
+ class TestClient
4
+ def initialize
5
+ @client = PunnditYoutube::Client.new
6
+ end
7
+
8
+ def should_find_video videoID
9
+ client = PunnditYoutube::Client.new
10
+ client.single_video(videoID)
11
+ end
12
+
13
+ def should_find_playlist playlistID
14
+ client = PunnditYoutube::Client.new
15
+ client.playlist(playlistID)
16
+ end
17
+
18
+ end
@@ -1,6 +1,16 @@
1
- require 'punndit_youtube'
1
+ require 'spec_helper'
2
2
 
3
- describe PunnditYoutube::Model::Video do
4
- it "should have title"
3
+ describe PunnditYoutube do
4
+ it "should find video" do
5
+ client = TestClient.new
6
+ video = client.should_find_video("9OEYK60naug")
7
+ video.title.should_not be_empty
8
+ end
9
+
10
+ it "should find playlist" do
11
+ client = TestClient.new
12
+ playlist = client.should_find_playlist("PLA2F6CB53687F34AA")
13
+ playlist.title.should_not be_empty
14
+ end
5
15
 
6
16
  end
@@ -0,0 +1,11 @@
1
+ require 'rspec'
2
+ require 'punndit_youtube'
3
+ require 'punndit_helper'
4
+ require "net/http"
5
+ require "uri"
6
+ require "json"
7
+
8
+ RSpec.configure do |config|
9
+ config.color_enabled = true
10
+ config.formatter = 'documentation'
11
+ 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.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-28 00:00:00.000000000 Z
12
+ date: 2012-08-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -27,11 +27,11 @@ dependencies:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  version: '2.6'
30
- description: simple_youtube is a Ruby client for parsing the YouTube API v2 using
30
+ description: punndit_youtube is a Ruby client for parsing the YouTube API v2 using
31
31
  JSON objects. This is a lot cleaner and simpler method than trying to use the XML
32
- data provided. As the name implies this is for simple tasks involving YouTube like
33
- getting a Playlist, Channel, or single video information. This version does not
34
- currently support advances searches on the YouTube API.
32
+ data provided. This is for simple tasks involving YouTube like getting a Playlist(s),
33
+ Channel, or single video information. This version does not currently support advances
34
+ searches on the YouTube API.
35
35
  email:
36
36
  - dbslone@gmail.com
37
37
  executables: []
@@ -54,7 +54,9 @@ files:
54
54
  - lib/punndit_youtube/record.rb
55
55
  - lib/punndit_youtube/version.rb
56
56
  - punndit_youtube.gemspec
57
+ - spec/punndit_helper.rb
57
58
  - spec/punndit_youtube_spec.rb
59
+ - spec/spec_helper.rb
58
60
  homepage: http://www.punndit.com
59
61
  licenses: []
60
62
  post_install_message:
@@ -80,4 +82,6 @@ signing_key:
80
82
  specification_version: 3
81
83
  summary: Ruby client for the YouTube API v2
82
84
  test_files:
85
+ - spec/punndit_helper.rb
83
86
  - spec/punndit_youtube_spec.rb
87
+ - spec/spec_helper.rb