-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.rb
49 lines (36 loc) · 1013 Bytes
/
example.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require 'hactor'
def start
Hactor.start url: 'http://haltalk.herokuapp.com/', actor: HomeActor.new
end
class HomeActor
include Hactor::Actor
def on_200(response)
response.follow 'ht:latest-posts', actor: LatestPostActor.new
name = 'CHANGE ME'
user_name = 'PLEASE_CHANGE_ME'
response.traverse('ht:signup', method: 'POST',
body: { username: user_name, real_name: name, password: 'blarb' },
actor: SignedUpActor.new)
response.follow('ht:me', expand_with: { name: user_name },
actor: ->(res) { puts res.properties })
end
end
class LatestPostActor
include Hactor::Actor
def on_200(response)
response.embedded_resources.each do |resource|
puts resource.link('self').href
puts resource.properties
end
end
end
class SignedUpActor
include Hactor::Actor
def on_201(response)
puts "Created an account"
end
def on_400(response)
puts "Failed to create account"
end
end
start()