Class: PHTwitVid
- Inherits:
-
Object
- Object
- PHTwitVid
- Defined in:
- lib/phtwitvid.rb
Instance Method Summary collapse
- #create_playlist(token, playlist_name) ⇒ Object
- #delete(token, video_id) ⇒ Object
- #embed(video_id, width, height) ⇒ Object
- #get_thumbnail_url(video_id) ⇒ Object
- #get_token(username, password) ⇒ Object
- #get_uploaded_videos(token) ⇒ Object
-
#initialize ⇒ PHTwitVid
constructor
A new instance of PHTwitVid.
- #profile(username) ⇒ Object
- #upload(token, message, video_path, post, source) ⇒ Object
Constructor Details
#initialize ⇒ PHTwitVid
Returns a new instance of PHTwitVid.
9 10 11 |
# File 'lib/phtwitvid.rb', line 9 def initialize $api_url = "https://im.twitvid.com/api" end |
Instance Method Details
#create_playlist(token, playlist_name) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/phtwitvid.rb', line 60 def create_playlist(token, playlist_name) params = { :query => {:token => token, :playlistName => playlist_name}} response = HTTParty.post("#{$api_url}/createPlaylist", params) xml = XmlSimple.xml_in(response.body, { 'KeyAttr' => 'name' }) return {'playlist_url' => xml['playlist_url'].to_s, 'playlist_id' => xml['playlist_id'].to_s} end |
#delete(token, video_id) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/phtwitvid.rb', line 41 def delete(token, video_id) params = { :query => {:token => token, :media_id => video_id}} response = HTTParty.post("#{$api_url}/delete", params) xml = XmlSimple.xml_in(response.body, { 'KeyAttr' => 'name' }) return xml['rsp stat'] end |
#embed(video_id, width, height) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/phtwitvid.rb', line 48 def (video_id, width, height) if width == nil || height == nil width = '425' height = '344' end return "<object width=\"#{width}\" height=\"#{height}\"> <param name=\"movie\" value=\"http://www.twitvid.com/player/#{video_id}>\"></param> <param name=\"allowFullScreen\" value=\"true\"></param> <embed type=\"application/x-shockwave-flash\" src=\"http://www.twitvid.com/player/#{video_id}\" quality=\"high\" allowscriptaccess=\"always\" allowNetworking=\"all\" allowfullscreen=\"true\" wmode=\"transparent\" height=\"#{height}\" width=\"#{width}\"> </object>" end |
#get_thumbnail_url(video_id) ⇒ Object
73 74 75 |
# File 'lib/phtwitvid.rb', line 73 def get_thumbnail_url(video_id) return "http://cdn.twitvid.com/thumbnails/#{video_id}.jpg" end |
#get_token(username, password) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/phtwitvid.rb', line 13 def get_token(username, password) params = { :query => {:username => username, :password => password}} response = HTTParty.post("#{$api_url}/authenticate", params) xml = XmlSimple.xml_in(response.body, { 'KeyAttr' => 'name' }) if xml['token'] == nil return "Invalid username/password" else return xml['token'] end end |
#get_uploaded_videos(token) ⇒ Object
67 68 69 70 71 |
# File 'lib/phtwitvid.rb', line 67 def get_uploaded_videos(token) params = { :query => {:token => token}} response = HTTParty.post("#{$api_url}/getVideos", params) return response.body end |
#profile(username) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/phtwitvid.rb', line 77 def profile(username) unparsed_xml = open("http://www.twitter.com/users/show.xml?screen_name=#{username}"); xml = XmlSimple.xml_in(unparsed_xml, { 'KeyAttr' => 'name' }) return {'id' => xml['id'].to_s, 'name' => xml['name'].to_s, 'screen_name' => xml['screen_name'].to_s, 'location' => xml['location'].to_s, 'description' => xml['description'].to_s, 'url' => xml['url'].to_s, 'profile_image_url' => xml['profile_image_url'].to_s, 'followers' => xml['followers_count'].to_s, 'following' => xml['friends_count'].to_s, } end |
#upload(token, message, video_path, post, source) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/phtwitvid.rb', line 24 def upload(token, , video_path, post, source) f = File.new(video_path, File::RDWR) agent = WWW::Mechanize.new response = agent.post( "#{$api_url}/#{post}", { :media => f, :token => token, :message => , :source => source } ) f.close xml = XmlSimple.xml_in(response.body, { 'KeyAttr' => 'name' }) return {'media_url' => xml['media_url'].to_s, 'media_id' => xml['media_id'].to_s} end |