kewego_party 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.autotest +1 -0
  2. data/.gitignore +6 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +7 -0
  5. data/CHANGELOG.md +2 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +20 -0
  8. data/README.md +47 -0
  9. data/Rakefile +10 -0
  10. data/TODO.md +4 -0
  11. data/kewego_party.gemspec +35 -0
  12. data/lib/kewego_party.rb +29 -0
  13. data/lib/kewego_party/cache.rb +42 -0
  14. data/lib/kewego_party/client.rb +52 -0
  15. data/lib/kewego_party/client/app.rb +16 -0
  16. data/lib/kewego_party/client/auth.rb +35 -0
  17. data/lib/kewego_party/client/channel.rb +57 -0
  18. data/lib/kewego_party/client/channel_list.rb +18 -0
  19. data/lib/kewego_party/client/upload.rb +31 -0
  20. data/lib/kewego_party/client/video.rb +36 -0
  21. data/lib/kewego_party/configuration.rb +49 -0
  22. data/lib/kewego_party/connection.rb +20 -0
  23. data/lib/kewego_party/exceptions.rb +5 -0
  24. data/lib/kewego_party/parse_xml.rb +19 -0
  25. data/lib/kewego_party/request.rb +55 -0
  26. data/lib/kewego_party/version.rb +3 -0
  27. data/spec/fixtures/app_get_auth_token.xml +6 -0
  28. data/spec/fixtures/app_get_token.xml +5 -0
  29. data/spec/fixtures/cassette_library/app_check_token.yml +68 -0
  30. data/spec/fixtures/cassette_library/app_get_token.yml +30 -0
  31. data/spec/fixtures/cassette_library/channel_get_details.yml +68 -0
  32. data/spec/fixtures/cassette_library/channel_get_player_code.yml +69 -0
  33. data/spec/fixtures/cassette_library/channel_get_thumbnail.yml +68 -0
  34. data/spec/fixtures/cassette_library/channel_get_videos.yml +68 -0
  35. data/spec/fixtures/cassette_library/channel_list_get_channels.yml +68 -0
  36. data/spec/fixtures/cassette_library/channel_list_get_details.yml +68 -0
  37. data/spec/fixtures/cassette_library/upload_get_available_categories.yml +115 -0
  38. data/spec/fixtures/cassette_library/video_get_details.yml +69 -0
  39. data/spec/fixtures/cassette_library/video_get_stats.yml +60 -0
  40. data/spec/fixtures/kewego_response_error.xml +5 -0
  41. data/spec/fixtures/not_kewego_response.xml +4 -0
  42. data/spec/fixtures/upload_get_upload_progress.xml +8 -0
  43. data/spec/kewego_party/client/app_spec.rb +28 -0
  44. data/spec/kewego_party/client/auth_spec.rb +45 -0
  45. data/spec/kewego_party/client/cache_spec.rb +34 -0
  46. data/spec/kewego_party/client/channel_list_spec.rb +36 -0
  47. data/spec/kewego_party/client/channel_spec.rb +59 -0
  48. data/spec/kewego_party/client/request_spec.rb +31 -0
  49. data/spec/kewego_party/client/upload_spec.rb +39 -0
  50. data/spec/kewego_party/client/video_spec.rb +33 -0
  51. data/spec/kewego_party/client_spec.rb +20 -0
  52. data/spec/kewego_party_spec.rb +22 -0
  53. data/spec/spec_helper.rb +32 -0
  54. metadata +257 -0
