lita-genius 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/lita/handlers/genius.rb +23 -10
- data/lita-genius.gemspec +1 -2
- data/spec/lita/handlers/genius_spec.rb +4 -0
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64191fc2d664ec32485c2d16528c8a5f54e4b438
|
4
|
+
data.tar.gz: 12f19a6ca3230e4dca6685f628b52a3539156f41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1895e101852b68ce0965cd6ffae157062411ba9989978d274eb46c81e0b0771be7e3ea8158ca137597d13be2af0537e4bc9abf377debb99e936c13283f829f5
|
7
|
+
data.tar.gz: d52983076538cda0a98954a474198545e77b842da9f1b329d53b94ccef8b65b82e730203e98c54e8c80f875e08b16ab6c288c4f3c3b1598fcae1f6df6ab22a68
|
data/README.md
CHANGED
@@ -13,6 +13,16 @@ Add lita-genius to your Lita instance's Gemfile:
|
|
13
13
|
gem "lita-genius"
|
14
14
|
```
|
15
15
|
|
16
|
+
## Configuration
|
17
|
+
|
18
|
+
In order to use this plugin, you must obtain a [Genius client access token](http://genius.com/api-clients).
|
19
|
+
|
20
|
+
``` ruby
|
21
|
+
Lita.configure do |config|
|
22
|
+
config.handlers.genius.access_token = "YOUR ACCESS TOKEN GOES HERE"
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
16
26
|
## Usage
|
17
27
|
|
18
28
|
Using the `genius` command will return the top Genius result for your query. Song titles and lyrics are both valid types of search strings.
|
data/lib/lita/handlers/genius.rb
CHANGED
@@ -1,22 +1,35 @@
|
|
1
|
-
require "rapgenius"
|
2
|
-
|
3
1
|
module Lita
|
4
2
|
module Handlers
|
5
3
|
class Genius < Handler
|
6
4
|
|
5
|
+
API_URL = "http://api.genius.com"
|
6
|
+
|
7
|
+
config :access_token, type: String, required: true
|
8
|
+
|
7
9
|
route(/^genius\s+(.+)/i, :search, command:true,
|
8
10
|
help: {t("help.search_key") => t("help.search_value")})
|
9
11
|
|
10
12
|
def search(response)
|
11
13
|
query = response.matches.first.first
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
search_response = http.get(
|
15
|
+
"#{API_URL}/search",
|
16
|
+
{q: query},
|
17
|
+
{"Authorization" => "Bearer #{config.access_token}"}
|
18
|
+
)
|
19
|
+
songs = MultiJson.load(search_response.body)["response"]["hits"]
|
20
|
+
return response.reply "No songs found for '#{query}'" if songs.empty?
|
21
|
+
song = songs.first
|
22
|
+
id = song["result"]["id"]
|
23
|
+
song_response = http.get(
|
24
|
+
"#{API_URL}/songs/#{id}",
|
25
|
+
{text_format: "plain"},
|
26
|
+
{"Authorization" => "Bearer #{config.access_token}"}
|
27
|
+
)
|
28
|
+
description = MultiJson.load(song_response.body)["response"]["song"]["description"]["plain"].gsub(/\n+/, " ")
|
29
|
+
artist = song["result"]["primary_artist"]["name"]
|
30
|
+
title = song["result"]["title"]
|
31
|
+
response.reply description
|
32
|
+
response.reply "#{artist} - #{title} | http://genius.com/songs/#{id}"
|
20
33
|
end
|
21
34
|
|
22
35
|
end
|
data/lita-genius.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-genius"
|
3
|
-
spec.version = "0.1.
|
3
|
+
spec.version = "0.1.2"
|
4
4
|
spec.authors = ["Tristan Chong"]
|
5
5
|
spec.email = ["ong@tristaneuan.ch"]
|
6
6
|
spec.description = "A Lita handler that returns requested songs from (Rap) Genius."
|
@@ -15,7 +15,6 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.require_paths = ["lib"]
|
16
16
|
|
17
17
|
spec.add_runtime_dependency "lita", ">= 4.3"
|
18
|
-
spec.add_runtime_dependency "rapgenius", "1.0.5"
|
19
18
|
|
20
19
|
spec.add_development_dependency "bundler", "~> 1.3"
|
21
20
|
spec.add_development_dependency "pry-byebug"
|
@@ -2,6 +2,10 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Lita::Handlers::Genius, lita_handler: true do
|
4
4
|
|
5
|
+
before do
|
6
|
+
registry.config.handlers.genius.access_token = ENV["GENIUS_ACCESS_TOKEN"]
|
7
|
+
end
|
8
|
+
|
5
9
|
it { is_expected.to route_command("genius weeknd montreal").to(:search) }
|
6
10
|
|
7
11
|
describe "#search" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-genius
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tristan Chong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.3'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rapgenius
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.0.5
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 1.0.5
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: bundler
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|