-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.rb
137 lines (104 loc) · 2.68 KB
/
user.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# frozen_string_literal: true
require 'time'
module Kentaa
module Api
module Resources
class User < Resource
def object_key
"User_#{id}"
end
def site
Kentaa::Api::Resources::Site.new(config, id: site_id, options: options)
end
def site_id
data[:site_id]
end
def first_name
data[:first_name]
end
def infix
data[:infix]
end
def last_name
data[:last_name]
end
def name
[first_name, infix, last_name].reject { |s| s.to_s.empty? }.join(' ')
end
def email
data[:email]
end
def avatar_url
data[:avatar_url]
end
def address
data[:address]
end
def address2
data[:address2]
end
def street
data[:street]
end
def house_number
data[:house_number]
end
def house_number_addition
data[:house_number_addition]
end
def zipcode
data[:zipcode]
end
def city
data[:city]
end
def country
data[:country]
end
def phone
data[:phone]
end
def birthday
Date.parse(data[:birthday]) if data[:birthday]
end
def gender
data[:gender]
end
def locale
data[:locale]
end
def consent
Kentaa::Api::Deprecation.warn('#consent is deprecated. Please use #consents instead.', caller)
@consent ||= Kentaa::Api::Resources::Consent.new(data[:consent]) if data[:consent]
end
def consents
@consents ||= begin
consents = []
if data[:consents]
data[:consents].each do |consent|
consents << Kentaa::Api::Resources::Consent.new(consent)
end
end
consents
end
end
def actions
@actions ||= Kentaa::Api::Resources::List.new(config, resource_class: Kentaa::Api::Resources::Action, endpoint_path: "/users/#{id}/actions")
end
def avatar
@avatar ||= Kentaa::Api::Resources::Avatar.new(config, options: options.merge(endpoint_path: "/users/#{id}"))
end
private
def load_resource
request.get("/users/#{id}", options)
end
def create_resource(attributes)
request.post('/users', options, attributes)
end
def update_resource(attributes)
request.patch("/users/#{id}", options, attributes)
end
end
end
end
end