the-city-admin 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. data/lib/api/address.rb +51 -0
  2. data/lib/api/address_list.rb +62 -0
  3. data/lib/api/api_object.rb +100 -0
  4. data/lib/api/barcode.rb +43 -0
  5. data/lib/api/checkin.rb +37 -0
  6. data/lib/api/checkin_list.rb +62 -0
  7. data/lib/api/family.rb +47 -0
  8. data/lib/api/family_member.rb +28 -0
  9. data/lib/api/group.rb +162 -0
  10. data/lib/api/group_address.rb +31 -0
  11. data/lib/api/group_address_list.rb +63 -0
  12. data/lib/api/group_checkin.rb +36 -0
  13. data/lib/api/group_checkin_list.rb +63 -0
  14. data/lib/api/group_event_attendance.rb +28 -0
  15. data/lib/api/group_event_attendance_list.rb +63 -0
  16. data/lib/api/group_export.rb +22 -0
  17. data/lib/api/group_export_list.rb +63 -0
  18. data/lib/api/group_invitation.rb +26 -0
  19. data/lib/api/group_invitation_list.rb +63 -0
  20. data/lib/api/group_list.rb +74 -0
  21. data/lib/api/group_role.rb +27 -0
  22. data/lib/api/group_role_list.rb +62 -0
  23. data/lib/api/group_tag.rb +20 -0
  24. data/lib/api/group_tag_list.rb +62 -0
  25. data/lib/api/metric.rb +50 -0
  26. data/lib/api/metric_list.rb +72 -0
  27. data/lib/api/metric_measurement.rb +29 -0
  28. data/lib/api/metric_measurement_list.rb +62 -0
  29. data/lib/api/role.rb +43 -0
  30. data/lib/api/role_list.rb +73 -0
  31. data/lib/api/skill.rb +21 -0
  32. data/lib/api/skill_list.rb +73 -0
  33. data/lib/api/skilled_user_id_list.rb +73 -0
  34. data/lib/api/skilled_user_list.rb +73 -0
  35. data/lib/api/tag.rb +32 -0
  36. data/lib/api/tag_group_list.rb +73 -0
  37. data/lib/api/tag_list.rb +73 -0
  38. data/lib/api/terminology.rb +32 -0
  39. data/lib/api/terminology_list.rb +73 -0
  40. data/lib/api/user.rb +207 -0
  41. data/lib/api/user_address.rb +31 -0
  42. data/lib/api/user_address_list.rb +62 -0
  43. data/lib/api/user_admin_privilege.rb +28 -0
  44. data/lib/api/user_admin_privilege_list.rb +63 -0
  45. data/lib/api/user_barcode.rb +20 -0
  46. data/lib/api/user_count.rb +40 -0
  47. data/lib/api/user_family_list.rb +71 -0
  48. data/lib/api/user_family_member.rb +28 -0
  49. data/lib/api/user_invitation.rb +26 -0
  50. data/lib/api/user_invitation_list.rb +63 -0
  51. data/lib/api/user_list.rb +72 -0
  52. data/lib/api/user_note.rb +31 -0
  53. data/lib/api/user_note_list.rb +63 -0
  54. data/lib/api/user_process.rb +21 -0
  55. data/lib/api/user_process_list.rb +63 -0
  56. data/lib/api/user_role.rb +34 -0
  57. data/lib/api/user_role_list.rb +74 -0
  58. data/lib/api/user_skill.rb +22 -0
  59. data/lib/api/user_skill_list.rb +74 -0
  60. data/lib/api/web_hook.rb +34 -0
  61. data/lib/api/web_hook_list.rb +74 -0
  62. data/lib/auto_load.rb +23 -0
  63. data/lib/cachers/cache_adapter.rb +50 -0
  64. data/lib/cachers/file/json_cache.rb +135 -0
  65. data/lib/common.rb +124 -0
  66. data/lib/exceptions.rb +5 -0
  67. data/lib/readers/address_list_reader.rb +21 -0
  68. data/lib/readers/address_reader.rb +22 -0
  69. data/lib/readers/api_reader.rb +28 -0
  70. data/lib/readers/checkin_list_reader.rb +21 -0
  71. data/lib/readers/checkin_reader.rb +22 -0
  72. data/lib/readers/family_reader.rb +21 -0
  73. data/lib/readers/group_address_list_reader.rb +25 -0
  74. data/lib/readers/group_checkin_list_reader.rb +25 -0
  75. data/lib/readers/group_event_attendance_list_reader.rb +25 -0
  76. data/lib/readers/group_export_list_reader.rb +25 -0
  77. data/lib/readers/group_invitation_list_reader.rb +23 -0
  78. data/lib/readers/group_list_reader.rb +25 -0
  79. data/lib/readers/group_reader.rb +21 -0
  80. data/lib/readers/group_role_list_reader.rb +23 -0
  81. data/lib/readers/group_tag_list_reader.rb +23 -0
  82. data/lib/readers/metric_list_reader.rb +22 -0
  83. data/lib/readers/metric_measurement_list_reader.rb +21 -0
  84. data/lib/readers/metric_measurement_reader.rb +22 -0
  85. data/lib/readers/metric_reader.rb +21 -0
  86. data/lib/readers/role_list_reader.rb +21 -0
  87. data/lib/readers/skill_list_reader.rb +21 -0
  88. data/lib/readers/skilled_user_id_list_reader.rb +22 -0
  89. data/lib/readers/skilled_user_list_reader.rb +22 -0
  90. data/lib/readers/tag_group_list_reader.rb +22 -0
  91. data/lib/readers/tag_list_reader.rb +22 -0
  92. data/lib/readers/tag_reader.rb +22 -0
  93. data/lib/readers/terminology_list_reader.rb +22 -0
  94. data/lib/readers/terminology_reader.rb +22 -0
  95. data/lib/readers/user_address_list_reader.rb +25 -0
  96. data/lib/readers/user_admin_privilege_list_reader.rb +23 -0
  97. data/lib/readers/user_count_reader.rb +32 -0
  98. data/lib/readers/user_family_list_reader.rb +24 -0
  99. data/lib/readers/user_invitation_list_reader.rb +23 -0
  100. data/lib/readers/user_list_reader.rb +25 -0
  101. data/lib/readers/user_note_list_reader.rb +23 -0
  102. data/lib/readers/user_process_list_reader.rb +23 -0
  103. data/lib/readers/user_reader.rb +24 -0
  104. data/lib/readers/user_role_list_reader.rb +23 -0
  105. data/lib/readers/user_skill_list_reader.rb +23 -0
  106. data/lib/readers/web_hook_list_reader.rb +21 -0
  107. data/lib/the_city_admin.rb +82 -0
  108. data/lib/writers/api_writer.rb +54 -0
  109. data/lib/writers/family_writer.rb +25 -0
  110. data/lib/writers/group_address_writer.rb +32 -0
  111. data/lib/writers/group_writer.rb +25 -0
  112. data/lib/writers/metric_measurement_writer.rb +25 -0
  113. data/lib/writers/metric_writer.rb +29 -0
  114. data/lib/writers/skill_writer.rb +25 -0
  115. data/lib/writers/tag_writer.rb +27 -0
  116. data/lib/writers/terminology_writer.rb +19 -0
  117. data/lib/writers/user_address_writer.rb +32 -0
  118. data/lib/writers/user_admin_privilege_writer.rb +24 -0
  119. data/lib/writers/user_invitation_writer.rb +23 -0
  120. data/lib/writers/user_note_writer.rb +25 -0
  121. data/lib/writers/user_role_writer.rb +28 -0
  122. data/lib/writers/user_skill_writer.rb +23 -0
  123. data/lib/writers/user_writer.rb +46 -0
  124. data/lib/writers/web_hook_writer.rb +20 -0
  125. metadata +184 -0
