muri 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -16,6 +16,8 @@ MURI Currently supports:
16
16
  ** "API documentation":http://twitpic.com/api.do
17
17
  * Facebook (photos and albums)
18
18
  ** "API documentation":http://wiki.developers.facebook.com/index.php/API
19
+ * Picasa (photos)
20
+ ** "API documentation":http://code.google.com/apis/picasaweb/docs/2.0/developers_guide.html
19
21
 
20
22
  h3. Installation & basic usage
21
23
 
@@ -43,7 +45,6 @@ Assuming the URI was successfully parsed (thus @a.valid? == true@), all media ty
43
45
  <code>
44
46
  a.media_service # 'Youtube'
45
47
  a.media_id # 'blahblahblah'
46
- a.media_original_url # 'http://www.youtube.com/watch?v=blahblahblah&feature=rec-LGOUT-exp_fresh+div-1r-1-HM'
47
48
  a.media_uri # URI object for 'http://www.youtube.com/watch?v=blahblahblah&feature=rec-LGOUT-exp_fresh+div-1r-1-HM'
48
49
  </code>
49
50
  </pre>
@@ -58,9 +59,12 @@ Assuming the URI was successfully parsed (thus @a.valid? == true@), all media ty
58
59
  </code>
59
60
  </pre>
60
61
 
62
+ * Services with a @media_api_id@ also have a @media_api_type@, which indicates what sort of API call should be made (be it 'photo', 'video', 'media', 'set', 'album', or 'playlist', depending on URI type)
63
+
64
+
61
65
  *NOTE: Facebook photos return a @media_api_id@ which can be used to search for photo information in a Facebook photos.get API call as the pid. This pid is NOT the same as the pid found in the query string (the @media_id@)*
62
66
 
63
- * Services with a @media_api_id@ also have a @media_api_type@, which indicates what sort of API call should be made (be it 'photo', 'video', 'media', 'set', 'album', or 'playlist', depending on URI type)
67
+ *ALSO NOTE: Picasa @media_api_id@ is a partial string for using the photo API call, so for example @'bananastalktome/album/TestForAPI/photoid/5450524726782297346'@, thus the API call would be @"http://picasaweb.google.com/data/feed/api/user/#{media_api_id}"@*
64
68
 
65
69
 
