ankoder 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -17,7 +17,6 @@ lib/ankoder/profile.rb
17
17
  lib/ankoder/upload.rb
18
18
  lib/ankoder/version.rb
19
19
  lib/ankoder/video.rb
20
- log/debug.log
21
20
  script/destroy
22
21
  script/generate
23
22
  script/txt2html
data/lib/ankoder/auth.rb CHANGED
@@ -44,8 +44,8 @@ module Ankoder
44
44
 
45
45
  # Same as initialize
46
46
  #
47
- # Auth::create 'login', 'password'
48
- def self.create(login, password, &block)
47
+ # Auth::create 'login', 'password'
48
+ def self.create(login= Configuration::auth_user, password =Configuration::auth_password, &block)
49
49
  new(:login => login, :password => password, &block)
50
50
  end
51
51
 
data/lib/ankoder/base.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  module Ankoder
2
2
  # You can connect to the _ankoderapi_session service permanently
3
3
  #
4
+ # Base::establish_connection! :login => "login", :password => "password"
5
+ #
4
6
  # You can access all the resources and manipulate the objects like in ActiveRecord
5
7
  #
6
8
  # v = Video.find(15).update_attributes :name => "My edited title"
@@ -21,10 +21,19 @@ module Ankoder
21
21
  raise ServerError, message if code == 500
22
22
  end
23
23
 
24
- def header(session=nil) #:nodoc:
24
+ def header(session=nil,action=nil,path=nil) #:nodoc:
25
25
  h = {}
26
26
  h.merge!({"Cookie" => "_ankoderapi_session=#{session};"}) if session
27
27
  h.merge!({"User-Agent" => "_ankoderapi_session ruby API - #{VERSION::STRING}"})
28
+ if !Configuration::access_key.blank? and !Configuration::private_key.blank?
29
+ h.merge!({"ankoder_access_key" => Configuration::access_key})
30
+ h.merge!({"ankoder_date" => Time.now.httpdate })
31
+
32
+ salt = Digest::SHA1.hexdigest("-#{Time.now.httpdate}-#{action}-#{path}-")[0..19]
33
+ passkey = Base64.encode64(HMAC::SHA1::digest(Configuration::private_key, salt)).strip
34
+ h.merge!({"ankoder_passkey" => "#{passkey}"})
35
+ end
36
+ h
28
37
  end
29
38
 
30
39
  # Login to _ankoderapi_session service. Return the session ID.
@@ -40,30 +49,30 @@ module Ankoder
40
49
  # GET on path
41
50
  def get(path, session=nil)
42
51
  path += ".#{OUT_FORMAT}" unless path.include? "."
43
- res = Net::HTTP.start(HOST) {|http| http.get(path, header(session))}
52
+ res = Net::HTTP.start(Configuration::host,Configuration::port) {|http| http.get(path, header(session,"GET",path))}
44
53
  raise_if_response_error(res)
45
54
  res
46
55
  end
47
56
 
48
57
  # POST on path and pass the query(Hash)
49
58
  def post(path, query={}, session=nil)
50
- res = Net::HTTP.start(HOST) {|http| http.post(path, query.merge(:format => OUT_FORMAT).to_a.map{|x| x.join("=")}.join("&"), self.header(session))}
59
+ res = Net::HTTP.start(Configuration::host,Configuration::port) {|http| http.post(path, query.merge(:format => OUT_FORMAT).to_a.map{|x| x.join("=")}.join("&"), self.header(session,"POST",path))}
51
60
  raise_if_response_error(res)
52
61
  res
53
62
  end
54
63
 
55
64
  # PUT on path and pass the query(Hash)
56
65
  def put(path, query={}, session=nil)
57
- req = Net::HTTP::Put.new(path, header(session))
66
+ req = Net::HTTP::Put.new(path, header(session,"PUT",path))
58
67
  req.form_data = query.merge(:format => OUT_FORMAT)
59
- res = Net::HTTP.new(HOST).start {|http| http.request(req) }
68
+ res = Net::HTTP.new(Configuration::host,Configuration::port).start {|http| http.request(req) }
60
69
  raise_if_response_error(res)
61
70
  true
62
71
  end
63
72
 
64
73
  # DELETE on path
65
74
  def delete(path, session=nil)
66
- res = Net::HTTP.start(HOST) {|http| http.delete(path+"."+OUT_FORMAT, header(session))}
75
+ res = Net::HTTP.start(Configuration::host,Configuration::port) {|http| http.delete(path+"."+OUT_FORMAT, header(session,"DELETE",path))}
67
76
  raise_if_response_error(res)
68
77
  true
69
78
  end
@@ -75,7 +84,7 @@ module Ankoder
75
84
 
76
85
  boundary = '349832898984244898448024464570528145'
77
86
  query = params.collect {|p| '--' + boundary + "\r\n" + p}.join('') + "--" + boundary + "--\r\n"
