nico 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/HISTORY.md +1 -0
- data/README.md +5 -1
- data/bin/nico +10 -0
- data/lib/nico.rb +20 -3
- data/lib/nico/aliases.rb +3 -0
- data/lib/nico/matchers/daft_punk_matcher.rb +15 -0
- data/lib/nico/message.rb +26 -0
- data/lib/nico/room.rb +24 -0
- data/lib/nico/room/listener.rb +16 -0
- data/lib/nico/room/responder.rb +18 -0
- data/lib/nico/version.rb +1 -1
- data/nico.gemspec +2 -0
- metadata +34 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 059b976f83a39cdc762f8ee13eb60f6b92913e4e
|
4
|
+
data.tar.gz: e9c987171b724de13470e88cb912fa4cea3ff871
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bc54618745debdf7c52c70d4558649b140c6ffb0d4897aac454991b69696c9a7a89c0fdf3bfc2009bdd0fcca0a880d39c6073d2cd06194b28e2ed4e1be250c1
|
7
|
+
data.tar.gz: 917ec38d803e586b31df6259290f1873a21dc05484dca688e8c6863232b9d97be3327e09fdf22e977699b19cfab0b8cf56bad776d3110ab782176e7176713e48
|
data/Gemfile
CHANGED
data/HISTORY.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
v0.1.0 - 2014/02/05 Nico.run accepts optional parameters
|
data/README.md
CHANGED
@@ -18,7 +18,11 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
From the command line run:
|
22
|
+
|
23
|
+
$ nico
|
24
|
+
|
25
|
+
Remember to define the following environment variables: `CAMPFIRE_SUBDOMAIN`, `CAMPFIRE_ROOM_ID` and `CAMPFIRE_TOKEN`.
|
22
26
|
|
23
27
|
## Contributing
|
24
28
|
|
data/bin/nico
ADDED
data/lib/nico.rb
CHANGED
@@ -1,5 +1,22 @@
|
|
1
|
-
require
|
1
|
+
require 'nico/room'
|
2
2
|
|
3
|
+
# Provides a method to listen and respond to messages in a Campfire room.
|
3
4
|
module Nico
|
4
|
-
#
|
5
|
-
|
5
|
+
# Listen and respond to messages in a Campfire room.
|
6
|
+
#
|
7
|
+
# @example Interact in the room https://xxx.campfirenow.com/room/123 as the user with token 'abcd'
|
8
|
+
#
|
9
|
+
# require 'nico'
|
10
|
+
# Nico.run 'xxx', 123, 'abcd'
|
11
|
+
#
|
12
|
+
# @param [String] subdomain The campfirenow.com subdomain that hosts the room
|
13
|
+
# @param [Integer] room_id The ID of the Campfire room
|
14
|
+
# @param [String] token The token of the Campfire user to interact with
|
15
|
+
#
|
16
|
+
# @see https://github.com/37signals/campfire-api for Campfire API documentation
|
17
|
+
def self.run(options = {})
|
18
|
+
Room.new(options).listen do |room, request|
|
19
|
+
room.respond_with request.response if request.relevant?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/nico/aliases.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Nico
|
2
|
+
module Matchers
|
3
|
+
class DaftPunkMatcher
|
4
|
+
def self.match
|
5
|
+
/what is your favorite daft punk/i
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.response
|
9
|
+
top = ['Daftendirekt ', 'WDPK ', 'Revolution ', 'Da ', 'Phoenix ', 'Fresh ', 'Around the ', 'Rollin\' & ', 'Teachers ', 'High ', 'Rock \'n ', 'Oh ', 'Burnin\' ', 'Indo silver ', 'Alive ', 'Funk ', 'One more ', 'Aero', 'Digital ', 'Harder, better, ', 'Crescen', 'Night', 'Super', 'High ', 'Something about ', 'Voyager', 'Veridis ', 'Short ', 'Face ', 'Human ', 'The prime time of ', 'Robot ', 'Steam ', 'Make ', 'The ', 'On/', 'Television rules ', 'Techno', 'Emo', 'Give life back to ', 'The game of ', 'Giorgio ', 'With', 'Instant ', 'Lose yourself to ', 'Touch', 'Get ', 'Beyond', 'Mother', 'Fragments of ', 'Doin\' it ', 'Contact']
|
10
|
+
bottom = ['83.7 FM', '909', 'funk', 'world', 'scratchin\'', 'fidelity', 'roll', 'yeah', 'club', 'ad', 'time', 'dynamic', 'love', 'faster, stronger', 'dolls', 'vision', 'heroes', 'life', 'us', 'quo', 'circuit', 'to face', 'after all', 'your life', 'rock', 'machine', 'love', 'brainwasher', 'off', 'the nation', 'logic', 'tion', 'music', 'love', 'by Moroder', 'in', 'crush', 'dance', 'lucky', 'board', 'time', 'right']
|
11
|
+
[top.sample, bottom.sample].join
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/nico/message.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'nico/aliases'
|
2
|
+
require 'nico/matchers/daft_punk_matcher'
|
3
|
+
|
4
|
+
module Nico
|
5
|
+
class Message
|
6
|
+
attr_reader :body
|
7
|
+
|
8
|
+
def initialize(json)
|
9
|
+
# also available: id, user_id, starred, created_at, type, room_id
|
10
|
+
@body = json['body'] || ''
|
11
|
+
end
|
12
|
+
|
13
|
+
def relevant?
|
14
|
+
@body.start_with? *Nico::ALIASES
|
15
|
+
end
|
16
|
+
|
17
|
+
def response
|
18
|
+
# This should loop through the regex and respond adequately
|
19
|
+
# And one of these regex will add to the regex (and save to github)
|
20
|
+
case @body
|
21
|
+
when Matchers::DaftPunkMatcher.match then Matchers::DaftPunkMatcher.response
|
22
|
+
else "You said #{@body}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/nico/room.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'nico/room/listener'
|
2
|
+
require 'nico/room/responder'
|
3
|
+
|
4
|
+
module Nico
|
5
|
+
class Room
|
6
|
+
def initialize(options = {})
|
7
|
+
@requests = Listener.new options[:room_id], options[:token]
|
8
|
+
@responses = Responder.new options[:subdomain], options[:room_id], options[:token]
|
9
|
+
end
|
10
|
+
|
11
|
+
def listen
|
12
|
+
@requests.each{|request| yield self, request}
|
13
|
+
end
|
14
|
+
|
15
|
+
def each_message
|
16
|
+
@requests.each{|request| yield request.body}
|
17
|
+
end
|
18
|
+
|
19
|
+
def respond_with(response)
|
20
|
+
@responses.push response
|
21
|
+
end
|
22
|
+
alias :say :respond_with
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'nico/message'
|
2
|
+
require 'yajl/http_stream'
|
3
|
+
|
4
|
+
module Nico
|
5
|
+
class Listener
|
6
|
+
def initialize(id, token)
|
7
|
+
@url = "http://#{token}:x@streaming.campfirenow.com/room/#{id}/live.json"
|
8
|
+
end
|
9
|
+
|
10
|
+
def each
|
11
|
+
Yajl::HttpStream.get(URI.parse @url) do |json|
|
12
|
+
yield Message.new(json)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Nico
|
4
|
+
class Responder
|
5
|
+
def initialize(subdomain, id, token)
|
6
|
+
@http = Net::HTTP.new "#{subdomain}.campfirenow.com", 443
|
7
|
+
@http.use_ssl = true
|
8
|
+
@request = Net::HTTP::Post.new "/room/#{id}/speak.json"
|
9
|
+
@request.basic_auth token, 'x'
|
10
|
+
@request['Content-Type'] = 'application/json'
|
11
|
+
end
|
12
|
+
|
13
|
+
def push(response)
|
14
|
+
@request.body = {message: {body: response}}.to_json
|
15
|
+
@http.request @request
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/nico/version.rb
CHANGED
data/nico.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_dependency 'yajl-ruby', '~> 1.2' # Read Campfire Streaming API
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
24
|
spec.add_development_dependency "rake"
|
23
25
|
end
|
metadata
CHANGED
@@ -1,56 +1,79 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nico
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- claudiob
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: yajl-ruby
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
|
-
- - ~>
|
31
|
+
- - "~>"
|
18
32
|
- !ruby/object:Gem::Version
|
19
33
|
version: '1.3'
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
|
-
- - ~>
|
38
|
+
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '1.3'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- -
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- -
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
description: Campfire Bot
|
42
56
|
email:
|
43
57
|
- claudiob@gmail.com
|
44
|
-
executables:
|
58
|
+
executables:
|
59
|
+
- nico
|
45
60
|
extensions: []
|
46
61
|
extra_rdoc_files: []
|
47
62
|
files:
|
48
|
-
- .gitignore
|
63
|
+
- ".gitignore"
|
49
64
|
- Gemfile
|
65
|
+
- HISTORY.md
|
50
66
|
- LICENSE.txt
|
51
67
|
- README.md
|
52
68
|
- Rakefile
|
69
|
+
- bin/nico
|
53
70
|
- lib/nico.rb
|
71
|
+
- lib/nico/aliases.rb
|
72
|
+
- lib/nico/matchers/daft_punk_matcher.rb
|
73
|
+
- lib/nico/message.rb
|
74
|
+
- lib/nico/room.rb
|
75
|
+
- lib/nico/room/listener.rb
|
76
|
+
- lib/nico/room/responder.rb
|
54
77
|
- lib/nico/version.rb
|
55
78
|
- nico.gemspec
|
56
79
|
homepage: ''
|
@@ -63,17 +86,17 @@ require_paths:
|
|
63
86
|
- lib
|
64
87
|
required_ruby_version: !ruby/object:Gem::Requirement
|
65
88
|
requirements:
|
66
|
-
- -
|
89
|
+
- - ">="
|
67
90
|
- !ruby/object:Gem::Version
|
68
91
|
version: '0'
|
69
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
93
|
requirements:
|
71
|
-
- -
|
94
|
+
- - ">="
|
72
95
|
- !ruby/object:Gem::Version
|
73
96
|
version: '0'
|
74
97
|
requirements: []
|
75
98
|
rubyforge_project:
|
76
|
-
rubygems_version: 2.
|
99
|
+
rubygems_version: 2.2.0
|
77
100
|
signing_key:
|
78
101
|
specification_version: 4
|
79
102
|
summary: Campfire Bot
|