66
70
  * A direct media url for Youtube, Photobucket (photos, not albums), Twitpic, Imageshack (@http://img#{num}.imageshack.us/img#{num}/#{NUMBER}/#{IMAGENAME}@ format) and flickr (@http://farm#{num}.static.flickr.com/@ format)
@@ -72,7 +76,7 @@ d
72
76
  </code>
73
77
  </pre>
74
78
 
75
- * A media landing website url for Facebook, Youtube, Photobucket, Imageshack, Vimeo, Twitpic, and Flickr (flickr returns the @http://flic.kr/p/#{ID}@ short url)
79
+ * A media landing website url for Facebook, Picasa, Youtube, Photobucket, Imageshack, Vimeo, Twitpic, and Flickr (flickr returns the @http://flic.kr/p/#{ID}@ short url)
76
80
 
77
81
  <pre>
78
82
  <code>
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
- :minor: 0
3
+ :minor: 1
4
4
  :patch: 0
data/lib/muri/base.rb CHANGED
@@ -12,12 +12,14 @@ class Muri
12
12
  PARSERS = { }
13
13
 
14
14
  # Defines is_#{service}? and is_#{service type constant}? methods, and sets service name constnat
15
- ['Youtube', 'Flickr', 'Vimeo', 'Imageshack', 'Photobucket', 'Facebook', 'Twitpic'].each do |filter|
15
+ ['Youtube', 'Flickr', 'Vimeo', 'Imageshack', 'Photobucket', 'Facebook', 'Twitpic', 'Picasa'].each do |filter|
16
16
  eval "include Filter::#{filter}"
17
17
  is_service = "is_#{filter.downcase}?"
18
18
  define_method(is_service) { self.media_service == filter }
19
19
  self.constants.reject { |c| c !~ /^#{filter.upcase}/ }.each do |exp|
20
- define_method("is_#{exp.downcase}?") { self.media_api_type == eval(exp) && eval("self.#{is_service}") }
20
+ define_method("is_#{exp.downcase}?") do
21
+ self.media_api_type == eval(exp) && self.instance_eval(is_service)
22
+ end
21
23
  end
22
24
  const_set "#{filter.upcase}_SERVICE_NAME", "#{filter}"
23
25
  end
@@ -0,0 +1,42 @@
1
+ class Muri
2
+ module Filter
3
+ module Picasa
4
+
5
+ private
6
+ PICASA_PHOTO = 'photo'
7
+
8
+ def self.included(base)
9
+ base.class_eval do
10
+ self::PARSERS[Muri::Filter::Picasa] = "picasa_parse"
11
+ end
12
+ end
13
+
14
+ def self.parsable?(uri)
15
+ uri.host =~ /^(www\.)?picasaweb\.google\.com$/i
16
+ end
17
+
18
+ def picasa_parse
19
+ self.media_service = PICASA_SERVICE_NAME
20
+ url_common = "http://picasaweb.google.com"
21
+ reencoded_url = URI.parse(URI.encode self.uri.to_s)
22
+
23
+ if reencoded_url.path =~ /^\/(.[^\/]+)\/(.+)/i
24
+ username = $1
25
+ album_photoid = $2.split("%23")
26
+ photoid = album_photoid.last
27
+ album = album_photoid[0..-2].join("#")#in case other hash symbols exist
28
+ self.media_id = photoid
29
+ self.media_website = "#{url_common}/#{username}/#{album}##{photoid}"
30
+ self.media_api_type = PICASA_PHOTO
31
+ self.media_api_id = "#{username}/album/#{album}/photoid/#{photoid}"
32
+ else
33
+ raise UnsupportedURI
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+ end
40
+ # http://picasaweb.google.com/bananastalktome/TestForAPI#5450524726782297346
41
+ # API Call: http://picasaweb.google.com/data/feed/api/user/bananastalktome/album/TestForAPI/photoid/5450524726782297346
42
+ # #=%23
data/muri.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{muri}
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["William Schneider"]
12
- s.date = %q{2010-03-28}
12
+ s.date = %q{2010-04-01}
13
13
  s.description = %q{Automatically get media information from the URL.}
14
14
  s.email = %q{bananastalktome@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  "lib/muri/filters/flickr.rb",
28
28
  "lib/muri/filters/imageshack.rb",
29
29
  "lib/muri/filters/photobucket.rb",
30
+ "lib/muri/filters/picasa.rb",
30
31
  "lib/muri/filters/twitpic.rb",
31
32
  "lib/muri/filters/vimeo.rb",
32
33
  "lib/muri/filters/youtube.rb",
@@ -36,6 +37,7 @@ Gem::Specification.new do |s|
36
37
  "test/flickr_test.rb",
37
38
  "test/imageshack_test.rb",
38
39
  "test/photobucket_test.rb",
40
+ "test/picasa_test.rb",
39
41
  "test/twitpic_test.rb",
40
42
  "test/vimeo_test.rb",
41
43
  "test/youtube_test.rb"
@@ -50,6 +52,7 @@ Gem::Specification.new do |s|
50
52
  "test/twitpic_test.rb",
51
53
  "test/photobucket_test.rb",
52
54
  "test/vimeo_test.rb",
55
+ "test/picasa_test.rb",
53
56
  "test/imageshack_test.rb",
54
57
  "test/error_test.rb",
55
58
  "test/flickr_test.rb",
@@ -2,9 +2,17 @@ require 'lib/muri.rb'
2
2
 
3
3
  shared_examples_for "Facebook parse" do
4
4
  it "should be Facebook service" do
5
- @a.media_service.should == 'Facebook'
5
+ #@a.media_service.should == 'Facebook'
6
+ @a.is_facebook?.should == true
6
7
  end
7
-
8
+
9
+ it "should be not be other services" do
10
+ #@a.media_service.should == 'Facebook'
11
+ @a.is_vimeo?.should == false
12
+ @a.is_flickr?.should == false
13
+ @a.is_youtube?.should == false
14
+ end
15
+
8
16
  it "should be valid" do
9
17
  @a.valid?.should == true
10
18
  end
@@ -15,6 +23,14 @@ shared_examples_for "Facebook parse photo" do
15
23
  it "should have media api type = FACEBOOK_PHOTO" do
16
24
  @a.media_api_type.should == Muri::FACEBOOK_PHOTO
17
25
  end
26
+
27
+ it "should be facebook photo" do
28
+ @a.is_facebook_photo?.should == true
29
+ end
30
+
31
+ it "should not be flickr photo" do
32
+ @a.is_flickr_photo?.should == false
33
+ end
18
34
  end
19
35
 
20
36
  {'http://www.facebook.com/photo.php?pid=34929102&l=a1abf8cd37&id=15201063' =>
data/test/flickr_test.rb CHANGED
@@ -1,8 +1,17 @@
1
1
  require 'lib/muri.rb'
2
2
  shared_examples_for "Flickr parse" do
3
3
  it "should be Flickr service" do
4
- @a.media_service.should == 'Flickr'
4
+ # @a.media_service.should == 'Flickr'
5
+ @a.is_flickr?.should == true
5
6
  end
7
+
8
+ it "should be not be other services" do
9
+ @a.is_vimeo?.should == false
10
+ @a.is_youtube?.should == false
11
+ @a.is_facebook?.should == false
12
+ @a.is_photobucket?.should == false
13
+ end
14
+
6
15
  it "should be valid" do
7
16
  @a.valid?.should == true
8
17
  end
@@ -12,13 +21,25 @@ shared_examples_for "Flickr parse photo" do
12
21
  it_should_behave_like "Flickr parse"
13
22
  it "should have media api type = FLICKR_PHOTO" do
14
23
  @a.media_api_type.should == Muri::FLICKR_PHOTO
15
- end
24
+ end
25
+
26
+ it "should be flickr photo" do
27
+ @a.is_flickr_photo?.should == true
28
+ end
29
+
30
+ it "should not be facebook photo" do
31
+ @a.is_facebook_photo?.should == false
32
+ end
16
33
  end
17
34
 
18
35
  shared_examples_for "Flickr parse set" do
19
36
  it_should_behave_like "Flickr parse"
20
37
  it "should have media api type = FLICKR_SET" do
21
38
  @a.media_api_type.should == Muri::FLICKR_SET
39
+ end
40
+
41
+ it "should be flickr set" do
42
+ @a.is_flickr_set?.should == true
22
43
  end
23
44
  end
24
45
 
@@ -2,8 +2,17 @@ require 'lib/muri.rb'
2
2
 
3
3
  shared_examples_for "Imageshack parse" do
4
4
  it "should be Imageshack service" do
5
- @a.media_service.should == 'Imageshack'
5
+ #@a.media_service.should == 'Imageshack'
6
+ @a.is_imageshack?.should == true
6
7
  end
8
+
9
+ it "should be not be other services" do
10
+ @a.is_vimeo?.should == false
11
+ @a.is_youtube?.should == false
12
+ @a.is_facebook?.should == false
13
+ @a.is_photobucket?.should == false
14
+ end
15
+
7
16
  it "should be valid" do
8
17
  @a.valid?.should == true
9
18
  end
@@ -2,9 +2,17 @@ require 'lib/muri.rb'
2
2
 
3
3
  shared_examples_for "Photobucket parse" do
4
4
  it "should be Photobucket service" do
5
- @a.media_service.should == 'Photobucket'
5
+ #@a.media_service.should == 'Photobucket'
6
+ @a.is_photobucket?.should == true
6
7
  end
7
8
 
9
+ it "should be not be other services" do
10
+ @a.is_vimeo?.should == false
11
+ @a.is_youtube?.should == false
12
+ @a.is_facebook?.should == false
13
+ @a.is_flickr?.should == false
14
+ end
15
+
8
16
  it "should be valid" do
9
17
  @a.valid?.should == true
10
18
  end
@@ -16,6 +24,10 @@ shared_examples_for "Photobucket parse photo" do
16
24
  it "should have media api type = PHOTOBUCKET_MEDIA" do
17
25
  @a.media_api_type.should == Muri::PHOTOBUCKET_MEDIA
18
26
  end
27
+
28
+ it "should be photobucket media" do
29
+ @a.is_photobucket_media?.should == true
30
+ end
19
31
  end
20
32
 
21
33
  shared_examples_for "Photobucket parse album" do
@@ -24,6 +36,14 @@ shared_examples_for "Photobucket parse album" do
24
36
  it "should have media api type = PHOTOBUCKET_ALBUM" do
25
37
  @a.media_api_type.should == Muri::PHOTOBUCKET_ALBUM
26
38
  end
39
+
40
+ it "should be photobucket album" do
41
+ @a.is_photobucket_album?.should == true
42
+ end
43
+
44
+ it "should not be facebook album" do
45
+ @a.is_facebook_album?.should == false
46
+ end
27
47
  end
28
48
  shared_examples_for "Photobucket parse group album" do
29
49
  it_should_behave_like "Photobucket parse"
@@ -31,6 +51,10 @@ shared_examples_for "Photobucket parse group album" do
31
51
  it "should have media api type = PHOTOBUCKET_GROUP_ALBUM" do
32
52
  @a.media_api_type.should == Muri::PHOTOBUCKET_GROUP_ALBUM
33
53
  end
54
+
55
+ it "should be group album" do
56
+ @a.is_photobucket_group_album?.should == true
57
+ end
34
58
  end
35
59
 
36
60
  {'http://gs0001.photobucket.com/groups/0001/F9P8EG7YR8/' =>
@@ -0,0 +1,71 @@
1
+ require 'lib/muri.rb'
2
+ shared_examples_for "Picasa parse" do
3
+ it "should be Picasa service" do
4
+ @a.is_picasa?.should == true
5
+ end
6
+
7
+ it "should be not be other services" do
8
+ @a.is_vimeo?.should == false
9
+ @a.is_youtube?.should == false
10
+ @a.is_facebook?.should == false
11
+ @a.is_photobucket?.should == false
12
+ end
13
+
14
+ it "should be valid" do
15
+ @a.valid?.should == true
16
+ end
17
+ end
18
+
19
+ shared_examples_for "Picasa parse photo" do
20
+ it_should_behave_like "Picasa parse"
21
+ it "should have media api type = PICASA_PHOTO" do
22
+ @a.media_api_type.should == Muri::PICASA_PHOTO
23
+ end
24
+
25
+ it "should be picasa photo" do
26
+ @a.is_picasa_photo?.should == true
27
+ end
28
+
29
+ it "should not be facebook photo" do
30
+ @a.is_facebook_photo?.should == false
31
+ end
32
+ end
33
+
34
+ {'http://picasaweb.google.com/bananastalktome/TestForAPI#5450524726782297346' =>
35
+ { :media_id => '5450524726782297346',
36
+ :media_website => 'http://picasaweb.google.com/bananastalktome/TestForAPI#5450524726782297346',
37
+ :media_api_id => 'bananastalktome/album/TestForAPI/photoid/5450524726782297346'
38
+ }
39
+ }.each do |url, values|
40
+
41
+ describe "Picasa parse #{values[:type]} #{url}" do
42
+ before(:all) do
43
+ @a = Muri.parse url
44
+ end
45
+ it_should_behave_like "Picasa parse photo"
46
+
47
+ if values[:media_id]
48
+ it "should have media id" do
49
+ @a.media_id.should == values[:media_id]
50
+ end
51
+ end
52
+
53
+ if values[:media_website]
54
+ it "should have a website" do
55
+ @a.media_website.should == values[:media_website]
56
+ end
57
+ end
58
+
59
+ if values[:media_api_id]
60
+ it "should have media api id" do
61
+ @a.media_api_id.should == values[:media_api_id]
62
+ end
63
+ end
64
+
65
+ if values[:media_thumbnail]
66
+ it "should have media thumbnail" do
67
+ @a.media_thumbnail.should == values[:media_thumbnail]
68
+ end
69
+ end
70
+ end
71
+ end
data/test/twitpic_test.rb CHANGED
@@ -1,8 +1,17 @@
1
1
  require 'lib/muri.rb'
2
2
  shared_examples_for "Twitpic parse" do
3
3
  it "should be Twitpic service" do
4
- @a.media_service.should == 'Twitpic'
4
+ #@a.media_service.should == 'Twitpic'
5
+ @a.is_twitpic?.should == true
5
6
  end
7
+
8
+ it "should be not be other services" do
9
+ @a.is_vimeo?.should == false
10
+ @a.is_youtube?.should == false
11
+ @a.is_facebook?.should == false
12
+ @a.is_flickr?.should == false
13
+ end
14
+
6
15
  it "should be valid" do
7
16
  @a.valid?.should == true
8
17
  end
@@ -12,7 +21,15 @@ shared_examples_for "Twitpic parse photo" do
12
21
  it_should_behave_like "Twitpic parse"
13
22
  it "should have media api type = TWITPIC_PHOTO" do
14
23
  @a.media_api_type.should == Muri::TWITPIC_PHOTO
24
+ end
25
+
26
+ it "should be twitpic photo" do
27
+ @a.is_twitpic_photo?.should == true
15
28
  end
29
+
30
+ it "should not be facebook photo" do
31
+ @a.is_facebook_photo?.should == false
32
+ end
16
33
  end
17
34
  {'http://twitpic.com/17d7th' =>
18
35
  { :media_id => '17d7th',
data/test/vimeo_test.rb CHANGED
@@ -2,9 +2,17 @@ require 'lib/muri.rb'
2
2
 
3
3
  shared_examples_for "Vimeo parse" do
4
4
  it "should be Vimeo service" do
5
- @a.media_service.should == 'Vimeo'
5
+ #@a.media_service.should == 'Vimeo'
6
+ @a.is_vimeo?.should == true
6
7
  end
7
8
 
9
+ it "should be not be other services" do
10
+ @a.is_photobucket?.should == false
11
+ @a.is_youtube?.should == false
12
+ @a.is_facebook?.should == false
13
+ @a.is_flickr?.should == false
14
+ end
15
+
8
16
  it "should be valid" do
9
17
  @a.valid?.should == true
10
18
  end
@@ -17,6 +25,14 @@ shared_examples_for "Vimeo parse video" do
17
25
  it "should have media api type = VIMEO_VIDEO" do
18
26
  @a.media_api_type.should == Muri::VIMEO_VIDEO
19
27
  end
28
+
29
+ it "should be vimeo video" do
30
+ @a.is_vimeo_video?.should == true
31
+ end
32
+
33
+ it "should not be youtube video" do
34
+ @a.is_youtube_video?.should == false
35
+ end
20
36
  end
21
37
  shared_examples_for "Vimeo parse album" do
22
38
  it_should_behave_like "Vimeo parse"
@@ -24,6 +40,14 @@ shared_examples_for "Vimeo parse album" do
24
40
  it "should have media api type = VIMEO_ALBUM" do
25
41
  @a.media_api_type.should == Muri::VIMEO_ALBUM
26
42
  end
43
+
44
+ it "should be vimeo album" do
45
+ @a.is_vimeo_album?.should == true
46
+ end
47
+
48
+ it "should not be photobucket album" do
49
+ @a.is_photobucket_album?.should == false
50
+ end
27
51
  end
28
52
 
29
53
  {'http://vimeo.com/moogaloop.swf?clip_id=7312128&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1' =>
data/test/youtube_test.rb CHANGED
@@ -1,9 +1,17 @@
1
1
  require 'lib/muri.rb'
2
2
  shared_examples_for "Youtube parse" do
3
3
  it "should be Youtube service" do
4
- @a.media_service.should == 'Youtube'
4
+ #@a.media_service.should == 'Youtube'
5
+ @a.is_youtube?.should == true
5
6
  end
6
7
 
8
+ it "should be not be other services" do
9
+ @a.is_photobucket?.should == false
10
+ @a.is_vimeo?.should == false
11
+ @a.is_facebook?.should == false
12
+ @a.is_flickr?.should == false
13
+ end
14
+
7
15
  it "should be valid" do
8
16
  @a.valid?.should == true
9
17
  end
@@ -15,6 +23,14 @@ shared_examples_for "Youtube parse single" do
15
23
  it "should have media api type = YOUTUBE_VIDEO" do
16
24
  @a.media_api_type.should == Muri::YOUTUBE_VIDEO
17
25
  end
26
+
27
+ it "should be youtube video" do
28
+ @a.is_youtube_video?.should == true
29
+ end
30
+
31
+ it "should not be vimeo video" do
32
+ @a.is_vimeo_video?.should == false
33
+ end
18
34
  end
19
35
 
20
36
  shared_examples_for "Youtube parse playlist" do
@@ -22,7 +38,11 @@ shared_examples_for "Youtube parse playlist" do
22
38
 
23
39
  it "should have media api type = YOUTUBE_PLAYLIST" do
24
40
  @a.media_api_type.should == Muri::YOUTUBE_PLAYLIST
25
- end
41
+ end
42
+
43
+ it "should be youtube playlist" do
44
+ @a.is_youtube_playlist?.should == true
45
+ end
26
46
  end
27
47
 
28
48
  {'http://www.youtube.com/v/4CYDFoEz8rg&hl=en_US&fs=1&' =>
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
+ - 1
7
8
  - 0
8
- - 0
9
- version: 1.0.0
9
+ version: 1.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - William Schneider
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-28 00:00:00 -04:00
17
+ date: 2010-04-01 00:00:00 -04:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -38,6 +38,7 @@ files:
38
38
  - lib/muri/filters/flickr.rb
39
39
  - lib/muri/filters/imageshack.rb
40
40
  - lib/muri/filters/photobucket.rb
41
+ - lib/muri/filters/picasa.rb
41
42
  - lib/muri/filters/twitpic.rb
42
43
  - lib/muri/filters/vimeo.rb
43
44
  - lib/muri/filters/youtube.rb
@@ -47,6 +48,7 @@ files:
47
48
  - test/flickr_test.rb
48
49
  - test/imageshack_test.rb
49
50
  - test/photobucket_test.rb
51
+ - test/picasa_test.rb
50
52
  - test/twitpic_test.rb
51
53
  - test/vimeo_test.rb
52
54
  - test/youtube_test.rb
@@ -85,6 +87,7 @@ test_files:
85
87
  - test/twitpic_test.rb
86
88
  - test/photobucket_test.rb
87
89
  - test/vimeo_test.rb
90
+ - test/picasa_test.rb
88
91
  - test/imageshack_test.rb
89
92
  - test/error_test.rb
90
93
  - test/flickr_test.rb