78
- res = Net::HTTP.start(HOST) {|http| http.post(path, query, header(session).merge("Content-Type" => "multipart/form-data; boundary=" + boundary))}
87
+ res = Net::HTTP.start(Configuration::host,Configuration::port) {|http| http.post(path, query, header(session,"POST",path).merge("Content-Type" => "multipart/form-data; boundary=" + boundary))}
79
88
  raise_if_response_error(res)
80
89
  res
81
90
  end
@@ -3,7 +3,6 @@ module Ankoder
3
3
 
4
4
  class Download < Base
5
5
  # Download file from the given URL
6
- #
7
6
  # Download.create('url' => 'http://host.com/file.avi', :postback_url => 'http://your_own_host.com/postback/download')
8
7
  #
9
8
  # the return result would be the Video record that you can save for further checking
data/lib/ankoder/ext.rb CHANGED
@@ -63,7 +63,7 @@ module Ankoder
63
63
 
64
64
  # Select Ankoder#Base object containing the conditions
65
65
  #
66
- # Profile.find(:all).find_with_conditions(:name => "aaa")
66
+ # Profile.find(:all).find_with_conditions(:name => "bar")
67
67
  def find_with_conditions(conditions={})
68
68
  return self if conditions.nil? or conditions.empty?
69
69
  res = []
data/lib/ankoder/job.rb CHANGED
@@ -6,13 +6,12 @@ module Ankoder
6
6
  #
7
7
  # Video_ID is the video id that get from Ankoder::Download
8
8
  # Profile_ID is selected from the list of Ankoder::Profile.find(:all)
9
- #
9
+ #
10
10
  # Job.create(:original_file_id => "Video_ID", :profile_id => "Profile_ID",
11
11
  # :postback_url => 'http://your_own_host.com/postback/job')
12
- def self.create(attributes={}, &block)
12
+ def self.create(attributes={})
13
13
  job = super
14
14
  return job
15
15
  end
16
-
17
16
  end
18
17
  end
@@ -7,4 +7,3 @@ module Ankoder
7
7
 
8
8
  end
9
9
  end
10
-
@@ -2,7 +2,7 @@ module Ankoder #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/ankoder/video.rb CHANGED
@@ -7,7 +7,10 @@ module Ankoder
7
7
  # Videos.find(video_id)
8
8
  #
9
9
  class Video < Base
10
-
11
-
10
+ def self.url_for(video_id, expires_in = nil)
11
+ message = {:access_key => Configuration::access_key, :expires => expires(expires_in)}.to_json
12
+ encoded_message = Base64.encode64(HMAC::SHA1::digest(Configuration::private_key, message)).strip
13
+ "http://#{Configuration::host}/video/#{video_id}/download/?message=#{CGI.escape(message)}&signature=#{encoded_message}"
14
+ end
12
15
  end
13
16
  end
data/lib/ankoder.rb CHANGED
@@ -1,10 +1,8 @@
1
- $:.unshift File.dirname(__FILE__)
2
-
3
1
  require "xmlsimple"
4
2
  require "cgi"
5
3
 
6
4
  module Ankoder
7
- HOST = "api.ankoder.com" unless const_defined? :HOST
5
+
8
6
  OUT_FORMAT = "xml" unless const_defined? :OUT_FORMAT
9
7
  RESOURCES = %w{job profile download video account upload} unless const_defined? :RESOURCES
10
8
  DEFAULT_EXPIRY = 300 unless const_defined? :DEFAULT_EXPIRY
@@ -33,6 +31,26 @@ module Ankoder
33
31
  class ServerError < RuntimeError; end
34
32
  class SessionNotFound < RuntimeError; end
35
33
 
34
+ class Configuration
35
+ cattr_accessor :private_key , :access_key , :auth_user , :auth_password , :host , :port
36
+ end
37
+
38
+ def self.load_config
39
+ begin
40
+ globe_config = YAML::load(ERB.new((IO.read("#{RAILS_ROOT}/config/ankoder.yml"))).result)
41
+ auth_config = globe_config["#{RAILS_ENV}"]
42
+ Configuration::private_key = auth_config["private_key"]
43
+ Configuration::access_key = auth_config["access_key"]
44
+ Configuration::auth_user = auth_config["auth_user"]
45
+ Configuration::auth_password = auth_config["auth_password"]
46
+ Configuration::host = auth_config["host"] || "api.ankoder.com"
47
+ Configuration::port = auth_config["port"] || "80"
48
+ rescue
49
+ raise $!, " Ankoder: problems trying to load '\"#{RAILS_ROOT}/config/ankoder.yml\")}'"
50
+ raise
51
+ end
52
+ end
53
+
36
54
  # Convert the XML response into Hash
37
55
  def self.response(xml)
38
56
  XmlSimple.xml_in(xml, {'ForceArray' => false})
@@ -59,6 +77,7 @@ end
59
77
 
60
78
  $: << File.dirname(File.expand_path(__FILE__))
61
79
 
