ocelots 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -24,7 +24,27 @@ Override the default url (http://ocelots.herokuapp.com) with your own instance b
24
24
 
25
25
  You should now be ready to roll:
26
26
 
27
- ocelots phone user@mail.com
27
+ ### Profile lookup
28
+
29
+ ocelots profile user@mail.com
30
+
31
+ This command performs an immediate lookup of a user's profile by their email address.
32
+
33
+ ### Chat shell
34
+
35
+ You can enter a very basic interactive antechamber (chat client) shell:
36
+
37
+ ocelots antechamber team_slug
38
+
39
+ ### IRC bot
40
+
41
+ You can also run an irc bot that will answer basic queries in a channel:
42
+
43
+ ocelots_bot ocelots irc.freenode.org 6667 '#channel'
44
+
45
+ At this stage, the bot will respond to a message to look up a phone number:
46
+
47
+ phone for user@mail.com
28
48
 
29
49
  ## Contributing
30
50
 
data/bin/ocelots CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  $: << File.dirname(__FILE__)+'/../lib'
4
4
 
5
- require 'ocelots'
5
+ require 'ocelots/cli'
6
6
 
7
7
  include Ocelots::Cli
8
8
 
data/bin/ocelots_bot ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.dirname(__FILE__)+'/../lib'
4
+
5
+ require 'ocelots/bot'
6
+
7
+ include Ocelots::Bot
8
+
9
+ execute *ARGV
data/lib/ocelots.rb CHANGED
@@ -1,4 +1,33 @@
1
+ require 'httparty'
2
+ require 'cgi'
3
+
1
4
  module Ocelots
2
- end
5
+ def request_profile email
6
+ get "profiles/#{Digest::MD5.hexdigest email}"
7
+ end
8
+
9
+ def request_antechamber team_slug, from
10
+ get "antechamber/#{team_slug}", from: from
11
+ end
12
+
13
+ def post_antechamber team_slug, content
14
+ post "antechamber/#{team_slug}", body: {content: content}, headers: {'ContentType' => 'application/json'}
15
+ end
16
+
17
+ def get command, params
18
+ HTTParty.get url_for command, params
19
+ end
20
+
21
+ def post command, params
22
+ HTTParty.post url_for(command), params
23
+ end
24
+
25
+ def url_for command, params={}
26
+ params[:auth_token] = ENV['OCELOTS_AUTH_TOKEN']
27
+ "#{base_url}/api/#{command}?#{params.map{ |k,v| "#{k}=#{CGI.escape v.to_s}" }.join('&')}"
28
+ end
3
29
 
4
- require 'ocelots/cli'
30
+ def base_url
31
+ ENV['OCELOTS_URL'] || 'http://ocelots.herokuapp.com'
32
+ end
33
+ end
@@ -0,0 +1,29 @@
1
+ require 'cinch'
2
+ require 'ocelots'
3
+
4
+ module Ocelots::Bot
5
+ include Ocelots
6
+
7
+ def execute *args
8
+ RiplWatir
9
+ bot = Cinch::Bot.new do
10
+ configure do |c|
11
+ c.nick = args.shift
12
+ c.server = args.shift
13
+ c.port = args.shift.to_i
14
+ c.channels = args
15
+ end
16
+
17
+ on :message, /^phone for (.+)$/ do |m, text|
18
+ visit_page(:gab).search text
19
+ phone = on_page(:gab).phone
20
+ if phone
21
+ m.reply "phone for #{text} is #{phone}"
22
+ else
23
+ m.reply "couldn't find a phone number for #{text} sorry"
24
+ end
25
+ end
26
+ end
27
+ bot.start
28
+ end
29
+ end
data/lib/ocelots/cli.rb CHANGED
@@ -1,30 +1,43 @@
1
- require 'httparty'
1
+ require 'ocelots'
2
2
 
3
3
  module Ocelots::Cli
4
+ include Ocelots
5
+
4
6
  def execute *args
5
7
  command, *args = *args
6
8
  send command, *args
7
9
  end
8
10
 
9
11
  def profile email
10
- persona_id = Digest::MD5.hexdigest email
11
- response = request "profiles/#{persona_id}"
12
+ response = request_profile email
12
13
  if response
13
14
  show response, :full_name
14
15
  show response, :phone
15
16
  show response, :photo_url
16
17
  end
17
18
  end
19
+
20
+ def antechamber team_slug
21
+ Thread.new do
22
+ from = 0
23
+ loop do
24
+ messages = request_antechamber team_slug, from
25
+ messages.reverse.each do |message|
26
+ from = message['id']
27
+ person = message['person']
28
+ ts = Time.at message['timestamp'].to_i
29
+ puts "#{ts.strftime('%d/%m %H:%M:%S')} #{person['full_name']}: #{message['content']}"
30
+ end
31
+ sleep 5
32
+ end
33
+ end
34
+ loop do
35
+ message = $stdin.gets
36
+ post_antechamber team_slug, message
37
+ end
38
+ end
18
39
  private
19
40
  def show response, field
20
41
  puts response[field.to_s] if response[field.to_s]
21
42
  end
22
-
23
- def request command
24
- HTTParty.get "#{base_url}/api/#{command}?auth_token=#{ENV['OCELOTS_AUTH_TOKEN']}"
25
- end
26
-
27
- def base_url
28
- ENV['OCELOTS_URL'] || 'http://ocelots.herokuapp.com'
29
- end
30
43
  end
data/ocelots.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "ocelots"
7
- gem.version = '0.0.2'
7
+ gem.version = '0.0.3'
8
8
  gem.authors = ["Mark Ryall"]
9
9
  gem.email = ["mark@ryall.name"]
10
10
  gem.description = %q{Command line wrapper for ocelots api}
@@ -20,5 +20,6 @@ Gem::Specification.new do |gem|
20
20
  gem.require_paths = ["lib"]
21
21
 
22
22
  gem.add_dependency 'httparty'
23
+ gem.add_dependency 'cinch'
23
24
  gem.add_development_dependency 'rake'
24
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ocelots
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-20 00:00:00.000000000 Z
12
+ date: 2012-11-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
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: '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: '0'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: rake
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -48,6 +64,7 @@ email:
48
64
  - mark@ryall.name
49
65
  executables:
50
66
  - ocelots
67
+ - ocelots_bot
51
68
  extensions: []
52
69
  extra_rdoc_files: []
53
70
  files:
@@ -57,7 +74,9 @@ files:
57
74
  - README.md
58
75
  - Rakefile
59
76
  - bin/ocelots
77
+ - bin/ocelots_bot
60
78
  - lib/ocelots.rb
79
+ - lib/ocelots/bot.rb
61
80
  - lib/ocelots/cli.rb
62
81
  - ocelots.gemspec
63
82
  homepage: http://github.com/ocelots/ocelots_gem
@@ -74,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
93
  version: '0'
75
94
  segments:
76
95
  - 0
77
- hash: 1806221170895511770
96
+ hash: -3497293529455536224
78
97
  required_rubygems_version: !ruby/object:Gem::Requirement
79
98
  none: false
80
99
  requirements:
@@ -83,10 +102,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
102
  version: '0'
84
103
  segments:
85
104
  - 0
86
- hash: 1806221170895511770
105
+ hash: -3497293529455536224
87
106
  requirements: []
88
107
  rubyforge_project:
89
- rubygems_version: 1.8.24
108
+ rubygems_version: 1.8.23
90
109
  signing_key:
91
110
  specification_version: 3
92
111
  summary: This gem encapsulates usage of the ocelots api and provides a command line