retort_api 1.0.2
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 +7 -0
- data/lib/retort_api.rb +115 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 732d3308b2ae06021aff3d636cae24e48c339de1
|
4
|
+
data.tar.gz: e30fd49e6679f2fe78e5a3bf026efb0f0156a515
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 85d2cb0c843609b63f897b9249915ef842fbefe89965a57081e5d7cb7d5d6afcd64452ee19e76e865643a62478961afb48a275bfa7309a73d7e324cb786a29a3
|
7
|
+
data.tar.gz: 5bfb5caf2f2573903d7f19a7bd6fe2037d78e23d4539a98323a90edc156df3be67731fe84e530352e5cc0fbf8b13dc7feb256ea229a4739b4fe7cf6ee9f6d362
|
data/lib/retort_api.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
class RetortApi
|
2
|
+
require 'httparty'
|
3
|
+
|
4
|
+
#TODO: Identity mirroring for most endpoints
|
5
|
+
#TODO: Rate limiting as needed
|
6
|
+
#TODO: HTTPS on API
|
7
|
+
#TODO: Handle failed requests to Retort
|
8
|
+
#TODO: Setting to fall back on no-identity if no results found for an identity
|
9
|
+
#TODO: Excluding specific identities (or creating inclusive identity groups)
|
10
|
+
|
11
|
+
BASE_URL = 'http://www.retort.us/'
|
12
|
+
|
13
|
+
def self.get_retort stimulus:
|
14
|
+
json = JSON.parse HTTParty.get([
|
15
|
+
BASE_URL,
|
16
|
+
'/retort/get',
|
17
|
+
"?stimulus=#{stimulus}"
|
18
|
+
].join).body
|
19
|
+
|
20
|
+
json["response"]
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.add_retort stimulus:, response:
|
24
|
+
JSON.parse HTTParty.get([
|
25
|
+
BASE_URL,
|
26
|
+
'/retort/add',
|
27
|
+
"?stimulus=#{stimulus}&response=#{response}"
|
28
|
+
].join).body
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.get_opening_message
|
32
|
+
json = JSON.parse HTTParty.get([
|
33
|
+
BASE_URL,
|
34
|
+
'/retort/random/opening'
|
35
|
+
].join).body
|
36
|
+
|
37
|
+
json["response"]
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.markov_chain identity: nil
|
41
|
+
HTTParty.get([
|
42
|
+
BASE_URL,
|
43
|
+
'/markov/create',
|
44
|
+
"?#{self.parameterize_hash identity}"
|
45
|
+
].join).body
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.markov_ipsum identity: nil
|
49
|
+
HTTParty.get([
|
50
|
+
BASE_URL,
|
51
|
+
'/markov/ipsum',
|
52
|
+
"?#{self.parameterize_hash identity}"
|
53
|
+
].join).body
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.get_word_before after_word
|
57
|
+
json = JSON.parse HTTParty.get([
|
58
|
+
BASE_URL,
|
59
|
+
'/bigram/prior',
|
60
|
+
"?after=#{after_word}"
|
61
|
+
].join).body
|
62
|
+
|
63
|
+
json["prior"]
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.get_all_words_before after_word
|
67
|
+
JSON.parse HTTParty.get([
|
68
|
+
BASE_URL,
|
69
|
+
'/bigram/antecedents',
|
70
|
+
"?after=#{after_word}"
|
71
|
+
].join).body
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.get_word_after previous_word
|
75
|
+
json = JSON.parse HTTParty.get([
|
76
|
+
BASE_URL,
|
77
|
+
'/bigram/next',
|
78
|
+
"?prior=#{previous_word}"
|
79
|
+
].join).body
|
80
|
+
|
81
|
+
json["after"]
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.get_all_words_after previous_word
|
85
|
+
JSON.parse HTTParty.get([
|
86
|
+
BASE_URL,
|
87
|
+
'/bigram/consequents',
|
88
|
+
"?prior=#{previous_word}"
|
89
|
+
].join).body
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.add_bigram prior, after, identity: nil
|
93
|
+
JSON.parse HTTParty.get([
|
94
|
+
BASE_URL,
|
95
|
+
'/bigram/add',
|
96
|
+
"?prior=#{prior}&after=#{after}#{parameterize_hash identity}"
|
97
|
+
].join).body
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.parse_bigram message, identity: nil
|
101
|
+
JSON.parse HTTParty.get([
|
102
|
+
BASE_URL,
|
103
|
+
'/bigram/parse',
|
104
|
+
"?message=#{message}#{parameterize_hash identity}"
|
105
|
+
].join).body
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def self.parameterize_hash identity_hash
|
111
|
+
# Turns {medium: 'twitter', identifier: 'drusepth'} to "&medium=twitter&identifier=drusepth"
|
112
|
+
(identity_hash || {}).map { |key, value| "&#{key}=#{value}" }.join
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: retort_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Brown
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Wrapper for retort.us Markov generation
|
14
|
+
email: andrew@indentlabs.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/retort_api.rb
|
20
|
+
homepage: http://www.retort.us/
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.4.5.1
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Wrapper for retort.us Markov generation
|
44
|
+
test_files: []
|