pandorified 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile.lock +3 -3
- data/README.md +23 -16
- data/lib/pandorified.rb +33 -0
- data/lib/pandorified/result.rb +30 -26
- data/lib/pandorified/session.rb +7 -5
- data/lib/pandorified/version.rb +1 -1
- metadata +11 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 86625391ab1a874c65ff69bb838fdcb9cf5849b9
|
4
|
+
data.tar.gz: 60b899f6ac7405e7225e32eca029226125d17f1e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a4c51bab5d8f395558f4ecddf3bb8e6d5c70076831ecfbf4d0c865e6e4cc5971cd34fc9b1d98a9c4cd1c79442c5830ce459aa6e7eef2f8df6f60444c6fc6a1e1
|
7
|
+
data.tar.gz: af8ebc3a61fbfc2a2f219d483d073d3cf28441940bd8c475ed51a779fde6d17e5dbb26b079221569ba0e16725712386cc357896e9f2d4db3a9ea34631b9f86c3
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
pandorified (0.
|
4
|
+
pandorified (0.8.0)
|
5
5
|
nokogiri
|
6
6
|
rest-client
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: http://rubygems.org/
|
10
10
|
specs:
|
11
|
-
mime-types (1.
|
12
|
-
nokogiri (1.5.
|
11
|
+
mime-types (1.22)
|
12
|
+
nokogiri (1.5.9)
|
13
13
|
rest-client (1.6.7)
|
14
14
|
mime-types (>= 1.16)
|
15
15
|
|
data/README.md
CHANGED
@@ -1,52 +1,59 @@
|
|
1
1
|
Summary
|
2
2
|
-------
|
3
3
|
|
4
|
-
Pandorified
|
4
|
+
Pandorified is a simple Ruby wrapper for the Pandorabots API. Talk to chat bots in your Ruby scripts!
|
5
5
|
|
6
6
|
Installation
|
7
7
|
------------
|
8
8
|
|
9
9
|
gem install pandorified
|
10
10
|
|
11
|
+
Or add Pandorified to your project's Gemfile:
|
12
|
+
|
13
|
+
gem 'pandorified'
|
14
|
+
|
11
15
|
Getting Started
|
12
16
|
---------------
|
13
17
|
|
14
|
-
|
18
|
+
To interact with the Pandorabots, you need to know the BOTID of the bot you wish to talk to. If you have published your own bot, the BOTID will be listed on your Botmaster page.
|
19
|
+
|
20
|
+
Here is a basic example:
|
15
21
|
|
16
22
|
require 'pandorified'
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
24
|
+
CHOMSKY_BOTID = 'b0dafd24ee35a477'
|
25
|
+
|
26
|
+
# Send a message to Chomsky and print the response
|
27
|
+
puts Pandorified.talk!("Hello, Bot!", CHOMSKY_BOTID)
|
21
28
|
|
22
|
-
|
29
|
+
If you want the bot to remember who you are, you can create a session object and re-use it.
|
23
30
|
|
24
|
-
|
25
|
-
|
31
|
+
bot = Pandorified::Session.new('b0dafd24ee35a477')
|
32
|
+
puts bot.talk!("Hello")
|
33
|
+
puts bot.talk!("Goodbye now!")
|
26
34
|
|
27
|
-
|
35
|
+
Full documentation is available [here](http://rubydoc.info/gems/pandorified/frames). If anything in the documentation is not clear, please [report it as a bug][1].
|
28
36
|
|
29
37
|
Contributing
|
30
38
|
------------
|
31
39
|
|
32
|
-
|
33
|
-
|
34
|
-
If you've found a bug or have a feature suggestion, let me know on the [issue tracker](https://bitbucket.org/xtagon/pandorified/issues?status=new&status=open).
|
35
|
-
|
36
|
-
I welcome all suggestions, questions, and other feedback. Feel free to [drop me a line](mailto:xtagon@gmail.com).
|
40
|
+
If you've found a bug or have a feature suggestion, let me know on the [issue tracker][1] or [send me an e-mail][2]. I welcome all feedback, and I'd love to hear about what cool things you've made with this!
|
37
41
|
|
38
42
|
Author
|
39
43
|
------
|
40
44
|
|
41
|
-
[Justin Workman]
|
45
|
+
[Justin Workman][2]
|
42
46
|
|
43
47
|
License
|
44
48
|
-------
|
45
49
|
|
46
|
-
Copyright © 2011-
|
50
|
+
Copyright © 2011-2013 Justin Workman
|
47
51
|
|
48
52
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
49
53
|
|
50
54
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
51
55
|
|
52
56
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
57
|
+
|
58
|
+
[1]: https://bitbucket.org/xtagon/pandorified/issues?status=new&status=open
|
59
|
+
[2]: mailto:xtagon@gmail.com
|
data/lib/pandorified.rb
CHANGED
@@ -1,2 +1,35 @@
|
|
1
1
|
require 'pandorified/version'
|
2
|
+
require 'pandorified/result'
|
2
3
|
require 'pandorified/session'
|
4
|
+
|
5
|
+
module Pandorified
|
6
|
+
# Send a message to a bot and receive a response.
|
7
|
+
#
|
8
|
+
# See {Pandorified::Result} for ways to handle the response, or use {.talk!} which raises an exception on errors.
|
9
|
+
# If you want to remember the {botid} and {custid} between multiple calls, you should use {Pandorabots::Session} instead of this method.
|
10
|
+
#
|
11
|
+
# @param [String] input Text to say to the bot.
|
12
|
+
# @param [String] botid A valid Pandorabots botid.
|
13
|
+
# @param [String] custid An itentifier used to keep track of this conversaion.
|
14
|
+
#
|
15
|
+
# @return [Pandorified::Result] The bot's response as a result object.
|
16
|
+
def self.talk(input, botid, custid = nil)
|
17
|
+
Pandorified::Session.new(botid, custid).talk(input)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Send a message to a bot and receive a response (if successsful).
|
21
|
+
#
|
22
|
+
# If Pandorabots respondes with an error, {Pandorified::PandorabotsError} is raised.
|
23
|
+
# If you'd rather check for and handle the error yourself, use {.talk} instead of this method.
|
24
|
+
#
|
25
|
+
# If you want to remember the {botid} and {custid} between multiple calls, you should use {Pandorabots::Session} instead of this method.
|
26
|
+
#
|
27
|
+
# @param [String] input Text to say to the bot.
|
28
|
+
# @param [String] botid A valid Pandorabots botid.
|
29
|
+
# @param [String] custid An itentifier used to keep track of this conversaion.
|
30
|
+
#
|
31
|
+
# @return [String] The bot's response text.
|
32
|
+
def self.talk!(input, botid, custid = nil)
|
33
|
+
Pandorified::Session.new(botid, custid).talk!(input).to_s
|
34
|
+
end
|
35
|
+
end
|
data/lib/pandorified/result.rb
CHANGED
@@ -9,6 +9,13 @@ module Pandorified
|
|
9
9
|
@xml = Nokogiri::XML(RestClient.post(API_URL, params))
|
10
10
|
end
|
11
11
|
|
12
|
+
# @return [String] The bot's response to the input.
|
13
|
+
def that
|
14
|
+
@that ||= @xml.xpath('/result/that').first.text.strip
|
15
|
+
end
|
16
|
+
|
17
|
+
alias_method :to_s, :that
|
18
|
+
|
12
19
|
# Check the status of this result. See {#success?} and {#error?}.
|
13
20
|
#
|
14
21
|
# @return [Number] A status number as returned by Pandorabots.
|
@@ -16,31 +23,6 @@ module Pandorified
|
|
16
23
|
@status ||= @xml.xpath('/result/@status').first.value.to_i
|
17
24
|
end
|
18
25
|
|
19
|
-
# @return [String] The botid of the bot this result is for.
|
20
|
-
def botid
|
21
|
-
@botid ||= @xml.xpath('/result/@botid').first.value
|
22
|
-
end
|
23
|
-
|
24
|
-
# @return [String] The custid for this session.
|
25
|
-
def custid
|
26
|
-
@custid ||= @xml.xpath('/result/@custid').first.value
|
27
|
-
end
|
28
|
-
|
29
|
-
# @return [String] The orginal input that triggered this response.
|
30
|
-
def input
|
31
|
-
@input ||= @xml.xpath('/result/input').first.text
|
32
|
-
end
|
33
|
-
|
34
|
-
# @return [String] The bot's response to the input.
|
35
|
-
def that
|
36
|
-
@that ||= @xml.xpath('/result/that').first.text
|
37
|
-
end
|
38
|
-
|
39
|
-
# @return [String] The error message as returned by Pandorabots, if an error occured.
|
40
|
-
def message
|
41
|
-
@message ||= @xml.xpath('/result/message').first.text
|
42
|
-
end
|
43
|
-
|
44
26
|
# @return `true` if this result was successful (no error was returned by Pandorabots), `false` otherwise.
|
45
27
|
def success?
|
46
28
|
self.status.zero?
|
@@ -56,6 +38,28 @@ module Pandorified
|
|
56
38
|
!self.success?
|
57
39
|
end
|
58
40
|
|
59
|
-
|
41
|
+
# @return [String] The error message as returned by Pandorabots, if an error occured.
|
42
|
+
def message
|
43
|
+
return nil if self.success?
|
44
|
+
@message ||= @xml.xpath('/result/message').first.text
|
45
|
+
end
|
46
|
+
|
47
|
+
alias_method :error, :message
|
48
|
+
alias_method :error_message, :message
|
49
|
+
|
50
|
+
# @return [String] The botid of the bot this result is for.
|
51
|
+
def botid
|
52
|
+
@botid ||= @xml.xpath('/result/@botid').first.value
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [String] The custid for this session.
|
56
|
+
def custid
|
57
|
+
@custid ||= @xml.xpath('/result/@custid').first.value
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [String] The orginal input that triggered this response.
|
61
|
+
def input
|
62
|
+
@input ||= @xml.xpath('/result/input').first.text
|
63
|
+
end
|
60
64
|
end
|
61
65
|
end
|
data/lib/pandorified/session.rb
CHANGED
@@ -7,7 +7,7 @@ module Pandorified
|
|
7
7
|
class Session
|
8
8
|
# A new session for conversing with a bot.
|
9
9
|
#
|
10
|
-
# @note If you choose not to specify a {custid}, one will be chosen
|
10
|
+
# @note If you choose not to specify a {custid}, one will be automatically chosen and remembered throughout the session.
|
11
11
|
#
|
12
12
|
# @param [String] botid A valid Pandorabots botid.
|
13
13
|
# @param [String] custid An identifier used to keep track of this conversation.
|
@@ -18,11 +18,12 @@ module Pandorified
|
|
18
18
|
|
19
19
|
# Send a message to this session's bot and receive a response.
|
20
20
|
#
|
21
|
-
#
|
21
|
+
# See {Pandorified::Result} for how to check for an error response and get the error message.
|
22
|
+
# Alternatively, you can use {#talk!} instead of this method, which raises an exception when Pandorabots API returns an error.
|
22
23
|
#
|
23
24
|
# @param [String] input Text to say to the bot.
|
24
25
|
#
|
25
|
-
# @return [
|
26
|
+
# @return [Pandorified::Result] The bot's response as a result object.
|
26
27
|
def talk(input)
|
27
28
|
result = Pandorified::Result.new(botid: @botid, custid: @custid, input: input)
|
28
29
|
@custid ||= result.custid if result.success?
|
@@ -30,9 +31,9 @@ module Pandorified
|
|
30
31
|
end
|
31
32
|
|
32
33
|
# Send a message to this session's bot and receive a response (if successful).
|
33
|
-
# If Pandorabots responds with an error, {Pandorified::Exceptions::PandorabotsError} is raised.
|
34
34
|
#
|
35
|
-
#
|
35
|
+
# If Pandorabots API responds with an error, {Pandorified::PandorabotsError} is raised with the specific error message.
|
36
|
+
# If you'd like to check for and handle the error yourself, you can use {#talk} instead of this method.
|
36
37
|
#
|
37
38
|
# @param [String] input Text to say to the bot.
|
38
39
|
#
|
@@ -40,6 +41,7 @@ module Pandorified
|
|
40
41
|
def talk!(input)
|
41
42
|
result = self.talk(input)
|
42
43
|
raise Pandorified::PandorabotsError, "Pandorabots returned status #{result.status}: #{result.message}" if result.error?
|
44
|
+
result.that
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
data/lib/pandorified/version.rb
CHANGED
metadata
CHANGED
@@ -1,46 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pandorified
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.9.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Justin Workman
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2013-04-09 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rest-client
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: nokogiri
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description: Pandorified makes it easy for your Ruby scripts to interact with chat
|
@@ -62,26 +57,25 @@ files:
|
|
62
57
|
- pandorified.gemspec
|
63
58
|
homepage:
|
64
59
|
licenses: []
|
60
|
+
metadata: {}
|
65
61
|
post_install_message:
|
66
62
|
rdoc_options: []
|
67
63
|
require_paths:
|
68
64
|
- lib
|
69
65
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
66
|
requirements:
|
72
|
-
- -
|
67
|
+
- - '>='
|
73
68
|
- !ruby/object:Gem::Version
|
74
69
|
version: '0'
|
75
70
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
-
none: false
|
77
71
|
requirements:
|
78
|
-
- -
|
72
|
+
- - '>='
|
79
73
|
- !ruby/object:Gem::Version
|
80
74
|
version: '0'
|
81
75
|
requirements: []
|
82
76
|
rubyforge_project:
|
83
|
-
rubygems_version:
|
77
|
+
rubygems_version: 2.0.0.rc.2
|
84
78
|
signing_key:
|
85
|
-
specification_version:
|
79
|
+
specification_version: 4
|
86
80
|
summary: A Ruby client for the Pandorabots API.
|
87
81
|
test_files: []
|