Module: Wordhop

Defined in:
lib/wordhop.rb

Defined Under Namespace

Classes: Partay

Constant Summary collapse

EVENTS =
[:'chat response', :'socket_id_set'].freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.apikeyObject

Return a Hash of hooks.



33
34
35
# File 'lib/wordhop.rb', line 33

def apikey
  @apikey
end

.clientkeyObject

Returns the value of attribute clientkey.



17
18
19
# File 'lib/wordhop.rb', line 17

def clientkey
  @clientkey
end

.platformObject

Returns the value of attribute platform.



17
18
19
# File 'lib/wordhop.rb', line 17

def platform
  @platform
end

.tokenObject

Returns the value of attribute token.



17
18
19
# File 'lib/wordhop.rb', line 17

def token
  @token
end

Class Method Details

.assistanceRequested(x) ⇒ Object



110
111
112
113
114
# File 'lib/wordhop.rb', line 110

def assistanceRequested(x)
    puts 'assistanceRequested'
    options = {'body':x, 'headers':headers}
    return Partay.post('/human', options)
end

.headersObject



49
50
51
# File 'lib/wordhop.rb', line 49

def headers
    @headers = {'apikey':apikey,'clientkey':clientkey,'platform':platform, 'token': token}
end

.hooksObject



53
54
55
# File 'lib/wordhop.rb', line 53

def hooks
    @hooks ||= {}
end

.hopIn(x) ⇒ Object



92
93
94
95
96
# File 'lib/wordhop.rb', line 92

def hopIn(x)
    puts 'hopIn'
    options = {'body':x, 'headers':headers}
    return Partay.post('/in', options)
end

.hopOut(x) ⇒ Object



98
99
100
101
102
# File 'lib/wordhop.rb', line 98

def hopOut(x)
    puts 'hopOut'
    options = {'body':x, 'headers':headers}
    return Partay.post('/out', options)
end

.initializeObject



19
20
21
22
23
24
# File 'lib/wordhop.rb', line 19

def initialize
    @apikey
    @clientkey
    @token
    @platform
end

.logUnknownIntent(x) ⇒ Object



104
105
106
107
108
# File 'lib/wordhop.rb', line 104

def logUnknownIntent(x)
    puts 'logUnknownIntent'
    options = {'body':x, 'headers':headers}
    return Partay.post('/unknown', options)
end

.new(*args, &block) ⇒ Object



26
27
28
29
30
# File 'lib/wordhop.rb', line 26

def new(*args, &block)
    obj = allocate
    obj.initialize(*args, &block)
    obj
end

.on(event, &block) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/wordhop.rb', line 77

def on(event, &block)
    unless EVENTS.include? event
        raise ArgumentError,
        "#{event} is not a valid event; " \
        "available events are #{EVENTS.join(',')}"
    end
    hooks[event] = block
end

.trigger(event, *args) ⇒ Object



86
87
88
89
90
# File 'lib/wordhop.rb', line 86

def trigger(event, *args)
    hooks.fetch(event).call(*args)
rescue KeyError
    $stderr.puts "Ignoring #{event} (no hook registered)"
end