the-city-admin 0.1.5 → 0.2.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.
data/README.rdoc CHANGED
@@ -29,10 +29,7 @@ Next you will need to initialize a connection
29
29
 
30
30
  == Example usage
31
31
 
32
-
33
- === Get list of group
34
-
35
- TheCity::AdminApi.connect(THECITY_KEY, THECITY_TOKEN)
32
+ Checkout the examples folder.
36
33
 
37
34
 
38
35
  == Additional resources
data/index.rb CHANGED
@@ -5,33 +5,245 @@
5
5
  # @authors Robbie Lieb <robbie@onthecity.org>, Wes Hays <wes@onthecity.org>
6
6
  # *******************************************
7
7
 
8
+ # TCA_ENV = 'development'
9
+ # THE_CITY_ADMIN_PATH = 'http://api.devthecity.org:9292'
8
10
 
9
11
  require 'ruby-debug'
10
12
  require File.dirname(__FILE__) + '/lib/the_city_admin.rb'
11
13
 
12
- key = '132412341234123412341234'
13
- token = 'asdf1234asdf1234'
14
+ # key = '66c59e2ee24553e7237259e30b4c17365681b95c'
15
+ # token = 'a9ae4af3c3e80102'
14
16
 
17
+ key = '2bcee1fdccd31f1ef35a7c6708daf5a446a61ee2'
18
+ token = 'e37ae7fb2042a17a'
15
19
 
16
20
  TheCity::AdminApi.connect(key, token)
17
21
 
18
22
 
19
- done = false
20
- page = 1
21
- count = 0
23
+ puts "-----------------------------"
24
+ puts "##### FUNDS / DONATIONS / PLEDGES #######"
25
+ puts "-----------------------------"
22
26
 
23
- while !done
24
- group_list = TheCity::GroupList.new({:page => page})
25
27
 
26
- group_list.each do |group|
27
- count += 1
28
- puts "#{count}) #{group.name}"
29
- end
28
+ # donation_list = TheCity::DonationList.new({:page => 1, :include_details => 1, :start_date => '2012-09-01', :end_date => '2012-09-30'})
30
29
 
31
- if group_list.total_pages <= page
32
- done = true
33
- else
34
- page += 1
35
- end
30
+ # donation_list.each do |donation|
31
+ # puts [donation.user_name, donation.amount].join(' :: ')
32
+ # end
33
+
34
+
35
+ fund_list = TheCity::FundList.new({:page => 1})
36
+
37
+ fund_list.each do |fund|
38
+ puts [fund.id, fund.name].join(' :: ')
36
39
  end
37
40
 
