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,74 @@
1
+ module TheCity
2
+
3
+ class GroupList
4
+
5
+ include Enumerable
6
+
7
+ attr_reader :total_entries, :total_pages, :per_page, :current_page
8
+
9
+
10
+ # Constructor.
11
+ #
12
+ # @param options A hash of options for loading the list.
13
+ #
14
+ # Options:
15
+ # :page - The page number to get.
16
+ # :reader - The Reader to use to load the data.
17
+ # :search - (optional) A group name to search on.
18
+ #
19
+ #
20
+ # Examples:
21
+ # UserList.new
22
+ #
23
+ # UserList.new({:page => 2})
24
+ #
25
+ def initialize(options = {})
26
+ options[:page] ||= 1
27
+ reader = options[:reader] || TheCity::GroupListReader.new(options)
28
+ @json_data = reader.load_feed
29
+
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 groups in the list.
38
+ #
39
+ # @return array of group names.
40
+ def all_names
41
+ @json_data['groups'].collect { |group| group['name'] }
42
+ end
43
+ alias :names :all_names
44
+
45
+
46
+ # Get the specified group.
47
+ #
48
+ # @param index The index of the group to get.
49
+ #
50
+ # @return [Group]
51
+ def [](index)
52
+ Group.new( @json_data['groups'][index] ) if @json_data['groups'][index]
53
+ end
54
+
55
+
56
+ # This method is needed for Enumerable.
57
+ def each &block
58
+ @json_data['groups'].each{ |group| yield( Group.new(group) )}
59
+ end
60
+
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['groups'].empty?
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,27 @@
1
+ module TheCity
2
+
3
+ class GroupRole < ApiObject
4
+
5
+ tc_attr_accessor :active,
6
+ :created_at,
7
+ :id,
8
+ :last_engaged,
9
+ :title,
10
+ :user_api_url,
11
+ :user_id,
12
+ :user_name,
13
+ :user_type
14
+
15
+
16
+ # Constructor.
17
+ #
18
+ # @param json_data JSON data of the group role.
19
+ def initialize(json_data)
20
+ initialize_from_json_object(json_data)
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+
27
+
@@ -0,0 +1,62 @@
1
+ module TheCity
2
+
3
+ class GroupRoleList
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
+ # :group_id - The ID of the group 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
+ # GroupRoleList.new({:group_id => 12345})
21
+ #
22
+ # GroupRoleList.new({:group_id => 12345, :page => 2})
23
+ #
24
+ def initialize(options = {})
25
+ reader = options[:reader] || TheCity::GroupRoleListReader.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 group role.
36
+ #
37
+ # @param index The index of the group role to get.
38
+ #
39
+ # @return [GroupRole]
40
+ def [](index)
41
+ GroupRole.new( @json_data['roles'][index] ) if @json_data['roles'][index]
42
+ end
43
+
44
+
45
+ # This method is needed for Enumerable.
46
+ def each &block
47
+ @json_data['roles'].each{ |role| yield( GroupRole.new(role) )}
48
+ end
49
+
50
+ # Alias the count method
51
+ alias :size :count
52
+
53
+ # Checks if the list is empty.
54
+ #
55
+ # @return True on empty, false otherwise.
56
+ def empty?
57
+ @json_data['roles'].empty?
58
+ end
59
+
60
+ end
61
+
62
+ end
@@ -0,0 +1,20 @@
1
+ module TheCity
2
+
3
+ class GroupTag < ApiObject
4
+
5
+ tc_attr_accessor :name,
6
+ :tag_id
7
+
8
+
9
+ # Constructor.
10
+ #
11
+ # @param json_data JSON data of the group tag.
12
+ def initialize(json_data)
13
+ initialize_from_json_object(json_data)
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+
20
+
@@ -0,0 +1,62 @@
1
+ module TheCity
2
+
3
+ class GroupTagList
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
+ # :group_id - The ID of the group 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
+ # GroupTagList.new({:group_id => 12345})
21
+ #
22
+ # GroupTagList.new({:group_id => 12345, :page => 2})
23
+ #
24
+ def initialize(options = {})
25
+ reader = options[:reader] || TheCity::GroupTagListReader.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 group tag.
36
+ #
37
+ # @param index The index of the group tag to get.
38
+ #
39
+ # @return [GroupTag]
40
+ def [](index)
41
+ GroupTag.new( @json_data['tags'][index] ) if @json_data['tags'][index]
42
+ end
43
+
44
+
45
+ # This method is needed for Enumerable.
46
+ def each &block
47
+ @json_data['tags'].each{ |tag| yield( GroupTag.new(tag) )}
48
+ end
49
+
50
+ # Alias the count method
51
+ alias :size :count
52
+
53
+ # Checks if the list is empty.
54
+ #
55
+ # @return True on empty, false otherwise.
56
+ def empty?
57
+ @json_data['tags'].empty?
58
+ end
59
+
60
+ end
61
+
62
+ end
data/lib/api/metric.rb ADDED
@@ -0,0 +1,50 @@
1
+ module TheCity
2
+
3
+ class Metric < ApiObject
4
+ tc_attr_accessor :id,
5
+ :name,
6
+ :description,
7
+ :category,
8
+ :subcategory,
9
+ :is_percent
10
+
11
+
12
+ # Loads the metric by the specified ID.
13
+ #
14
+ # @param metric_id The ID of the user to load.
15
+ #
16
+ # Returns a new {Metric} object.
17
+ def self.load_by_id(metric_id)
18
+ metric_reader = MetricReader.new(metric_id)
19
+ self.new(metric_reader.load_feed)
20
+ end
21
+
22
+
23
+ # Constructor.
24
+ #
25
+ # @param json_data (optional) The object that has the data.
26
+ # @param options (optional) Options for including more information.
27
+ def initialize(json_data = nil, options = {})
28
+ @writer_object = MetricWriter
29
+ initialize_from_json_object(json_data) unless json_data.nil?
30
+
31
+ @measurement_list = nil
32
+ end
33
+
34
+
35
+ # Address information.
36
+ #
37
+ # @return [UserAddressList]
38
+ def measurements
39
+ return @measurement_list unless @measurement_list.nil?
40
+ return nil unless self.id
41
+
42
+ reader = MetricMeasurementListReader.new(self.id)
43
+ @measurement_list = MetricMeasurementList.new(reader)
44
+ return @measurement_list
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+
@@ -0,0 +1,72 @@
1
+ module TheCity
2
+
3
+ class MetricList
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 filters for loading the list.
12
+ #
13
+ # Options:
14
+ # :page - The page number to get.
15
+ # :filter - (optional) The filters are below and only one can be specified.
16
+ # ::created_in_the_last_N_PERIOD - A string specifying the period of time to look back for users created.
17
+ # N_PERIOD is in days, weeks, months or years.
18
+ # ::contact_updated_in_the_last_N_PERIOD - A string specifying the period of time to look back for users created.
19
+ # N_PERIOD is in days, weeks, months or years.
20
+ # ::with_external_id_1 - The external ID to reference.
21
+ # ::with_external_id_2 - The external ID to reference.
22
+ # ::with_external_id_3 - The external ID to reference.
23
+ # ::without_external_id_1 - The external ID to reference.
24
+ # ::without_external_id_2 - The external ID to reference.
25
+ # ::without_external_id_3 - The external ID to reference.
26
+ #
27
+ #
28
+ # Examples:
29
+ # MetricList.new({:filter => :created_in_the_last_7_days})
30
+ #
31
+ # MetricList.new({:page => 2, :filter => :contact_updated_in_the_last_2_weeks})
32
+ #
33
+ def initialize(options = {})
34
+ options[:page] ||= 1
35
+ reader = options[:reader] || TheCity::MetricListReader.new(options)
36
+ @json_data = reader.load_feed
37
+
38
+ @total_entries = @json_data['total_entries']
39
+ @total_pages = @json_data['total_pages']
40
+ @per_page = @json_data['per_page']
41
+ @current_page = @json_data['current_page']
42
+ end
43
+
44
+ # Get the specified metric.
45
+ #
46
+ # @param index The index of the user to get.
47
+ #
48
+ # @return [Metric]
49
+ def [](index)
50
+ Metric.new( @json_data['metrics'][index] ) if @json_data['metrics'][index]
51
+ end
52
+
53
+
54
+ # This method is needed for Enumerable.
55
+ def each &block
56
+ @json_data['metrics'].each{ |metric| yield( Metric.new(metric) )}
57
+ end
58
+
59
+
60
+ # Alias the count method
61
+ alias :size :count
62
+
63
+ # Checks if the list is empty.
64
+ #
65
+ # @return True on empty, false otherwise.
66
+ def empty?
67
+ @json_data['metrics'].empty?
68
+ end
69
+
70
+ end
71
+
72
+ end
@@ -0,0 +1,29 @@
1
+ module TheCity
2
+
3
+ class MetricMeasurement < ApiObject
4
+
5
+ tc_attr_accessor :id,
6
+ :created_at,
7
+ :value
8
+
9
+
10
+ # Constructor.
11
+ #
12
+ # @param json_data JSON data of the role.
13
+ def initialize(json_data)
14
+ initialize_from_json_object(json_data)
15
+ end
16
+
17
+ # Save this object.
18
+ #
19
+ # @return True on success, otherwise false.
20
+ def save
21
+ writer = MetricMeasurementWriter.new(self.to_attributes)
22
+ writer.save_feed
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+
29
+
@@ -0,0 +1,62 @@
1
+ module TheCity
2
+
3
+ class MetricMeasurementList
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
+ # MetricMeasurementList.new({:group_id => 12345})
20
+ #
21
+ # MetricMeasurementList.new({:group_id => 12345, :page => 2})
22
+ #
23
+ def initialize(options = {})
24
+ options[:page] ||= 1
25
+ reader = options[:reader] || TheCity::MetricMeasurementListReader.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 user role.
36
+ #
37
+ # @param index The index of the user role to get.
38
+ #
39
+ # @return [UserRole]
40
+ def [](index)
41
+ MetricMeasurement.new( @json_data['measurements'][index] ) if @json_data['measurements'][index]
42
+ end
43
+
44
+
45
+ # This method is needed for Enumerable.
46
+ def each &block
47
+ @json_data['measurements'].each{ |measurement| yield( MatricMeasurement.new(measurement) )}
48
+ end
49
+
50
+ # Alias the count method
51
+ alias :size :count
52
+
53
+ # Checks if the list is empty.
54
+ #
55
+ # @return True on empty, false otherwise.
56
+ def empty?
57
+ @json_data['measurements'].empty?
58
+ end
59
+
60
+ end
61
+
62
+ end