active_public_resources 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NDA3ZjczNDA1MmRjMDhiMzdkNzMwNDkyY2I4NjZmZmMwNGFmN2YxYQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NDliYWYzMjQ3NmM0ZDIxOTA4NThlOTJmNTE3NjEwYTY4MDMyYzM5ZQ==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Yzk1Njk5MmY3NDhlY2U3MDFkMmNmZjQxZmI2Njk3ZWZhNzM1NjY0ZDA1NGNl
|
10
|
+
MWY3ODM3Y2JiY2Q5OTFmODY2MWJkMTRiYjk0OWRiZTUxYmU4ZWRiMjExNjkw
|
11
|
+
NTNhYmYxMGU2MTg5YmVhZmRmNzE5NTExNzYxNGZiMzExNWQ2YjM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
Yjk3MjFmMDY2MWI4YTcyYWYzMWJiNDZkNWVjZmUyN2YxNzgyY2Q0NzZhYzQw
|
14
|
+
YjJjMzAzZmFmYWU5NDk2ZmU3ODQ1YzU2ZDc2ZjViMjdjMjY0ZWI2OWIzODNk
|
15
|
+
NGE1ZTFmNTRmYWQyOWQ5YWRiZjNmY2IyODQ1NjIyYmM5M2M1ODI=
|
@@ -1,41 +1,53 @@
|
|
1
1
|
require 'net/https'
|
2
|
+
require 'iso8601'
|
2
3
|
|
3
4
|
module ActivePublicResources
|
4
5
|
module Drivers
|
5
6
|
class Youtube < Driver
|
6
7
|
|
7
8
|
DRIVER_NAME = "youtube"
|
9
|
+
API_KEY = ENV['YOUTUBE_API_KEY']
|
8
10
|
|
9
11
|
def perform_request(request_criteria)
|
10
12
|
request_criteria.validate_presence!([:query])
|
11
|
-
|
12
|
-
uri = URI('https://gdata.youtube.com/feeds/api/videos')
|
13
|
+
uri = URI('https://www.googleapis.com/youtube/v3/search')
|
13
14
|
params = {
|
14
|
-
'v' => 2,
|
15
15
|
'q' => request_criteria.query,
|
16
|
-
'
|
17
|
-
'
|
16
|
+
'part' => 'snippet',
|
17
|
+
'type' => 'video',
|
18
|
+
'order' => sort(request_criteria.sort),
|
18
19
|
'safeSearch' => content_filter(request_criteria.content_filter),
|
19
|
-
'
|
20
|
-
'
|
20
|
+
'maxResults' => request_criteria.per_page || 25,
|
21
|
+
'key' => API_KEY
|
21
22
|
}
|
23
|
+
params['pageToken'] = request_criteria.page if request_criteria.is_a? String
|
24
|
+
params['userIp'] = request_criteria.remote_ip if request_criteria.remote_ip
|
22
25
|
|
23
26
|
uri.query = URI.encode_www_form(params)
|
24
27
|
|
25
28
|
res = Net::HTTP.get_response(uri)
|
26
29
|
results = JSON.parse(res.body)
|
27
|
-
|
28
|
-
return parse_results(request_criteria, results)
|
30
|
+
return video_details(request_criteria, results)
|
29
31
|
end
|
30
32
|
|
31
33
|
private
|
32
34
|
|
35
|
+
def video_details(request_criteria, results)
|
36
|
+
video_ids = results['items'].map { |item| item['id']['videoId']}
|
37
|
+
uri = URI('https://www.googleapis.com/youtube/v3/videos')
|
38
|
+
params = { 'part' => 'snippet,contentDetails,statistics', 'id' => video_ids.join(','), 'key' => API_KEY }
|
39
|
+
uri.query = URI.encode_www_form(params)
|
40
|
+
res = Net::HTTP.get_response(uri)
|
41
|
+
videos = JSON.parse(res.body)['items']
|
42
|
+
return parse_results(request_criteria, results, videos)
|
43
|
+
end
|
44
|
+
|
33
45
|
def sort(val)
|
34
46
|
case val
|
35
47
|
when APR::RequestCriteria::SORT_RELEVANCE
|
36
48
|
'relevance'
|
37
49
|
when APR::RequestCriteria::SORT_RECENT
|
38
|
-
'
|
50
|
+
'date'
|
39
51
|
when APR::RequestCriteria::SORT_POPULAR
|
40
52
|
'viewCount'
|
41
53
|
else
|
@@ -54,45 +66,47 @@ module ActivePublicResources
|
|
54
66
|
end
|
55
67
|
end
|
56
68
|
|
57
|
-
def parse_results(request_criteria, results)
|
69
|
+
def parse_results(request_criteria, results, videos)
|
58
70
|
@driver_response = DriverResponse.new(
|
59
71
|
:criteria => request_criteria,
|
60
72
|
:next_criteria => next_criteria(request_criteria, results),
|
61
|
-
:total_items => results['
|
62
|
-
:items =>
|
73
|
+
:total_items => results['pageInfo']['totalResults'].to_i,
|
74
|
+
:items => videos.map { |video| parse_video(video) }
|
63
75
|
)
|
64
76
|
end
|
65
77
|
|
66
78
|
def next_criteria(request_criteria, results)
|
67
|
-
|
68
|
-
per_page = results['feed']['openSearch$itemsPerPage']['$t'].to_i
|
69
|
-
total = results['feed']['openSearch$totalResults']['$t'].to_i
|
70
|
-
if (start_index + per_page) < total
|
79
|
+
if results['nextPageToken']
|
71
80
|
return RequestCriteria.new({
|
72
81
|
:query => request_criteria.query,
|
73
|
-
:page =>
|
74
|
-
:per_page =>
|
82
|
+
:page => results['nextPageToken'],
|
83
|
+
:per_page => results['pageInfo']['resultsPerPage'].to_i
|
75
84
|
})
|
76
85
|
end
|
77
86
|
end
|
78
87
|
|
79
|
-
|
80
|
-
|
88
|
+
|
89
|
+
|
90
|
+
def parse_video(item)
|
91
|
+
video_id = item['id']
|
92
|
+
snippet = item['snippet']
|
93
|
+
statistics = item['statistics']
|
94
|
+
details = item['contentDetails']
|
81
95
|
video = APR::ResponseTypes::Video.new
|
82
|
-
video.id
|
83
|
-
video.title
|
84
|
-
video.description
|
85
|
-
video.thumbnail_url
|
86
|
-
video.url
|
87
|
-
video.embed_url
|
88
|
-
video.duration
|
89
|
-
video.num_views
|
90
|
-
video.num_likes
|
91
|
-
video.num_comments
|
92
|
-
video.created_date
|
93
|
-
video.username
|
94
|
-
video.width
|
95
|
-
video.height
|
96
|
+
video.id = video_id
|
97
|
+
video.title = snippet['title']
|
98
|
+
video.description = snippet['description']
|
99
|
+
video.thumbnail_url = snippet['thumbnails']['default']['url']
|
100
|
+
video.url = "https://www.youtube.com/watch?v=#{video_id}&feature=youtube_gdata_player"
|
101
|
+
video.embed_url = "https://www.youtube.com/embed/#{video_id}?feature=oembed"
|
102
|
+
video.duration = ISO8601::Duration.new(details['duration']).to_seconds
|
103
|
+
video.num_views = statistics['viewCount'] ? statistics['viewCount'].to_i : 0
|
104
|
+
video.num_likes = statistics['likeCount'] ? statistics['likeCount'].to_i : 0
|
105
|
+
video.num_comments = statistics['commentCount'] ? statistics['commentCount'] : 0
|
106
|
+
video.created_date = Date.parse(snippet['publishedAt'])
|
107
|
+
video.username = snippet['channelTitle']
|
108
|
+
video.width = 640
|
109
|
+
video.height = 360
|
96
110
|
|
97
111
|
# Return Types
|
98
112
|
video.return_types << APR::ReturnTypes::Url.new(
|
@@ -105,7 +119,7 @@ module ActivePublicResources
|
|
105
119
|
video.return_types << APR::ReturnTypes::Iframe.new(
|
106
120
|
:driver => DRIVER_NAME,
|
107
121
|
:remote_id => video.id,
|
108
|
-
:url =>
|
122
|
+
:url => video.embed_url,
|
109
123
|
:text => video.title,
|
110
124
|
:title => video.title,
|
111
125
|
:width => 640,
|
@@ -13,7 +13,7 @@ module ActivePublicResources
|
|
13
13
|
CONTENT_FILTER_STRICT = 'strict'
|
14
14
|
]
|
15
15
|
|
16
|
-
attr_accessor :query, :page, :per_page, :content_filter, :sort, :folder
|
16
|
+
attr_accessor :query, :page, :per_page, :content_filter, :sort, :folder, :remote_ip
|
17
17
|
|
18
18
|
def initialize(args={})
|
19
19
|
args.each do |k,v|
|
metadata
CHANGED
@@ -1,43 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_public_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.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: 2015-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - '>='
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 4.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - '>='
|
24
|
+
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 4.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activemodel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - '>='
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 4.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - '>='
|
38
|
+
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 4.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: iso8601
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.8.6
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.8.6
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: vimeo
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +80,7 @@ dependencies:
|
|
66
80
|
- - ~>
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '1.3'
|
69
|
-
description: ' Normalized searching and browsing of public resources '
|
83
|
+
description: ! ' Normalized searching and browsing of public resources '
|
70
84
|
email:
|
71
85
|
- cavneb@gmail.com
|
72
86
|
executables: []
|
@@ -148,17 +162,17 @@ require_paths:
|
|
148
162
|
- lib
|
149
163
|
required_ruby_version: !ruby/object:Gem::Requirement
|
150
164
|
requirements:
|
151
|
-
- - '>='
|
165
|
+
- - ! '>='
|
152
166
|
- !ruby/object:Gem::Version
|
153
167
|
version: '0'
|
154
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
169
|
requirements:
|
156
|
-
- - '>='
|
170
|
+
- - ! '>='
|
157
171
|
- !ruby/object:Gem::Version
|
158
172
|
version: '0'
|
159
173
|
requirements: []
|
160
174
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.2.
|
175
|
+
rubygems_version: 2.2.2
|
162
176
|
signing_key:
|
163
177
|
specification_version: 4
|
164
178
|
summary: Normalized searching and browsing of public resources
|