Skip to content
This repository has been archived by the owner on Sep 25, 2020. It is now read-only.

Implemented schemas.video.category #8

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
57 changes: 32 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 8 additions & 0 deletions lib/youku/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -48,3 +55,4 @@ def comments
require 'youku/v2/users'
require 'youku/v2/videos'
require 'youku/v2/comments'
require 'youku/v2/schemas'
2 changes: 1 addition & 1 deletion lib/youku/v2/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions lib/youku/v2/schemas.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Youku
module V2
class Schemas < Base
BASE_URI = "#{BASE_URI}/schemas"

# Public: Get video API.
#
# Returns the instance of Youku::V2::Schemas::Video.
def video
Video.new(client)
end

class Video < Base
BASE_URI = "#{BASE_URI}/video"

# Public: Get video categories.
#
# See: http://open.youku.com/docs?id=90
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ curl -vvv http://open.youku.com/docs?id=90
< HTTP/1.1 301 Moved Permanently
...
< Location: http://cloud.youku.com?id=90

Can you change to http://cloud.youku.com/docs?id=90

#
# Returns the instance of Youku::V2::Request.
def category()
Youku::V2::Request.new "#{BASE_URI}/category.json"
end
end
end
end
end
28 changes: 28 additions & 0 deletions spec/youku/v2/schemas_spec.rb
Original file line number Diff line number Diff line change
@@ -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