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,63 @@
1
+ module TheCity
2
+
3
+ class UserNoteList
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 notes for. (required)
15
+ # :page - The page number to get.
16
+ # :reader - The Reader to use to load the data.
17
+ #
18
+ #
19
+ # Examples:
20
+ # UserNoteList.new({:user_id => 12345})
21
+ #
22
+ # UserNoteList.new({:user_id => 12345, :page => 2})
23
+ #
24
+ def initialize(options = {})
25
+ options[:page] ||= 1
26
+ reader = options[:reader] || TheCity::UserNoteListReader.new(options)
27
+ @json_data = reader.load_feed
28
+
29
+ @total_entries = @json_data['total_entries']
30
+ @total_pages = @json_data['total_pages']
31
+ @per_page = @json_data['per_page']
32
+ @current_page = @json_data['current_page']
33
+ end
34
+
35
+
36
+ # Get the specified note.
37
+ #
38
+ # @param index The index of the note to get.
39
+ #
40
+ # @return [UserNote]
41
+ def [](index)
42
+ UserNote.new( @json_data['notes'][index] ) if @json_data['notes'][index]
43
+ end
44
+
45
+
46
+ # This method is needed for Enumerable.
47
+ def each &block
48
+ @json_data['notes'].each{ |note| yield( UserNote.new(note) )}
49
+ end
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['notes'].empty?
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -0,0 +1,21 @@
1
+ module TheCity
2
+
3
+ class UserProcess < ApiObject
4
+
5
+ tc_attr_accessor :id,
6
+ :name,
7
+ :state
8
+
9
+
10
+ # Constructor.
11
+ #
12
+ # @param json_data JSON data of the note.
13
+ def initialize(json_data)
14
+ initialize_from_json_object(json_data)
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+
21
+
@@ -0,0 +1,63 @@
1
+ module TheCity
2
+
3
+ class UserProcessList
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 user processes for. (required)
15
+ # :page - The page number to get.
16
+ # :reader - The Reader to use to load the data.
17
+ #
18
+ #
19
+ # Examples:
20
+ # UserProcessList.new({:user_id => 12345})
21
+ #
22
+ # UserProcessList.new({:user_id => 12345, :page => 2})
23
+ #
24
+ def initialize(options = {})
25
+ options[:page] ||= 1
26
+ reader = options[:reader] || TheCity::UserProcessListReader.new(options)
27
+ @json_data = reader.load_feed
28
+
29
+ @total_entries = @json_data['total_entries']
30
+ @total_pages = @json_data['total_pages']
31
+ @per_page = @json_data['per_page']
32
+ @current_page = @json_data['current_page']
33
+ end
34
+
35
+
36
+ # Get the specified processes.
37
+ #
38
+ # @param index The index of the process to get.
39
+ #
40
+ # @return [UserProcesses]
41
+ def [](index)
42
+ UserProcess.new( @json_data['processes'][index] ) if @json_data['processes'][index]
43
+ end
44
+
45
+
46
+ # This method is needed for Enumerable.
47
+ def each &block
48
+ @json_data['processes'].each{ |process| yield( UserProcess.new(process) )}
49
+ end
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['processes'].empty?
59
+ end
60
+
61
+ end
62
+
63
+ end
@@ -0,0 +1,34 @@
1
+ module TheCity
2
+
3
+ class UserRole < ApiObject
4
+
5
+ GroupTypes = {:cg => 'CG', :service => 'Service', :campus => 'Campus'}
6
+
7
+ Titles = {:leader => 'Leader', :manager => 'Manager',
8
+ :volunteer => 'Volunteer', :participant => 'Participant'}
9
+
10
+ tc_attr_accessor :user_id,
11
+ :active,
12
+ :created_at,
13
+ :group_api_url,
14
+ :group_id,
15
+ :group_name,
16
+ :group_type,
17
+ :id,
18
+ :last_engaged,
19
+ :title
20
+
21
+
22
+ # Constructor.
23
+ #
24
+ # @param json_data (optional) JSON data of the user role.
25
+ def initialize(json_data = nil)
26
+ @writer_object = UserRoleWriter
27
+ initialize_from_json_object(json_data) unless json_data.nil?
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
34
+
@@ -0,0 +1,74 @@
1
+ module TheCity
2
+
3
+ class UserRoleList
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 roles for. (required)
15
+ # :page - The page number to get.
16
+ # :reader - The Reader to use to load the data.
17
+ #
18
+ #
19
+ # Examples:
20
+ # UserRoleList.new({:user_id => 12345})
21
+ #
22
+ # UserRoleList.new({:user_id => 12345, :page => 2})
23
+ #
24
+ def initialize(options = {})
25
+ options[:page] ||= 1
26
+ reader = options[:reader] || TheCity::UserRoleListReader.new(options)
27
+ @json_data = reader.load_feed
28
+
29
+ @user_id = options[:user_id] || nil
30
+ @total_entries = @json_data['total_entries']
31
+ @total_pages = @json_data['total_pages']
32
+ @per_page = @json_data['per_page']
33
+ @current_page = @json_data['current_page']
34
+ end
35
+
36
+
37
+ # All the roles in the list.
38
+ #
39
+ # @return array of role names.
40
+ def all_roles
41
+ return [] if @json_data['roles'].nil?
42
+ @json_data['roles'].collect { |role| role['title'] }
43
+ end
44
+ alias :roles :all_roles
45
+
46
+
47
+ # Get the specified user role.
48
+ #
49
+ # @param index The index of the user role to get.
50
+ #
51
+ # @return [UserRole]
52
+ def [](index)
53
+ UserRole.new( @json_data['roles'][index].merge({:user_id => @user_id}) ) if @json_data['roles'][index]
54
+ end
55
+
56
+
57
+ # This method is needed for Enumerable.
58
+ def each &block
59
+ @json_data['roles'].each{ |role| yield( UserRole.new(role.merge({:user_id => @user_id})) )}
60
+ end
61
+
62
+ # Alias the count method
63
+ alias :size :count
64
+
65
+ # Checks if the list is empty.
66
+ #
67
+ # @return True on empty, false otherwise.
68
+ def empty?
69
+ @json_data['roles'].empty?
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,22 @@
1
+ module TheCity
2
+
3
+ class UserSkill < ApiObject
4
+
5
+ tc_attr_accessor :user_id,
6
+ :name,
7
+ :skill_id
8
+
9
+
10
+ # Constructor.
11
+ #
12
+ # @param json_data (optional) JSON data of the user skill.
13
+ def initialize(json_data = nil)
14
+ @writer_object = UserSkillWriter
15
+ initialize_from_json_object(json_data) unless json_data.nil?
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+
@@ -0,0 +1,74 @@
1
+ module TheCity
2
+
3
+ class UserSkillList
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 user skills for. (required)
15
+ # :page - The page number to get.
16
+ # :reader - The Reader to use to load the data.
17
+ #
18
+ #
19
+ # Examples:
20
+ # UserSkillList.new({:user_id => 12345})
21
+ #
22
+ # UserSkillList.new({:user_id => 12345, :page => 2})
23
+ #
24
+ def initialize(options = {})
25
+ options[:page] ||= 1
26
+ reader = options[:reader] || TheCity::UserSkillListReader.new(options)
27
+ @json_data = reader.load_feed
28
+
29
+ @user_id = options[:user_id] || nil
30
+ @total_entries = @json_data['total_entries']
31
+ @total_pages = @json_data['total_pages']
32
+ @per_page = @json_data['per_page']
33
+ @current_page = @json_data['current_page']
34
+ end
35
+
36
+
37
+ # All the skills in the list.
38
+ #
39
+ # @return array of skill names.
40
+ def all_skills
41
+ return [] if @json_data['skills'].nil?
42
+ @json_data['skills'].collect { |skill| skill['name'] }
43
+ end
44
+ alias :skills :all_skills
45
+
46
+
47
+ # Get the specified skill.
48
+ #
49
+ # @param index The index of the skill to get.
50
+ #
51
+ # @return [UserSkill]
52
+ def [](index)
53
+ UserSkill.new( @json_data['skills'][index].merge({:user_id => @user_id}) ) if @json_data['skills'][index]
54
+ end
55
+
56
+
57
+ # This method is needed for Enumerable.
58
+ def each &block
59
+ @json_data['skills'].each{ |skill| yield( UserSkill.new(skill.merge({:user_id => @user_id})) ) }
60
+ end
61
+
62
+ # Alias the count method
63
+ alias :size :count
64
+
65
+ # Checks if the list is empty.
66
+ #
67
+ # @return True on empty, false otherwise.
68
+ def empty?
69
+ @json_data['skills'].empty?
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,34 @@
1
+ module TheCity
2
+
3
+ class WebHook < ApiObject
4
+
5
+ Objects = {:user => 'User', :group => 'Group', :invitation => 'Invitation',
6
+ :privilege => 'Privilege', :checkin => 'Checkin', :address => 'Address'}
7
+
8
+ Events = {:create => 'create', :update => 'update', :destroy => 'destroy', :expire => 'expire'}
9
+
10
+
11
+ tc_attr_accessor :id,
12
+ :callback_uri,
13
+ :event,
14
+ :object
15
+
16
+ # Constructor.
17
+ #
18
+ # @param json_data (optional) JSON data of the web hook.
19
+ def initialize(json_data = nil)
20
+ @writer_object = WebHookWriter
21
+ initialize_from_json_object(json_data) unless json_data.nil?
22
+ end
23
+
24
+
25
+ # The name of the hook based on the event and object
26
+ def name
27
+ "#{self.object}::#{self.event}"
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+
34
+
@@ -0,0 +1,74 @@
1
+ module TheCity
2
+
3
+ class WebHookList
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
+ # WebHookListReader.new
20
+ #
21
+ # UserSkillList.new({:page => 2})
22
+ #
23
+ def initialize(options = {})
24
+ options[:page] ||= 1
25
+ reader = options[:reader] || TheCity::WebHookListReader.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 web_hooks in the list.
36
+ #
37
+ # @return array of web_hook names.
38
+ def all_web_hooks
39
+ return [] if @json_data['web_hooks'].nil?
40
+ @json_data['web_hooks'].collect { |web_hook| [web_hook['object'], web_hook['event']].join('::') }
41
+ end
42
+ alias :web_hooks :all_web_hooks
43
+
44
+
45
+ # Get the specified web hook.
46
+ #
47
+ # @param index The index of the web hook to get.
48
+ #
49
+ # @return [WebHook]
50
+ def [](index)
51
+ WebHook.new( @json_data['web_hooks'][index] ) if @json_data['web_hooks'][index]
52
+ end
53
+
54
+
55
+ # This method is needed for Enumerable.
56
+ #
57
+ # @return [WebHook]
58
+ def each &block
59
+ @json_data['web_hooks'].each{ |web_hook| yield( WebHook.new(web_hook) ) }
60
+ end
61
+
62
+ # Alias the count method
63
+ alias :size :count
64
+
65
+ # Checks if the list is empty.
66
+ #
67
+ # @return True on empty, false otherwise.
68
+ def empty?
69
+ @json_data['web_hooks'].empty?
70
+ end
71
+
72
+ end
73
+
74
+ end