pandorified 0.9.13 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.devcontainer/Dockerfile +31 -0
- data/.devcontainer/devcontainer.json +10 -0
- data/.gitattributes +1 -0
- data/.gitignore +6 -6
- data/.rspec +1 -1
- data/.rubocop.yml +12 -12
- data/Gemfile +5 -5
- data/README.md +1 -1
- data/Rakefile +14 -13
- data/lib/pandorified/result.rb +10 -12
- data/lib/pandorified/session.rb +20 -1
- data/lib/pandorified/version.rb +1 -1
- data/lib/pandorified.rb +48 -48
- data/pandorified.gemspec +3 -3
- data/spec/lib/pandorified_spec.rb +120 -3
- data/spec/spec_helper.rb +113 -113
- metadata +15 -29
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 88d40fc6d68b74277ad68df2ea47dd434554a78ea76f34f4e56af36471643d94
|
|
4
|
+
data.tar.gz: b57523f67d8a8dd6c66ad50558925b1132ca109f34854addf45e5df98b5723ea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1345a2df43b6cda07ac6f29d3ca08bae3da805672f822e084765c7e715c1cdf6d0363726d34e023638eaeef87b2a7ceb82dc28825f7ee4d407d4ad72f89c1869
|
|
7
|
+
data.tar.gz: c7971327d86af6c2f69187e434158c5a96cd6716963dd3d933e12de3d856e03229bcba571299fda77013c8023831b83bda9041e236d6cb0fdc068186ebf7e511
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
FROM ruby:latest
|
|
2
|
+
|
|
3
|
+
ARG USERNAME=vscode
|
|
4
|
+
ARG USER_UID=1000
|
|
5
|
+
ARG USER_GID=${USER_UID}
|
|
6
|
+
|
|
7
|
+
RUN apt-get update \
|
|
8
|
+
&& apt-get install -y --no-install-recommends \
|
|
9
|
+
build-essential \
|
|
10
|
+
ca-certificates \
|
|
11
|
+
git \
|
|
12
|
+
sudo \
|
|
13
|
+
&& rm -rf /var/lib/apt/lists/* \
|
|
14
|
+
&& groupadd --gid ${USER_GID} ${USERNAME} \
|
|
15
|
+
&& useradd --uid ${USER_UID} --gid ${USER_GID} -m ${USERNAME} \
|
|
16
|
+
&& echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/${USERNAME} \
|
|
17
|
+
&& chmod 0440 /etc/sudoers.d/${USERNAME} \
|
|
18
|
+
&& mkdir -p /workspaces /usr/local/bundle \
|
|
19
|
+
/home/${USERNAME}/.bundle /home/${USERNAME}/.bundle/bin /home/${USERNAME}/.gem \
|
|
20
|
+
&& chown -R ${USERNAME}:${USERNAME} /workspaces /usr/local/bundle \
|
|
21
|
+
/home/${USERNAME}/.bundle /home/${USERNAME}/.bundle/bin /home/${USERNAME}/.gem
|
|
22
|
+
|
|
23
|
+
USER ${USERNAME}
|
|
24
|
+
WORKDIR /workspaces/pandorified-gem
|
|
25
|
+
|
|
26
|
+
ENV BUNDLE_RETRY=3 \
|
|
27
|
+
BUNDLE_PATH=/home/${USERNAME}/.bundle \
|
|
28
|
+
BUNDLE_APP_CONFIG=/home/${USERNAME}/.bundle \
|
|
29
|
+
BUNDLE_BIN=/home/${USERNAME}/.bundle/bin \
|
|
30
|
+
GEM_HOME=/home/${USERNAME}/.gem \
|
|
31
|
+
PATH="${PATH}:/home/${USERNAME}/.bundle/bin"
|
data/.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
* text=auto eol=lf
|
data/.gitignore
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
*.gem
|
|
2
|
-
.bundle
|
|
3
|
-
.yardoc
|
|
4
|
-
Gemfile.lock
|
|
5
|
-
pkg/*
|
|
6
|
-
doc/*
|
|
1
|
+
*.gem
|
|
2
|
+
.bundle
|
|
3
|
+
.yardoc
|
|
4
|
+
Gemfile.lock
|
|
5
|
+
pkg/*
|
|
6
|
+
doc/*
|
data/.rspec
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
--require spec_helper
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
Metrics/BlockLength:
|
|
2
|
-
ExcludedMethods:
|
|
3
|
-
- describe
|
|
4
|
-
|
|
5
|
-
Style/HashEachMethods:
|
|
6
|
-
Enabled: true
|
|
7
|
-
|
|
8
|
-
Style/HashTransformKeys:
|
|
9
|
-
Enabled: false
|
|
10
|
-
|
|
11
|
-
Style/HashTransformValues:
|
|
12
|
-
Enabled: false
|
|
1
|
+
Metrics/BlockLength:
|
|
2
|
+
ExcludedMethods:
|
|
3
|
+
- describe
|
|
4
|
+
|
|
5
|
+
Style/HashEachMethods:
|
|
6
|
+
Enabled: true
|
|
7
|
+
|
|
8
|
+
Style/HashTransformKeys:
|
|
9
|
+
Enabled: false
|
|
10
|
+
|
|
11
|
+
Style/HashTransformValues:
|
|
12
|
+
Enabled: false
|
data/Gemfile
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
source 'https://rubygems.org'
|
|
4
|
-
|
|
5
|
-
gemspec
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source 'https://rubygems.org'
|
|
4
|
+
|
|
5
|
+
gemspec
|
data/README.md
CHANGED
|
@@ -53,7 +53,7 @@ Author
|
|
|
53
53
|
License
|
|
54
54
|
-------
|
|
55
55
|
|
|
56
|
-
Copyright © 2011-
|
|
56
|
+
Copyright © 2011-2026 Justin Workman
|
|
57
57
|
|
|
58
58
|
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:
|
|
59
59
|
|
data/Rakefile
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'bundler/
|
|
4
|
-
require '
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
require 'bundler/gem_tasks'
|
|
5
|
+
require 'rspec/core/rake_task'
|
|
6
|
+
|
|
7
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
8
|
+
|
|
9
|
+
task default: :spec
|
|
10
|
+
|
|
11
|
+
desc 'Open an irb session preloaded with this library'
|
|
12
|
+
task :console do
|
|
13
|
+
sh 'irb -rubygems -I lib -r pandorified.rb'
|
|
14
|
+
end
|
data/lib/pandorified/result.rb
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require '
|
|
4
|
-
require '
|
|
3
|
+
require 'rexml/document'
|
|
4
|
+
require 'rexml/xpath'
|
|
5
5
|
|
|
6
6
|
module Pandorified
|
|
7
|
-
API_URL = 'https://www.pandorabots.com/pandora/talk-xml'
|
|
8
|
-
|
|
9
7
|
# The result of sending a message to a bot, including the response message if
|
|
10
8
|
# successful.
|
|
11
9
|
class Result
|
|
12
|
-
def initialize(
|
|
13
|
-
@xml =
|
|
10
|
+
def initialize(response_body)
|
|
11
|
+
@xml = REXML::Document.new(response_body)
|
|
14
12
|
end
|
|
15
13
|
|
|
16
14
|
# @return [String] The bot's response to the input.
|
|
17
15
|
def that
|
|
18
|
-
@that ||= @xml
|
|
16
|
+
@that ||= REXML::XPath.first(@xml, '/result/that').text.strip
|
|
19
17
|
end
|
|
20
18
|
|
|
21
19
|
alias to_s that
|
|
@@ -24,7 +22,7 @@ module Pandorified
|
|
|
24
22
|
#
|
|
25
23
|
# @return [Number] A status number as returned by Pandorabots.
|
|
26
24
|
def status
|
|
27
|
-
@status ||= @xml
|
|
25
|
+
@status ||= REXML::XPath.first(@xml, '/result/@status').value.to_i
|
|
28
26
|
end
|
|
29
27
|
|
|
30
28
|
# @return `true` if this result was successful (no error was returned by
|
|
@@ -49,7 +47,7 @@ module Pandorified
|
|
|
49
47
|
def message
|
|
50
48
|
return nil if success?
|
|
51
49
|
|
|
52
|
-
@message ||= @xml
|
|
50
|
+
@message ||= REXML::XPath.first(@xml, '/result/message').text
|
|
53
51
|
end
|
|
54
52
|
|
|
55
53
|
alias error message
|
|
@@ -57,17 +55,17 @@ module Pandorified
|
|
|
57
55
|
|
|
58
56
|
# @return [String] The botid of the bot this result is for.
|
|
59
57
|
def botid
|
|
60
|
-
@botid ||= @xml
|
|
58
|
+
@botid ||= REXML::XPath.first(@xml, '/result/@botid').value
|
|
61
59
|
end
|
|
62
60
|
|
|
63
61
|
# @return [String] The custid for this session.
|
|
64
62
|
def custid
|
|
65
|
-
@custid ||= @xml
|
|
63
|
+
@custid ||= REXML::XPath.first(@xml, '/result/@custid').value
|
|
66
64
|
end
|
|
67
65
|
|
|
68
66
|
# @return [String] The orginal input that triggered this response.
|
|
69
67
|
def input
|
|
70
|
-
@input ||= @xml
|
|
68
|
+
@input ||= REXML::XPath.first(@xml, '/result/input').text
|
|
71
69
|
end
|
|
72
70
|
end
|
|
73
71
|
end
|
data/lib/pandorified/session.rb
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'net/http'
|
|
3
4
|
require 'pandorified/result'
|
|
5
|
+
require 'uri'
|
|
4
6
|
|
|
5
7
|
module Pandorified
|
|
8
|
+
API_URL = 'https://www.pandorabots.com/pandora/talk-xml'
|
|
9
|
+
|
|
6
10
|
# Raised when Pandorabots returns an API result with a non-zero status.
|
|
7
11
|
class PandorabotsError < StandardError; end
|
|
8
12
|
|
|
@@ -33,11 +37,12 @@ module Pandorified
|
|
|
33
37
|
#
|
|
34
38
|
# @return [Pandorified::Result] The bot's response as a result object.
|
|
35
39
|
def talk(input)
|
|
36
|
-
|
|
40
|
+
response_body = post_talk_xml!(
|
|
37
41
|
botid: @botid,
|
|
38
42
|
custid: @custid,
|
|
39
43
|
input: input
|
|
40
44
|
)
|
|
45
|
+
result = Pandorified::Result.new(response_body)
|
|
41
46
|
|
|
42
47
|
@custid ||= result.custid if result.success?
|
|
43
48
|
|
|
@@ -67,5 +72,19 @@ module Pandorified
|
|
|
67
72
|
|
|
68
73
|
result.that
|
|
69
74
|
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def post_talk_xml!(params)
|
|
79
|
+
uri = URI(API_URL)
|
|
80
|
+
request = Net::HTTP::Post.new(uri)
|
|
81
|
+
request.set_form_data(params)
|
|
82
|
+
|
|
83
|
+
Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
|
|
84
|
+
response = http.request(request)
|
|
85
|
+
response.value
|
|
86
|
+
response.body
|
|
87
|
+
end
|
|
88
|
+
end
|
|
70
89
|
end
|
|
71
90
|
end
|
data/lib/pandorified/version.rb
CHANGED
data/lib/pandorified.rb
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'pandorified/version'
|
|
4
|
-
require 'pandorified/result'
|
|
5
|
-
require 'pandorified/session'
|
|
6
|
-
|
|
7
|
-
# This is the top-level module for interacting with the Pandorabots API.
|
|
8
|
-
#
|
|
9
|
-
# There are some sugar methods which delegate to {Pandorified::Session} under
|
|
10
|
-
# the hood.
|
|
11
|
-
module Pandorified
|
|
12
|
-
# Send a message to a bot and receive a response.
|
|
13
|
-
#
|
|
14
|
-
# See {Pandorified::Result} for ways to handle the response, or use {.talk!}
|
|
15
|
-
# which raises an exception on errors.
|
|
16
|
-
#
|
|
17
|
-
# If you want to remember the {botid} and {custid} between multiple calls,
|
|
18
|
-
# you should use {Pandorabots::Session} instead of this method.
|
|
19
|
-
#
|
|
20
|
-
# @param [String] input Text to say to the bot.
|
|
21
|
-
# @param [String] botid A valid Pandorabots botid.
|
|
22
|
-
# @param [String] custid An itentifier used to keep track of this conversaion.
|
|
23
|
-
#
|
|
24
|
-
# @return [Pandorified::Result] The bot's response as a result object.
|
|
25
|
-
def self.talk(input, botid, custid = nil)
|
|
26
|
-
Pandorified::Session.new(botid, custid).talk(input)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# Send a message to a bot and receive a response (if successsful).
|
|
30
|
-
#
|
|
31
|
-
# If Pandorabots responds with an error, {Pandorified::PandorabotsError} is
|
|
32
|
-
# raised.
|
|
33
|
-
#
|
|
34
|
-
# If you'd rather check for and handle the error yourself, use {.talk}
|
|
35
|
-
# instead of this method.
|
|
36
|
-
#
|
|
37
|
-
# If you want to remember the {botid} and {custid} between multiple calls,
|
|
38
|
-
# you should use {Pandorabots::Session} instead of this method.
|
|
39
|
-
#
|
|
40
|
-
# @param [String] input Text to say to the bot.
|
|
41
|
-
# @param [String] botid A valid Pandorabots botid.
|
|
42
|
-
# @param [String] custid An itentifier used to keep track of this conversaion.
|
|
43
|
-
#
|
|
44
|
-
# @return [String] The bot's response text.
|
|
45
|
-
def self.talk!(input, botid, custid = nil)
|
|
46
|
-
Pandorified::Session.new(botid, custid).talk!(input).to_s
|
|
47
|
-
end
|
|
48
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'pandorified/version'
|
|
4
|
+
require 'pandorified/result'
|
|
5
|
+
require 'pandorified/session'
|
|
6
|
+
|
|
7
|
+
# This is the top-level module for interacting with the Pandorabots API.
|
|
8
|
+
#
|
|
9
|
+
# There are some sugar methods which delegate to {Pandorified::Session} under
|
|
10
|
+
# the hood.
|
|
11
|
+
module Pandorified
|
|
12
|
+
# Send a message to a bot and receive a response.
|
|
13
|
+
#
|
|
14
|
+
# See {Pandorified::Result} for ways to handle the response, or use {.talk!}
|
|
15
|
+
# which raises an exception on errors.
|
|
16
|
+
#
|
|
17
|
+
# If you want to remember the {botid} and {custid} between multiple calls,
|
|
18
|
+
# you should use {Pandorabots::Session} instead of this method.
|
|
19
|
+
#
|
|
20
|
+
# @param [String] input Text to say to the bot.
|
|
21
|
+
# @param [String] botid A valid Pandorabots botid.
|
|
22
|
+
# @param [String] custid An itentifier used to keep track of this conversaion.
|
|
23
|
+
#
|
|
24
|
+
# @return [Pandorified::Result] The bot's response as a result object.
|
|
25
|
+
def self.talk(input, botid, custid = nil)
|
|
26
|
+
Pandorified::Session.new(botid, custid).talk(input)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Send a message to a bot and receive a response (if successsful).
|
|
30
|
+
#
|
|
31
|
+
# If Pandorabots responds with an error, {Pandorified::PandorabotsError} is
|
|
32
|
+
# raised.
|
|
33
|
+
#
|
|
34
|
+
# If you'd rather check for and handle the error yourself, use {.talk}
|
|
35
|
+
# instead of this method.
|
|
36
|
+
#
|
|
37
|
+
# If you want to remember the {botid} and {custid} between multiple calls,
|
|
38
|
+
# you should use {Pandorabots::Session} instead of this method.
|
|
39
|
+
#
|
|
40
|
+
# @param [String] input Text to say to the bot.
|
|
41
|
+
# @param [String] botid A valid Pandorabots botid.
|
|
42
|
+
# @param [String] custid An itentifier used to keep track of this conversaion.
|
|
43
|
+
#
|
|
44
|
+
# @return [String] The bot's response text.
|
|
45
|
+
def self.talk!(input, botid, custid = nil)
|
|
46
|
+
Pandorified::Session.new(botid, custid).talk!(input).to_s
|
|
47
|
+
end
|
|
48
|
+
end
|
data/pandorified.gemspec
CHANGED
|
@@ -10,6 +10,8 @@ Gem::Specification.new do |spec|
|
|
|
10
10
|
spec.authors = 'Justin Workman'
|
|
11
11
|
spec.email = 'xtagon@gmail.com'
|
|
12
12
|
spec.summary = 'A Ruby client for the Pandorabots API.'
|
|
13
|
+
spec.license = 'MIT'
|
|
14
|
+
spec.required_ruby_version = '>= 3.0'
|
|
13
15
|
|
|
14
16
|
spec.description = <<~DOC.chomp
|
|
15
17
|
Pandorified makes it easy for your Ruby scripts to interact with chat bots hosted on Pandorabots.
|
|
@@ -25,9 +27,7 @@ Gem::Specification.new do |spec|
|
|
|
25
27
|
|
|
26
28
|
spec.require_paths = ['lib']
|
|
27
29
|
|
|
28
|
-
spec.
|
|
29
|
-
spec.add_runtime_dependency 'rest-client', '>= 1.7.3'
|
|
30
|
-
|
|
30
|
+
spec.add_development_dependency 'rake', '~> 13.2'
|
|
31
31
|
spec.add_development_dependency 'bundler-audit'
|
|
32
32
|
spec.add_development_dependency 'rspec'
|
|
33
33
|
spec.add_development_dependency 'rubocop'
|
|
@@ -3,7 +3,118 @@
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
|
|
5
5
|
describe Pandorified do
|
|
6
|
-
describe '
|
|
6
|
+
describe '.talk' do
|
|
7
|
+
let(:input) { 'Are you a robot?' }
|
|
8
|
+
let(:botid) { 'np218q9s7r346nqo' }
|
|
9
|
+
let(:custid) { nil }
|
|
10
|
+
|
|
11
|
+
let(:request_body) do
|
|
12
|
+
{
|
|
13
|
+
'botid' => botid,
|
|
14
|
+
'custid' => nil,
|
|
15
|
+
'input' => input
|
|
16
|
+
}
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
context 'when successful' do
|
|
20
|
+
subject(:result) { described_class.talk(input, botid, custid) }
|
|
21
|
+
|
|
22
|
+
let(:that) { 'Of course not!' }
|
|
23
|
+
let(:session_custid) { 'fec7cfc40e5b751a' }
|
|
24
|
+
|
|
25
|
+
let(:response_body) do
|
|
26
|
+
<<~XML
|
|
27
|
+
<result status="0" botid="#{botid}" custid="#{session_custid}">
|
|
28
|
+
<input>#{input}</input>
|
|
29
|
+
<that>#{that}</that>
|
|
30
|
+
</result>
|
|
31
|
+
XML
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
let(:response_headers) do
|
|
35
|
+
{ content_type: 'text/xml' }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
before :each do
|
|
39
|
+
stub_request(:post, 'https://www.pandorabots.com/pandora/talk-xml')
|
|
40
|
+
.with(body: request_body)
|
|
41
|
+
.to_return(
|
|
42
|
+
status: 200,
|
|
43
|
+
body: response_body,
|
|
44
|
+
headers: response_headers
|
|
45
|
+
)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'returns the parsed successful response' do
|
|
49
|
+
expect(result).to be_successful
|
|
50
|
+
expect(result.error?).to be(false)
|
|
51
|
+
expect(result.status).to eq(0)
|
|
52
|
+
expect(result.botid).to eq(botid)
|
|
53
|
+
expect(result.custid).to eq(session_custid)
|
|
54
|
+
expect(result.input).to eq(input)
|
|
55
|
+
expect(result.that).to eq(that)
|
|
56
|
+
expect(result.message).to be_nil
|
|
57
|
+
expect(result.to_s).to eq(that)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
context 'when unsuccessful' do
|
|
62
|
+
subject(:result) { described_class.talk(input, botid, custid) }
|
|
63
|
+
|
|
64
|
+
let(:response_body) do
|
|
65
|
+
<<~XML
|
|
66
|
+
<result status="1" botid="#{botid}" custid="fec7cfc40e5b751a">
|
|
67
|
+
<input>#{input}</input>
|
|
68
|
+
<message>Something went wrong!</message>
|
|
69
|
+
</result>
|
|
70
|
+
XML
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
let(:response_headers) do
|
|
74
|
+
{ content_type: 'text/xml' }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
before :each do
|
|
78
|
+
stub_request(:post, 'https://www.pandorabots.com/pandora/talk-xml')
|
|
79
|
+
.with(body: request_body)
|
|
80
|
+
.to_return(
|
|
81
|
+
status: 200,
|
|
82
|
+
body: response_body,
|
|
83
|
+
headers: response_headers
|
|
84
|
+
)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'returns the parsed error response' do
|
|
88
|
+
expect(result.error?).to be(true)
|
|
89
|
+
expect(result).not_to be_successful
|
|
90
|
+
expect(result.status).to eq(1)
|
|
91
|
+
expect(result.botid).to eq(botid)
|
|
92
|
+
expect(result.custid).to eq('fec7cfc40e5b751a')
|
|
93
|
+
expect(result.input).to eq(input)
|
|
94
|
+
expect(result.message).to eq('Something went wrong!')
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
context 'when the HTTP response is non-success' do
|
|
99
|
+
subject(:result) { described_class.talk(input, botid, custid) }
|
|
100
|
+
|
|
101
|
+
before :each do
|
|
102
|
+
stub_request(:post, 'https://www.pandorabots.com/pandora/talk-xml')
|
|
103
|
+
.with(body: request_body)
|
|
104
|
+
.to_return(
|
|
105
|
+
status: 404,
|
|
106
|
+
body: 'Not Found',
|
|
107
|
+
headers: { content_type: 'text/plain' }
|
|
108
|
+
)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it 'raises an HTTP error' do
|
|
112
|
+
expect { result }.to raise_error(Net::HTTPClientException)
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
describe '.talk!' do
|
|
7
118
|
let(:input) { 'Are you a robot?' }
|
|
8
119
|
let(:botid) { 'np218q9s7r346nqo' }
|
|
9
120
|
let(:custid) { nil }
|
|
@@ -23,7 +134,10 @@ describe Pandorified do
|
|
|
23
134
|
|
|
24
135
|
let(:response_body) do
|
|
25
136
|
<<~XML
|
|
26
|
-
<result status="0" botid="#{botid}" custid="fec7cfc40e5b751a"
|
|
137
|
+
<result status="0" botid="#{botid}" custid="fec7cfc40e5b751a">
|
|
138
|
+
<input>#{input}</input>
|
|
139
|
+
<that>#{that}</that>
|
|
140
|
+
</result>
|
|
27
141
|
XML
|
|
28
142
|
end
|
|
29
143
|
|
|
@@ -49,7 +163,10 @@ describe Pandorified do
|
|
|
49
163
|
|
|
50
164
|
let(:response_body) do
|
|
51
165
|
<<~XML
|
|
52
|
-
<result status="1" botid="#{botid}" custid="fec7cfc40e5b751a"
|
|
166
|
+
<result status="1" botid="#{botid}" custid="fec7cfc40e5b751a">
|
|
167
|
+
<input>#{input}</input>
|
|
168
|
+
<message>Something went wrong!</message>
|
|
169
|
+
</result>
|
|
53
170
|
XML
|
|
54
171
|
end
|
|
55
172
|
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'pandorified'
|
|
4
|
-
|
|
5
|
-
require 'webmock/rspec'
|
|
6
|
-
|
|
7
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
|
8
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
|
9
|
-
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
|
10
|
-
# this file to always be loaded, without a need to explicitly require it in any
|
|
11
|
-
# files.
|
|
12
|
-
#
|
|
13
|
-
# Given that it is always loaded, you are encouraged to keep this file as
|
|
14
|
-
# light-weight as possible. Requiring heavyweight dependencies from this file
|
|
15
|
-
# will add to the boot time of your test suite on EVERY test run, even for an
|
|
16
|
-
# individual file that may not need all of that loaded. Instead, consider making
|
|
17
|
-
# a separate helper file that requires the additional dependencies and performs
|
|
18
|
-
# the additional setup, and require it from the spec files that actually need
|
|
19
|
-
# it.
|
|
20
|
-
#
|
|
21
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
22
|
-
RSpec.configure do |config|
|
|
23
|
-
# rspec-expectations config goes here. You can use an alternate
|
|
24
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
|
25
|
-
# assertions if you prefer.
|
|
26
|
-
config.expect_with :rspec do |expectations|
|
|
27
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
|
28
|
-
# and `failure_message` of custom matchers include text for helper methods
|
|
29
|
-
# defined using `chain`, e.g.:
|
|
30
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
|
31
|
-
# # => "be bigger than 2 and smaller than 4"
|
|
32
|
-
# ...rather than:
|
|
33
|
-
# # => "be bigger than 2"
|
|
34
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
|
38
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
|
39
|
-
config.mock_with :rspec do |mocks|
|
|
40
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
|
41
|
-
# a real object. This is generally recommended, and will default to
|
|
42
|
-
# `true` in RSpec 4.
|
|
43
|
-
mocks.verify_partial_doubles = true
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
|
47
|
-
# have no way to turn it off -- the option exists only for backwards
|
|
48
|
-
# compatibility in RSpec 3). It causes shared context metadata to be
|
|
49
|
-
# inherited by the metadata hash of host groups and examples, rather than
|
|
50
|
-
# triggering implicit auto-inclusion in groups with matching metadata.
|
|
51
|
-
config.shared_context_metadata_behavior = :apply_to_host_groups
|
|
52
|
-
|
|
53
|
-
# The settings below are suggested to provide a good initial experience
|
|
54
|
-
# with RSpec, but feel free to customize to your heart's content.
|
|
55
|
-
|
|
56
|
-
# This allows you to limit a spec run to individual examples or groups
|
|
57
|
-
# you care about by tagging them with `:focus` metadata. When nothing
|
|
58
|
-
# is tagged with `:focus`, all examples get run. RSpec also provides
|
|
59
|
-
# aliases for `it`, `describe`, and `context` that include `:focus`
|
|
60
|
-
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
|
61
|
-
#
|
|
62
|
-
# config.filter_run_when_matching :focus
|
|
63
|
-
|
|
64
|
-
# Allows RSpec to persist some state between runs in order to support
|
|
65
|
-
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
|
66
|
-
# you configure your source control system to ignore this file.
|
|
67
|
-
#
|
|
68
|
-
# config.example_status_persistence_file_path = "spec/examples.txt"
|
|
69
|
-
|
|
70
|
-
# Limits the available syntax to the non-monkey patched syntax that is
|
|
71
|
-
# recommended. For more details, see:
|
|
72
|
-
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
|
73
|
-
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
|
74
|
-
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
|
75
|
-
#
|
|
76
|
-
# config.disable_monkey_patching!
|
|
77
|
-
|
|
78
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
|
79
|
-
# be too noisy due to issues in dependencies.
|
|
80
|
-
#
|
|
81
|
-
# config.warnings = true
|
|
82
|
-
|
|
83
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
|
84
|
-
# file, and it's useful to allow more verbose output when running an
|
|
85
|
-
# individual spec file.
|
|
86
|
-
#
|
|
87
|
-
# if config.files_to_run.one?
|
|
88
|
-
# # Use the documentation formatter for detailed output,
|
|
89
|
-
# # unless a formatter has already been configured
|
|
90
|
-
# # (e.g. via a command-line flag).
|
|
91
|
-
# config.default_formatter = "doc"
|
|
92
|
-
# end
|
|
93
|
-
|
|
94
|
-
# Print the 10 slowest examples and example groups at the
|
|
95
|
-
# end of the spec run, to help surface which specs are running
|
|
96
|
-
# particularly slow.
|
|
97
|
-
#
|
|
98
|
-
# config.profile_examples = 10
|
|
99
|
-
|
|
100
|
-
# Run specs in random order to surface order dependencies. If you find an
|
|
101
|
-
# order dependency and want to debug it, you can fix the order by providing
|
|
102
|
-
# the seed, which is printed after each run.
|
|
103
|
-
# --seed 1234
|
|
104
|
-
#
|
|
105
|
-
# config.order = :random
|
|
106
|
-
|
|
107
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
|
108
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
|
109
|
-
# test failures related to randomization by passing the same `--seed` value
|
|
110
|
-
# as the one that triggered the failure.
|
|
111
|
-
#
|
|
112
|
-
# Kernel.srand config.seed
|
|
113
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'pandorified'
|
|
4
|
+
|
|
5
|
+
require 'webmock/rspec'
|
|
6
|
+
|
|
7
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
|
8
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
|
9
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
|
10
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
|
11
|
+
# files.
|
|
12
|
+
#
|
|
13
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
|
14
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
|
15
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
|
16
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
|
17
|
+
# a separate helper file that requires the additional dependencies and performs
|
|
18
|
+
# the additional setup, and require it from the spec files that actually need
|
|
19
|
+
# it.
|
|
20
|
+
#
|
|
21
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
22
|
+
RSpec.configure do |config|
|
|
23
|
+
# rspec-expectations config goes here. You can use an alternate
|
|
24
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
|
25
|
+
# assertions if you prefer.
|
|
26
|
+
config.expect_with :rspec do |expectations|
|
|
27
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
|
28
|
+
# and `failure_message` of custom matchers include text for helper methods
|
|
29
|
+
# defined using `chain`, e.g.:
|
|
30
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
|
31
|
+
# # => "be bigger than 2 and smaller than 4"
|
|
32
|
+
# ...rather than:
|
|
33
|
+
# # => "be bigger than 2"
|
|
34
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
|
38
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
|
39
|
+
config.mock_with :rspec do |mocks|
|
|
40
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
|
41
|
+
# a real object. This is generally recommended, and will default to
|
|
42
|
+
# `true` in RSpec 4.
|
|
43
|
+
mocks.verify_partial_doubles = true
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
|
47
|
+
# have no way to turn it off -- the option exists only for backwards
|
|
48
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
|
49
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
|
50
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
|
51
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
|
52
|
+
|
|
53
|
+
# The settings below are suggested to provide a good initial experience
|
|
54
|
+
# with RSpec, but feel free to customize to your heart's content.
|
|
55
|
+
|
|
56
|
+
# This allows you to limit a spec run to individual examples or groups
|
|
57
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
|
58
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
|
59
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
|
60
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
|
61
|
+
#
|
|
62
|
+
# config.filter_run_when_matching :focus
|
|
63
|
+
|
|
64
|
+
# Allows RSpec to persist some state between runs in order to support
|
|
65
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
|
66
|
+
# you configure your source control system to ignore this file.
|
|
67
|
+
#
|
|
68
|
+
# config.example_status_persistence_file_path = "spec/examples.txt"
|
|
69
|
+
|
|
70
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
|
71
|
+
# recommended. For more details, see:
|
|
72
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
|
73
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
|
74
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
|
75
|
+
#
|
|
76
|
+
# config.disable_monkey_patching!
|
|
77
|
+
|
|
78
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
|
79
|
+
# be too noisy due to issues in dependencies.
|
|
80
|
+
#
|
|
81
|
+
# config.warnings = true
|
|
82
|
+
|
|
83
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
|
84
|
+
# file, and it's useful to allow more verbose output when running an
|
|
85
|
+
# individual spec file.
|
|
86
|
+
#
|
|
87
|
+
# if config.files_to_run.one?
|
|
88
|
+
# # Use the documentation formatter for detailed output,
|
|
89
|
+
# # unless a formatter has already been configured
|
|
90
|
+
# # (e.g. via a command-line flag).
|
|
91
|
+
# config.default_formatter = "doc"
|
|
92
|
+
# end
|
|
93
|
+
|
|
94
|
+
# Print the 10 slowest examples and example groups at the
|
|
95
|
+
# end of the spec run, to help surface which specs are running
|
|
96
|
+
# particularly slow.
|
|
97
|
+
#
|
|
98
|
+
# config.profile_examples = 10
|
|
99
|
+
|
|
100
|
+
# Run specs in random order to surface order dependencies. If you find an
|
|
101
|
+
# order dependency and want to debug it, you can fix the order by providing
|
|
102
|
+
# the seed, which is printed after each run.
|
|
103
|
+
# --seed 1234
|
|
104
|
+
#
|
|
105
|
+
# config.order = :random
|
|
106
|
+
|
|
107
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
|
108
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
|
109
|
+
# test failures related to randomization by passing the same `--seed` value
|
|
110
|
+
# as the one that triggered the failure.
|
|
111
|
+
#
|
|
112
|
+
# Kernel.srand config.seed
|
|
113
|
+
end
|
metadata
CHANGED
|
@@ -1,43 +1,28 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pandorified
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.10.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Justin Workman
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
13
|
+
name: rake
|
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
|
16
15
|
requirements:
|
|
17
|
-
- - "
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: 1.14.3
|
|
20
|
-
type: :runtime
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - ">="
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: 1.14.3
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: rest-client
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
16
|
+
- - "~>"
|
|
32
17
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
34
|
-
type: :
|
|
18
|
+
version: '13.2'
|
|
19
|
+
type: :development
|
|
35
20
|
prerelease: false
|
|
36
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
22
|
requirements:
|
|
38
|
-
- - "
|
|
23
|
+
- - "~>"
|
|
39
24
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
25
|
+
version: '13.2'
|
|
41
26
|
- !ruby/object:Gem::Dependency
|
|
42
27
|
name: bundler-audit
|
|
43
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -115,6 +100,9 @@ executables: []
|
|
|
115
100
|
extensions: []
|
|
116
101
|
extra_rdoc_files: []
|
|
117
102
|
files:
|
|
103
|
+
- ".devcontainer/Dockerfile"
|
|
104
|
+
- ".devcontainer/devcontainer.json"
|
|
105
|
+
- ".gitattributes"
|
|
118
106
|
- ".gitignore"
|
|
119
107
|
- ".rspec"
|
|
120
108
|
- ".rubocop.yml"
|
|
@@ -128,11 +116,10 @@ files:
|
|
|
128
116
|
- pandorified.gemspec
|
|
129
117
|
- spec/lib/pandorified_spec.rb
|
|
130
118
|
- spec/spec_helper.rb
|
|
131
|
-
|
|
132
|
-
|
|
119
|
+
licenses:
|
|
120
|
+
- MIT
|
|
133
121
|
metadata:
|
|
134
122
|
rubygems_mfa_required: 'true'
|
|
135
|
-
post_install_message:
|
|
136
123
|
rdoc_options: []
|
|
137
124
|
require_paths:
|
|
138
125
|
- lib
|
|
@@ -140,15 +127,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
140
127
|
requirements:
|
|
141
128
|
- - ">="
|
|
142
129
|
- !ruby/object:Gem::Version
|
|
143
|
-
version: '0'
|
|
130
|
+
version: '3.0'
|
|
144
131
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
132
|
requirements:
|
|
146
133
|
- - ">="
|
|
147
134
|
- !ruby/object:Gem::Version
|
|
148
135
|
version: '0'
|
|
149
136
|
requirements: []
|
|
150
|
-
rubygems_version:
|
|
151
|
-
signing_key:
|
|
137
|
+
rubygems_version: 4.0.6
|
|
152
138
|
specification_version: 4
|
|
153
139
|
summary: A Ruby client for the Pandorabots API.
|
|
154
140
|
test_files: []
|