data/.autotest ADDED
@@ -0,0 +1 @@
1
+ require 'autotest/bundler'
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea
6
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=nested
3
+ --backtrace
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - rbx
6
+ - rbx-2.0
7
+ - ree
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ * 0.0.1
2
+ - Added api_cache as dependency to cache app_token
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Paco Guzmán
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # The Kewego Ruby Gem
2
+ Simple ruby wrapper for Kewego API
3
+
4
+ ## <a name="installation">Installation</a>
5
+ gem install kewego_party
6
+
7
+ ## <a name="ci">Continuous Integration</a>
8
+ [![Build Status](https://secure.travis-ci.org/aspgems/kewego_party.png)](http://travis-ci.org/aspgems/kewego_party)
9
+
10
+ ## <a name="examples">Examples</a>
11
+ ### <a name="video-details">Video Details</a>
12
+
13
+ ````ruby
14
+ client = KewegoParty::Client.new(:token => your_api_token)
15
+ client.video_get_details(video_identifier)
16
+ => <#Hashie::Rash access="public" audience_classification="all_public" author="charhadas" available_formats=<#Hashie::Rash format=["ipadHQ", "iphone", "iphone3G", "normal", "old", "slides"]> available_subtitles="available_subtitle" broadcast_end_date="2037-12-31 23:59:59" broadcast_start_date="2011-07-06 13:26:20" categories=<#Hashie::Rash category="Actualidades"> chapter_available="no" comments="0" country="es" default_display_subtitle="none" default_format="sd" description="<p>Entrevista Charhadas</p>" duration="221" keywords=<#Hashie::Rash keyword=["entrevista", "ceos", "socias"]> language="es" metadata=nil pid="" postal_code="28023" production_date="0000-00-00 00:00:00" publication_date="2011-07-06 13:26:20" rate="0" rating_count="0" ratio="1.7778" slide_available="no" thumbnails=<#Hashie::Rash large=<#Hashie::Rash url=["http://tll.kewego.com/t/0/0071/400x300_iLyROoaf22Mr_1.jpg", "http://tll.kewego.com/t/0/0071/400x300_iLyROoaf22Mr_2.jpg", "http://tll.kewego.com/t/0/0071/400x300_iLyROoaf22Mr_3.jpg"]> medium=<#Hashie::Rash url=["http://tll.kewego.com/t/0/0071/154x114_iLyROoaf22Mr_1.jpg", "http://tll.kewego.com/t/0/0071/154x114_iLyROoaf22Mr_2.jpg", "http://tll.kewego.com/t/0/0071/154x114_iLyROoaf22Mr_3.jpg"]> small=<#Hashie::Rash url=["http://tll.kewego.com/t/0/0071/74x54_iLyROoaf22Mr_1.jpg", "http://tll.kewego.com/t/0/0071/74x54_iLyROoaf22Mr_2.jpg", "http://tll.kewego.com/t/0/0071/74x54_iLyROoaf22Mr_3.jpg"]>> title="Entrevista CharHadas" videoblog_link=nil views="16">
17
+ ````
18
+
19
+ ## <a name="pulls">Submitting a Pull Request</a>
20
+ 1. Fork the project.
21
+ 2. Create a topic branch.
22
+ 3. Implement your feature or bug fix.
23
+ 4. Add specs for your feature or bug fix.
24
+ 5. Run <tt>bundle exec rake spec</tt>. If your changes are not 100% covered, go back to step 6.
25
+ 6. Commit and push your changes.
26
+ 7. Submit a pull request. Please do not include changes to the version or gemspec. (If you want to create your own version for some reason, please do so in a separate commit.)
27
+
28
+ ## <a name="rubies">Supported Rubies</a>
29
+ This library aims to support and is [tested
30
+ against](http://travis-ci.org/aspgems/kewego_party) the following Ruby
31
+ implementations:
32
+
33
+ * Ruby 1.8.7
34
+ * Ruby 1.9.2
35
+ * Ruby 1.9.3
36
+ * [Rubinius](http://rubini.us/)
37
+ * [Ruby Enterprise Edition](http://www.rubyenterpriseedition.com/)
38
+
39
+ If something doesn't work on one of these interpreters, it should be considered
40
+ a bug.
41
+
42
+ ## <a name="inspiration">Inspiration</a>
43
+ KewegoParty was inspired by [Octokit](https://github.com/pengwynn/octokit).
44
+
45
+ ## <a name="copyright">Copyright</a>
46
+ Copyright (c) 2011 [ASPgems](http://aspgems.com).
47
+ See [LICENSE](https://github.com/aspgems/kewego_party/blob/master/LICENSE) for details.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :test => :spec
10
+ task :default => :spec
data/TODO.md ADDED
@@ -0,0 +1,4 @@
1
+ ## <a name="todos">TODOs</a>
2
+
3
+ * Rails integration
4
+ * How to submit a video to Kewego Platform
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "kewego_party/version"
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "kewego_party"
7
+ gem.rubyforge_project = "kewego_party party"
8
+ gem.summary = %q{Ruby wrapper for the Kewego API using HTTP Party}
9
+ gem.description = %q{Ruby wrapper for the Kewego API using HTTP Party}
10
+
11
+ gem.homepage = "https://github.com/aspgems/kewego_party"
12
+ gem.authors = ["Paco Guzman"]
13
+ gem.email = ["fjguzman@aspgems.com"]
14
+
15
+ gem.version = KewegoParty::VERSION
16
+
17
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ gem.files = `git ls-files`.split("\n")
19
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+
21
+ gem.platform = Gem::Platform::RUBY
22
+ gem.require_paths = ['lib']
23
+ gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
24
+
25
+ gem.add_runtime_dependency 'httparty', '~> 0.7.8'
26
+ gem.add_runtime_dependency 'multi_xml', '~> 0.2'
27
+ gem.add_runtime_dependency 'rash', '~> 0.3'
28
+ gem.add_runtime_dependency 'hashie', '~> 1.0.0'
29
+ gem.add_runtime_dependency 'api_cache', '~> 0.2.3'
30
+
31
+ gem.add_development_dependency 'rake', '~> 0.9'
32
+ gem.add_development_dependency 'rspec', '~> 2.6'
33
+ gem.add_development_dependency 'vcr', '~> 1.10'
34
+ gem.add_development_dependency 'webmock', '~> 1.6'
35
+ end
@@ -0,0 +1,29 @@
1
+ require "kewego_party/version"
2
+
3
+ require 'api_cache'
4
+
5
+ require 'kewego_party/configuration'
6
+ require 'kewego_party/client'
7
+ require 'kewego_party/exceptions'
8
+
9
+ module KewegoParty
10
+ extend Configuration
11
+ class << self
12
+ # Alias for KewegoParty::Client.new
13
+ #
14
+ # @return [KewegoParty::Client]
15
+ def new(options={})
16
+ KewegoParty::Client.new(options)
17
+ end
18
+
19
+ # Delegate to KewegoParty::Client.new
20
+ def method_missing(method, *args, &block)
21
+ return super unless new.respond_to?(method)
22
+ new.send(method, *args, &block)
23
+ end
24
+
25
+ def respond_to?(method, include_private=false)
26
+ new.respond_to?(method, include_private) || super(method, include_private)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,42 @@
1
+ module KewegoParty
2
+ module Cache
3
+
4
+ def app_reset_app_token
5
+ with_caching(app_token_cache_key, :cache => 0, :period => 0) do
6
+ app_get_token
7
+ end
8
+ end
9
+
10
+ def app_token
11
+ self.app_token = with_caching(app_token_cache_key, :cache => app_token_cache_timeout, :period => 0) do
12
+ app_get_token
13
+ end
14
+ @app_token
15
+ end
16
+
17
+ def app_token=(token)
18
+ @app_token = token
19
+ end
20
+
21
+ protected
22
+ def with_caching(key, options)
23
+ APICache.get(key, options) do
24
+ yield
25
+ end
26
+ rescue APICache::TimeoutError => err
27
+ raise KewegoParty::TimeoutException.new
28
+ end
29
+
30
+ def app_token_cache_key
31
+ 'app_get_token'
32
+ end
33
+
34
+ def app_token_cache_timeout
35
+ 22 * 3600
36
+ end
37
+
38
+ def cache_fail
39
+ raise
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,52 @@
1
+ require 'httparty'
2
+
3
+ require 'kewego_party/cache'
4
+ require 'kewego_party/connection'
5
+ require 'kewego_party/request'
6
+
7
+ require 'kewego_party/client/app'
8
+ require 'kewego_party/client/auth'
9
+ require 'kewego_party/client/channel_list'
10
+ require 'kewego_party/client/channel'
11
+ require 'kewego_party/client/upload'
12
+ require 'kewego_party/client/video'
13
+
14
+ module KewegoParty
15
+ class Client
16
+ include ::HTTParty
17
+
18
+ include KewegoParty::Cache
19
+ include KewegoParty::Connection
20
+ include KewegoParty::Request
21
+
22
+ include KewegoParty::Client::App
23
+ include KewegoParty::Client::Auth
24
+ include KewegoParty::Client::ChannelList
25
+ include KewegoParty::Client::Channel
26
+ include KewegoParty::Client::Upload
27
+ include KewegoParty::Client::Video
28
+
29
+ attr_accessor(*(Configuration::VALID_OPTIONS_KEYS - [:app_token]))
30
+
31
+ def initialize(options={})
32
+ options = KewegoParty.options.merge(options)
33
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
34
+ send("#{key}=", options[key])
35
+ end
36
+ end
37
+
38
+ def caching_store=(store)
39
+ @caching_store = store
40
+ APICache.store = store
41
+ end
42
+
43
+ private
44
+ def process_response(response, xml_path = [])
45
+ Array(xml_path).unshift(:kewego_response, :message).inject(response) do |response, path|
46
+ raise KewegoParty::InvalidResponseException.new(path) unless response.key?(path)
47
+
48
+ response[path]
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,16 @@
1
+ module KewegoParty
2
+ class Client
3
+ module App
4
+ def app_get_token
5
+ response = get("/app/getToken/", {:appKey => token})
6
+ self.app_token = process_response(response, [:app_token])
7
+ @app_token
8
+ end
9
+
10
+ def app_check_token
11
+ response = get("/app/checkToken/", {:appKey => token, :appToken => app_token})
12
+ process_response(response, [:app_token])
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,35 @@
1
+ module KewegoParty
2
+ class Client
3
+ module Auth
4
+ # Generates a user token needed for adding and updating data in kewego
5
+ #
6
+ # @param options [Hash] A customizable set of options.
7
+ # @option options [String] :username(configuration.login). User name to login
8
+ # @option options [String] :password(configuration.password). Password to login
9
+ # @return [String] returns the user token
10
+ # @see http://developers.kewego.com/documentation/auth/getauthtoken.html
11
+ # @example receive the user token
12
+ # KewegoParty.auth_get_auth_token
13
+ def auth_get_auth_token(options = {})
14
+ options = {:appToken => app_token, :username => self.login, :password => self.password}.merge options
15
+ response = get('/api/getAuthToken/', options, 2)
16
+ process_response(response, [:token])
17
+ end
18
+
19
+ # Generates a user token needed for adding and updating data in kewego
20
+ #
21
+ # @param options [Hash] A customizable set of options.
22
+ # @option options [String] :username(configuration.login). User name to login
23
+ # @option options [String] :password(configuration.password). Password to login
24
+ # @return [String] returns the user token
25
+ # @see http://developers.kewego.com/documentation/auth/getauthtoken.html
26
+ # @example receive the user token
27
+ # KewegoParty.auth_get_login_token
28
+ def auth_get_login_token(options = {})
29
+ options = {:appToken => app_token, :username => self.login, :password => self.password}.merge options
30
+ response = get('/api/getLoginToken/', options, 2)
31
+ process_response(response, [:token])
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,57 @@
1
+ module KewegoParty
2
+ class Client
3
+ module Channel
4
+
5
+ def channel_get_videos(csig, options = {})
6
+ options = {:csig => csig, :appToken => app_token}.merge options
7
+ response = get('/channel/getVideos/', options)
8
+ process_response(response, [])
9
+ end
10
+
11
+ def channel_get_details(csig, options = {})
12
+ options = {:csig => csig, :appToken => app_token}.merge options
13
+ response = get('/channel/getDetails/', options)
14
+ process_response(response, [:channel])
15
+ end
16
+
17
+ # Thumbnail for a video
18
+ #
19
+ # @param csig [String] A Kewego channel Identifier.
20
+ # @param options [Hash] A customizable set of options.
21
+ # @option options [String] :size (normal) Size of the thumbnail - Possible values: small/normal/large
22
+ # @option options [Integer] :pos (1) Position of the video in the channel
23
+ # @option options [Integer] :index (1) index of the thumbnail - Possible values: 1/2/3
24
+ # @return [String] A thumbnail
25
+ # @see http://developers.kewego_party.com/documentation/channel/getthumbnail.html
26
+ # @example receive a thumbnail from those available in the channel (csig)
27
+ # KewegoParty.get_thumbnail("some_csig_identifier")
28
+ def channel_get_thumbnail(csig, options = {})
29
+ options = {:csig => csig, :appToken => app_token}.merge options
30
+ get("/channel/getThumbnail/", options)
31
+ end
32
+
33
+ # Allows you to get the embedded code of a channel from the channel identifier (CSIG).
34
+ #
35
+ # @param csig [String] A Kewego channel Identifier.
36
+ # @param language_code [String] ('es') Language of the player
37
+ # @param options [Hash] A customizable set of options.
38
+ # @option options [String] :player_key
39
+ # @option options [String] :skin_key
40
+ # @option options [Boolean] :autostart
41
+ # @option options [String] :advertise
42
+ # @option options [Integer] :width (400)
43
+ # @option options [Integer] :height (300)
44
+ # @return [String] A Player embedded code
45
+ # @see http://developers.kewego.com/documentation/channel/getplayercode.html
46
+ # @example get the embedded code of a channel from the channel identifier (csig)
47
+ # KewegoParty.get_player_code("some_csig_identifier")
48
+ def channel_get_player_code(csig, language_code = "es", options = {})
49
+ default_options = {:csig => csig, :appToken => app_token, :language_code => language_code}
50
+ options = default_options.merge options
51
+
52
+ response = get('/channel/getPlayerCode/', options)
53
+ process_response(response, [:blog])
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,18 @@
1
+ module KewegoParty
2
+ class Client
3
+ module ChannelList
4
+
5
+ def channel_list_get_channels(lsig, options = {})
6
+ options = {:start => 0, :max_result_per_page => 100, :lsig => lsig, :appToken => app_token}.merge options
7
+ response = get("/channelList/getChannels/", options)
8
+ process_response(response, [:channels])
9
+ end
10
+
11
+ def channel_list_get_details(lsig)
12
+ options = {:lsig => lsig, :appToken => app_token}
13
+ response = get("/channelList/getDetails/", options)
14
+ process_response(response, [])
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,31 @@
1
+ module KewegoParty
2
+ class Client
3
+ module Upload
4
+
5
+ # List of categories available for a video upload
6
+ #
7
+ # @return [Array] returns the available categories for a video upload.
8
+ # @see http://developers.kewego.com/documentation/upload/getavailablecategories.html
9
+ # @example receive the available categories
10
+ # KewegoParty.upload_get_available_categories
11
+ def upload_get_available_categories
12
+ options = {:appToken => app_token}
13
+ response = get("/upload/getAvailableCategories", options)
14
+ process_response(response, [:categories, :category])
15
+ end
16
+
17
+ # Status of a video upload
18
+ #
19
+ # @param upload_key [String] unique key used to follow an upload, declared in uploadVideo call as X-Progress-ID
20
+ # @return [Hashie::Rash] returns the status of the video upload
21
+ # @see http://developers.kewego.com/documentation/upload/getuploadprogress.html
22
+ # @example receive the status of an upload
23
+ # KewegoParty.upload_get_upload_progress('cd26e3d0fd21fec2589c6f7dd41078')
24
+ def upload_get_upload_progress(upload_key)
25
+ options = {:appToken => app_token, :upload_key => upload_key}
26
+ response = get("/upload/getUploadProgress", options)
27
+ process_response(response, [])
28
+ end
29
+ end
30
+ end
31
+ end