@@ -0,0 +1,73 @@
1
+ module TheCity
2
+
3
+ class TagList
4
+
5
+ include Enumerable
6
+
7
+ attr_reader :total_entries, :total_pages, :per_page, :current_page
8
+
9
+ # Constructor.
10
+ #
11
+ # @param options A hash of options for loading the list.
12
+ #
13
+ # Options:
14
+ # :page - The page number to get.
15
+ # :reader - The Reader to use to load the data.
16
+ #
17
+ #
18
+ # Examples:
19
+ # TagList.new
20
+ #
21
+ # TagList.new({:page => 2})
22
+ #
23
+ def initialize(options = {})
24
+ options[:page] ||= 1
25
+ reader = options[:reader] || TheCity::TagListReader.new(options)
26
+ @json_data = reader.load_feed
27
+
28
+ @total_entries = @json_data['total_entries']
29
+ @total_pages = @json_data['total_pages']
30
+ @per_page = @json_data['per_page']
31
+ @current_page = @json_data['current_page']
32
+ end
33
+
34
+
35
+ # All the tags in the list.
36
+ #
37
+ # @return array of tag names.
38
+ def all_tags
39
+ return [] if @json_data['tags'].nil?
40
+ @json_data['tags'].collect { |tag| tag['name'] }
41
+ end
42
+ alias :tags :all_tags
43
+
44
+
45
+ # Get the specified tag.
46
+ #
47
+ # @param index The index of the tag to get.
48
+ #
49
+ # @return [Tag]
50
+ def [](index)
51
+ Tag.new( @json_data['tags'][index] ) if @json_data['tags'][index]
52
+ end
53
+
54
+
55
+ # This method is needed for Enumerable.
56
+ def each &block
57
+ @json_data['tags'].each{ |tag| yield( Tag.new(tag) )}
58
+ end
59
+
60
+
61
+ # Alias the count method
62
+ alias :size :count
63
+
64
+ # Checks if the list is empty.
65
+ #
66
+ # @return True on empty, false otherwise.
67
+ def empty?
68
+ @json_data['tags'].empty?
69
+ end
70
+
71
+ end
72
+
73
+ end
@@ -0,0 +1,32 @@
1
+ module TheCity
2
+
3
+ class Terminology < ApiObject
4
+
5
+ tc_attr_accessor :term,
6
+ :label
7
+
8
+
9
+ # Loads the terminology by the specified term.
10
+ #
11
+ # @param term The term of the Terminology to load.
12
+ #
13
+ # Returns a new {Terminology} object.
14
+ def self.load_by_term(term)
15
+ reader = TerminologyReader.new(term)
16
+ self.new(reader.load_feed)
17
+ rescue
18
+ nil
19
+ end
20
+
21
+ # Constructor.
22
+ #
23
+ # @param json_data JSON data of the Terminology.
24
+ def initialize(json_data)
25
+ @writer_object = TerminologyWriter
26
+ self.term = json_data.keys[0]
27
+ self.label = json_data.values[0]
28
+ end
29
+
30
+ end
31
+
32
+ end
@@ -0,0 +1,73 @@
1
+ module TheCity
2
+
3
+ class TerminologyList
4
+
5
+ include Enumerable
6
+
7
+ attr_reader :total_entries, :total_pages, :per_page, :current_page
8
+
9
+ # Constructor.
10
+ #
11
+ # @param options A hash of options for loading the list.
12
+ #
13
+ # Options:
14
+ # :page - The page number to get.
15
+ # :reader - The Reader to use to load the data.
16
+ #
17
+ #
18
+ # Examples:
19
+ # TerminologyList.new
20
+ #
21
+ # TerminologyList.new({:page => 2})
22
+ #
23
+ def initialize(options = {})
24
+ options[:page] ||= 1
25
+ reader = options[:reader] || TheCity::TerminologyListReader.new(options)
26
+ @json_data = reader.load_feed
27
+
28
+ @total_entries = @json_data['total_entries']
29
+ @total_pages = @json_data['total_pages']
30
+ @per_page = @json_data['per_page']
31
+ @current_page = @json_data['current_page']
32
+ end
33
+
34
+
35
+ # All the terms in the list.
36
+ #
37
+ # @return array of term names.
38
+ def all_labels
39
+ return [] if @json_data['labels'].nil?
40
+ @json_data['labels'].collect { |label| label.values[0] }
41
+ end
42
+ alias :labels :all_labels
43
+
44
+
45
+ # Get the specified tag.
46
+ #
47
+ # @param index The index of the tag to get.
48
+ #
49
+ # @return [Tag]
50
+ def [](index)
51
+ Terminology.new( @json_data['labels'][index] ) if @json_data['labels'][index]
52
+ end
53
+
54
+
55
+ # This method is needed for Enumerable.
56
+ def each &block
57
+ @json_data['labels'].each{ |tag| yield( Terminology.new(tag) )}
58
+ end
59
+
60
+
61
+ # Alias the count method
62
+ alias :size :count
63
+
64
+ # Checks if the list is empty.
65
+ #
66
+ # @return True on empty, false otherwise.
67
+ def empty?
68
+ @json_data['labels'].empty?
69
+ end
70
+
71
+ end
72
+
73
+ end
data/lib/api/user.rb ADDED
@@ -0,0 +1,207 @@
1
+ module TheCity
2
+
3
+ class User < ApiObject
4
+ Gender = {:male => 'Male', :female => 'Female'}
5
+ PhoneType = {:home => 'Home', :work => 'Work', :mobile => 'Mobile'}
6
+ MaritalStatus = {:never_married => 'Never Married', :engaged => 'Engaged',
7
+ :married => 'Married', :separated => 'Separated',
8
+ :divorced => 'Divorced', :remarried => 'Re-Married',
9
+ :widowed => 'Widowed', :cohabiting => 'Cohabiting'}
10
+
11
+
12
+ tc_attr_accessor :admin_url,
13
+ :api_url,
14
+ :internal_url,
15
+ :updated_at,
16
+ :last_logged_in,
17
+ :secondary_phone,
18
+ :last_engaged,
19
+ :title,
20
+ :internal_url,
21
+ :id,
22
+ :first,
23
+ :primary_campus_name,
24
+ :last,
25
+ :head_of_household,
26
+ :nickname,
27
+ :active,
28
+ :primary_phone_type,
29
+ :primary_phone,
30
+ :member_since,
31
+ :birthdate,
32
+ :email_bouncing,
33
+ :secondary_phone_type,
34
+ :primary_campus_id,
35
+ :contact_updated_at,
36
+ :type,
37
+ :staff,
38
+ :created_at,
39
+ :gender,
40
+ :external_id_1,
41
+ :external_id_2,
42
+ :external_id_3,
43
+ :middle,
44
+ :email
45
+
46
+
47
+ # Loads the user by the specified ID.
48
+ #
49
+ # @param user_id The ID of the user to load.
50
+ #
51
+ # Returns a new {User} object.
52
+ def self.load_by_id(user_id)
53
+ reader = UserReader.new(user_id)
54
+ self.new(reader.load_feed)
55
+ rescue
56
+ nil
57
+ end
58
+
59
+
60
+ # Constructor.
61
+ #
62
+ # @param json_data (optional) The object that has the data. This can be a {UserReader} or Hash object.
63
+ # @param options (optional) Options for including more information.
64
+ def initialize(json_data = nil, options = {})
65
+ @writer_object = UserWriter
66
+ initialize_from_json_object(json_data) unless json_data.nil?
67
+
68
+ @address_list = nil
69
+ @family_list = nil
70
+ @note_list = nil
71
+ @role_list = nil
72
+ @skill_list = nil
73
+ @process_list = nil
74
+ @invitation_list = nil
75
+ @admin_privilege_list = nil
76
+ end
77
+
78
+
79
+ # The first and last name of the user.
80
+ #
81
+ # @return A string of the full name
82
+ def full_name
83
+ use_name = self.nickname.to_s.empty? ? self.first : self.nickname
84
+ [use_name, self.last].compact.join(' ')
85
+ end
86
+
87
+
88
+ # Address information.
89
+ #
90
+ # @param force_reload (optional) Data is cached on first call. If data needs to be
91
+ # reloaded from the server on a subsequent call then
92
+ # a force reload is need.
93
+ #
94
+ # @return [UserAddressList]
95
+ def addresses(force_reload = false)
96
+ unless force_reload
97
+ return @address_list unless @address_list.nil?
98
+ end
99
+ return nil unless self.id
100
+
101
+ @address_list = UserAddressList.new({:user_id => self.id})
102
+ return @address_list
103
+ end
104
+
105
+
106
+ # The family information.
107
+ #
108
+ # @return [UserFamilyList]
109
+ def family(force_reload = false)
110
+ unless force_reload
111
+ return @family_list unless @user_list.nil?
112
+ end
113
+ return nil unless self.id
114
+
115
+ @family_list = UserFamilyList.new({:user_id => self.id})
116
+ return @family_list
117
+ end
118
+
119
+
120
+ # The notes for this user.
121
+ #
122
+ # @return [UserNoteList]
123
+ def notes(force_reload = false)
124
+ unless force_reload
125
+ return @note_list unless @note_list.nil?
126
+ end
127
+ return nil unless self.id
128
+
129
+ @note_list = UserNoteList.new({:user_id => self.id})
130
+ return @note_list
131
+ end
132
+
133
+
134
+ # The roles for this user.
135
+ #
136
+ # @return [UserRoleList]
137
+ def roles(force_reload = false)
138
+ unless force_reload
139
+ return @role_list unless @role_list.nil?
140
+ end
141
+ return nil unless self.id
142
+
143
+ @role_list = UserRoleList.new({:user_id => self.id})
144
+ return @role_list
145
+ end
146
+
147
+
148
+ # The skills for this user.
149
+ #
150
+ # @return [UserSkillList]
151
+ def skills(force_reload = false)
152
+ unless force_reload
153
+ return @skill_list unless @skill_list.nil?
154
+ end
155
+ return nil unless self.id
156
+
157
+ @skill_list = UserSkillList.new({:user_id => self.id})
158
+ return @skill_list
159
+ end
160
+
161
+
162
+ # The processes for this user.
163
+ #
164
+ # @return [UserProcessList]
165
+ def processes(force_reload = false)
166
+ unless force_reload
167
+ return @process_list unless @process_list.nil?
168
+ end
169
+ return nil unless self.id
170
+
171
+ @process_list = UserProcessList.new({:user_id => self.id})
172
+ return @process_list
173
+ end
174
+
175
+
176
+ # The invitations for this user.
177
+ #
178
+ # @return [UserInvitationList]
179
+ def invitations(force_reload = false)
180
+ unless force_reload
181
+ return @invitation_list unless @invitation_list.nil?
182
+ end
183
+ return nil unless self.id
184
+
185
+ @invitation_list = UserInvitationList.new({:user_id => self.id})
186
+ return @invitation_list
187
+ end
188
+
189
+
190
+ # The invitations for this user.
191
+ #
192
+ # @return [UserAdminPrivilegeList]
193
+ def admin_privileges(force_reload = false)
194
+ unless force_reload
195
+ return @admin_privilege_list unless @admin_privilege_list.nil?
196
+ end
197
+ return nil unless self.id
198
+
199
+ @admin_privilege_list = UserAdminPrivilegeList.new({:user_id => self.id})
200
+ return @admin_privilege_list
201
+ end
202
+
203
+ end
204
+
205
+ end
206
+
207
+
@@ -0,0 +1,31 @@
1
+ module TheCity
2
+
3
+ class UserAddress < ApiObject
4
+
5
+ tc_attr_accessor :city,
6
+ :created_at,
7
+ :id,
8
+ :latitude,
9
+ :location_type,
10
+ :longitude,
11
+ :privacy,
12
+ :state,
13
+ :street,
14
+ :updated_at,
15
+ :user_id,
16
+ :zipcode
17
+
18
+
19
+ # Constructor.
20
+ #
21
+ # @param json_data (optional) JSON data of the user address.
22
+ def initialize(json_data = nil)
23
+ @writer_object = UserAddressWriter
24
+ initialize_from_json_object(json_data) unless json_data.nil?
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+
31
+
@@ -0,0 +1,62 @@
1
+ module TheCity
2
+
3
+ class UserAddressList
4
+
5
+ include Enumerable
6
+
7
+ attr_reader :total_entries, :total_pages, :per_page, :current_page
8
+
9
+ # Constructor.
10
+ #
11
+ # @param options A hash of options for loading the list.
12
+ #
13
+ # Options:
14
+ # :user_id - The ID of the user to load the addresses for. (required)
15
+ # :page - The page number to get.
16
+ # :reader - The Reader to use to load the data.
17
+ #
18
+ #
19
+ # Examples:
20
+ # UserAddressList.new({:user_id => 12345})
21
+ #
22
+ # UserAddressList.new({:user_id => 12345, :page => 2})
23
+ #
24
+ def initialize(options = {})
25
+ reader = options[:reader] || TheCity::UserAddressListReader.new(options)
26
+ @json_data = reader.load_feed
27
+
28
+ @total_entries = @json_data['total_entries']
29
+ @total_pages = @json_data['total_pages']
30
+ @per_page = @json_data['per_page']
31
+ @current_page = @json_data['current_page']
32
+ end
33
+
34
+
35
+ # Get the specified note.
36
+ #
37
+ # @param index The index of the note to get.
38
+ #
39
+ # @return [UserAddress]
40
+ def [](index)
41
+ UserAddress.new( @json_data['addresses'][index] ) if @json_data['addresses'][index]
42
+ end
43
+
44
+
45
+ # This method is needed for Enumerable.
46
+ def each &block
47
+ @json_data['addresses'].each{ |address| yield( UserAddress.new(address) )}
48
+ end
49
+
50
+
51
+ # Alias the count method
52
+ alias :size :count
53
+
54
+ # Checks if the list is empty.
55
+ #
56
+ # @return True on empty, false otherwise.
57
+ def empty?
58
+ @json_data['addresses'].empty?
59
+ end
60
+ end
61
+
62
+ end