From 398d8576a3442c631488cfb71e1ac78db500317f Mon Sep 17 00:00:00 2001 From: BenjaminSchaaf Date: Thu, 10 Dec 2015 16:56:19 +1100 Subject: [PATCH 1/4] Added schemas.video.category api function --- lib/youku/client.rb | 8 ++++++++ lib/youku/v2/request.rb | 2 +- lib/youku/v2/schemas.rb | 31 +++++++++++++++++++++++++++++++ spec/youku/v2/schemas_spec.rb | 28 ++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 lib/youku/v2/schemas.rb create mode 100644 spec/youku/v2/schemas_spec.rb diff --git a/lib/youku/client.rb b/lib/youku/client.rb index 44c03d3..5f55cb0 100644 --- a/lib/youku/client.rb +++ b/lib/youku/client.rb @@ -40,6 +40,13 @@ def users def comments Youku::V2::Comments.new(self) end + + # Public: Get users API. + # + # Returns the instance of Youku::V2::Users. + def schemas + Youku::V2::Schemas.new(self) + end end end @@ -48,3 +55,4 @@ def comments require 'youku/v2/users' require 'youku/v2/videos' require 'youku/v2/comments' +require 'youku/v2/schemas' diff --git a/lib/youku/v2/request.rb b/lib/youku/v2/request.rb index 17b6693..9a9f5d2 100644 --- a/lib/youku/v2/request.rb +++ b/lib/youku/v2/request.rb @@ -11,7 +11,7 @@ class Request # # url - The String url. # params - The Hash query params. - def initialize(url, params) + def initialize(url, params = {}) @url = url @params = params @response = Typhoeus::Request.new(url, params: params, connecttimeout: 5, timeout: 10).run diff --git a/lib/youku/v2/schemas.rb b/lib/youku/v2/schemas.rb new file mode 100644 index 0000000..57c562b --- /dev/null +++ b/lib/youku/v2/schemas.rb @@ -0,0 +1,31 @@ +module Youku + module V2 + class Schemas < Base + BASE_URI = "#{BASE_URI}/schemas" + + # Public: Get hot API. + # + # Returns the instance of Youku::V2::Comments::Video. + def video + Video.new(client) + end + + class Video < Base + BASE_URI = "#{BASE_URI}/video" + + # Public: Get hot comments given a video. + # + # See: http://open.youku.com/docs?id=36 + # + # video_id - The string video ID. + # page - The Integer page number. + # count - The Integer page size. + # + # Returns the instance of Youku::V2::Request. + def category() + Youku::V2::Request.new "#{BASE_URI}/category.json" + end + end + end + end +end diff --git a/spec/youku/v2/schemas_spec.rb b/spec/youku/v2/schemas_spec.rb new file mode 100644 index 0000000..0d8b3ab --- /dev/null +++ b/spec/youku/v2/schemas_spec.rb @@ -0,0 +1,28 @@ +require 'spec_helper' + +describe Youku::V2::Schemas do + + let(:client) { Youku::Client.new(client_id: 'client-id') } + + describe '#video' do + subject { client.schemas.video } + + it { expect(subject).to be_a Youku::V2::Schemas::Video } + it { expect(subject.client).to eq client } + end + + describe '::Video' do + describe '#category' do + let(:url) { 'https://openapi.youku.com/v2/schemas/video/category.json' } + let(:query) { {} } + + before do + stub_request(:get, url).with(query: query).to_return(status: 200) + end + + subject { client.schemas.video.category } + + it_should_behave_like 'a base Youku API V2 requests' + end + end +end From 6713c624a83998b2ce1c67851c1e1bae88a62fac Mon Sep 17 00:00:00 2001 From: BenjaminSchaaf Date: Thu, 10 Dec 2015 21:32:20 +1100 Subject: [PATCH 2/4] Fixed documentation --- lib/youku/v2/schemas.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/youku/v2/schemas.rb b/lib/youku/v2/schemas.rb index 57c562b..d126e8e 100644 --- a/lib/youku/v2/schemas.rb +++ b/lib/youku/v2/schemas.rb @@ -3,9 +3,9 @@ module V2 class Schemas < Base BASE_URI = "#{BASE_URI}/schemas" - # Public: Get hot API. + # Public: Get video API. # - # Returns the instance of Youku::V2::Comments::Video. + # Returns the instance of Youku::V2::Schemas::Video. def video Video.new(client) end @@ -13,13 +13,9 @@ def video class Video < Base BASE_URI = "#{BASE_URI}/video" - # Public: Get hot comments given a video. + # Public: Get video categories. # - # See: http://open.youku.com/docs?id=36 - # - # video_id - The string video ID. - # page - The Integer page number. - # count - The Integer page size. + # See: http://open.youku.com/docs?id=90 # # Returns the instance of Youku::V2::Request. def category() From f57214efdd2ddec7265c0e2526938d9471442fed Mon Sep 17 00:00:00 2001 From: BenjaminSchaaf Date: Fri, 11 Dec 2015 02:12:34 +1100 Subject: [PATCH 3/4] Cleaned up and updated README --- README.md | 57 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index a975c83..f946dc9 100644 --- a/README.md +++ b/README.md @@ -1,49 +1,56 @@ # Youku Ruby Gem -[![Build Status](https://secure.travis-ci.org/Shuttlerock/youku_client.png)](http://travis-ci.org/Shuttlerock/youku_client) [![Code Climate](https://codeclimate.com/github/Shuttlerock/youku_client/badges/gpa.svg)](https://codeclimate.com/github/Shuttlerock/youku_client) +[![Build Status](https://secure.travis-ci.org/Shuttlerock/youku_client.png)](http://travis-ci.org/Shuttlerock/youku_client) +[![Code Climate](https://codeclimate.com/github/Shuttlerock/youku_client/badges/gpa.svg)](https://codeclimate.com/github/Shuttlerock/youku_client) This is the unofficial Ruby wrapper for the Youku v2 API. It supports not all -endpoints currently available on the -[Youku API](http://open.youku.com/docs?id=0). +endpoints currently available on the [Youku API](http://open.youku.com/docs?id=0). ## Installation - gem install youku_client +``` bash +gem install youku_client +``` ### Some quick examples First, instantiate the Client class: - >> client = Youku.new(client_id: 'id', client_secret: 'secret') +``` ruby +>> client = Youku.new(client_id: 'id', client_secret: 'secret') +``` Get users by IDs: - >> client.users.show_batch(user_ids: '1,2') +``` ruby +>> client.users.show_batch(user_ids: '1,2') +``` Implemented API endpoints: - - `comments.by_video` - - `comments.hot.by_video` - - `comments.show_batch` - - `comments.show` - - `searches.video.by_keyword` - - `users.friendship.followers` - - `users.friendship.followings` - - `users.show_batch` - - `users.show` - - `videos.by_category` - - `videos.by_related` - - `videos.by_user` - - `videos.favorite.by_user` - - `videos.show_basic_batch` - - `videos.show_basic` - - `videos.show_batch` - - `videos.show` +- `comments.by_video` +- `comments.show` +- `comments.show_batch` +- `comments.hot.by_video` +- `searches.video.by_keyword` +- `users.show_batch` +- `users.show` +- `users.friendship.followers` +- `users.friendship.followings` +- `videos.show_basic` +- `videos.show_basic_batch` +- `videos.show` +- `videos.show_batch` +- `videos.by_user` +- `videos.by_related` +- `videos.by_category` +- `videos.favorite.by_user` +- `schemas.video.category` ### Contributions and Pull Requests -No request is too small and I encourage everyone to get involved. So -please if you would like to contribute, let me know and throw me a pull request! +No request is too small and I encourage everyone to get involved. So please if +you would like to contribute, let me know and throw me a pull request! ### Requirements From 54c4556119e3adea8db0cb9cf3a4f92b604b593b Mon Sep 17 00:00:00 2001 From: BenjaminSchaaf Date: Fri, 11 Dec 2015 02:48:27 +1100 Subject: [PATCH 4/4] Updated ChANGELOG --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aee55d6..29ac97c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +Unreleased +---------- +* [Implemented schemas.video.category](https://github.com/Shuttlerock/youku_client/pull/8) ([@BenjaminSchaaf](https://github.com/BenjaminSchaaf)) + 0.0.3 ------ * [Completed non-authenticated portion of the comments API](https://github.com/Shuttlerock/youku_client/pull/7) ([@BenjaminSchaaf](https://github.com/BenjaminSchaaf))