the-city-admin 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,22 @@
1
+ module TheCity
2
+
3
+ class TagListReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # @param options A hash of options for requesting data from the server.
8
+ # @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
9
+ def initialize(options = {}, cacher = nil)
10
+ page = options[:page] || 1
11
+
12
+ @class_key = "tag_list_#{page}"
13
+ @url_data_path = "/tags"
14
+ @url_data_params = {:page => page}
15
+
16
+ # The object to store and load the cache.
17
+ @cacher = cacher unless cacher.nil?
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,22 @@
1
+ module TheCity
2
+
3
+ class TagReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # @param tag_id The ID of the tag to load.
8
+ # @param options (optional) Options for including more information.
9
+ # @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
10
+ def initialize(tag_id, options = {}, cacher = nil)
11
+ @class_key = "tags_#{tag_id}"
12
+ @url_data_path = "/tags/#{tag_id}"
13
+
14
+ # The object to store and load the cache.
15
+ @cacher = cacher unless cacher.nil?
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+
@@ -0,0 +1,22 @@
1
+ module TheCity
2
+
3
+ class TerminologyListReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # @param options A hash of options for requesting data from the server.
8
+ # @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
9
+ def initialize(options = {}, cacher = nil)
10
+ page = options[:page] || 1
11
+
12
+ @class_key = "terminology_list_#{page}"
13
+ @url_data_path = "/terminology"
14
+ @url_data_params = {:page => page}
15
+
16
+ # The object to store and load the cache.
17
+ @cacher = cacher unless cacher.nil?
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,22 @@
1
+ module TheCity
2
+
3
+ class TerminologyReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # @param term The name of the term to load.
8
+ # @param options (optional) Options for including more information.
9
+ # @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
10
+ def initialize(term, options = {}, cacher = nil)
11
+ @class_key = "terminology_#{term}"
12
+ @url_data_path = "/terminology/#{term}"
13
+
14
+ # The object to store and load the cache.
15
+ @cacher = cacher unless cacher.nil?
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+
@@ -0,0 +1,25 @@
1
+ module TheCity
2
+
3
+ class UserAddressListReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # @param options A hash of options for requesting data from the server.
8
+ # :: user_id is required
9
+ # @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
10
+ def initialize(options = {}, cacher = nil)
11
+ page = options[:page] || 1
12
+ user_id = options[:user_id]
13
+ @class_key = "users_#{user_id}_addresses"
14
+ @url_data_path = "/users/#{user_id}/addresses"
15
+ @url_data_params = {:page => page}
16
+
17
+ # The object to store and load the cache.
18
+ @cacher = cacher unless cacher.nil?
19
+ end
20
+
21
+ end
22
+
23
+ end
24
+
25
+
@@ -0,0 +1,23 @@
1
+ module TheCity
2
+
3
+ class UserAdminPrivilegeListReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # @param options A hash of options for requesting data from the server.
8
+ # :: user_id is required
9
+ # @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
10
+ def initialize(options = {}, cacher = nil)
11
+ page = options[:page] || 1
12
+ user_id = options[:user_id]
13
+ @class_key = "users_#{user_id}_admin_privileges_#{page}"
14
+ @url_data_path = "/users/#{user_id}/admin_privileges"
15
+ @url_data_params = {:page => page}
16
+
17
+ # The object to store and load the cache.
18
+ @cacher = cacher unless cacher.nil?
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,32 @@
1
+ module TheCity
2
+
3
+ class UserCountReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # @param options (optional) Options for including more information.
8
+ # @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
9
+ #
10
+ # Options:
11
+ # :filter - The Reader to use to load the data.
12
+ #
13
+ #
14
+ # Examples:
15
+ # UserCount.new
16
+ #
17
+ # UserCount.new({:filter => :created_in_the_last_7_Days})
18
+ def initialize(options = {}, cacher = nil)
19
+ @class_key = "users_count_#{options[:filter] || ''}"
20
+ @url_data_path = "/users/count"
21
+
22
+ @url_data_params = {:filter => options[:filter] || ''}
23
+
24
+ # The object to store and load the cache.
25
+ @cacher = cacher unless cacher.nil?
26
+ end
27
+
28
+ end
29
+
30
+ end
31
+
32
+
@@ -0,0 +1,24 @@
1
+ module TheCity
2
+
3
+ class UserFamilyListReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # @param options A hash of options for requesting data from the server.
8
+ # :: user_id is required
9
+ # @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
10
+ def initialize(options = {}, cacher = nil)
11
+ page = options[:page] || 1
12
+ user_id = options[:user_id]
13
+ @class_key = "users_#{user_id}_family"
14
+ @url_data_path = "/users/#{user_id}/family"
15
+
16
+ # The object to store and load the cache.
17
+ @cacher = cacher unless cacher.nil?
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+
24
+
@@ -0,0 +1,23 @@
1
+ module TheCity
2
+
3
+ class UserInvitationListReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # @param options A hash of options for requesting data from the server.
8
+ # :: user_id is required
9
+ # @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
10
+ def initialize(options = {}, cacher = nil)
11
+ page = options[:page] || 1
12
+ user_id = options[:user_id]
13
+ @class_key = "users_#{user_id}_invitations_#{page}"
14
+ @url_data_path = "/users/#{user_id}/invitations"
15
+ @url_data_params = {:page => page}
16
+
17
+ # The object to store and load the cache.
18
+ @cacher = cacher unless cacher.nil?
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,25 @@
1
+ module TheCity
2
+
3
+ class UserListReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # @param page The page number to get. Default is 1.
8
+ # @param options A hash of options for requesting data from the server.
9
+ # @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
10
+ def initialize(options = {}, cacher = nil)
11
+ page = options[:page] || 1
12
+ filter = options[:filter]
13
+
14
+ @class_key = "user_list_#{page}_#{filter.to_s.downcase.gsub(' ','')}"
15
+ @url_data_path = "/users"
16
+ @url_data_params = {:page => page}
17
+ @url_data_params.merge!({:filter => filter}) if filter
18
+
19
+ # The object to store and load the cache.
20
+ @cacher = cacher unless cacher.nil?
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,23 @@
1
+ module TheCity
2
+
3
+ class UserNoteListReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # @param options A hash of options for requesting data from the server.
8
+ # :: user_id is required
9
+ # @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
10
+ def initialize(options = {}, cacher = nil)
11
+ page = options[:page] || 1
12
+ user_id = options[:user_id]
13
+ @class_key = "users_#{user_id}_notes_#{page}"
14
+ @url_data_path = "/users/#{user_id}/notes"
15
+ @url_data_params = {:page => page}
16
+
17
+ # The object to store and load the cache.
18
+ @cacher = cacher unless cacher.nil?
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,23 @@
1
+ module TheCity
2
+
3
+ class UserProcessListReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # @param options A hash of options for requesting data from the server.
8
+ # :: user_id is required
9
+ # @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
10
+ def initialize(options = {}, cacher = nil)
11
+ page = options[:page] || 1
12
+ user_id = options[:user_id]
13
+ @class_key = "users_#{user_id}_processes_#{page}"
14
+ @url_data_path = "/users/#{user_id}/processes"
15
+ @url_data_params = {:page => page}
16
+
17
+ # The object to store and load the cache.
18
+ @cacher = cacher unless cacher.nil?
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,24 @@
1
+ module TheCity
2
+
3
+ class UserReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # @param user_id The ID of the user to load.
8
+ # @param options (optional) Options for including more information.
9
+ # 'include_custom_fields' => true/false. Default is false.
10
+ # @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
11
+ def initialize(user_id, options = {}, cacher = nil)
12
+ @class_key = "users_#{user_id}"
13
+ @url_data_path = "/users/#{user_id}"
14
+ @url_data_params = {:include_custom_fields => true}
15
+
16
+ # The object to store and load the cache.
17
+ @cacher = cacher unless cacher.nil?
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+
24
+
@@ -0,0 +1,23 @@
1
+ module TheCity
2
+
3
+ class UserRoleListReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # @param options A hash of options for requesting data from the server.
8
+ # :: user_id is required
9
+ # @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
10
+ def initialize(options = {}, cacher = nil)
11
+ page = options[:page] || 1
12
+ user_id = options[:user_id]
13
+ @class_key = "users_#{user_id}_roles_#{page}"
14
+ @url_data_path = "/users/#{user_id}/roles"
15
+ @url_data_params = {:page => page}
16
+
17
+ # The object to store and load the cache.
18
+ @cacher = cacher unless cacher.nil?
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,23 @@
1
+ module TheCity
2
+
3
+ class UserSkillListReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # @param options A hash of options for requesting data from the server.
8
+ # :: user_id is required
9
+ # @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
10
+ def initialize(options = {}, cacher = nil)
11
+ page = options[:page] || 1
12
+ user_id = options[:user_id]
13
+ @class_key = "users_#{user_id}_skills_#{page}"
14
+ @url_data_path = "/users/#{user_id}/skills"
15
+ @url_data_params = {:page => page}
16
+
17
+ # The object to store and load the cache.
18
+ @cacher = cacher unless cacher.nil?
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,21 @@
1
+ module TheCity
2
+
3
+ class WebHookListReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # @param options A hash of options for requesting data from the server.
8
+ # @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
9
+ def initialize(options = {}, cacher = nil)
10
+ page = options[:page] || 1
11
+ @class_key = "web_hooks_#{page}"
12
+ @url_data_path = "/webhooks"
13
+ @url_data_params = {:page => page}
14
+
15
+ # The object to store and load the cache.
16
+ @cacher = cacher unless cacher.nil?
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,82 @@
1
+ require 'rubygems'
2
+ require 'openssl'
3
+ require 'cgi'
4
+ require 'Base64'
5
+ require 'openssl'
6
+ require 'net/http'
7
+ require 'net/https'
8
+ require 'typhoeus'
9
+ require 'json'
10
+
11
+
12
+ TCA_ENV = 'development'
13
+ #TCA_ENV = 'staging'
14
+
15
+ # The path to the lib directory.
16
+ THECITY_LIB_DIR = File.dirname(__FILE__)
17
+
18
+ # The path to the storage directory that will be used for caching data to disk.
19
+ THECITY_STORAGE_DIR = File.dirname(__FILE__) + '/../storage/'
20
+
21
+
22
+
23
+ # TODO: This needs to be moved into a config file.
24
+ ######################################################
25
+ if TCA_ENV == 'production'
26
+ raise 'Admin API path not set for production' # Delete this exception when set
27
+ THE_CITY_ADMIN_PATH = ''
28
+ THE_CITY_ADMIN_API_VERSION = 'application/vnd.thecity.admin.v1+json'
29
+
30
+ elsif TCA_ENV == 'development'
31
+ THE_CITY_ADMIN_PATH = 'http://0.0.0.0:9292'
32
+ THE_CITY_ADMIN_API_VERSION = 'application/vnd.thecity.admin.v1+json'
33
+
34
+ elsif TCA_ENV == 'staging'
35
+ THE_CITY_ADMIN_PATH = 'https://api.stagethecity.org'
36
+ THE_CITY_ADMIN_API_VERSION = 'application/vnd.thecity.admin.v1+json'
37
+
38
+ elsif TCA_ENV == 'test'
39
+ raise 'Admin API path not set for testing' # Delete this exception when set
40
+ THE_CITY_ADMIN_PATH = ''
41
+ THE_CITY_ADMIN_API_VERSION = 'application/vnd.thecity.admin.v1+json'
42
+ end
43
+ ######################################################
44
+
45
+
46
+
47
+ require File.dirname(__FILE__) + '/auto_load.rb'
48
+
49
+ require File.dirname(__FILE__) + '/common.rb'
50
+
51
+
52
+ # This class is meant to be a wrapper TheCity Admin API (OnTheCity.org).
53
+ module TheCity
54
+
55
+ class AdminApi
56
+
57
+ attr_reader :api_key, :api_token
58
+
59
+
60
+ # Alias for calling the *new* method.
61
+ def self.connect(api_key, api_token)
62
+ self.new(api_key, api_token)
63
+ end
64
+
65
+
66
+ # Constructor.
67
+ #
68
+ # @param api_key The API key for the church.
69
+ # @param api_token The API token for the church.
70
+ def initialize(api_key, api_token)
71
+ raise TheCityExceptions::UnableToConnectToTheCity.new('Key and Token cannot be nil.') if api_key.nil? or api_token.nil?
72
+
73
+ # Create a constant for the churches API key.
74
+ TheCity::AdminApi::const_set(:API_KEY, api_key) unless defined?(API_KEY)
75
+
76
+ # Create a constant for the churches API Token.
77
+ TheCity::AdminApi::const_set(:API_TOKEN, api_token) unless defined?(API_TOKEN)
78
+ end
79
+
80
+ end
81
+
82
+ end