ruboty-youtube 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 86b5bd73c93e91658d17838358d507878b6352c5
4
+ data.tar.gz: 3e005e8a0fdebc43029c9750ff365f7320421d26
5
+ SHA512:
6
+ metadata.gz: 59597a09dc05dd0320692926c4108cf832afe5877765cfcff8a4a9e531c3aa881314b9742a91c1ec859c07bb99e79536ae0922de5f39b0d00dff741aa475112a
7
+ data.tar.gz: a0a458be42b7da047e31e1a507956be165ffacdf693f79dfc7d884d4e99608712b5d60120e771306165d42e2305bffd913810ff755d551cf3b4a9c4ebf6f048d
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-youtube.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 kaihar4
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # Ruboty::Youtube
2
+
3
+ Ruboty handler to search a movie from YouTube.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ruboty-youtube'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```
16
+ @ruboty yt top <keyword> - Search a movie from YouTube
17
+ @ruboty yt rand <keyword> - Search a random movie from YouTube
18
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,19 @@
1
+ module Ruboty
2
+ module Handlers
3
+ class Youtube < Base
4
+ on /yt (?<mode>.+?) (?<keyword>.+)/, name: 'yt', description: 'Search a movie from YouTube'
5
+
6
+ def yt(message)
7
+ if url = search(message[:keyword], message[:mode].to_sym)
8
+ message.reply(url)
9
+ end
10
+ end
11
+
12
+ private
13
+
14
+ def search(query, mode)
15
+ Ruboty::Youtube::Client.new(query, mode).get
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,52 @@
1
+ require 'json'
2
+
3
+ require 'faraday'
4
+
5
+ module Ruboty
6
+ module Youtube
7
+ class Client
8
+ YOUTUBE_API_URL = 'http://gdata.youtube.com'
9
+
10
+ def initialize(query, mode)
11
+ @conn = Faraday.new(url: YOUTUBE_API_URL) do |faraday|
12
+ faraday.request :url_encoded
13
+ faraday.adapter Faraday.default_adapter
14
+ end
15
+ @query = query
16
+ @mode = mode
17
+ end
18
+
19
+ def get
20
+ response = @conn.get do |req|
21
+ req.url '/feeds/api/videos', params
22
+ end.body
23
+ videos = JSON.parse(response)['feed']['entry']
24
+ # when @mode is :top -> videos.length is 1
25
+ videos.sample['link'].first['href']
26
+ rescue
27
+ nil
28
+ end
29
+
30
+ private
31
+
32
+ def params
33
+ case @mode
34
+ when :top
35
+ {
36
+ orderBy: "relevance",
37
+ 'max-results' => 1,
38
+ alt: 'json',
39
+ q: @query
40
+ }
41
+ when :rand
42
+ {
43
+ orderBy: "relevance",
44
+ 'max-results' => 15,
45
+ alt: 'json',
46
+ q: @query
47
+ }
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Youtube
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'ruboty'
2
+ require 'ruboty/youtube/client'
3
+ require 'ruboty/handlers/youtube'
@@ -0,0 +1,24 @@
1
+ $LOAD_PATH << File.expand_path('../lib', __FILE__)
2
+ require 'ruboty/youtube/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'ruboty-youtube'
6
+ spec.version = Ruboty::Youtube::VERSION
7
+ spec.authors = ['kaihar4']
8
+ spec.email = ['kaihar4@gmail.com']
9
+ spec.summary = 'Search a movie from YouTube'
10
+ spec.description = spec.summary
11
+ spec.homepage = 'https://github.com/kaihar4/ruboty-youtube'
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_dependency 'ruboty'
20
+ spec.add_dependency 'faraday'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.7'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-youtube
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - kaihar4
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Search a movie from YouTube
70
+ email:
71
+ - kaihar4@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/ruboty/handlers/youtube.rb
82
+ - lib/ruboty/youtube.rb
83
+ - lib/ruboty/youtube/client.rb
84
+ - lib/ruboty/youtube/version.rb
85
+ - ruboty-youtube.gemspec
86
+ homepage: https://github.com/kaihar4/ruboty-youtube
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.2
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Search a movie from YouTube
110
+ test_files: []