41
+ sfund = TheCity::Fund.load_fund_by_id(fund_list.first.id)
42
+
43
+ puts [sfund.id, sfund.name].join(' :-: ')
44
+
45
+ # done = false
46
+ # page = 1
47
+ # count = 0
48
+
49
+ # while !done
50
+ # group_list = TheCity::GroupList.new({:page => page, :group_types => 'CG', :include_inactive => true})
51
+
52
+ # group_list.each do |group|
53
+ # count += 1
54
+ # puts "#{count}) #{group.name}"
55
+ # end
56
+
57
+ # if group_list.total_pages <= page
58
+ # done = true
59
+ # else
60
+ # page += 1
61
+ # end
62
+ # end
63
+
64
+
65
+ # done = false
66
+ # page = 1
67
+ # count = 0
68
+
69
+ # while !done
70
+ # tag_list = TheCity::TagList.new({:page => page})
71
+
72
+ # tag_list.each do |tag|
73
+ # count += 1
74
+ # puts "#{count}) #{tag.name} :: #{tag.id}"
75
+ # end
76
+
77
+ # if tag_list.total_pages <= page
78
+ # done = true
79
+ # else
80
+ # page += 1
81
+ # end
82
+ # end
83
+
84
+
85
+
86
+
87
+
88
+ # puts "-----------------------------"
89
+ # puts "##### USERS #######"
90
+ # puts "-----------------------------"
91
+
92
+
93
+ # user_list = TheCity::UserList.new
94
+
95
+ # user_list.each do |u|
96
+ # puts u.full_name
97
+ # end
98
+
99
+ # puts "-----------------------------"
100
+
101
+ # user = TheCity::User.new
102
+ # user.title = 'Deacon'
103
+ # user.first = 'James'
104
+ # user.middle = 'Wesley'
105
+ # user.last = 'Hays'
106
+ # user.nickname = 'Wes'
107
+ # user.gender = TheCity::User::Gender[:male]
108
+ # user.email = 'someguy@somewhere.org'
109
+ # user.staff = false
110
+ # user.member_since = Time.now.strftime("%Y-%m-%d")
111
+ # user.birthdate = '1980-09-27'
112
+ # user.primary_phone = '775-111-2222'
113
+ # user.primary_phone_type = TheCity::User::PhoneType[:mobile]
114
+ # user.secondary_phone = '775-333-4444'
115
+ # user.secondary_phone_type = TheCity::User::PhoneType[:home]
116
+ # user.marital_status = TheCity::User::MaritalStatus[:married]
117
+ # #user.primary_campus_id
118
+ # #user.external_id_1
119
+ # #user.external_id_2
120
+ # #user.external_id_3
121
+
122
+ # if user.save
123
+ # puts "User #{user.full_name} saved (#{user.id})"
124
+ # else
125
+ # user.error_messages.each { |em| puts em }
126
+ # end
127
+
128
+ # user2 = TheCity::User.load_by_id(user.id)
129
+ # user2.email = 'somegirl@somewhere.org'
130
+ # user2.nickname = 'dog'
131
+
132
+ # if user2.save
133
+ # puts "User #{user2.full_name} updated (#{user2.id})"
134
+ # else
135
+ # user2.error_messages.each { |em| puts em }
136
+ # end
137
+
138
+ # if user.delete
139
+ # puts "User #{user.full_name} deleted (#{user.id})"
140
+ # else
141
+ # puts "Something bad happened"
142
+ # #user.error_messages.each { |em| puts em }
143
+ # end
144
+
145
+
146
+ # puts "-----------------------------"
147
+
148
+ # user_list = TheCity::UserList.new
149
+
150
+ # user = user_list[0]
151
+ # puts user.full_name
152
+ # user.first = 'Wes'
153
+ # puts user.full_name
154
+ # user.save
155
+ # puts user.id
156
+
157
+ # user2 = TheCity::User.load_by_id(user.id)
158
+ # puts user2.full_name
159
+
160
+ # puts "User has #{user.addresses.size} addresses"
161
+ # puts "User has #{user.family.size} family members"
162
+ # puts "User has #{user.notes.size} notes"
163
+ # puts "User has #{user.roles.size} roles"
164
+ # puts "User has #{user.skills.size} skills"
165
+ # #puts "User has #{user.processes.size} processes"
166
+ # puts "User has #{user.invitations.size} invitations"
167
+ # #puts "User has #{user.admin_privileges.size} admin_privileges"
168
+
169
+
170
+ # This is currenly returning a 404 if no family members are found
171
+ # puts user.family[0].name
172
+
173
+
174
+
175
+ # puts "-----------------------------"
176
+
177
+
178
+ # group_list = TheCity::GroupList.new(:)
179
+ # puts group.name
180
+ # group.name = 'Wes Group'
181
+ # puts group.name
182
+ # group.save
183
+ # group2 = TheCity::Group.load_by_id(group.id)
184
+ # puts group2.name
185
+
186
+
187
+ # puts "-----------------------------"
188
+ # puts "##### GROUPS #######"
189
+ # puts "-----------------------------"
190
+
191
+ # group_list = TheCity::GroupList.new
192
+
193
+ # group = group_list[13]
194
+ # puts "Group Name: #{group.name} (#{group.id})"
195
+
196
+ # if group.roles.size == 0
197
+ # puts "No group roles found"
198
+ # else
199
+ # puts group.roles[0].title
200
+ # end
201
+
202
+ # if group.tags.size == 0
203
+ # puts "No group tags found"
204
+ # else
205
+ # puts group.tags[0].name
206
+ # end
207
+
208
+ # if group.invitations.size == 0
209
+ # puts "No group invitations found"
210
+ # else
211
+ # puts group.invitations[0].id
212
+ # end
213
+
214
+
215
+ # puts "-----------------------------"
216
+ # puts "##### SKILLS #######"
217
+ # puts "-----------------------------"
218
+
219
+ # skill_list = TheCity::SkillList.new
220
+
221
+ # puts skill_list.inspect
222
+
223
+ # # skill_list.each do |skill|
224
+ # # puts skill.name
225
+ # # end
226
+
227
+
228
+ # puts "-----------------------------"
229
+ # puts "##### USERS #######"
230
+ # puts "-----------------------------"
231
+
232
+ # done = false
233
+ # page = 1
234
+
235
+
236
+ # while !done
237
+ # user_list = TheCity::UserList.new({:page => page})
238
+
239
+ # user_list.each do |user|
240
+ # puts user.full_name
241
+ # end
242
+
243
+ # if user_list.total_pages <= page
244
+ # done = true
245
+ # else
246
+ # page += 1
247
+ # end
248
+ # end
249
+
@@ -0,0 +1,51 @@
1
+ module TheCity
2
+
3
+ class Donation < ApiObject
4
+ tc_attr_accessor :id,
5
+ :user_id,
6
+ :fund_id,
7
+ :batch_id,
8
+ :amount,
9
+ :instrument_type,
10
+ :donation_state,
11
+ :donation_date,
12
+ :created_at,
13
+ :updated_at,
14
+ :fund_name,
15
+ :primary_campus_id,
16
+ :user_name,
17
+ :user_type,
18
+ :user_api_url,
19
+ :user_is_member,
20
+ :spouse_id,
21
+ :spouse_name,
22
+ :spouse_is_member
23
+
24
+ # Loads the donation by the specified ID.
25
+ #
26
+ # @param donation_id The ID of the donation to load.
27
+ #
28
+ # Returns a new {Donation} object.
29
+ def self.load_donation_by_id(pledge_id)
30
+ donation_reader = DonationReader.new(Pledge_id)
31
+ self.new(donation_reader)
32
+ end
33
+
34
+
35
+
36
+ # Constructor.
37
+ #
38
+ # @param reader (optional) The object that has the data. This can be a {DonationReader} or Hash object.
39
+ def initialize(reader = nil)
40
+ if reader.is_a?(DonationReader)
41
+ initialize_from_json_object(reader.load_feed)
42
+ elsif reader.is_a?(Hash)
43
+ initialize_from_json_object(reader)
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ end
50
+
51
+
@@ -0,0 +1,74 @@
1
+ module TheCity
2
+
3
+ class DonationList
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 donation name to search on.
18
+ #
19
+ #
20
+ # Examples:
21
+ # DonationList.new
22
+ #
23
+ # DonationList.new({:page => 2})
24
+ #
25
+ def initialize(options = {})
26
+ options[:page] ||= 1
27
+ reader = options[:reader] || TheCity::DonationListReader.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 donations in the list.
38
+ #
39
+ # @return array of donation names.
40
+ def all_names
41
+ @json_data['donations'].collect { |donation| donation['user_name'] }
42
+ end
43
+ alias :names :all_names
44
+
45
+
46
+ # Get the specified donation.
47
+ #
48
+ # @param index The index of the donation to get.
49
+ #
50
+ # @return [donation]
51
+ def [](index)
52
+ Donation.new( @json_data['donations'][index] ) if @json_data['donations'][index]
53
+ end
54
+
55
+
56
+ # This method is needed for Enumerable.
57
+ def each &block
58
+ @json_data['donations'].each{ |donation| yield( Donation.new(donation) )}
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['donations'].empty?
70
+ end
71
+
72
+ end
73
+
74
+ end
data/lib/api/fund.rb ADDED
@@ -0,0 +1,45 @@
1
+ module TheCity
2
+
3
+ class Fund < ApiObject
4
+ tc_attr_accessor :id,
5
+ :name,
6
+ :tax_deductible,
7
+ :group_id,
8
+ :fund_state,
9
+ :pledge_type,
10
+ :pledge_state,
11
+ :pledge_inactive_date,
12
+ :pledge_description,
13
+ :online_givable,
14
+ :external_id,
15
+ :created_at,
16
+ :updated_at
17
+
18
+ # Loads the fund by the specified ID.
19
+ #
20
+ # @param fund_id The ID of the fund to load.
21
+ #
22
+ # Returns a new {Fund} object.
23
+ def self.load_fund_by_id(fund_id)
24
+ fund_reader = FundReader.new(fund_id)
25
+ self.new(fund_reader)
26
+ end
27
+
28
+
29
+
30
+ # Constructor.
31
+ #
32
+ # @param reader (optional) The object that has the data. This can be a {FundReader} or Hash object.
33
+ def initialize(reader = nil)
34
+ if reader.is_a?(FundReader)
35
+ initialize_from_json_object(reader.load_feed)
36
+ elsif reader.is_a?(Hash)
37
+ initialize_from_json_object(reader)
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ end
44
+
45
+
@@ -0,0 +1,74 @@
1
+ module TheCity
2
+
3
+ class FundList
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 fund name to search on.
18
+ #
19
+ #
20
+ # Examples:
21
+ # FundList.new
22
+ #
23
+ # FundList.new({:page => 2})
24
+ #
25
+ def initialize(options = {})
26
+ options[:page] ||= 1
27
+ reader = options[:reader] || TheCity::FundListReader.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 funds in the list.
38
+ #
39
+ # @return array of fund names.
40
+ def all_names
41
+ @json_data['funds'].collect { |fund| fund['user_name'] }
42
+ end
43
+ alias :names :all_names
44
+
45
+
46
+ # Get the specified fund.
47
+ #
48
+ # @param index The index of the fund to get.
49
+ #
50
+ # @return [fund]
51
+ def [](index)
52
+ Fund.new( @json_data['funds'][index] ) if @json_data['funds'][index]
53
+ end
54
+
55
+
56
+ # This method is needed for Enumerable.
57
+ def each &block
58
+ @json_data['funds'].each{ |fund| yield( Fund.new(fund) )}
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['funds'].empty?
70
+ end
71
+
72
+ end
73
+
74
+ end
data/lib/api/pledge.rb CHANGED
@@ -7,7 +7,16 @@ module TheCity
7
7
  :amount,
