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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4b099232d6c0b02497b383540cd083c1ae0db22
4
- data.tar.gz: 016a389d1a02cc878852e6ce94386c0d4e78f4a1
3
+ metadata.gz: 64191fc2d664ec32485c2d16528c8a5f54e4b438
4
+ data.tar.gz: 12f19a6ca3230e4dca6685f628b52a3539156f41
5
5
  SHA512:
6
- metadata.gz: fe208bce4587fb3f68e6c7c0913660642c320a0bfb24cd93ace145d64562392b8484c503eb214d2230d1593d96b29f7ba5c64e2c6d1614762cbc85c9261718a9
7
- data.tar.gz: c8d6c679c6135b395f3bdfb7c146ad8a86c51e11c141038820efaad390af7b8ef7e38422c7d4909c8a7536bfbd7623f4d67ef94ae9bdb0ac194971010c2b3e99
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.
@@ -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
- songs = RapGenius.search(query)
13
- if !songs.empty?
14
- song = songs.first
15
- response.reply song.description.gsub(/\n+/, " ")
16
- response.reply "#{song.artist.name} - #{song.title} | http://genius.com/songs/#{song.id}"
17
- else
18
- response.reply "No songs found for '#{query}'"
19
- end
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.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.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-06 00:00:00.000000000 Z
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