cinch-lastfm 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2013 by Anton Sebvie
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # Cinch-Lastfm
2
+
3
+ This is the Cinch Last.fm plugin adding "recently played" functionality.
4
+
5
+ ## Getting Started
6
+
7
+ This section is yet to be done, and will be done as this becomes a gem.
8
+
9
+ require 'cinch'
10
+ require 'cinch/plugins/lastfm'
11
+
12
+ Cinch::Plugins::Lastfm.configure do |c|
13
+ c.lfmapi = "yourlastfmapikey"
14
+ end
15
+
16
+ bot = Cinch::Bot.new do
17
+ configure do |c|
18
+ c.plugins.plugins = [Cinch::Plugins::Lastfm]
19
+ end
20
+ end
21
+
22
+ ## Commands
23
+
24
+ Reacts to *!np username*
25
+
26
+ TODO
27
+ -----
28
+
29
+ * Feature a redis backend
30
+ * Minor improvements
31
+ * Better docs
32
+
33
+
@@ -0,0 +1,42 @@
1
+ require 'cinch'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ module Cinch
6
+ module Plugins
7
+ class Lastfm
8
+ include Cinch::Plugin
9
+ #attr_accessor :backend
10
+ # Redis backend
11
+
12
+ class << self
13
+ attr_accessor :lfmapi #:host, :port # Redis backend scrub
14
+
15
+ def configure(&block)
16
+ yield self
17
+ end
18
+ end
19
+
20
+ def initialize(*args)
21
+ super
22
+ # @backend = Redis.new(self.class.host, self.class.port)
23
+ # Will feature a redis backend
24
+ end
25
+
26
+ match %r{np ([a-zA-Z0-9]+)}, :method => :now_playing
27
+
28
+ # Gets Now Playing for an user
29
+ def now_playing(m, nick)
30
+ artist, track = get_data(nick)
31
+ m.reply("#{nick} has recently played: #{artist} - #{track}")
32
+ end
33
+
34
+ def get_data(nick)
35
+ lfmXML = Nokogiri::XML(open("http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=#{nick}&api_key=#{self.class.lfmapi}"))
36
+ artist = lfmXML.xpath('//artist').first.content
37
+ track = lfmXML.xpath('//name').first.content
38
+ [artist, track]
39
+ end
40
+ end #Lastfm
41
+ end #Plugins
42
+ end #Cinch
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Cinch::Plugins::Lastfm do
4
+
5
+ before :each do
6
+ Cinch::Plugins::Lastfm.any_instance.stub(:__register).and_return(true)
7
+ @bot = double()
8
+ end
9
+
10
+ context "#now_playing" do
11
+ before :each do
12
+ @lfmbot = Cinch::Plugins::Lastfm.new(@bot)
13
+ @message = double()
14
+ @lfmbot.stub(:get_data).and_return(["Artist","Track"])
15
+ @message.should_receive(:reply).with("czujechlodno has recently played: Artist - Track")
16
+ end
17
+
18
+ it "should get now_playing" do
19
+ @lfmbot.now_playing(@message, "czujechlodno")
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1 @@
1
+ require_relative '../lib/cinch/plugins/lastfm'
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cinch-lastfm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Anton Sebvie
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: cinch
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 2.0.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 2.0.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: This is the Cinch Last.fm plugin adding 'recently played' functionality.
63
+ email: fatkuntroller@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files:
67
+ - README.md
68
+ files:
69
+ - Gemfile
70
+ - LICENSE
71
+ - README.md
72
+ - spec/lastfm_spec.rb
73
+ - spec/spec_helper.rb
74
+ - lib/cinch/plugins/lastfm.rb
75
+ homepage: https://github.com/fatcuntroller/cinch-lastfm
76
+ licenses: []
77
+ post_install_message:
78
+ rdoc_options:
79
+ - --main
80
+ - README.md
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 1.8.24
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Cinch Lastfm plugin
101
+ test_files: []