8
8
  :pledge_date,
9
9
  :created_at,
10
- :updated_at
10
+ :updated_at,
11
+ :fund_name,
12
+ :primary_campus_id,
13
+ :user_name,
14
+ :user_type,
15
+ :user_api_url,
16
+ :user_is_member,
17
+ :spouse_id,
18
+ :spouse_name,
19
+ :spouse_is_name
11
20
 
12
21
 
13
22
  # Loads the pledge by the specified ID.
@@ -17,7 +26,7 @@ module TheCity
17
26
  # Returns a new {Pledge} object.
18
27
  def self.load_pledge_by_id(pledge_id)
19
28
  pledge_reader = PledgeReader.new(Pledge_id)
20
- self.new(Pledge_reader)
29
+ self.new(pledge_reader)
21
30
  end
22
31
 
23
32
 
@@ -18,9 +18,9 @@ module TheCity
18
18
  #
19
19
  #
20
20
  # Examples:
21
- # UserList.new
21
+ # PledgeList.new
22
22
  #
23
- # UserList.new({:page => 2})
23
+ # PledgeList.new({:page => 2})
24
24
  #
25
25
  def initialize(options = {})
26
26
  options[:page] ||= 1
@@ -38,7 +38,7 @@ module TheCity
38
38
  #
39
39
  # @return array of pledge names.
