active_public_resources 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_public_resources/drivers/youtube.rb +32 -35
- data/lib/active_public_resources/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 750a849ad37794a269bab5b663992a2ee9101a10
|
4
|
+
data.tar.gz: 17a0f5735242ebd52b93b020a3deb4a931ae3376
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d859e2ffb42e9b9dfa2b0e2bca4401de468d0e5aa34aeeb65e90b5a622436af796fadfe6014c1104b45fd12bdf10b77f10e032c8cd4c205f62aff20977b0e37d
|
7
|
+
data.tar.gz: 9953aebb19aa8ea776f35d8b98e74d4e90115781f0cb8f8e47390baa67965231be473f841b4047dde577fadb4d7fa495d99bb0259dd66838d4f16a37713f55c5
|
@@ -18,21 +18,21 @@ module ActivePublicResources
|
|
18
18
|
def perform_request(request_criteria)
|
19
19
|
request_criteria.set_default_criteria!(@default_request_criteria)
|
20
20
|
unless request_criteria.validate_presence(:query) || request_criteria.validate_presence(:channel)
|
21
|
-
raise ArgumentError "
|
21
|
+
raise ArgumentError "You must specify at least a query or channel"
|
22
22
|
end
|
23
23
|
|
24
24
|
uri = URI('https://www.googleapis.com/youtube/v3/search')
|
25
25
|
params = {
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
q: request_criteria.query,
|
27
|
+
part: 'snippet',
|
28
|
+
type: 'video',
|
29
|
+
order: sort(request_criteria.sort),
|
30
|
+
safeSearch: content_filter(request_criteria.content_filter),
|
31
|
+
maxResults: request_criteria.per_page || 25,
|
32
|
+
key: API_KEY
|
33
33
|
}
|
34
34
|
|
35
|
-
params['pageToken'] = request_criteria.page if request_criteria.
|
35
|
+
params['pageToken'] = request_criteria.page if request_criteria.page && request_criteria.page != 1
|
36
36
|
params['userIp'] = request_criteria.remote_ip if request_criteria.remote_ip
|
37
37
|
params['channelId'] = channel_id(request_criteria.channel_name) if channel_id(request_criteria.channel_name)
|
38
38
|
|
@@ -50,10 +50,10 @@ module ActivePublicResources
|
|
50
50
|
if channel_name
|
51
51
|
uri = URI('https://www.googleapis.com/youtube/v3/search')
|
52
52
|
params = {
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
q: channel_name,
|
54
|
+
part: 'id',
|
55
|
+
type: 'channel',
|
56
|
+
key: API_KEY
|
57
57
|
}
|
58
58
|
uri.query = URI.encode_www_form(params)
|
59
59
|
res = Net::HTTP.get_response(uri)
|
@@ -64,7 +64,6 @@ module ActivePublicResources
|
|
64
64
|
return false
|
65
65
|
end
|
66
66
|
|
67
|
-
|
68
67
|
def video_details(request_criteria, results)
|
69
68
|
video_ids = results['items'].map { |item| item['id']['videoId']}
|
70
69
|
uri = URI('https://www.googleapis.com/youtube/v3/videos')
|
@@ -101,25 +100,23 @@ module ActivePublicResources
|
|
101
100
|
|
102
101
|
def parse_results(request_criteria, results, videos)
|
103
102
|
@driver_response = DriverResponse.new(
|
104
|
-
:
|
105
|
-
:
|
106
|
-
:
|
107
|
-
:
|
103
|
+
criteria: request_criteria,
|
104
|
+
next_criteria: next_criteria(request_criteria, results),
|
105
|
+
total_items: results['pageInfo']['totalResults'].to_i,
|
106
|
+
items: videos.map { |video| parse_video(video) }
|
108
107
|
)
|
109
108
|
end
|
110
109
|
|
111
110
|
def next_criteria(request_criteria, results)
|
112
111
|
if results['nextPageToken']
|
113
112
|
return RequestCriteria.new({
|
114
|
-
:
|
115
|
-
:
|
116
|
-
:
|
113
|
+
query: request_criteria.query,
|
114
|
+
page: results['nextPageToken'],
|
115
|
+
per_page: results['pageInfo']['resultsPerPage'].to_i
|
117
116
|
})
|
118
117
|
end
|
119
118
|
end
|
120
119
|
|
121
|
-
|
122
|
-
|
123
120
|
def parse_video(item)
|
124
121
|
video_id = item['id']
|
125
122
|
snippet = item['snippet']
|
@@ -143,20 +140,20 @@ module ActivePublicResources
|
|
143
140
|
|
144
141
|
# Return Types
|
145
142
|
video.return_types << APR::ReturnTypes::Url.new(
|
146
|
-
:
|
147
|
-
:
|
148
|
-
:
|
149
|
-
:
|
150
|
-
:
|
143
|
+
driver: DRIVER_NAME,
|
144
|
+
remote_id: video.id,
|
145
|
+
url: video.url,
|
146
|
+
text: video.title,
|
147
|
+
title: video.title
|
151
148
|
)
|
152
149
|
video.return_types << APR::ReturnTypes::Iframe.new(
|
153
|
-
:
|
154
|
-
:
|
155
|
-
:
|
156
|
-
:
|
157
|
-
:
|
158
|
-
:
|
159
|
-
:
|
150
|
+
driver: DRIVER_NAME,
|
151
|
+
remote_id: video.id,
|
152
|
+
url: video.embed_url,
|
153
|
+
text: video.title,
|
154
|
+
title: video.title,
|
155
|
+
width: 640,
|
156
|
+
height: 360
|
160
157
|
)
|
161
158
|
|
162
159
|
video
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_public_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Berry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|