-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
220 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.svn |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
require 'open-uri' | ||
require 'hpricot' | ||
require File.join(File.dirname(__FILE__), 'lib', 'youtube_client') | ||
require File.join(File.dirname(__FILE__), 'lib', 'youtube_client') | ||
require File.join(File.dirname(__FILE__), 'lib', 'flickr_client') | ||
require File.join(File.dirname(__FILE__), 'lib', 'twitter_client') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Flickr | ||
|
||
class Client | ||
|
||
BASE_URL = "http://api.flickr.com/services/rest" | ||
DEFAULT_PARAMS = { :api_key => "", :format => "rest" } | ||
FEED_URLS = { | ||
:list_photosets => "#{BASE_URL}?method=flickr.photosets.getList&%s" | ||
} | ||
|
||
def self.photosets(options = {}) | ||
options = DEFAULT_PARAMS.merge(options) | ||
feed = open(format("#{FEED_URLS[:list_photosets]}", options.to_param)).read | ||
Flickr::Parser.parse_photosets(feed, options[:user_id]) | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Flickr | ||
|
||
class Parser | ||
|
||
def self.parse_photosets(feed, user_id) | ||
res = [] | ||
doc = Hpricot(feed) | ||
(doc/"photoset").each do |set| | ||
res << parse_photoset(set, user_id) | ||
end | ||
return res | ||
end | ||
|
||
def self.parse_photoset(elem, user_id) | ||
set = PhotoSet.new(user_id) | ||
set.id = elem.attributes['id'] | ||
set.photos = elem.attributes['photos'] | ||
set.videos = elem.attributes['videos'] | ||
set.primary = elem.attributes['primary'] | ||
set.farm = elem.attributes['farm'] | ||
set.secret = elem.attributes['secret'] | ||
set.server = elem.attributes['server'] | ||
set.description = elem.at('description').inner_html | ||
set.title = elem.at('title').inner_html | ||
return set | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Flickr | ||
|
||
class PhotoSet | ||
attr_accessor :id, :photos, :videos, :title, :description | ||
attr_accessor :server, :farm, :secret, :primary, :user_id | ||
|
||
def initialize(user_id) | ||
self.user_id = user_id | ||
end | ||
|
||
def image_url(type = :small) | ||
t = case type | ||
when :thumbnail then "t" | ||
when :small then "s" | ||
when :medium then "m" | ||
when :large then "b" | ||
when :original then "o" | ||
else "s" | ||
end | ||
return "http://farm#{farm}.static.flickr.com/#{server}/#{primary}_#{secret}_#{t}.jpg" | ||
end | ||
|
||
def url | ||
"http://www.flickr.com/photos/#{user_id}/sets/#{id}" | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Dir.glob(File.join(File.dirname(__FILE__), 'flickr', '*.rb')).each do |file| | ||
require file | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Twitter | ||
|
||
class Client | ||
|
||
BASE_URL = "https://twitter.com/" | ||
DEFAULT_PARAMS = { :count => 9, :format => "xml" } | ||
FEED_URLS = { | ||
:user_timeline => "#{BASE_URL}statuses/user_timeline/%s.%s?%s" | ||
} | ||
|
||
def self.user_timeline(user_id, options = {}) | ||
options = DEFAULT_PARAMS.merge(options) | ||
feed = open(format(FEED_URLS[:user_timeline], user_id, options.delete(:format), options.to_param)).read | ||
Twitter::Parser.parse_statuses(feed) | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Twitter | ||
|
||
class Parser | ||
|
||
def self.parse_statuses(feed) | ||
res = [] | ||
doc = Hpricot(feed) | ||
(doc/"status").each do |entry| | ||
res << parse_status(entry) | ||
end | ||
return res | ||
end | ||
|
||
def self.parse_status(entry) | ||
tweet = Tweet.new | ||
tweet.text = entry.at('text').inner_html | ||
tweet.created_at = Time.zone.parse(entry.at('created_at').inner_html) | ||
tweet.source = entry.at('source').inner_html | ||
tweet.id = entry.at('id').inner_html | ||
tweet.user_id = entry.at('user id').inner_html | ||
tweet.user_image_url = entry.at('user profile_image_url').inner_html | ||
return tweet | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Twitter | ||
|
||
class Tweet | ||
|
||
attr_accessor :id, :text, :source, :created_at, :user_id, :user_image_url | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Dir.glob(File.join(File.dirname(__FILE__), 'twitter', '*.rb')).each do |file| | ||
require file | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module YouTube | ||
|
||
class Client | ||
|
||
BASE_URL = "http://gdata.youtube.com/feeds/api/" | ||
DEFAULT_PARAMS = { "v" => 2, "max-results" => 5, "format" => 5 } | ||
FEED_URLS = { | ||
:user_uploads => "#{BASE_URL}users/%s/uploads?%s" | ||
} | ||
|
||
def self.user_uploads(user, options = {}) | ||
options = DEFAULT_PARAMS.merge(options) | ||
feed = open(format(FEED_URLS[:user_uploads], user, options.to_param)).read | ||
YouTube::Parser.parse(feed) | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module YouTube | ||
|
||
class Parser | ||
|
||
def self.parse(feed) | ||
res = [] | ||
doc = Hpricot(feed) | ||
(doc/"entry").each do |entry| | ||
res << parse_entry(entry) | ||
end | ||
return res | ||
end | ||
|
||
def self.parse_entry(entry) | ||
video = Video.new | ||
video.id = entry.at("media:group yt:videoid").inner_html | ||
video.title = entry.at("title").inner_html | ||
video.published = Time.zone.parse(entry.at("published").inner_html) | ||
video.updated = Time.zone.parse(entry.at("updated").inner_html) | ||
video.uploaded = Time.zone.parse(entry.at("media:group yt:uploaded").inner_html) | ||
video.author = entry.at("author name").inner_html | ||
video.description = entry.at("media:group media:description").inner_html | ||
video.link = entry.at("media:group media:player").attributes['url'] | ||
video.thumbnail = entry.at("media:group media:thumbnail").attributes['url'] | ||
video.rating = entry.at("gd:rating").attributes | ||
video.keywords = entry.at("media:group media:keywords").inner_html.split(',') | ||
video.duration = entry.at("media:group yt:duration").attributes['seconds'].to_i | ||
return video | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module YouTube | ||
|
||
class Video | ||
attr_accessor :id, :title, :author, :description, :link, :thumbnail | ||
attr_accessor :published, :updated, :uploaded, :rating, :keywords, :duration | ||
|
||
def embed(options = {}) | ||
options[:width] ||= 480 | ||
options[:height] ||= 295 | ||
options[:hl] ||= 'de' | ||
return <<-HTML | ||
<object width="#{options[:width]}" height="#{options[:height]}"> | ||
<param name="movie" value="http://www.youtube.com/v/#{id}&hl=#{options[:hl]}&fs=1&rel=0"></param> | ||
<param name="allowFullScreen" value="true"></param> | ||
<param name="allowscriptaccess" value="always"></param> | ||
<embed src="http://www.youtube.com/v/#{id}&hl=#{options[:hl]}&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="#{options[:width]}" height="#{options[:height]}"> | ||
</embed> | ||
</object> | ||
HTML | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,3 @@ | ||
module YouTube | ||
|
||
class Client | ||
|
||
OPEN_URI_OPTIONS = { | ||
:proxy => nil | ||
} | ||
|
||
FEED_OPTIONS = { | ||
"v" => 2, | ||
"max-results" => 5, | ||
"format" => 5 | ||
} | ||
|
||
FEED_URLS = { | ||
:user_uploads => "http://gdata.youtube.com/feeds/api/users/%s/uploads?%s" | ||
} | ||
|
||
def self.user_uploads(user, options = {}) | ||
options = FEED_OPTIONS.merge(options) | ||
feed = open(format(FEED_URLS[:user_uploads], user, options.to_param), OPEN_URI_OPTIONS).read | ||
YouTube::Parser.parse(feed) | ||
end | ||
|
||
end | ||
|
||
class Video | ||
attr_accessor :id, :title, :author, :description, :link, :thumbnail | ||
attr_accessor :published, :updated, :uploaded, :rating, :keywords, :duration | ||
|
||
def embed(options = {}) | ||
options[:width] ||= 480 | ||
options[:height] ||= 295 | ||
options[:hl] ||= 'de' | ||
return <<-HTML | ||
<object width="#{options[:width]}" height="#{options[:height]}"> | ||
<param name="movie" value="http://www.youtube.com/v/#{id}&hl=#{options[:hl]}&fs=1&rel=0"></param> | ||
<param name="allowFullScreen" value="true"></param> | ||
<param name="allowscriptaccess" value="always"></param> | ||
<embed src="http://www.youtube.com/v/#{id}&hl=#{options[:hl]}&fs=1&rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="#{options[:width]}" height="#{options[:height]}"> | ||
</embed> | ||
</object> | ||
HTML | ||
end | ||
end | ||
|
||
class Parser | ||
|
||
def self.parse(feed) | ||
res = [] | ||
doc = Hpricot(feed) | ||
(doc/"entry").each do |entry| | ||
res << parse_entry(entry) | ||
end | ||
return res | ||
end | ||
|
||
def self.parse_entry(entry) | ||
video = Video.new | ||
video.id = entry.at("media:group yt:videoid").inner_html | ||
video.title = entry.at("title").inner_html | ||
video.published = DateTime.strptime(entry.at("published").inner_html, "%Y-%m-%dT%H:%M:%S.000Z") | ||
video.updated = DateTime.strptime(entry.at("updated").inner_html, "%Y-%m-%dT%H:%M:%S.000Z") | ||
video.uploaded = DateTime.strptime(entry.at("media:group yt:uploaded").inner_html, "%Y-%m-%dT%H:%M:%S.000Z") | ||
video.author = entry.at("author name").inner_html | ||
video.description = entry.at("media:group media:description").inner_html | ||
video.link = entry.at("media:group media:player").attributes['url'] | ||
video.thumbnail = entry.at("media:group media:thumbnail").attributes['url'] | ||
video.rating = entry.at("gd:rating").attributes | ||
video.keywords = entry.at("media:group media:keywords").inner_html.split(',') | ||
video.duration = entry.at("media:group yt:duration").attributes['seconds'].to_i | ||
return video | ||
end | ||
|
||
end | ||
Dir.glob(File.join(File.dirname(__FILE__), 'youtube', '*.rb')).each do |file| | ||
require file | ||
end |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.