40
40
  def all_names
41
- @json_data['pledges'].collect { |pledge| pledge['id'] }
41
+ @json_data['pledges'].collect { |pledge| pledge['user_name'] }
42
42
  end
43
43
  alias :names :all_names
44
44
 
@@ -49,7 +49,7 @@ module TheCity
49
49
  #
50
50
  # @return [pledge]
51
51
  def [](index)
52
- pledge.new( @json_data['pledges'][index] ) if @json_data['pledges'][index]
52
+ Pledge.new( @json_data['pledges'][index] ) if @json_data['pledges'][index]
53
53
  end
54
54
 
55
55
 
@@ -0,0 +1,23 @@
1
+ module TheCity
2
+
3
+ class DonationListReader < 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
+ options[:page] ||= 1
12
+
13
+ #@class_key = "pledge_list_#{options[:page]}_{some_kind_of_md5_thing_here}"
14
+ @url_data_path = "/donations"
15
+ @url_data_params = options
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 DonationReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # <b>donation_id</b> The ID of the donation to load.
8
+ # <b>CacheAdapter cacher</b> (optional) The cacher to be used to cache data.
9
+ def initialize(donation_id, cacher = nil)
10
+ #@class_key = "donations_#{donation_id}"
11
+ @url_data_path = "/donations/#{donation_id}"
12
+
13
+ # The object to store and load the cache.
14
+ @cacher = cacher unless cacher.nil?
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+
21
+
@@ -0,0 +1,23 @@
1
+ module TheCity
2
+
3
+ class FundListReader < 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
+ options[:page] ||= 1
12
+
13
+ #@class_key = "pledge_list_#{options[:page]}_{some_kind_of_md5_thing_here}"
14
+ @url_data_path = "/funds"
15
+ @url_data_params = options
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 FundReader < ApiReader
4
+
5
+ # Constructor.
6
+ #
7
+ # <b>fund_id</b> The ID of the fund to load.
8
+ # <b>CacheAdapter cacher</b> (optional) The cacher to be used to cache data.
9
+ def initialize(fund_id, cacher = nil)
10
+ #@class_key = "funds_#{fund_id}"
11
+ @url_data_path = "/funds/#{fund_id}"
12
+
13
+ # The object to store and load the cache.
14
+ @cacher = cacher unless cacher.nil?
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+
21
+
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  PROJECT_GEM = 'the-city-admin'
3
- PROJECT_GEM_VERSION = '0.1.5'
3
+ PROJECT_GEM_VERSION = '0.2.0'
4
4
 
