class RetortApi
Constants
- BASE_URL
TODO: Identity mirroring for retort endpoints TODO: Rate limiting as needed TODO: HTTPS on API TODO: Handle failed requests to Retort TODO: Setting to fall back on no-identity if no results found for an identity TODO: Excluding specific identities (or creating inclusive identity groups)
Public Class Methods
add_bigram(prior, after, identity: {})
click to toggle source
# File lib/retort_api.rb, line 92 def self.add_bigram prior, after, identity: {} JSON.parse HTTParty.get([ BASE_URL, '/bigram/add', "?prior=#{prior}&after=#{after}#{parameterize_hash identity}" ].join).body end
add_retort(stimulus:, response: JSON.parse HTTParty.get([ BASE_URL, '/retort/add', "?stimulus=
click to toggle source
# File lib/retort_api.rb, line 23 def self.add_retort stimulus:, response: JSON.parse HTTParty.get([ BASE_URL, '/retort/add', "?stimulus=#{stimulus}&response=#{response}" ].join).body end
get_all_words_after(previous_word, identity: {})
click to toggle source
# File lib/retort_api.rb, line 84 def self.get_all_words_after previous_word, identity: {} JSON.parse HTTParty.get([ BASE_URL, '/bigram/consequents', "?prior=#{previous_word}#{parameterize_hash identity}" ].join).body end
get_all_words_before(after_word, identity: {})
click to toggle source
# File lib/retort_api.rb, line 66 def self.get_all_words_before after_word, identity: {} JSON.parse HTTParty.get([ BASE_URL, '/bigram/antecedents', "?after=#{after_word}#{parameterize_hash identity}" ].join).body end
get_opening_message()
click to toggle source
# File lib/retort_api.rb, line 31 def self.get_opening_message json = JSON.parse HTTParty.get([ BASE_URL, '/retort/random/opening' ].join).body json["response"] end
get_retort(stimulus: json = JSON.parse HTTParty.get([ BASE_URL, '/retort/get', "?stimulus=
click to toggle source
# File lib/retort_api.rb, line 13 def self.get_retort stimulus: json = JSON.parse HTTParty.get([ BASE_URL, '/retort/get', "?stimulus=#{stimulus}" ].join).body json["response"] end
get_word_after(previous_word, identity: {})
click to toggle source
# File lib/retort_api.rb, line 74 def self.get_word_after previous_word, identity: {} json = JSON.parse HTTParty.get([ BASE_URL, '/bigram/next', "?prior=#{previous_word}#{parameterize_hash identity}" ].join).body json["after"] end
get_word_before(after_word, identity: {})
click to toggle source
# File lib/retort_api.rb, line 56 def self.get_word_before after_word, identity: {} json = JSON.parse HTTParty.get([ BASE_URL, '/bigram/prior', "?after=#{after_word}#{parameterize_hash identity}" ].join).body json["prior"] end
markov_chain(identity: nil)
click to toggle source
# File lib/retort_api.rb, line 40 def self.markov_chain identity: nil HTTParty.get([ BASE_URL, '/markov/create', "?#{self.parameterize_hash identity}" ].join).body end
markov_ipsum(identity: nil)
click to toggle source
# File lib/retort_api.rb, line 48 def self.markov_ipsum identity: nil HTTParty.get([ BASE_URL, '/markov/ipsum', "?#{self.parameterize_hash identity}" ].join).body end
parse_bigram(message, identity: {})
click to toggle source
# File lib/retort_api.rb, line 100 def self.parse_bigram message, identity: {} JSON.parse HTTParty.get([ BASE_URL, '/bigram/parse', "?message=#{message}#{parameterize_hash identity}" ].join).body end
Private Class Methods
parameterize_hash(identity_hash)
click to toggle source
# File lib/retort_api.rb, line 110 def self.parameterize_hash identity_hash # Turns {medium: 'twitter', identifier: 'drusepth'} to "&medium=twitter&identifier=drusepth" (identity_hash || {}).map { |key, value| "&#{key}=#{value}" }.join end