youku_client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/Gemfile +3 -0
- data/LICENSE +202 -0
- data/README.md +51 -0
- data/Rakefile +23 -0
- data/lib/youku/client.rb +43 -0
- data/lib/youku/v2/base.rb +9 -0
- data/lib/youku/v2/request.rb +53 -0
- data/lib/youku/v2/searches.rb +40 -0
- data/lib/youku/v2/users.rb +24 -0
- data/lib/youku/v2/videos.rb +62 -0
- data/lib/youku/version.rb +5 -0
- data/lib/youku_client.rb +19 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/support/shared_examples/youku_api_v2_examples.rb +14 -0
- data/spec/youku/client_spec.rb +27 -0
- data/spec/youku/v2/searches_spec.rb +39 -0
- data/spec/youku/v2/users_spec.rb +25 -0
- data/spec/youku/v2/videos_spec.rb +62 -0
- data/youku_client.gemspec +23 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f76877012802d8935a608f187c306eec028155eb
|
4
|
+
data.tar.gz: 42da00ca401e82d36bead60eabaef77340e5c91a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 76b6cb74aa40cb19966a356e2c313cb377db4c592c06800475731064662c2c73dd3d163991d673de8344e920bd7eca3b31c3cf54180f24a5cc2d88152776d830
|
7
|
+
data.tar.gz: dc2a550d00565bcb80e9841db7241d6531315d97ed02ace0a5ea0410f94b644241d94970b22942f27e4e48d1a158e78e8c1c4bdb01a7e8ffb4edc6efd2892161
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright 2015 Shuttlerock Ltd.
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
l
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Youku Ruby Gem
|
2
|
+
|
3
|
+
This is the unofficial Ruby wrapper for the Youku v2 API. It supports not all
|
4
|
+
endpoints currently available on the
|
5
|
+
[Youku API](http://open.youku.com/docs?id=0).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
gem install youku_client
|
10
|
+
|
11
|
+
### Some quick examples
|
12
|
+
|
13
|
+
First, instantiate the Client class:
|
14
|
+
|
15
|
+
>> client = Youku.new(client_id: 'id', client_secret: 'secret')
|
16
|
+
|
17
|
+
Get users by IDs:
|
18
|
+
|
19
|
+
>> client.users.show_batch(user_ids: '1,2')
|
20
|
+
|
21
|
+
Implemented API endpoints:
|
22
|
+
|
23
|
+
- `searches.video.by_keyword`
|
24
|
+
- `users.show_batch`
|
25
|
+
- `videos.video.by_user`
|
26
|
+
- `videos.video.show_batch`
|
27
|
+
- `videos.video.show`
|
28
|
+
|
29
|
+
### Contributions and Pull Requests
|
30
|
+
|
31
|
+
No request is too small and I encourage everyone to get involved. So
|
32
|
+
please if you would like to contribute, let me know and throw me a pull request!
|
33
|
+
|
34
|
+
### Requirements
|
35
|
+
|
36
|
+
* Ruby 1.9.x or 2.x.x
|
37
|
+
|
38
|
+
---
|
39
|
+
|
40
|
+
Copyright 2015 Shuttlerock Ltd.
|
41
|
+
|
42
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
43
|
+
use this work except in compliance with the License. You may obtain a copy of
|
44
|
+
the License in the LICENSE file, or at:
|
45
|
+
|
46
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
47
|
+
|
48
|
+
Unless required by applicable law or agreed to in writing, software
|
49
|
+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
50
|
+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
51
|
+
License for the specific language governing permissions and limitations.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
require File.dirname(__FILE__) + '/lib/youku/version'
|
5
|
+
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
task :build => :test do
|
9
|
+
system 'gem build youku_client.gemspec'
|
10
|
+
end
|
11
|
+
|
12
|
+
task :release => :build do
|
13
|
+
# tag and push
|
14
|
+
system "git tag v#{Youku::VERSION}"
|
15
|
+
system "git push origin --tags"
|
16
|
+
# push the gem
|
17
|
+
system "gem push youku_client-#{Youku::VERSION}.gem"
|
18
|
+
end
|
19
|
+
|
20
|
+
RSpec::Core::RakeTask.new(:test) do |t|
|
21
|
+
t.pattern = 'spec/**/*_spec.rb'
|
22
|
+
fail_on_error = true # be explicit
|
23
|
+
end
|
data/lib/youku/client.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Youku
|
2
|
+
class Client
|
3
|
+
BASE_URI = 'https://openapi.youku.com'
|
4
|
+
|
5
|
+
attr_reader :client_id, :client_secret
|
6
|
+
|
7
|
+
# Public: Constructor.
|
8
|
+
#
|
9
|
+
# client_id - The String Youku client ID.
|
10
|
+
# client_secret - The String Youku secret key.
|
11
|
+
def initialize(client_id: nil, client_secret: nil)
|
12
|
+
@client_id = client_id
|
13
|
+
@client_secret = client_secret
|
14
|
+
end
|
15
|
+
|
16
|
+
# Public: Get searches API.
|
17
|
+
#
|
18
|
+
# Returns the instance of Youku::V2::Searches.
|
19
|
+
def searches
|
20
|
+
Youku::V2::Searches.new(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Public: Get videos API.
|
24
|
+
#
|
25
|
+
# Returns the instance of Youku::V2::Videos.
|
26
|
+
def videos
|
27
|
+
Youku::V2::Videos.new(self)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Public: Get users API.
|
31
|
+
#
|
32
|
+
# Returns the instance of Youku::V2::Users.
|
33
|
+
def users
|
34
|
+
Youku::V2::Users.new(self)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
require 'youku/v2/base'
|
41
|
+
require 'youku/v2/searches'
|
42
|
+
require 'youku/v2/users'
|
43
|
+
require 'youku/v2/videos'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'typhoeus'
|
2
|
+
|
3
|
+
module Youku
|
4
|
+
module V2
|
5
|
+
class Request
|
6
|
+
attr_reader :url, :params, :response
|
7
|
+
|
8
|
+
# Public: Constructor.
|
9
|
+
#
|
10
|
+
# url - The String url.
|
11
|
+
# params - The Hash query params.
|
12
|
+
def initialize(url, params)
|
13
|
+
@url = url
|
14
|
+
@params = params
|
15
|
+
@response = Typhoeus::Request.new(url, params: params, connecttimeout: 5, timeout: 10).run
|
16
|
+
end
|
17
|
+
|
18
|
+
# Public: Get next page.
|
19
|
+
#
|
20
|
+
# Returns the instance of Youku::V2::Request.
|
21
|
+
def next_page
|
22
|
+
Request.new url, params.merge(page: params[:page] + 1)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns true at successful request , false otherwise.
|
26
|
+
def ok?
|
27
|
+
response.code == 200
|
28
|
+
end
|
29
|
+
|
30
|
+
# Public: Get response code.
|
31
|
+
#
|
32
|
+
# Returns Integer code of response.
|
33
|
+
def code
|
34
|
+
response.code
|
35
|
+
end
|
36
|
+
|
37
|
+
# Public: Get return code.
|
38
|
+
#
|
39
|
+
# Returns Integer return code.
|
40
|
+
def return_code
|
41
|
+
response.return_code
|
42
|
+
end
|
43
|
+
|
44
|
+
# Public: Get body.
|
45
|
+
#
|
46
|
+
# Returns the instance of Hashie::Mash.
|
47
|
+
def body
|
48
|
+
@body ||= Hashie::Mash.new(MultiJson.load response.body || '')
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Youku
|
2
|
+
module V2
|
3
|
+
class Searches < Base
|
4
|
+
|
5
|
+
# Public: Get video API.
|
6
|
+
#
|
7
|
+
# Returns the instance of Youku::V2::Searches::Video.
|
8
|
+
def video
|
9
|
+
Video.new(client)
|
10
|
+
end
|
11
|
+
|
12
|
+
class Video < Base
|
13
|
+
BASE_URI = "#{BASE_URI}/searches/video"
|
14
|
+
|
15
|
+
# Public: Get videos by keyword.
|
16
|
+
#
|
17
|
+
# See: http://open.youku.com/docs?id=81
|
18
|
+
#
|
19
|
+
# keyword - The space separated String of keywords.
|
20
|
+
# period - The String period.
|
21
|
+
# orderby - The String order of videos.
|
22
|
+
# page - The Integer page number.
|
23
|
+
# count - The Integer page size.
|
24
|
+
#
|
25
|
+
# Returns the instance of Youku::V2::Request.
|
26
|
+
def by_keyword(keyword, period: 'week', orderby: 'published', page: 1, count: 20)
|
27
|
+
Youku::V2::Request.new "#{BASE_URI}/by_keyword.json", {
|
28
|
+
client_id: client.client_id,
|
29
|
+
keyword: keyword,
|
30
|
+
period: period,
|
31
|
+
orderby: orderby,
|
32
|
+
page: page,
|
33
|
+
count: count
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Youku
|
2
|
+
module V2
|
3
|
+
class Users < Base
|
4
|
+
BASE_URI = "#{BASE_URI}/users"
|
5
|
+
|
6
|
+
# Public: Get users by IDs
|
7
|
+
#
|
8
|
+
# See: http://open.youku.com/docs?id=25
|
9
|
+
#
|
10
|
+
# user_ids - The comma separated String of user IDs.
|
11
|
+
# user_names - The comma separated String of user names.
|
12
|
+
#
|
13
|
+
# Returns the instance of Youku::V2::Request.
|
14
|
+
def show_batch(user_ids: nil, user_names: nil)
|
15
|
+
Youku::V2::Request.new "#{BASE_URI}/show_batch.json", {
|
16
|
+
client_id: client.client_id,
|
17
|
+
user_ids: user_ids,
|
18
|
+
user_names: user_names
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Youku
|
2
|
+
module V2
|
3
|
+
class Videos < Base
|
4
|
+
BASE_URI = "#{BASE_URI}/videos"
|
5
|
+
|
6
|
+
# Public: Get videos for given Youku user.
|
7
|
+
#
|
8
|
+
# See: http://open.youku.com/docs?id=49
|
9
|
+
#
|
10
|
+
# user_id - The String Youku user ID.
|
11
|
+
# user_name - The String Youku user name.
|
12
|
+
# orderby - The String order of videos.
|
13
|
+
# page - The Integer page number.
|
14
|
+
# count - The Integer page size.
|
15
|
+
#
|
16
|
+
# Returns the instance of Youku::V2::Request.
|
17
|
+
def by_user(user_id: nil, user_name: nil, orderby: 'published', page: 1, count: 20)
|
18
|
+
Youku::V2::Request.new "#{BASE_URI}/by_user.json", {
|
19
|
+
client_id: client.client_id,
|
20
|
+
user_id: user_id,
|
21
|
+
user_name: user_name,
|
22
|
+
orderby: orderby,
|
23
|
+
page: page,
|
24
|
+
count: count
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
# Public: Get video by ID
|
29
|
+
#
|
30
|
+
# See: http://open.youku.com/docs?id=46
|
31
|
+
#
|
32
|
+
# video_id - The String video ID.
|
33
|
+
# ext - The String video extension information.
|
34
|
+
#
|
35
|
+
# Returns the instance of Youku::V2::Request.
|
36
|
+
def show(video_id, ext: nil)
|
37
|
+
Youku::V2::Request.new "#{BASE_URI}/show.json", {
|
38
|
+
client_id: client.client_id,
|
39
|
+
video_id: video_id,
|
40
|
+
ext: ext
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
# Public: Get videos by IDs
|
45
|
+
#
|
46
|
+
# See: http://open.youku.com/docs?id=47
|
47
|
+
#
|
48
|
+
# video_ids - The comma separated String of video IDs.
|
49
|
+
# ext - The String video extension information.
|
50
|
+
#
|
51
|
+
# Returns the instance of Youku::V2::Request.
|
52
|
+
def show_batch(video_ids: nil, ext: nil)
|
53
|
+
Youku::V2::Request.new "#{BASE_URI}/show_batch.json", {
|
54
|
+
client_id: client.client_id,
|
55
|
+
video_ids: video_ids,
|
56
|
+
ext: ext
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/youku_client.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'youku/client'
|
2
|
+
|
3
|
+
module Youku
|
4
|
+
|
5
|
+
autoload :VERSION, File.join(File.dirname(__FILE__), 'youku/version')
|
6
|
+
|
7
|
+
class << self
|
8
|
+
# Public: Constructor.
|
9
|
+
#
|
10
|
+
# client_id - The String Youku client ID.
|
11
|
+
# client_secret - The String Youku secret key.
|
12
|
+
#
|
13
|
+
# Returns the instance of Youku::Client.
|
14
|
+
def new(client_id: nil, client_secret: nil)
|
15
|
+
Youku::Client.new(client_id: client_id, client_secret: client_secret)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
shared_examples 'a base Youku API V2 requests' do
|
2
|
+
|
3
|
+
it { expect(subject).to be_a Youku::V2::Request }
|
4
|
+
it { expect(subject.ok?).to be_truthy }
|
5
|
+
|
6
|
+
context '400 response code on request' do
|
7
|
+
before do
|
8
|
+
stub_request(:get, url).with(query: query).to_return(status: 404)
|
9
|
+
end
|
10
|
+
|
11
|
+
it { expect { subject }.to_not raise_error }
|
12
|
+
it { expect(subject.ok?).to be_falsy }
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Youku::Client do
|
4
|
+
|
5
|
+
let(:client) { Youku::Client.new }
|
6
|
+
|
7
|
+
describe '#searches' do
|
8
|
+
subject { client.searches }
|
9
|
+
|
10
|
+
it { expect(subject).to be_a Youku::V2::Searches }
|
11
|
+
it { expect(subject.client).to eq client }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#videos' do
|
15
|
+
subject { client.videos }
|
16
|
+
|
17
|
+
it { expect(subject).to be_a Youku::V2::Videos }
|
18
|
+
it { expect(subject.client).to eq client }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#users' do
|
22
|
+
subject { client.users }
|
23
|
+
|
24
|
+
it { expect(subject).to be_a Youku::V2::Users }
|
25
|
+
it { expect(subject.client).to eq client }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Youku::V2::Searches do
|
4
|
+
|
5
|
+
let(:client) { Youku::Client.new(client_id: 'client-id') }
|
6
|
+
let(:searches) { Youku::V2::Searches.new(client) }
|
7
|
+
|
8
|
+
describe '#video' do
|
9
|
+
subject { searches.video }
|
10
|
+
|
11
|
+
it { expect(subject).to be_a Youku::V2::Searches::Video }
|
12
|
+
it { expect(subject.client).to eq client }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '::Video' do
|
16
|
+
let(:video) { Youku::V2::Searches::Video.new(client) }
|
17
|
+
|
18
|
+
describe '#by_keyword' do
|
19
|
+
let(:url) { 'https://openapi.youku.com/v2/searches/video/by_keyword.json' }
|
20
|
+
let(:query) { {
|
21
|
+
client_id: client.client_id,
|
22
|
+
keyword: 2014,
|
23
|
+
period: 'week',
|
24
|
+
orderby: 'published',
|
25
|
+
page: 1,
|
26
|
+
count: 20
|
27
|
+
} }
|
28
|
+
|
29
|
+
before do
|
30
|
+
stub_request(:get, url).with(query: query).to_return(status: 200)
|
31
|
+
end
|
32
|
+
|
33
|
+
subject { video.by_keyword(2014) }
|
34
|
+
|
35
|
+
it_should_behave_like 'a base Youku API V2 requests'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Youku::V2::Users do
|
4
|
+
|
5
|
+
let(:client) { Youku::Client.new(client_id: 'client-id') }
|
6
|
+
let(:users) { Youku::V2::Users.new(client) }
|
7
|
+
|
8
|
+
describe '#show_batch' do
|
9
|
+
let(:url) { 'https://openapi.youku.com/v2/users/show_batch.json' }
|
10
|
+
let(:query) { {
|
11
|
+
client_id: client.client_id,
|
12
|
+
user_ids: nil,
|
13
|
+
user_names: 'jackie_chan',
|
14
|
+
} }
|
15
|
+
|
16
|
+
before do
|
17
|
+
stub_request(:get, url).with(query: query).to_return(status: 200)
|
18
|
+
end
|
19
|
+
|
20
|
+
subject { users.show_batch(user_names: 'jackie_chan') }
|
21
|
+
|
22
|
+
it_should_behave_like 'a base Youku API V2 requests'
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Youku::V2::Videos do
|
4
|
+
|
5
|
+
let(:client) { Youku::Client.new(client_id: 'client-id') }
|
6
|
+
let(:videos) { Youku::V2::Videos.new(client) }
|
7
|
+
|
8
|
+
describe '#show_batch' do
|
9
|
+
let(:url) { 'https://openapi.youku.com/v2/videos/show_batch.json' }
|
10
|
+
let(:query) { {
|
11
|
+
client_id: client.client_id,
|
12
|
+
video_ids: 123,
|
13
|
+
ext: nil,
|
14
|
+
} }
|
15
|
+
|
16
|
+
before do
|
17
|
+
stub_request(:get, url).with(query: query).to_return(status: 200)
|
18
|
+
end
|
19
|
+
|
20
|
+
subject { videos.show_batch(video_ids: 123) }
|
21
|
+
|
22
|
+
it_should_behave_like 'a base Youku API V2 requests'
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#show' do
|
26
|
+
let(:url) { 'https://openapi.youku.com/v2/videos/show.json' }
|
27
|
+
let(:query) { {
|
28
|
+
client_id: client.client_id,
|
29
|
+
video_id: 123,
|
30
|
+
ext: nil,
|
31
|
+
} }
|
32
|
+
|
33
|
+
before do
|
34
|
+
stub_request(:get, url).with(query: query).to_return(status: 200)
|
35
|
+
end
|
36
|
+
|
37
|
+
subject { videos.show(123) }
|
38
|
+
|
39
|
+
it_should_behave_like 'a base Youku API V2 requests'
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#by_user' do
|
43
|
+
let(:url) { 'https://openapi.youku.com/v2/videos/by_user.json' }
|
44
|
+
let(:query) { {
|
45
|
+
client_id: client.client_id,
|
46
|
+
user_id: 123,
|
47
|
+
user_name: nil,
|
48
|
+
orderby: 'published',
|
49
|
+
page: 1,
|
50
|
+
count: 20
|
51
|
+
} }
|
52
|
+
|
53
|
+
before do
|
54
|
+
stub_request(:get, url).with(query: query).to_return(status: 200)
|
55
|
+
end
|
56
|
+
|
57
|
+
subject { videos.by_user(user_id: 123) }
|
58
|
+
|
59
|
+
it_should_behave_like 'a base Youku API V2 requests'
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require File.join(File.dirname(__FILE__), 'lib/youku/version')
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.add_dependency 'typhoeus'
|
6
|
+
gem.add_dependency 'hashie'
|
7
|
+
gem.add_development_dependency 'rake'
|
8
|
+
gem.add_development_dependency 'rspec'
|
9
|
+
gem.add_development_dependency 'webmock'
|
10
|
+
gem.authors = ['Alexey Vokhmin', 'Dave Perrett', 'Oleg Dashevskii']
|
11
|
+
gem.description = %q{A Ruby wrapper for the Youku v2 API}
|
12
|
+
gem.email = ['avokhmin@gmail.com', 'dave@recurser.com', 'be9@be9.ru']
|
13
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
14
|
+
gem.files = `git ls-files`.split("\n")
|
15
|
+
gem.homepage = "https://github.com/Shuttlerock/youku_client"
|
16
|
+
gem.license = "Apache"
|
17
|
+
gem.name = "youku_client"
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
|
20
|
+
gem.summary = %q{Youku API wrapper}
|
21
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
gem.version = Youku::VERSION
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: youku_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexey Vokhmin
|
8
|
+
- Dave Perrett
|
9
|
+
- Oleg Dashevskii
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2015-07-20 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: typhoeus
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - ">="
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: hashie
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rake
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: rspec
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: webmock
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
description: A Ruby wrapper for the Youku v2 API
|
86
|
+
email:
|
87
|
+
- avokhmin@gmail.com
|
88
|
+
- dave@recurser.com
|
89
|
+
- be9@be9.ru
|
90
|
+
executables: []
|
91
|
+
extensions: []
|
92
|
+
extra_rdoc_files: []
|
93
|
+
files:
|
94
|
+
- ".gitignore"
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- lib/youku/client.rb
|
100
|
+
- lib/youku/v2/base.rb
|
101
|
+
- lib/youku/v2/request.rb
|
102
|
+
- lib/youku/v2/searches.rb
|
103
|
+
- lib/youku/v2/users.rb
|
104
|
+
- lib/youku/v2/videos.rb
|
105
|
+
- lib/youku/version.rb
|
106
|
+
- lib/youku_client.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
- spec/support/shared_examples/youku_api_v2_examples.rb
|
109
|
+
- spec/youku/client_spec.rb
|
110
|
+
- spec/youku/v2/searches_spec.rb
|
111
|
+
- spec/youku/v2/users_spec.rb
|
112
|
+
- spec/youku/v2/videos_spec.rb
|
113
|
+
- youku_client.gemspec
|
114
|
+
homepage: https://github.com/Shuttlerock/youku_client
|
115
|
+
licenses:
|
116
|
+
- Apache
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.3.6
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.4.7
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Youku API wrapper
|
138
|
+
test_files:
|
139
|
+
- spec/spec_helper.rb
|
140
|
+
- spec/support/shared_examples/youku_api_v2_examples.rb
|
141
|
+
- spec/youku/client_spec.rb
|
142
|
+
- spec/youku/v2/searches_spec.rb
|
143
|
+
- spec/youku/v2/users_spec.rb
|
144
|
+
- spec/youku/v2/videos_spec.rb
|