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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/bullhorn/rest/entities/base.rb', line 14
def define_methods(options={})
name = entity.to_s.classify
plural = entity.to_s.pluralize
name_plural = name.pluralize
if options[:owner_methods]
define_method("department_#{plural}") do |options={}|
params = {fields: '*'}.merge(options)
path = "department#{name_plural}"
conn.get path, params
end
define_method("user_#{plural}") do |options={}|
params = {fields: '*'}.merge(options)
path = "my#{name_plural}"
conn.get path, params
end
alias_method plural, "department_#{plural}"
else
define_method(plural) do |options={}|
send "query_#{plural}", where: "id IS NOT NULL"
end
end
define_method("query_#{plural}") do |options={}|
params = {fields: '*'}.merge(options)
path = "query/#{name}"
conn.get path, params
end
unless options[:immutable]
define_method("create_#{entity}") do |id, attributes={}|
path = "#{name}/#{id}"
conn.put path, attributes
end
define_method("update_#{entity}") do |id, attributes={}|
path = "#{name}/#{id}"
conn.post path, attributes
end
define_method("delete_#{entity}") do |id|
path = "#{name}/#{id}"
conn.delete path
end
end
end
|