xcezx-veoh 0.0.1

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.
Files changed (5) hide show
  1. data/README +30 -0
  2. data/Rakefile +69 -0
  3. data/lib/veoh.rb +89 -0
  4. data/test/test_veoh.rb +54 -0
  5. metadata +74 -0
data/README ADDED
@@ -0,0 +1,30 @@
1
+ = Veoh
2
+
3
+ A simple interface to the Veoh REST API documented
4
+ at http://www.veoh.com/rest/v2/doc.html
5
+
6
+ == About
7
+
8
+ Implements version 2 Veoh's API.
9
+
10
+ == Installing
11
+
12
+ Install the gem via:
13
+
14
+ % gem install veoh
15
+
16
+ == Usage
17
+
18
+ An example as:
19
+
20
+ require 'rubygems'
21
+ require 'veoh'
22
+
23
+ veoh = Veoh.new :apiKey => 'Your API Key'
24
+
25
+ # veoh.reflection.getAvailableCategories
26
+ results = veoh.call_method('veoh.reflection.getAvailableCategories')
27
+
28
+ # veoh.search.getRecommended
29
+ results = veoh.call_method('veoh.search.getRecommended',
30
+ { :type => 'video', :userToken => veoh.get_token( { :username => 'username', :password => 'p4ssw0rd' } ) } )
@@ -0,0 +1,69 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'lib/veoh'
8
+
9
+ NAME = 'veoh'
10
+ AUTHOR = 'xcezx'
11
+ EMAIL = 'http://mailhide.recaptcha.net/d?k=01ijfjwANz-PI4WWAaCtt3Ug==&c=DcAXl_NDJp97BPdftyD5Q87ymzuMKXCjIZbM6-r_2Bk='
12
+ DESCRIPTION = 'Simple interface to the Veoh REST API'
13
+ RUBYFORGE_PROJECT = 'veoh'
14
+ HOMEPAGE = 'http://github.com/xcezx/veoh/tree/master'
15
+ VERS = Veoh::VERSION
16
+
17
+ spec = Gem::Specification.new do |s|
18
+ s.name = NAME
19
+ s.version = VERS
20
+ s.platform = Gem::Platform::RUBY
21
+ s.has_rdoc = true
22
+ s.extra_rdoc_files = [ 'README' ]
23
+ s.rdoc_options << '--main' << 'README'
24
+ s.summary = DESCRIPTION
25
+ s.description = DESCRIPTION
26
+ s.author = AUTHOR
27
+ s.email = EMAIL
28
+ s.homepage = HOMEPAGE
29
+ s.rubyforge_project = RUBYFORGE_PROJECT
30
+ s.require_path = 'lib'
31
+ s.test_files = Dir['test/test_*.rb']
32
+
33
+ s.files = Dir.glob("{lib, test}/*") + [ 'README', 'Rakefile', ]
34
+
35
+ s.add_dependency('xml-simple', '>= 1.0.11')
36
+ s.add_dependency('pit', '>= 0.0.6')
37
+ end
38
+
39
+ desc 'Run tests'
40
+ task :default => [ :test ]
41
+
42
+ Rake::TestTask.new('test') do |t|
43
+ t.libs << 'test'
44
+ t.pattern = 'test/test_*.rb'
45
+ t.verbose = true
46
+ end
47
+
48
+ desc 'Generate RDoc'
49
+ Rake::RDocTask.new :rdoc do |rd|
50
+ rd.rdoc_dir = 'doc'
51
+ rd.rdoc_files.add 'lib', 'README'
52
+ rd.main = 'README'
53
+ end
54
+
55
+ desc 'Update gem spec'
56
+ task :gemspec do
57
+ open("veoh.gemspec", 'w') { |f| f.puts spec.to_ruby }
58
+ end
59
+
60
+ desc 'Build Gem'
61
+ Rake::GemPackageTask.new spec do |pkg|
62
+ pkg.need_tar = true
63
+ end
64
+
65
+ desc 'Clean up'
66
+ task :clean => [ :clobber_rdoc, :clobber_package ]
67
+
68
+ desc 'Clean up'
69
+ task :clobber => [ :clean ]
@@ -0,0 +1,89 @@
1
+ # = Veoh
2
+ #
3
+ #
4
+ # USAGE:
5
+ # require 'veoh'
6
+ # veoh = VeohAPI.new :apiKey => 'your-api-key'
7
+ # response = veoh.call_method( 'veoh.reflection.getAvailableCategories' )
8
+
9
+ require 'rubygems'
10
+ require 'net/http'
11
+ require 'net/https'
12
+ require 'xmlsimple'
13
+
14
+ class Veoh
15
+
16
+ VERSION = '0.0.1'
17
+
18
+ DEFAULT_HOST = 'http://www.veoh.com'
19
+ DEFAULT_HOST_SSL = 'https://www.veoh.com'
20
+ DEFAULT_API_PATH = '/rest/v2/execute.xml'
21
+
22
+ def initialize(opts = {})
23
+ raise 'API key required' unless opts[:apiKey]
24
+
25
+ @api_key = opts[:apiKey]
26
+ @secret = opts[:secret]
27
+ end
28
+
29
+ def call_method(method, opts = {}, verb = 'get', use_ssl = nil)
30
+ opts.update(:method => method, :apiKey => @api_key)
31
+
32
+ @host = use_ssl ? DEFAULT_HOST_SSL : DEFAULT_HOST
33
+ @api_path = DEFAULT_API_PATH
34
+
35
+ case verb
36
+ when 'get'
37
+ raw_response = get_request("#{@host}#{@api_path}", opts)
38
+ when 'post'
39
+ raw_response = post_request("#{@host}#{@api_path}", opts)
40
+ end
41
+
42
+ response = XmlSimple.xml_in(raw_response, { 'ForceArray' => nil })
43
+ raise get_error_message response unless response['stat'] == 'ok'
44
+ response
45
+ end
46
+
47
+ def get_token(opts = {})
48
+ raise 'Username and Password required.' unless opts[:username] and opts[:password]
49
+
50
+ response = call_method('veoh.people.authenticate', opts, 'post', true)
51
+ @token = response['authentication']['token']
52
+ end
53
+
54
+ private
55
+ def post_request(url, params)
56
+ uri = URI.parse(url)
57
+ http = Net::HTTP.new(uri.host, uri.port)
58
+
59
+ if uri.port == 443 then
60
+ http.use_ssl = true
61
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
62
+ end
63
+
64
+ http.start { |w|
65
+ request = Net::HTTP::Post.new(uri.path)
66
+ request.set_form_data( params )
67
+
68
+ w.request(request).body.to_s
69
+ }
70
+ end
71
+
72
+ private
73
+ def get_request(url, params)
74
+ uri = URI.parse(url)
75
+ uri.query = queryize params
76
+ Net::HTTP.get(uri).to_s
77
+ end
78
+
79
+ private
80
+ def queryize(hash)
81
+ hash.map { |i| i.map { |j| URI.escape j.to_s }.join '=' }.join('&')
82
+ end
83
+
84
+ private
85
+ def get_error_message(xml)
86
+ xml['errorList']['error']['errorMessage'].to_s
87
+ end
88
+
89
+ end
@@ -0,0 +1,54 @@
1
+
2
+ $LOAD_PATH << File.dirname(__FILE__) + '/../lib'
3
+ require 'test/unit'
4
+ require 'veoh'
5
+ require 'pit'
6
+ require 'pp'
7
+
8
+ config = Pit.get('veoh', :require => {
9
+ 'api_key' => 'your api key',
10
+ 'username' => 'your username',
11
+ 'password' => 'your password',
12
+ })
13
+
14
+ API_KEY = config['api_key']
15
+ USERNAME = config['username']
16
+ PASSWORD = config['password']
17
+
18
+ class VeohAPITest < Test::Unit::TestCase
19
+ def setup
20
+ @veoh = Veoh.new :apiKey => API_KEY
21
+ end
22
+
23
+ def test_instance
24
+ assert_instance_of Veoh, @veoh
25
+ end
26
+
27
+ def test_veoh_reflection_getAvailableCategories
28
+ results = @veoh.call_method('veoh.reflection.getAvailableCategories')
29
+
30
+ # is array?
31
+ assert_kind_of Array, results['categoryList']['category']
32
+ end
33
+
34
+ def test_veoh_reflection_getMethod
35
+ methodName = 'veoh.reflection.getSubCategories'
36
+ results = @veoh.call_method('veoh.reflection.getMethod', { :methodName => methodName } )
37
+
38
+ assert_equal methodName, results['methodList']['method']['name']
39
+ end
40
+
41
+ def test_veoh_collection_getCollectionMembership
42
+ results = @veoh.call_method('veoh.collection.getCollectionMembership', { :username => 'xcezx' })
43
+
44
+ assert_equal 0, results['subscriptionList']['items'].to_i
45
+ end
46
+
47
+ def test_veoh_people_authenticate
48
+ results = @veoh.get_token :username => USERNAME, :password => PASSWORD
49
+
50
+ assert_kind_of String, results
51
+ end
52
+
53
+ end
54
+
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xcezx-veoh
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - xcezx
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-12 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: xml-simple
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.0.11
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: pit
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 0.0.6
32
+ version:
33
+ description:
34
+ email: http://mailhide.recaptcha.net/d?k=01ijfjwANz-PI4WWAaCtt3Ug==&c=DcAXl_NDJp97BPdftyD5Q87ymzuMKXCjIZbM6-r_2Bk=
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files:
40
+ - README
41
+ files:
42
+ - lib/veoh.rb
43
+ - README
44
+ - Rakefile
45
+ - test/test_veoh.rb
46
+ has_rdoc: true
47
+ homepage: http://github.com/xcezx/veoh/tree/master
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --main
51
+ - README
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project: veoh
69
+ rubygems_version: 1.2.0
70
+ signing_key:
71
+ specification_version: 2
72
+ summary: Simple interface to the Veoh REST API
73
+ test_files:
74
+ - test/test_veoh.rb