edi 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/demo.gif +0 -0
- data/lib/edi/application.rb +14 -0
- data/lib/edi/services.rb +1 -0
- data/lib/edi/services/youtube.rb +42 -0
- data/lib/edi/version.rb +1 -1
- data/spec/services/youtube_spec.rb +7 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/support/fixtures/vcr_cassettes/youtube.yml +197 -0
- data/templates/project/.gitignore +0 -1
- data/templates/project/bot/core.rb +1 -1
- data/templates/project/config/services.yml +30 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08b997492f12ff6c87eb19a0a742646d988bc4fb
|
4
|
+
data.tar.gz: 8e4e80006cefa0a6e470dfab70d39353d4435224
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd1c0287699ba77721ea7d8e20d5f8ef3d297b691f562c48ffed6b5dee28c49e78c6c2109074a91c2b880ecffa6bc15f57d478d57b998f8041d3a53711406305
|
7
|
+
data.tar.gz: 53a05c1bce8eb200428663dc5beaea7bf3228fb0ac7ef020620d67703701dba23e3fb87b9be2df5e02d4b3f4cb91ac9e479238963f0614eab61fb46d96f47c42
|
data/README.md
CHANGED
data/demo.gif
ADDED
Binary file
|
data/lib/edi/application.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
require 'yaml'
|
1
2
|
module EDI
|
2
3
|
class Application
|
3
4
|
require 'active_support/dependencies'
|
4
5
|
|
5
6
|
def self.initialize!
|
6
7
|
add_edi_root_to_load_path
|
8
|
+
load_variables
|
7
9
|
autoload_paths
|
8
10
|
require File.join EDI.root, "bot/core"
|
9
11
|
require_initializers
|
@@ -28,5 +30,17 @@ module EDI
|
|
28
30
|
EDI.websocket.connect
|
29
31
|
end
|
30
32
|
|
33
|
+
def self.load_variables
|
34
|
+
load_yaml("config/services.yml").each do |key, value|
|
35
|
+
ENV[key] ||= value.to_s if value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def self.load_yaml(file)
|
42
|
+
YAML.load File.open(File.join(EDI.root, file)).read
|
43
|
+
end
|
44
|
+
|
31
45
|
end
|
32
46
|
end
|
data/lib/edi/services.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
class Youtube < EDI::Service
|
2
|
+
phrases "youtube"
|
3
|
+
|
4
|
+
environment :google_api_key
|
5
|
+
before_invoke :extract_search_term
|
6
|
+
|
7
|
+
def run
|
8
|
+
response = EDI.get("#{url}?#{params}").response
|
9
|
+
"https://youtu.be/#{response["items"].first["id"]["videoId"]}"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def extract_search_term
|
15
|
+
captures = text.match /youtube(?<term>.+)/i
|
16
|
+
@search_term = EDI.encode_uri(captures[:term])
|
17
|
+
end
|
18
|
+
|
19
|
+
def url
|
20
|
+
"https://www.googleapis.com/youtube/v3/search"
|
21
|
+
end
|
22
|
+
|
23
|
+
def params
|
24
|
+
[part, order, q, key].join("&")
|
25
|
+
end
|
26
|
+
|
27
|
+
def part
|
28
|
+
"part=snippet"
|
29
|
+
end
|
30
|
+
|
31
|
+
def order
|
32
|
+
"order=rating"
|
33
|
+
end
|
34
|
+
|
35
|
+
def key
|
36
|
+
"key=#{google_api_key}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def q
|
40
|
+
"q=#{@search_term}"
|
41
|
+
end
|
42
|
+
end
|
data/lib/edi/version.rb
CHANGED
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Youtube, vcr: { cassette_name: 'youtube' } do
|
4
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, youtube Harry Potter and the Half Blood Prince")) }
|
5
|
+
subject { described_class.new message }
|
6
|
+
it { expect(subject.invoke).to match /https:\/\/youtu.be/ }
|
7
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -49,5 +49,6 @@ VCR.configure do |config|
|
|
49
49
|
config.configure_rspec_metadata!
|
50
50
|
config.hook_into :webmock
|
51
51
|
config.filter_sensitive_data("<SLACK_WEBHOOK_URL>") { ENV["SLACK_WEBHOOK_URL"] }
|
52
|
+
config.filter_sensitive_data("<GOOGLE_API_KEY>") { ENV["GOOGLE_API_KEY"] }
|
52
53
|
config.allow_http_connections_when_no_cassette = true
|
53
54
|
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://www.googleapis.com/youtube/v3/search?key=<GOOGLE_API_KEY>&order=rating&part=snippet&q=%20Harry%20Potter%20and%20the%20Half%20Blood%20Prince
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept-Encoding:
|
11
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
User-Agent:
|
15
|
+
- Ruby
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Expires:
|
22
|
+
- Sun, 05 Apr 2015 01:57:17 GMT
|
23
|
+
Date:
|
24
|
+
- Sun, 05 Apr 2015 01:57:17 GMT
|
25
|
+
Cache-Control:
|
26
|
+
- private, max-age=120, must-revalidate, no-transform
|
27
|
+
Etag:
|
28
|
+
- '"OZTVc5giYjExcw9vrLsdrwdwB4c/Rqfqq96fQLysaoXmdQeaV_LGsrw"'
|
29
|
+
Vary:
|
30
|
+
- Origin
|
31
|
+
- X-Origin
|
32
|
+
Content-Type:
|
33
|
+
- application/json; charset=UTF-8
|
34
|
+
X-Content-Type-Options:
|
35
|
+
- nosniff
|
36
|
+
X-Frame-Options:
|
37
|
+
- SAMEORIGIN
|
38
|
+
X-Xss-Protection:
|
39
|
+
- 1; mode=block
|
40
|
+
Content-Length:
|
41
|
+
- '4448'
|
42
|
+
Server:
|
43
|
+
- GSE
|
44
|
+
Alternate-Protocol:
|
45
|
+
- 443:quic,p=0.5
|
46
|
+
body:
|
47
|
+
encoding: UTF-8
|
48
|
+
string: |
|
49
|
+
{
|
50
|
+
"kind": "youtube#searchListResponse",
|
51
|
+
"etag": "\"OZTVc5giYjExcw9vrLsdrwdwB4c/Rqfqq96fQLysaoXmdQeaV_LGsrw\"",
|
52
|
+
"nextPageToken": "CAUQAA",
|
53
|
+
"pageInfo": {
|
54
|
+
"totalResults": 450952,
|
55
|
+
"resultsPerPage": 5
|
56
|
+
},
|
57
|
+
"items": [
|
58
|
+
{
|
59
|
+
"kind": "youtube#searchResult",
|
60
|
+
"etag": "\"OZTVc5giYjExcw9vrLsdrwdwB4c/yLeseWVzdF_tBjtQAT-2T52hjic\"",
|
61
|
+
"id": {
|
62
|
+
"kind": "youtube#video",
|
63
|
+
"videoId": "9q5BT8eiLDk"
|
64
|
+
},
|
65
|
+
"snippet": {
|
66
|
+
"publishedAt": "2009-04-17T19:39:49.000Z",
|
67
|
+
"channelId": "UCYdxw1ouVnZR_gZrNRbhhkw",
|
68
|
+
"title": "Harry Potter and the Half-Blood Prince Trailer {# 5}",
|
69
|
+
"description": "Yes yes yea!! Another one. There are more scenes! I jut love it can't stop watching it! Finally #5.",
|
70
|
+
"thumbnails": {
|
71
|
+
"default": {
|
72
|
+
"url": "https://i.ytimg.com/vi/9q5BT8eiLDk/default.jpg"
|
73
|
+
},
|
74
|
+
"medium": {
|
75
|
+
"url": "https://i.ytimg.com/vi/9q5BT8eiLDk/mqdefault.jpg"
|
76
|
+
},
|
77
|
+
"high": {
|
78
|
+
"url": "https://i.ytimg.com/vi/9q5BT8eiLDk/hqdefault.jpg"
|
79
|
+
}
|
80
|
+
},
|
81
|
+
"channelTitle": "harrypotter6fan",
|
82
|
+
"liveBroadcastContent": "none"
|
83
|
+
}
|
84
|
+
},
|
85
|
+
{
|
86
|
+
"kind": "youtube#searchResult",
|
87
|
+
"etag": "\"OZTVc5giYjExcw9vrLsdrwdwB4c/qlPZXlzYdU-GFypQUZqGWQ-mkj4\"",
|
88
|
+
"id": {
|
89
|
+
"kind": "youtube#video",
|
90
|
+
"videoId": "46f94wBRo1o"
|
91
|
+
},
|
92
|
+
"snippet": {
|
93
|
+
"publishedAt": "2014-02-24T09:51:17.000Z",
|
94
|
+
"channelId": "UCw_D-n1MuDfiD6l0trSywGw",
|
95
|
+
"title": "Harry's Last Daze (Harry Potter Series (Years 1-7) tribute)",
|
96
|
+
"description": "This is a montage/music video/tribute to the Harry Potter series. The song is Last Daze by Petra. Please leave comments and rate this video. My website is at ...",
|
97
|
+
"thumbnails": {
|
98
|
+
"default": {
|
99
|
+
"url": "https://i.ytimg.com/vi/46f94wBRo1o/default.jpg"
|
100
|
+
},
|
101
|
+
"medium": {
|
102
|
+
"url": "https://i.ytimg.com/vi/46f94wBRo1o/mqdefault.jpg"
|
103
|
+
},
|
104
|
+
"high": {
|
105
|
+
"url": "https://i.ytimg.com/vi/46f94wBRo1o/hqdefault.jpg"
|
106
|
+
}
|
107
|
+
},
|
108
|
+
"channelTitle": "Coolkennyoptimus6",
|
109
|
+
"liveBroadcastContent": "none"
|
110
|
+
}
|
111
|
+
},
|
112
|
+
{
|
113
|
+
"kind": "youtube#searchResult",
|
114
|
+
"etag": "\"OZTVc5giYjExcw9vrLsdrwdwB4c/UMGAIOVjbYSBmKLUhfhzIS3O2yU\"",
|
115
|
+
"id": {
|
116
|
+
"kind": "youtube#video",
|
117
|
+
"videoId": "FdDgo5IRhZE"
|
118
|
+
},
|
119
|
+
"snippet": {
|
120
|
+
"publishedAt": "2012-03-03T18:09:06.000Z",
|
121
|
+
"channelId": "UCKOakHAEve2Nn6qjw2eyiuQ",
|
122
|
+
"title": "21. \"Hogwarts' Hymn\" - Harry Potter and The Goblet of Fire Soundtrack",
|
123
|
+
"description": "By Patrick Doyle.",
|
124
|
+
"thumbnails": {
|
125
|
+
"default": {
|
126
|
+
"url": "https://i.ytimg.com/vi/FdDgo5IRhZE/default.jpg"
|
127
|
+
},
|
128
|
+
"medium": {
|
129
|
+
"url": "https://i.ytimg.com/vi/FdDgo5IRhZE/mqdefault.jpg"
|
130
|
+
},
|
131
|
+
"high": {
|
132
|
+
"url": "https://i.ytimg.com/vi/FdDgo5IRhZE/hqdefault.jpg"
|
133
|
+
}
|
134
|
+
},
|
135
|
+
"channelTitle": "TheWizardingWiz",
|
136
|
+
"liveBroadcastContent": "none"
|
137
|
+
}
|
138
|
+
},
|
139
|
+
{
|
140
|
+
"kind": "youtube#searchResult",
|
141
|
+
"etag": "\"OZTVc5giYjExcw9vrLsdrwdwB4c/Nzls-p4AForJ8wRNIH75hgcshMs\"",
|
142
|
+
"id": {
|
143
|
+
"kind": "youtube#video",
|
144
|
+
"videoId": "QmBmrMrm3E0"
|
145
|
+
},
|
146
|
+
"snippet": {
|
147
|
+
"publishedAt": "2009-02-16T12:49:42.000Z",
|
148
|
+
"channelId": "UCTaqXam4FHoB_DsA4pxTv6Q",
|
149
|
+
"title": "Harry Potter and the Half-Blood Prince trailers",
|
150
|
+
"description": "3 trailers of the 6th movie, enjoy. Can't wait to see the whole movie, right! :3.",
|
151
|
+
"thumbnails": {
|
152
|
+
"default": {
|
153
|
+
"url": "https://i.ytimg.com/vi/QmBmrMrm3E0/default.jpg"
|
154
|
+
},
|
155
|
+
"medium": {
|
156
|
+
"url": "https://i.ytimg.com/vi/QmBmrMrm3E0/mqdefault.jpg"
|
157
|
+
},
|
158
|
+
"high": {
|
159
|
+
"url": "https://i.ytimg.com/vi/QmBmrMrm3E0/hqdefault.jpg"
|
160
|
+
}
|
161
|
+
},
|
162
|
+
"channelTitle": "Nereidinja",
|
163
|
+
"liveBroadcastContent": "none"
|
164
|
+
}
|
165
|
+
},
|
166
|
+
{
|
167
|
+
"kind": "youtube#searchResult",
|
168
|
+
"etag": "\"OZTVc5giYjExcw9vrLsdrwdwB4c/63hxzgKi_JcWfKsnnrr8FlZVLFo\"",
|
169
|
+
"id": {
|
170
|
+
"kind": "youtube#video",
|
171
|
+
"videoId": "CO45K-NeyCo"
|
172
|
+
},
|
173
|
+
"snippet": {
|
174
|
+
"publishedAt": "2009-07-24T22:06:48.000Z",
|
175
|
+
"channelId": "UCINUX6EM17_3lHneotigr-g",
|
176
|
+
"title": "Harry Potter and the Half Blood Prince Review part 2",
|
177
|
+
"description": "It's still Harry Potter. Hope you enjoy.",
|
178
|
+
"thumbnails": {
|
179
|
+
"default": {
|
180
|
+
"url": "https://i.ytimg.com/vi/CO45K-NeyCo/default.jpg"
|
181
|
+
},
|
182
|
+
"medium": {
|
183
|
+
"url": "https://i.ytimg.com/vi/CO45K-NeyCo/mqdefault.jpg"
|
184
|
+
},
|
185
|
+
"high": {
|
186
|
+
"url": "https://i.ytimg.com/vi/CO45K-NeyCo/hqdefault.jpg"
|
187
|
+
}
|
188
|
+
},
|
189
|
+
"channelTitle": "Narcoleptic23",
|
190
|
+
"liveBroadcastContent": "none"
|
191
|
+
}
|
192
|
+
}
|
193
|
+
]
|
194
|
+
}
|
195
|
+
http_version:
|
196
|
+
recorded_at: Sun, 05 Apr 2015 01:57:17 GMT
|
197
|
+
recorded_with: VCR 2.9.3
|
@@ -1 +0,0 @@
|
|
1
|
-
variables.sh
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Core < EDI::Core
|
2
2
|
# Use `register_services` to enable services in your EDI Bot. Available built-in services are:
|
3
|
-
# :dice, :eightball, :fact, :giphy, :i_heart_quotes, :img_flip, :tweet_that, :weather
|
3
|
+
# :dice, :eightball, :fact, :giphy, :i_heart_quotes, :img_flip, :tweet_that, :weather, :youtube
|
4
4
|
# You can make your own services with `edi generate service my_service`
|
5
5
|
register_services :fact
|
6
6
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# This file should hold your various variables required by your services. SLACK_EDI_TOKEN is the only absolutely required variable, the
|
2
|
+
# rest are optional depending on which built-in services you want to use. You should not check this file into source control
|
3
|
+
|
4
|
+
# Bot User Integration Token. Create your bot user integration at https://YOURTEAM.slack.com/services/new#diy
|
5
|
+
SLACK_EDI_TOKEN:
|
6
|
+
|
7
|
+
# Slack API Token. Required for Tweet That Service. Generate token at https://api.slack.com/web
|
8
|
+
SLACK_TOKEN:
|
9
|
+
|
10
|
+
# Giphy Service Configuration. Public Beta API Key Included Below
|
11
|
+
GIPHY_API_KEY: dc6zaTOxFJmzC
|
12
|
+
GIPHY_API_VERSION: v1
|
13
|
+
|
14
|
+
# Tweet That Service Variables
|
15
|
+
TWITTER_ACCESS_TOKEN:
|
16
|
+
TWITTER_CONSUMER_KEY:
|
17
|
+
TWITTER_CONSUMER_SECRET:
|
18
|
+
TWITTER_HANDLE:
|
19
|
+
TWITTER_TOKEN_SECRET:
|
20
|
+
|
21
|
+
# ImgFlip Service Variables. Set up a User at https://imgflip.com/signup
|
22
|
+
IMGFLIP_USER:
|
23
|
+
IMGFLIP_PASSWORD:
|
24
|
+
|
25
|
+
# ZIP Code to use as the default location for the weather service.
|
26
|
+
DEFAULT_LOCATION: 90210
|
27
|
+
|
28
|
+
# Google API Key for Youtube Service. Set up an application on Google Developer Console, Set Youtube Data API to On and create a
|
29
|
+
# Public API Key. Start Here: https://console.developers.google.com/
|
30
|
+
GOOGLE_API_KEY:
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: edi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DVG
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -295,6 +295,7 @@ files:
|
|
295
295
|
- Rakefile
|
296
296
|
- Vagrantfile
|
297
297
|
- bin/edi
|
298
|
+
- demo.gif
|
298
299
|
- edi.gemspec
|
299
300
|
- lib/edi.rb
|
300
301
|
- lib/edi/api/response.rb
|
@@ -341,6 +342,7 @@ files:
|
|
341
342
|
- lib/edi/services/null_service.rb
|
342
343
|
- lib/edi/services/tweet_that.rb
|
343
344
|
- lib/edi/services/weather.rb
|
345
|
+
- lib/edi/services/youtube.rb
|
344
346
|
- lib/edi/slack.rb
|
345
347
|
- lib/edi/slack/channel.rb
|
346
348
|
- lib/edi/slack/message.rb
|
@@ -366,6 +368,7 @@ files:
|
|
366
368
|
- spec/services/null_service_spec.rb
|
367
369
|
- spec/services/tweet_that_spec.rb
|
368
370
|
- spec/services/weather_spec.rb
|
371
|
+
- spec/services/youtube_spec.rb
|
369
372
|
- spec/slack/websocket_incoming_message_spec.rb
|
370
373
|
- spec/spec_helper.rb
|
371
374
|
- spec/support/fixtures/vcr_cassettes/fact.yml
|
@@ -388,6 +391,7 @@ files:
|
|
388
391
|
- spec/support/fixtures/vcr_cassettes/postable.yml
|
389
392
|
- spec/support/fixtures/vcr_cassettes/tweet_that.yml
|
390
393
|
- spec/support/fixtures/vcr_cassettes/weather.yml
|
394
|
+
- spec/support/fixtures/vcr_cassettes/youtube.yml
|
391
395
|
- spec/support/shared_contexts/server.rb
|
392
396
|
- spec/support/shared_contexts/service.rb
|
393
397
|
- templates/project/.gitignore
|
@@ -398,6 +402,7 @@ files:
|
|
398
402
|
- templates/project/config/.gitkeep
|
399
403
|
- templates/project/config/environment.rb
|
400
404
|
- templates/project/config/initializers/.gitkeep
|
405
|
+
- templates/project/config/services.yml
|
401
406
|
- templates/project/variables.sh.example
|
402
407
|
- templates/services/%name%.rb.tt
|
403
408
|
homepage: https://github.com/DVG/edi.git
|
@@ -438,6 +443,7 @@ test_files:
|
|
438
443
|
- spec/services/null_service_spec.rb
|
439
444
|
- spec/services/tweet_that_spec.rb
|
440
445
|
- spec/services/weather_spec.rb
|
446
|
+
- spec/services/youtube_spec.rb
|
441
447
|
- spec/slack/websocket_incoming_message_spec.rb
|
442
448
|
- spec/spec_helper.rb
|
443
449
|
- spec/support/fixtures/vcr_cassettes/fact.yml
|
@@ -460,5 +466,6 @@ test_files:
|
|
460
466
|
- spec/support/fixtures/vcr_cassettes/postable.yml
|
461
467
|
- spec/support/fixtures/vcr_cassettes/tweet_that.yml
|
462
468
|
- spec/support/fixtures/vcr_cassettes/weather.yml
|
469
|
+
- spec/support/fixtures/vcr_cassettes/youtube.yml
|
463
470
|
- spec/support/shared_contexts/server.rb
|
464
471
|
- spec/support/shared_contexts/service.rb
|