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,51 @@
1
+ module TheCity
2
+
3
+ class Address < 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
+ :group_id,
16
+ :zipcode
17
+
18
+
19
+ # Loads the address by the specified ID.
20
+ #
21
+ # @param address_id The ID of the address to load.
22
+ #
23
+ # Returns a new {Address} object.
24
+ def self.load_by_id(address_id)
25
+ reader = AddressReader.new(address_id)
26
+ self.new(reader.load_feed)
27
+ rescue
28
+ nil
29
+ end
30
+
31
+
32
+ # Constructor.
33
+ #
34
+ # @param json_data (optional) JSON data of the address.
35
+ def initialize(json_data = nil)
36
+ initialize_from_json_object(json_data) unless json_data.nil?
37
+ end
38
+
39
+ def save
40
+ raise 'Address does not have a save method'
41
+ end
42
+
43
+ def delete
44
+ raise 'Address does not have a delete method'
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
51
+
@@ -0,0 +1,62 @@
1
+ module TheCity
2
+
3
+ class AddressList
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
+ # AddressList.new
20
+ #
21
+ # AddressList.new({:page => 2})
22
+ #
23
+ def initialize(options = {})
24
+ reader = options[:reader] || TheCity::AddressListReader.new(options)
25
+ @json_data = reader.load_feed
26
+
27
+ @total_entries = @json_data['total_entries']
28
+ @total_pages = @json_data['total_pages']
29
+ @per_page = @json_data['per_page']
30
+ @current_page = @json_data['current_page']
31
+ end
32
+
33
+
34
+ # Get the specified note.
35
+ #
36
+ # @param index The index of the note to get.
37
+ #
38
+ # @return [Address]
39
+ def [](index)
40
+ Address.new( @json_data['addresses'][index] ) if @json_data['addresses'][index]
41
+ end
42
+
43
+
44
+ # This method is needed for Enumerable.
45
+ def each &block
46
+ @json_data['addresses'].each{ |address| yield( Address.new(address) )}
47
+ end
48
+
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['addresses'].empty?
58
+ end
59
+
60
+ end
61
+
62
+ end
@@ -0,0 +1,100 @@
1
+ module TheCity
2
+
3
+ # This class is the base class for all TheCity objects and is meant to be inherited.
4
+ #
5
+ class ApiObject
6
+ attr_reader :error_messages, :marked_for_destruction
7
+
8
+
9
+ # Used to specify a list of getters and setters.
10
+ def self.tc_attr_accessor(*vars)
11
+ @__tc_attributes ||= []
12
+ @__tc_attributes.concat(vars)
13
+ attr_accessor(*vars)
14
+ end
15
+
16
+
17
+ # A list of tc_attr_accessors that have been specified.
18
+ def self.__tc_attributes
19
+ @__tc_attributes
20
+ end
21
+
22
+ # Initializes the current object from the JSON data that was loaded into the Hash
23
+ #
24
+ # @param object_attributes A Hash of values to load into the current object.
25
+ def initialize_from_json_object(object_attributes)
26
+ if object_attributes.is_a?( Hash )
27
+ object_attributes.each do |key, value|
28
+ method_to_call = "#{key.to_s.downcase.gsub(' ', '_')}="
29
+ if respond_to?(method_to_call)
30
+ self.send(method_to_call, value)
31
+ else
32
+ # puts method_to_call # Show the missing methods
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+
39
+ # Returns the status of the current object.
40
+ def is_deleted?
41
+ @_deleted ||= false
42
+ end
43
+
44
+ # Gets the current object's attributes in a Hash.
45
+ #
46
+ # @return A hash of all the attributes.
47
+ def to_attributes
48
+ vals = {}
49
+ vals = {:marked_for_destruction => self.is_deleted?} if self.is_deleted?
50
+ self.class.__tc_attributes.each do |tca|
51
+ rep = self.send(tca)
52
+ if rep.class == Array
53
+ rep.collect! { |r| r.respond_to?(:to_attributes) ? r.to_attributes : r }
54
+ end
55
+ vals[tca] = rep
56
+ end
57
+ vals
58
+ end
59
+
60
+
61
+ # Sets the current object's attributes from a hash
62
+ def set_attributes(attribute_data)
63
+ attribute_data.each { |key, value| self.send("#{key}=", value) if self.respond_to?("#{key}=") }
64
+ end
65
+
66
+
67
+ # Save this object.
68
+ #
69
+ # @return True on success, otherwise false.
70
+ def save
71
+ writer = @writer_object.new(self.to_attributes)
72
+ result = writer.save_object
73
+ if result === false
74
+ @error_messages = writer.error_messages
75
+ else
76
+ self.set_attributes(result)
77
+ end
78
+ result === false ? false : true
79
+ end
80
+
81
+
82
+ # Delete this object.
83
+ #
84
+ # @return True on success, otherwise false.
85
+ def delete
86
+ writer = @writer_object.new(self.to_attributes)
87
+ result = writer.delete_object
88
+ if result === false
89
+ @error_messages = writer.error_messages
90
+ else
91
+ @_deleted = true
92
+ end
93
+ result === false ? false : true
94
+ end
95
+
96
+ end
97
+
98
+ end
99
+
100
+
@@ -0,0 +1,43 @@
1
+ module TheCity
2
+
3
+ class Barcode < ApiObject
4
+
5
+ tc_attr_accessor :user_id,
6
+ :user_name,
7
+ :id,
8
+ :created_at,
9
+ :barcode
10
+
11
+ # Loads the barocde by the specified ID.
12
+ #
13
+ # @param barcode_id The ID of the barcode to load.
14
+ #
15
+ # Returns a new {Barcode} object.
16
+ def self.load_by_id(barcode_id)
17
+ reader = BarcodeReader.new(barcode_id)
18
+ self.new(reader.load_feed)
19
+ rescue
20
+ nil
21
+ end
22
+
23
+
24
+ # Constructor.
25
+ #
26
+ # @param json_data (optional) JSON data of the barcode.
27
+ def initialize(json_data = nil)
28
+ initialize_from_json_object(json_data) unless json_data.nil?
29
+ end
30
+
31
+ def save
32
+ raise 'Barcode does not have a save method'
33
+ end
34
+
35
+ def delete
36
+ raise 'Barcode does not have a delete method'
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+
43
+
@@ -0,0 +1,37 @@
1
+ module TheCity
2
+
3
+ class Checkin < ApiObject
4
+
5
+ tc_attr_accessor :group,
6
+ :checked_out_by_user,
7
+ :special_instructions,
8
+ :parent_group_name,
9
+ :callboard_number,
10
+ :checked_in_at,
11
+ :barcode,
12
+ :checked_in_user,
13
+ :checked_in_user_id,
14
+ :id,
15
+ :checked_in_by_user,
16
+ :checked_in_by_user_id,
17
+ :parent_receipt_barcode,
18
+ :event,
19
+ :checked_in_user_notes,
20
+ :checked_out_at,
21
+ :parent_group_id,
22
+ :pager_number
23
+
24
+
25
+ # Constructor.
26
+ #
27
+ # @param json_data (optional) JSON data of the Checkin.
28
+ def initialize(json_data = nil)
29
+ @writer_object = CheckinWriter
30
+ initialize_from_json_object(json_data) unless json_data.nil?
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
37
+
@@ -0,0 +1,62 @@
1
+ module TheCity
2
+
3
+ class CheckinList
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
+ # CheckinList.new
20
+ #
21
+ # CheckinList.new({:page => 2})
22
+ #
23
+ def initialize(options = {})
24
+ reader = options[:reader] || TheCity::CheckinListReader.new(options)
25
+ @json_data = reader.load_feed
26
+
27
+ @total_entries = @json_data['total_entries']
28
+ @total_pages = @json_data['total_pages']
29
+ @per_page = @json_data['per_page']
30
+ @current_page = @json_data['current_page']
31
+ end
32
+
33
+
34
+ # Get the specified note.
35
+ #
36
+ # @param index The index of the checkin to get.
37
+ #
38
+ # @return [Checkin]
39
+ def [](index)
40
+ Checkin.new( @json_data['checkins'][index] ) if @json_data['checkins'][index]
41
+ end
42
+
43
+
44
+ # This method is needed for Enumerable.
45
+ def each &block
46
+ @json_data['checkins'].each{ |checkin| yield( Checkin.new(checkin) )}
47
+ end
48
+
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['checkins'].empty?
58
+ end
59
+
60
+ end
61
+
62
+ end
data/lib/api/family.rb ADDED
@@ -0,0 +1,47 @@
1
+ module TheCity
2
+
3
+ class Family < ApiObject
4
+
5
+ tc_attr_accessor :id,
6
+ :external_id,
7
+ :created_at,
8
+ :family_members
9
+
10
+
11
+ # Loads the family by the specified ID.
12
+ #
13
+ # @param family_id The ID of the family to load.
14
+ #
15
+ # Returns a new {Family} object.
16
+ def self.load_by_id(family_id)
17
+ reader = FamilyReader.new(family_id)
18
+ self.new(reader.load_feed)
19
+ rescue
20
+ nil
21
+ end
22
+
23
+ # Constructor.
24
+ #
25
+ # @param json_data (optional) JSON data of the Family.
26
+ def initialize(json_data = nil)
27
+ @family_members = []
28
+ @writer_object = FamilyWriter
29
+ initialize_from_json_object(json_data) unless json_data.nil?
30
+ end
31
+
32
+
33
+ # Alias family_members
34
+ def members
35
+ @family_members
36
+ end
37
+
38
+
39
+ def add_family_member(member)
40
+ @family_members << member
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+
@@ -0,0 +1,28 @@
1
+ module TheCity
2
+
3
+ class FamilyMember < ApiObject
4
+
5
+ Roles = {:spouse => 'Spouse', :child => 'Child', :temp_child => 'TempChild', :legal_child => 'LegalChild'}
6
+
7
+ tc_attr_accessor :name,
8
+ :admin_url,
9
+ :external_id_1,
10
+ :birthdate,
11
+ :user_id,
12
+ :barcodes,
13
+ :family_role,
14
+ :api_url,
15
+ :active,
16
+ :email
17
+
18
+ # Constructor.
19
+ #
20
+ # @param json_data (optional) JSON data of the Family member.
21
+ def initialize(json_data = nil)
22
+ initialize_from_json_object(json_data) unless json_data.nil?
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+
data/lib/api/group.rb ADDED
@@ -0,0 +1,162 @@
1
+ module TheCity
2
+
3
+ class Group < ApiObject
4
+ tc_attr_accessor :admin_url,
5
+ :api_url,
6
+ :created_at,
7
+ :external_description,
8
+ :group_type,
9
+ :id,
10
+ :internal_url,
11
+ :name,
12
+ :nickname,
13
+ :parent_id,
14
+ :plaza_url,
15
+ :smart_large_profile_pic,
16
+ :started_as_seed
17
+
18
+
19
+ # Loads the group by the specified ID.
20
+ #
21
+ # @param group_id The ID of the group to load.
22
+ #
23
+ # Returns a new {Group} object.
24
+ def self.load_group_by_id(group_id)
25
+ group_reader = GroupReader.new(group_id)
26
+ self.new(group_reader)
27
+ end
28
+
29
+
30
+
31
+ # Constructor.
32
+ #
33
+ # @param reader (optional) The object that has the data. This can be a {GroupReader} or Hash object.
34
+ def initialize(reader = nil)
35
+ if reader.is_a?(GroupReader)
36
+ initialize_from_json_object(reader.load_feed)
37
+ elsif reader.is_a?(Hash)
38
+ initialize_from_json_object(reader)
39
+ end
40
+
41
+ @address_list = nil
42
+ @checkin_list = nil
43
+ @event_attendance_list = nil
44
+ @export_list = nil
45
+ @invitations = nil
46
+ @role_list = nil
47
+ @tag_list = nil
48
+ end
49
+
50
+
51
+ # The address information.
52
+ #
53
+ # @return [GroupAddressList]
54
+ def addresses(force_reload = false)
55
+ unless force_reload
56
+ return @address_list unless @address_list.nil?
57
+ end
58
+ return nil unless self.id
59
+
60
+ @address_list = GroupAddressList.new({:group_id => self.id})
61
+ return @address_list
62
+ end
63
+
64
+
65
+ # The checkin information.
66
+ #
67
+ # @return [GroupCheckinList]
68
+ def checkins(force_reload = false)
69
+ unless force_reload
70
+ return @checkin_list unless @checkin_list.nil?
71
+ end
72
+ return nil unless self.id
73
+
74
+ @checkin_list = GroupCheckinList.new({:group_id => self.id})
75
+ return @checkin_list
76
+ end
77
+
78
+
79
+ # The checkin information.
80
+ #
81
+ # @return [GroupExportList]
82
+ def exports(force_reload = false)
83
+ unless force_reload
84
+ return @export_list unless @export_list.nil?
85
+ end
86
+ return nil unless self.id
87
+
88
+ @export_list = GroupExportList.new({:group_id => self.id})
89
+ return @export_list
90
+ end
91
+
92
+
93
+ # The checkin information.
94
+ #
95
+ # @return [GroupEventAttendanceList]
96
+ def event_attendances(force_reload = false)
97
+ unless force_reload
98
+ return @event_attendance_list unless @event_attendance_list.nil?
99
+ end
100
+ return nil unless self.id
101
+
102
+ @event_attendance_list = GroupEventAttendanceList.new({:group_id => self.id})
103
+ return @event_attendance_list
104
+ end
105
+
106
+
107
+ # The invitations for this group.
108
+ #
109
+ # @return [GroupInvitationList]
110
+ def invitations(force_reload = false)
111
+ unless force_reload
112
+ return @invitation_list unless @invitation_list.nil?
113
+ end
114
+ return nil unless self.id
115
+
116
+ @invitation_list = GroupInvitationList.new({:group_id => self.id})
117
+ return @invitation_list
118
+ end
119
+
120
+
121
+ # The roles for this group.
122
+ #
123
+ # @return [GroupRoleList]
124
+ def roles(force_reload = false)
125
+ unless force_reload
126
+ return @role_list unless @role_list.nil?
127
+ end
128
+ return nil unless self.id
129
+
130
+ @role_list = GroupRoleList.new({:group_id => self.id})
131
+ return @role_list
132
+ end
133
+
134
+
135
+ # The tags for this group.
136
+ #
137
+ # @return [GroupTagList]
138
+ def tags(force_reload = false)
139
+ unless force_reload
140
+ return @tag_list unless @tag_list.nil?
141
+ end
142
+ return nil unless self.id
143
+
144
+ @tag_list = GroupTagList.new({:group_id => self.id})
145
+ return @tag_list
146
+ end
147
+
148
+
149
+
150
+ # Save this object.
151
+ #
152
+ # @return True on success, otherwise false.
153
+ def save
154
+ writer = GroupWriter.new(self.to_attributes)
155
+ writer.save_feed
156
+ end
157
+
158
+ end
159
+
160
+ end
161
+
162
+