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,54 @@
1
+ module TheCity
2
+
3
+ # This adapter is the standard for all saving objects.
4
+ class ApiWriter
5
+ attr_reader :error_messages, :response_code
6
+
7
+ # Saves this object.
8
+ #
9
+ # @return True or ID on success, otherwise false.
10
+ def save_object
11
+ @url_data_params ||= {}
12
+ success = true
13
+
14
+ if @updatable_fields and !@updatable_fields.empty?
15
+ fields_to_remove = @url_data_params.keys - @updatable_fields
16
+ fields_to_remove.each { |ftr| @url_data_params.delete(ftr) }
17
+ end
18
+
19
+ begin
20
+ response = TheCity::admin_request(@url_action, @url_data_path, @url_data_params)
21
+ @response_code = response.code
22
+ # No content but is a success
23
+ success = response.code == 204 ? {'success' => true} : JSON.parse(response.body)
24
+ rescue Exception => e
25
+ @error_messages = e.message.split(',')
26
+ success = false
27
+ end
28
+
29
+ return success
30
+ end
31
+
32
+
33
+ # Deletes this object.
34
+ #
35
+ # @return True or ID on success, otherwise false.
36
+ def delete_object
37
+ success = true
38
+
39
+ begin
40
+ # @url_data_path should be the same as :put if this object is already
41
+ # setup and mapped to an object that exists
42
+ response = TheCity::admin_request(:delete, @url_data_delete_path)
43
+ success = response.code == 204 ? true : false # No content but is a success
44
+ rescue Exception => e
45
+ @error_messages = e.message.split(',')
46
+ success = false
47
+ end
48
+
49
+ return success
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,25 @@
1
+ module TheCity
2
+
3
+ class FamilyWriter < ApiWriter
4
+
5
+ # Constructor.
6
+ #
7
+ # @param data The json data to save.
8
+ def initialize(data)
9
+ if data[:id]
10
+ @url_action = :put
11
+ @url_data_path = "/families/#{data[:id]}"
12
+ else
13
+ @url_action = :post
14
+ @url_data_path = "/families"
15
+ end
16
+ @url_data_delete_path = "/families/#{data[:id]}"
17
+
18
+ @url_data_params = data
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+
@@ -0,0 +1,32 @@
1
+ module TheCity
2
+
3
+ class GroupAddressWriter < ApiWriter
4
+
5
+ # Constructor.
6
+ #
7
+ # @param data The json object data to save.
8
+ def initialize(data)
9
+ if data[:id]
10
+ @url_action = :put
11
+ @url_data_path = "/groups/#{data[:group_id]}/addresses/#{data[:id]}"
12
+ else
13
+ @url_action = :post
14
+ @url_data_path = "/groups/#{data[:group_id]}/addresses"
15
+ end
16
+ @url_data_delete_path = "/groups/#{data[:group_id]}/addresses/#{data[:id]}"
17
+
18
+ @url_data_params = data
19
+
20
+
21
+ @updatable_fields = [:city,
22
+ :zipcode,
23
+ :street,
24
+ :location_type,
25
+ :state]
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
32
+
@@ -0,0 +1,25 @@
1
+ module TheCity
2
+
3
+ class GroupWriter < ApiWriter
4
+
5
+ # Constructor.
6
+ #
7
+ # @param data The json data to save.
8
+ def initialize(data)
9
+ if data[:id]
10
+ @url_action = :put
11
+ @url_data_path = "/groups/#{data[:id]}"
12
+ else
13
+ @url_action = :post
14
+ @url_data_path = "/groups"
15
+ end
16
+ @url_data_delete_path = "/groups/#{data[:id]}"
17
+
18
+ @url_data_params = data
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+
@@ -0,0 +1,25 @@
1
+ module TheCity
2
+
3
+ class MetricMeasurementWriter < ApiWriter
4
+
5
+ # Constructor.
6
+ #
7
+ # @param data The json data to save.
8
+ def initialize(data)
9
+ if data[:id]
10
+ @url_action = :put
11
+ @url_data_path = "/metrics/#{data[:metric_id]}/measurements/#{data[:id]}"
12
+ else
13
+ @url_action = :post
14
+ @url_data_path = "/metrics/#{data[:metric_id]}/measurements"
15
+ end
16
+ @url_data_delete_path = "/metrics/#{data[:metric_id]}/measurements/#{data[:id]}"
17
+
18
+ @url_data_params = data
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+
@@ -0,0 +1,29 @@
1
+ module TheCity
2
+
3
+ class MetricWriter < ApiWriter
4
+
5
+ # Constructor.
6
+ #
7
+ # @param data The json data to save.
8
+ def initialize(data)
9
+ if data[:id]
10
+ @url_action = :put
11
+ @url_data_path = "/metrics/#{data[:id]}"
12
+ else
13
+ @url_action = :post
14
+ @url_data_path = "/metrics"
15
+ end
16
+ @url_data_delete_path = "/metrics/#{data[:id]}"
17
+
18
+ @url_data_params = data
19
+
20
+ @updatable_fields = [:name,
21
+ :description,
22
+ :category,
23
+ :subcategory,
24
+ :is_percent]
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,25 @@
1
+ module TheCity
2
+
3
+ class SkillWriter < ApiWriter
4
+
5
+ # Constructor.
6
+ #
7
+ # @param data The json data to save.
8
+ def initialize(data)
9
+ if data[:id]
10
+ @url_action = :put
11
+ @url_data_path = "/skills/#{data[:id]}"
12
+ else
13
+ @url_action = :post
14
+ @url_data_path = "/skills"
15
+ end
16
+ @url_data_delete_path = "/skills/#{data[:id]}"
17
+
18
+ @url_data_params = data
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+
@@ -0,0 +1,27 @@
1
+ module TheCity
2
+
3
+ class TagWriter < ApiWriter
4
+
5
+ # Constructor.
6
+ #
7
+ # @param data The json data to save.
8
+ def initialize(data)
9
+ if data[:id]
10
+ @url_action = :put
11
+ @url_data_path = "/tags/#{data[:id]}"
12
+ else
13
+ @url_action = :post
14
+ @url_data_path = "/tags"
15
+ end
16
+ @url_data_delete_path = "/tags/#{data[:id]}"
17
+
18
+ @url_data_params = data
19
+
20
+ @updatable_fields = [:name]
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+
27
+
@@ -0,0 +1,19 @@
1
+ module TheCity
2
+
3
+ class TerminologyWriter < ApiWriter
4
+
5
+ # Constructor.
6
+ #
7
+ # @param data The json data to save.
8
+ def initialize(data)
9
+ @url_action = :put
10
+ @url_data_path = "/terminology/#{data[:term]}"
11
+ @url_data_params = data
12
+ @updatable_fields = [:label]
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+
19
+
@@ -0,0 +1,32 @@
1
+ module TheCity
2
+
3
+ class UserAddressWriter < ApiWriter
4
+
5
+ # Constructor.
6
+ #
7
+ # @param data The json object data to save.
8
+ def initialize(data)
9
+ if data[:id]
10
+ @url_action = :put
11
+ @url_data_path = "/users/#{data[:user_id]}/addresses/#{data[:id]}"
12
+ else
13
+ @url_action = :post
14
+ @url_data_path = "/users/#{data[:user_id]}/addresses"
15
+ end
16
+ @url_data_delete_path = "/users/#{data[:user_id]}/addresses/#{data[:id]}"
17
+
18
+ @url_data_params = data
19
+
20
+
21
+ @updatable_fields = [:city,
22
+ :zipcode,
23
+ :street,
24
+ :location_type,
25
+ :state]
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
32
+
@@ -0,0 +1,24 @@
1
+ module TheCity
2
+
3
+ class UserAdminPrivilegeWriter < ApiWriter
4
+
5
+ # Constructor.
6
+ #
7
+ # @param data The json object data to save.
8
+ def initialize(data)
9
+ @url_action = :post
10
+ @url_data_path = "/users/#{data[:user_id]}/admin_privileges"
11
+
12
+ @url_data_params = data
13
+ end
14
+
15
+
16
+ def delete_object
17
+ raise TheCityExceptions::TheCityResponseError.new('Unable to delete Admin Privilege')
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+
24
+
@@ -0,0 +1,23 @@
1
+ module TheCity
2
+
3
+ class UserInvitationWriter < ApiWriter
4
+
5
+ # Constructor.
6
+ #
7
+ # @param data The json object data to save.
8
+ def initialize(data)
9
+ @url_action = :post
10
+ @url_data_path = "/users/#{data[:user_id]}/invitations"
11
+ @url_data_params = data
12
+ end
13
+
14
+
15
+ def delete_object
16
+ raise TheCityExceptions::TheCityResponseError.new('Unable to delete user invitation')
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+
23
+
@@ -0,0 +1,25 @@
1
+ module TheCity
2
+
3
+ class UserNoteWriter < ApiWriter
4
+
5
+ # Constructor.
6
+ #
7
+ # @param data The json object data to save.
8
+ def initialize(data)
9
+ if data[:id]
10
+ @url_action = :put
11
+ @url_data_path = "/users/#{data[:author_id]}/notes/#{data[:id]}"
12
+ else
13
+ @url_action = :post
14
+ @url_data_path = "/users/#{data[:author_id]}/notes"
15
+ end
16
+ @url_data_delete_path = "/users/#{data[:author_id]}/notes/#{data[:id]}"
17
+
18
+ @url_data_params = data
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+
@@ -0,0 +1,28 @@
1
+ module TheCity
2
+
3
+ class UserRoleWriter < ApiWriter
4
+
5
+ # Constructor.
6
+ #
7
+ # @param data The json object data to save.
8
+ def initialize(data)
9
+ if data[:id]
10
+ @url_action = :put
11
+ @url_data_path = "/users/#{data[:user_id]}/roles/#{data[:id]}"
12
+ else
13
+ @url_action = :post
14
+ @url_data_path = "/users/#{data[:user_id]}/roles"
15
+ end
16
+ @url_data_delete_path = "/users/#{data[:user_id]}/roles/#{data[:id]}"
17
+
18
+ # user_id is not an option to submit with this path.
19
+ data.delete(:user_id)
20
+
21
+ @url_data_params = data
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+
28
+
@@ -0,0 +1,23 @@
1
+ module TheCity
2
+
3
+ class UserSkillWriter < ApiWriter
4
+
5
+ # Constructor.
6
+ #
7
+ # @param data The json object data to save.
8
+ def initialize(data)
9
+ @url_action = :post
10
+ @url_data_path = "/users/#{data[:user_id]}/skills"
11
+ @url_data_delete_path = "/users/#{data[:user_id]}/skills/#{data[:skill_id] || data[:name]}"
12
+
13
+ # user_id is not an option to submit with this path.
14
+ data.delete(:user_id)
15
+
16
+ @url_data_params = data
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+
23
+
@@ -0,0 +1,46 @@
1
+ module TheCity
2
+
3
+ class UserWriter < ApiWriter
4
+
5
+ # Constructor.
6
+ #
7
+ # @param data The json object data to save.
8
+ def initialize(data)
9
+ if data[:id]
10
+ @url_action = :put
11
+ @url_data_path = "/users/#{data[:id]}"
12
+ else
13
+ @url_action = :post
14
+ @url_data_path = "/users"
15
+ end
16
+ @url_data_delete_path = "/users/#{data[:id]}"
17
+
18
+ @url_data_params = data
19
+
20
+ @updatable_fields = [:title,
21
+ :first,
22
+ :middle,
23
+ :last,
24
+ :nickname,
25
+ :gender,
26
+ :email,
27
+ :staff,
28
+ :primary_campus_id,
29
+ :member_since,
30
+ :birthdate,
31
+ :primary_phone,
32
+ :primary_phone_type,
33
+ :secondary_phone,
34
+ :secondary_phone_type,
35
+ :external_id_1,
36
+ :external_id_2,
37
+ :external_id_3,
38
+ :marital_status,
39
+ :is_an_organization]
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+
46
+