80
+ Ankoder.load_config if defined?(RAILS_ROOT)
62
81
  require "ankoder/ext"
63
82
  require "ankoder/version"
64
83
  require "ankoder/browser"
data/website/index.html CHANGED
@@ -33,40 +33,36 @@
33
33
  <h1>ankoder</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/ankoder"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/ankoder" class="numbers">0.0.2</a>
36
+ <a href="http://rubyforge.org/projects/ankoder" class="numbers">0.0.5</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;ankoder&#8217;</h1>
39
39
 
40
40
 
41
41
  <h2>What</h2>
42
- <p>ankoder is a service provided by rorcraft that allows you convert a Video of any format (YouTube's videos,etc) to MPEG4 (AVI/MOV/MP4/MP3/3GP) or FLV file online. And this gem is to provide the API for you to send request to our video encoding server.</p>
43
- <h2>Installing</h2>
44
-
45
-
46
- <pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">ankoder</span></pre>
47
- <h2>The basics</h2>
48
- <p>As this service is still in private beta stage, for every developer start to use this api , have to apply for the private testing account. To apply the testing account, please fill in the form in <a href="http://free.ankoder.com/">http://free.ankoder.com/</a> .</p>
49
- <h2>Demonstration of usage</h2>
50
- <p>After we have approved the application , we will assign the username and password to login the service, for example, api_user as username , and api_passowrd as password.</p>
51
- <h4>Add the following lines to ApplicationController</h4>
52
- <p>require &quot;ankoder&quot;<br />
53
- include &quot;Ankoder&quot;</p>
54
- <h4>To create a user session<br />
55
- </h4>
56
- <p>user = Auth.create(&quot;api_user&quot;, &quot;api_password&quot;)</p>
57
- <h4>To list out the available converting profile</h4>
58
- <p>profiles = user.profiles.find(:all)</p>
59
- <h4>To download a video from Youtube</h4>
60
- <p>download = user.downloads.create('url' =&gt;&quot;http://www.youtube.com/watch?v=Sex4w4h7Tqk&quot;) </p>
61
- <h4>To create a job to convert a video file</h4>
62
- <p>convert_job.create(:video_id =&gt;download.id , :profile_id =&gt; profile.id )</p>
63
- <h2>Forum</h2>
42
+
43
+
44
+ <h2>Installing</h2>
45
+
46
+
47
+ <p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">ankoder</span></pre></p>
48
+
49
+
50
+ <h2>The basics</h2>
51
+
52
+
53
+ <h2>Demonstration of usage</h2>
54
+
55
+
56
+ <h2>Forum</h2>
64
57
 
65
58
 
66
59
  <p><a href="http://groups.google.com/group/ankoder">http://groups.google.com/group/ankoder</a></p>
67
- <h2>Our development Blog</h2>
68
- <p><a href="http://devblog.rorcraft.com/">http://devblog.rorcraft.com/</a></p>
69
- <h2>How to submit patches</h2>
60
+
61
+
62
+ <p><span class="caps">TODO</span> &#8211; create Google Group &#8211; ankoder</p>
63
+
64
+
65
+ <h2>How to submit patches</h2>
70
66
 
71
67
 
72
68
  <p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people&#8217;s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
@@ -84,12 +80,11 @@
84
80
  <h2>Contact</h2>
85
81
 
86
82
 
87
- <p>Comments are welcome. Send an email to <a href="mailto:info@rorcraft.com">info@rorcraft.com</a></span> or via the <a href="http://groups.google.com/group/ankoder">forum</a></p>
83
+ <p>Comments are welcome. Send an email to <a href="mailto:FIXME"><span class="caps">FIXME</span> full name</a> email via the <a href="http://groups.google.com/group/ankoder">forum</a></p>
88
84
  <p class="coda">
89
- <a href="FIXME email"></a>Ankoder, a service by RoRCraft Limited,<br />
90
- Last Updated :
91
- 27th February 2008<br>
92
- Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a> </p>
85
+ <a href="FIXME email">FIXME full name</a>, 30th April 2008<br>
86
+ Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
87
+ </p>
93
88
  </div>
94
89
 
95
90
  <!-- insert site tracking codes here, like Google Urchin -->
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ankoder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ""
6
6
  authors:
7
7
  - RoRCraft.com
@@ -30,7 +30,7 @@ cert_chain:
30
30
  iplROzUF++Prmx2JGuO6kA==
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2008-04-02 00:00:00 +08:00
33
+ date: 2008-04-30 00:00:00 +08:00
34
34
  default_executable:
35
35
  dependencies: []
36
36
 
@@ -67,7 +67,6 @@ files:
67
67
  - lib/ankoder/upload.rb
68
68
  - lib/ankoder/version.rb
69
69
  - lib/ankoder/video.rb
70
- - log/debug.log
71
70
  - script/destroy
72
71
  - script/generate
73
72
  - script/txt2html
metadata.gz.sig CHANGED
Binary file
data/log/debug.log DELETED
File without changes