lita-youtube-me 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84e50b2bf564204b460ec3da6d9b267aab005701
4
- data.tar.gz: 816c091089bbf1ad1eb6c816003b6f28894cde66
3
+ metadata.gz: b69c15d7418f23826ab51582155b6a0f5aeefea6
4
+ data.tar.gz: 85623f1c85cb60c6e29bfa91389f8479e706406d
5
5
  SHA512:
6
- metadata.gz: 9c5b96f5cc3a162f7a02fdeb76260ca56d98f4ed44ebbdb5d1f64a9c687a2cd58599ece5c8d05fe3558826fc24a86bfca6852ff6e22f8b5328c175183ffbba6b
7
- data.tar.gz: c9d9a3686daafd6057a7c6eba8adda27e5b3fc6bec140838ea8ac1aaf24835d0495071d94dfe4c2e17e74eee518373c8d966a9f5d9425078aa04f62a07aee5ec
6
+ metadata.gz: cbc9658f85ca27ce1c7aee9c4bf5b7de6c0b348e90a12edb4611d08ab331d7fc1a6385b74a907f86e6984eaee2adfefd895dd48f3e735d27b68d32ed18cbf030
7
+ data.tar.gz: 65a7a70f4f42160aa0a6b0de9699634d6069630262ffb3c2701b1bace3dda6ec695520b64d8f8f92644f112917ffeab3d83c3a4a899fc6f255832f3ca352b61c
data/README.md CHANGED
@@ -23,11 +23,13 @@ end
23
23
  ### Optional attributes
24
24
  * `video_info` (boolean) - When set to `true`, Lita will return additional information (title, duration, etc.) about the video. Default: `false`
25
25
  * `detect_urls` (boolean) - When set to `true`, Lita will return additional information about any YouTube URLs it detects. Default: `false`
26
+ * `top_result` (boolean) - When set to `true`, Lita will return the top result in response to a video search. Default: `false`, which returns a random result selected from the top 15.
26
27
 
27
28
  ``` ruby
28
29
  Lita.configure do |config|
29
30
  config.handlers.youtube_me.video_info = true
30
31
  config.handlers.youtube_me.detect_urls = true
32
+ config.handlers.youtube_me.top_result = true
31
33
  end
32
34
  ```
33
35
 
@@ -9,6 +9,7 @@ module Lita
9
9
  config :api_key, type: String, required: true
10
10
  config :video_info, types: [TrueClass, FalseClass], default: false
11
11
  config :detect_urls, types: [TrueClass, FalseClass], default: false
12
+ config :top_result, types: [TrueClass, FalseClass], default: false
12
13
 
13
14
  route(/^(?:youtube|yt)(?: me)?\s+(.*)/i, :find_video, command: true, help: {
14
15
  "youtube (me) QUERY" => "Gets a YouTube video."
@@ -28,8 +29,8 @@ module Lita
28
29
  key: config.api_key
29
30
  )
30
31
  return if http_response.status != 200
31
- videos = MultiJson.load(http_response.body)["items"]
32
- video = videos.sample
32
+ videos = MultiJson.load(http_response.body)["items"].select { |v| v["id"].key?("videoId") }
33
+ video = config.top_result ? videos.first : videos.sample
33
34
  id = video["id"]["videoId"]
34
35
  response.reply "https://www.youtube.com/watch?v=#{id}"
35
36
  if config.video_info
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-youtube-me"
3
- spec.version = "0.0.4"
3
+ spec.version = "0.0.5"
4
4
  spec.authors = ["Taylor Lapeyre"]
5
5
  spec.email = ["taylorlapeyre@gmail.com"]
6
6
  spec.description = %q{A Lita handler that replies with a youtube URL when given a query.}
@@ -30,6 +30,13 @@ describe Lita::Handlers::YoutubeMe, lita_handler: true do
30
30
  expect(replies.last).to match(/youtube\.com/)
31
31
  end
32
32
 
33
+ it "does not attempt to return a playlist" do
34
+ send_command("youtube babbletron birds")
35
+ expect(replies.count).to eq 1
36
+ expect(replies.last).to_not be_nil
37
+ expect(replies.last).not_to match(/^https:\/\/www\.youtube\.com\/watch\?v=$/)
38
+ end
39
+
33
40
  it "displays info for a requested video when the video_info config variable is true" do
34
41
  registry.config.handlers.youtube_me.video_info = true
35
42
  send_command("yt soccer")
@@ -68,6 +75,12 @@ describe Lita::Handlers::YoutubeMe, lita_handler: true do
68
75
  expect(replies.count).to eq 0
69
76
  end
70
77
 
78
+ it "returns the top video in response to a query when the top_result config variable is true" do
79
+ registry.config.handlers.youtube_me.top_result = true
80
+ send_command("yt polica lay your cards out")
81
+ expect(replies.first).to match(/Rl03afAqeFQ/)
82
+ end
83
+
71
84
  it "does not return a video in response to a query when the API key is invalid" do
72
85
  registry.config.handlers.youtube_me.api_key = "this key doesn't work"
73
86
  send_command("youtube me soccer")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-youtube-me
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Lapeyre
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-09 00:00:00.000000000 Z
11
+ date: 2015-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita