cleverbot_io 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +4 -0
- data/lib/cleverbot.rb +50 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: baa72db1b8644ae3cb3da7ea0bd67247f9ac8cdb
|
4
|
+
data.tar.gz: 62ff76a48deb80a6f8a3dbb7178f18b2dc6af61d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 84ac7b30f4d5ed396ada526ee27106a7dbb7f1f0eb1b5f5e410f89ba1f38698653be3d31439e972d37c27ee766a1dd985de40d607b0993fd5f2051a878eb40ef
|
7
|
+
data.tar.gz: f7ad9ded49e0b903edc2f699645d9ad7aeb505b14d00fb3bea92be2eb225214ae0a2cd2cdc46c95207f996a2528adcc79af91f6fee107220cbe16d0173a93e9c
|
data/CHANGELOG.md
ADDED
data/lib/cleverbot.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'httpclient'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class Cleverbot
|
5
|
+
attr_accessor :api_user
|
6
|
+
attr_accessor :api_key
|
7
|
+
attr_accessor :nick
|
8
|
+
|
9
|
+
def initialize(api_user, api_key, nick = nil)
|
10
|
+
@api_user = api_user
|
11
|
+
@api_key = api_key
|
12
|
+
@nick = nick
|
13
|
+
@client = HTTPClient.new
|
14
|
+
end
|
15
|
+
|
16
|
+
# Creates a new bot instance based on the nick. If no nick has been set, this will set a random one.
|
17
|
+
# @return [Boolean] Whether the request was successful. If true, nick will be set.
|
18
|
+
def create
|
19
|
+
params = {
|
20
|
+
user: @api_user,
|
21
|
+
key: @api_key
|
22
|
+
}
|
23
|
+
params[:nick] = @nick unless @nick.nil?
|
24
|
+
response = JSON.parse(@client.post('https://cleverbot.io/1.0/create', params).body)
|
25
|
+
@nick = response['nick'] if response['status'] == 'success'
|
26
|
+
|
27
|
+
response['status'] == 'success'
|
28
|
+
end
|
29
|
+
|
30
|
+
# Sends the bot a message and returns its response. If the nick has not been set, it will call #{create}.
|
31
|
+
# @param str [String] The message to send to the bot.
|
32
|
+
# @return [String] The bot's response, or its error message.
|
33
|
+
def say(str)
|
34
|
+
params = {
|
35
|
+
user: @api_user,
|
36
|
+
key: @api_key,
|
37
|
+
text: str
|
38
|
+
}
|
39
|
+
if @nick.nil?
|
40
|
+
create
|
41
|
+
end
|
42
|
+
params[:nick] = @nick
|
43
|
+
response = JSON.parse(@client.post('https://cleverbot.io/1.0/ask', params).body)
|
44
|
+
if response['status'] == 'success'
|
45
|
+
response['response']
|
46
|
+
else
|
47
|
+
response['status']
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cleverbot_io
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eli Foster
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httpclient
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.7.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.7.1
|
27
|
+
description: A very basic wrapper to the Cleverbot.io web API.
|
28
|
+
email: elifosterwy@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- CHANGELOG.md
|
34
|
+
- lib/cleverbot.rb
|
35
|
+
homepage: https://github.com/elifoster/cleverbot_io
|
36
|
+
licenses:
|
37
|
+
- CC-BY-NC-ND-4.0
|
38
|
+
metadata:
|
39
|
+
issue_tracker: https://github.com/elifoster/cleverbot_io/issues
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.5.1
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: A Ruby wrapper for the Cleverbot.io web API.
|
60
|
+
test_files: []
|