5
5
  s.name = PROJECT_GEM
6
6
  s.version = PROJECT_GEM_VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the-city-admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-01 00:00:00.000000000 Z
12
+ date: 2012-10-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: typhoeus
@@ -66,8 +66,12 @@ files:
66
66
  - lib/api/barcode.rb
67
67
  - lib/api/checkin.rb
68
68
  - lib/api/checkin_list.rb
69
+ - lib/api/donation.rb
70
+ - lib/api/donation_list.rb
69
71
  - lib/api/family.rb
70
72
  - lib/api/family_member.rb
73
+ - lib/api/fund.rb
74
+ - lib/api/fund_list.rb
71
75
  - lib/api/group.rb
72
76
  - lib/api/group_address.rb
73
77
  - lib/api/group_address_list.rb
@@ -135,7 +139,11 @@ files:
135
139
  - lib/readers/api_reader.rb
136
140
  - lib/readers/checkin_list_reader.rb
137
141
  - lib/readers/checkin_reader.rb
142
+ - lib/readers/donation_list_reader.rb
143
+ - lib/readers/donation_reader.rb
138
144
  - lib/readers/family_reader.rb
145
+ - lib/readers/fund_list_reader.rb
146
+ - lib/readers/fund_reader.rb
139
147
  - lib/readers/group_address_list_reader.rb
140
148
  - lib/readers/group_checkin_list_reader.rb
141
149
  - lib/readers/group_event_attendance_list_reader.rb