the-city-admin 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.rvmrc +1 -1
- data/Gemfile +1 -1
- data/Gemfile.lock +8 -14
- data/README.rdoc +58 -0
- data/{test_scripts → examples}/addresses.rb +0 -0
- data/{test_scripts → examples}/barcodes_checkins.rb +0 -0
- data/{test_scripts → examples}/city_keys.rb +0 -0
- data/{test_scripts → examples}/familes.rb +0 -0
- data/{test_scripts → examples}/groups.rb +0 -0
- data/{test_scripts → examples}/metrics.rb +0 -0
- data/{test_scripts → examples}/roles.rb +0 -0
- data/{test_scripts → examples}/skills.rb +0 -0
- data/{test_scripts → examples}/tags.rb +0 -0
- data/{test_scripts → examples}/terminology.rb +0 -0
- data/examples/thecity_headers.rb +49 -0
- data/{test_scripts → examples}/users.rb +0 -0
- data/{test_scripts → examples}/webhooks.rb +0 -0
- data/index.rb +17 -137
- data/lib/api/pledge.rb +40 -0
- data/lib/api/pledge_list.rb +74 -0
- data/lib/api/user_process_answer.rb +22 -0
- data/lib/api/user_process_answer_list.rb +64 -0
- data/lib/readers/address_list_reader.rb +1 -1
- data/lib/readers/address_reader.rb +1 -1
- data/lib/readers/api_reader.rb +4 -4
- data/lib/readers/checkin_list_reader.rb +1 -1
- data/lib/readers/checkin_reader.rb +1 -1
- data/lib/readers/family_reader.rb +1 -1
- data/lib/readers/group_address_list_reader.rb +1 -1
- data/lib/readers/group_checkin_list_reader.rb +1 -1
- data/lib/readers/group_event_attendance_list_reader.rb +1 -1
- data/lib/readers/group_export_list_reader.rb +1 -1
- data/lib/readers/group_invitation_list_reader.rb +1 -1
- data/lib/readers/group_list_reader.rb +3 -5
- data/lib/readers/group_reader.rb +1 -1
- data/lib/readers/group_role_list_reader.rb +1 -1
- data/lib/readers/group_tag_list_reader.rb +1 -1
- data/lib/readers/metric_list_reader.rb +1 -1
- data/lib/readers/metric_measurement_list_reader.rb +1 -1
- data/lib/readers/metric_measurement_reader.rb +1 -1
- data/lib/readers/metric_reader.rb +1 -1
- data/lib/readers/pledge_list_reader.rb +23 -0
- data/lib/readers/pledge_reader.rb +21 -0
- data/lib/readers/role_list_reader.rb +1 -1
- data/lib/readers/skill_list_reader.rb +1 -1
- data/lib/readers/skilled_user_id_list_reader.rb +1 -1
- data/lib/readers/skilled_user_list_reader.rb +1 -1
- data/lib/readers/tag_group_list_reader.rb +1 -1
- data/lib/readers/tag_list_reader.rb +1 -1
- data/lib/readers/tag_reader.rb +1 -1
- data/lib/readers/terminology_list_reader.rb +1 -1
- data/lib/readers/terminology_reader.rb +1 -1
- data/lib/readers/user_address_list_reader.rb +1 -1
- data/lib/readers/user_admin_privilege_list_reader.rb +1 -1
- data/lib/readers/user_count_reader.rb +1 -1
- data/lib/readers/user_family_list_reader.rb +1 -1
- data/lib/readers/user_invitation_list_reader.rb +1 -1
- data/lib/readers/user_list_reader.rb +1 -1
- data/lib/readers/user_note_list_reader.rb +1 -1
- data/lib/readers/user_process_answer_list_reader.rb +24 -0
- data/lib/readers/user_process_list_reader.rb +1 -1
- data/lib/readers/user_reader.rb +1 -1
- data/lib/readers/user_role_list_reader.rb +1 -1
- data/lib/readers/user_skill_list_reader.rb +1 -1
- data/lib/readers/web_hook_list_reader.rb +1 -1
- data/spec/api/user_process_answer_list_spec.rb +84 -0
- data/spec/factories/user_process_answer.rb +13 -0
- data/spec/factories/user_process_answer_list.rb +12 -0
- data/spec/spec_helper.rb +1 -0
- data/thecity_admin_api.gemspec +3 -3
- metadata +32 -20
- data/README +0 -1
- data/notes.txt +0 -21
- data/status.txt +0 -187
- data/thecity_headers.rb +0 -27
data/.gitignore
CHANGED
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm ruby-1.9.2-
|
1
|
+
rvm ruby-1.9.2-p320@admin-api
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -5,18 +5,22 @@ GEM
|
|
5
5
|
activesupport (3.2.8)
|
6
6
|
i18n (~> 0.6)
|
7
7
|
multi_json (~> 1.0)
|
8
|
-
archive-tar-minitar (0.5.2)
|
9
8
|
autotest (4.4.6)
|
10
9
|
ZenTest (>= 4.4.1)
|
11
10
|
columnize (0.3.6)
|
11
|
+
debugger (1.2.0)
|
12
|
+
columnize (>= 0.3.1)
|
13
|
+
debugger-linecache (~> 1.1.1)
|
14
|
+
debugger-ruby_core_source (~> 1.1.3)
|
15
|
+
debugger-linecache (1.1.2)
|
16
|
+
debugger-ruby_core_source (>= 1.1.1)
|
17
|
+
debugger-ruby_core_source (1.1.3)
|
12
18
|
diff-lcs (1.1.3)
|
13
19
|
factory_girl (4.0.0)
|
14
20
|
activesupport (>= 3.0.0)
|
15
21
|
ffi (1.1.5)
|
16
22
|
i18n (0.6.1)
|
17
23
|
json (1.7.5)
|
18
|
-
linecache19 (0.5.12)
|
19
|
-
ruby_core_source (>= 0.1.4)
|
20
24
|
mime-types (1.19)
|
21
25
|
multi_json (1.3.6)
|
22
26
|
rspec (2.11.0)
|
@@ -27,16 +31,6 @@ GEM
|
|
27
31
|
rspec-expectations (2.11.2)
|
28
32
|
diff-lcs (~> 1.1.3)
|
29
33
|
rspec-mocks (2.11.2)
|
30
|
-
ruby-debug-base19 (0.11.25)
|
31
|
-
columnize (>= 0.3.1)
|
32
|
-
linecache19 (>= 0.5.11)
|
33
|
-
ruby_core_source (>= 0.1.4)
|
34
|
-
ruby-debug19 (0.11.6)
|
35
|
-
columnize (>= 0.3.1)
|
36
|
-
linecache19 (>= 0.5.11)
|
37
|
-
ruby-debug-base19 (>= 0.11.19)
|
38
|
-
ruby_core_source (0.1.5)
|
39
|
-
archive-tar-minitar (>= 0.5.2)
|
40
34
|
typhoeus (0.4.2)
|
41
35
|
ffi (~> 1.0)
|
42
36
|
mime-types (~> 1.18)
|
@@ -46,8 +40,8 @@ PLATFORMS
|
|
46
40
|
|
47
41
|
DEPENDENCIES
|
48
42
|
autotest
|
43
|
+
debugger
|
49
44
|
factory_girl
|
50
45
|
json
|
51
46
|
rspec
|
52
|
-
ruby-debug19
|
53
47
|
typhoeus
|
data/README.rdoc
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
= The City Admin API
|
2
|
+
|
3
|
+
This Ruby project is an API wrapper for TheCity Admin API (https://api.onthecity.org)
|
4
|
+
|
5
|
+
|
6
|
+
== Install / Setup
|
7
|
+
|
8
|
+
Installing the gem
|
9
|
+
|
10
|
+
gem install the-city-admin
|
11
|
+
|
12
|
+
|
13
|
+
To add it to your Gemfile
|
14
|
+
|
15
|
+
gem 'the-city-admin', :require => 'the_city_admin'
|
16
|
+
|
17
|
+
|
18
|
+
Add your church's City API Token and API Key to [RAILS_ROOT]/config/initializers/thecity_config.rb
|
19
|
+
|
20
|
+
THECITY_KEY = '**** YOUR CITY API KEY ****'
|
21
|
+
THECITY_TOKEN = '**** YOUR CITY API TOKEN ****'
|
22
|
+
|
23
|
+
|
24
|
+
Next you will need to initialize a connection
|
25
|
+
|
26
|
+
TheCity::AdminApi.connect(THECITY_KEY, THECITY_TOKEN)
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
== Example usage
|
31
|
+
|
32
|
+
|
33
|
+
=== Get list of group
|
34
|
+
|
35
|
+
TheCity::AdminApi.connect(THECITY_KEY, THECITY_TOKEN)
|
36
|
+
|
37
|
+
|
38
|
+
== Additional resources
|
39
|
+
|
40
|
+
* The City Admin API: https://github.com/thecity/thecity-admin-ruby
|
41
|
+
* The City developer community page: http://developer.onthecity.org
|
42
|
+
|
43
|
+
|
44
|
+
== License
|
45
|
+
|
46
|
+
This project is released under the MIT license (see LICENSE).
|
47
|
+
|
48
|
+
This project is maintained by Wes Hays (https://github.com/weshays).
|
49
|
+
|
50
|
+
|
51
|
+
== Contributors
|
52
|
+
|
53
|
+
Chris Morris: https://github.com/chrismo
|
54
|
+
|
55
|
+
|
56
|
+
== Want to Contribute?
|
57
|
+
|
58
|
+
If you would like to get involved in this project, then please fork the project. Make changes, add features, write some tests, and then send us a pull request.
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'Base64'
|
2
|
+
require 'CGI'
|
3
|
+
require 'openssl'
|
4
|
+
require 'net/http'
|
5
|
+
require 'net/https'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
|
9
|
+
# The City API keys
|
10
|
+
key = '**** YOUR CITY API KEY ****'
|
11
|
+
token = '**** YOUR CITY API TOKEN ****'
|
12
|
+
|
13
|
+
|
14
|
+
# API endpoint to get data from
|
15
|
+
path = '/groups'
|
16
|
+
url = 'https://api.onthecity.org' + path
|
17
|
+
|
18
|
+
|
19
|
+
# Build signature
|
20
|
+
current_time = Time.now.to_i.to_s
|
21
|
+
string_to_sign = current_time.to_s + 'GET' + url
|
22
|
+
unencoded_hmac = OpenSSL::HMAC.digest('sha256', key, string_to_sign)
|
23
|
+
unescaped_hmac = Base64.encode64(unencoded_hmac).chomp
|
24
|
+
hmac_signature = CGI.escape(unescaped_hmac)
|
25
|
+
|
26
|
+
|
27
|
+
# Build headers
|
28
|
+
headers = {}
|
29
|
+
headers['X-City-Sig'] = hmac_signature
|
30
|
+
headers['X-City-User-Token'] = token
|
31
|
+
headers['X-City-Time'] = current_time
|
32
|
+
headers['Accept'] = 'application/vnd.thecity.admin.v1+json'
|
33
|
+
headers['Content-Type'] = 'application/json'
|
34
|
+
|
35
|
+
|
36
|
+
# API Request
|
37
|
+
uri = URI.parse(url)
|
38
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
39
|
+
http.use_ssl = true
|
40
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # read into this
|
41
|
+
request = Net::HTTP::Get.new(uri.request_uri, headers)
|
42
|
+
response = http.request(request)
|
43
|
+
groups_data = JSON.parse(response.body)
|
44
|
+
|
45
|
+
|
46
|
+
# Output group names
|
47
|
+
groups_data['groups'].each do |group|
|
48
|
+
puts group['name']
|
49
|
+
end
|
File without changes
|
File without changes
|
data/index.rb
CHANGED
@@ -5,153 +5,33 @@
|
|
5
5
|
# @authors Robbie Lieb <robbie@onthecity.org>, Wes Hays <wes@onthecity.org>
|
6
6
|
# *******************************************
|
7
7
|
|
8
|
+
|
8
9
|
require 'ruby-debug'
|
9
10
|
require File.dirname(__FILE__) + '/lib/the_city_admin.rb'
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
TCA_ENV = 'production'
|
12
|
+
key = '132412341234123412341234'
|
13
|
+
token = 'asdf1234asdf1234'
|
15
14
|
|
16
|
-
key = '2bcee1fdccd31f1ef35a7c6708daf5a446a61ee3'
|
17
|
-
token = 'e37ae7fb2042a17b'
|
18
15
|
|
19
16
|
TheCity::AdminApi.connect(key, token)
|
20
17
|
|
21
|
-
# puts "-----------------------------"
|
22
|
-
# puts "##### USERS #######"
|
23
|
-
# puts "-----------------------------"
|
24
|
-
|
25
|
-
|
26
|
-
# user_list = TheCity::UserList.new
|
27
|
-
|
28
|
-
# user_list.each do |u|
|
29
|
-
# puts u.full_name
|
30
|
-
# end
|
31
|
-
|
32
|
-
# puts "-----------------------------"
|
33
|
-
|
34
|
-
# user = TheCity::User.new
|
35
|
-
# user.title = 'Deacon'
|
36
|
-
# user.first = 'James'
|
37
|
-
# user.middle = 'Wesley'
|
38
|
-
# user.last = 'Hays'
|
39
|
-
# user.nickname = 'Wes'
|
40
|
-
# user.gender = TheCity::User::Gender[:male]
|
41
|
-
# user.email = 'someguy@somewhere.org'
|
42
|
-
# user.staff = false
|
43
|
-
# user.member_since = Time.now.strftime("%Y-%m-%d")
|
44
|
-
# user.birthdate = '1980-09-27'
|
45
|
-
# user.primary_phone = '775-111-2222'
|
46
|
-
# user.primary_phone_type = TheCity::User::PhoneType[:mobile]
|
47
|
-
# user.secondary_phone = '775-333-4444'
|
48
|
-
# user.secondary_phone_type = TheCity::User::PhoneType[:home]
|
49
|
-
# user.marital_status = TheCity::User::MaritalStatus[:married]
|
50
|
-
# #user.primary_campus_id
|
51
|
-
# #user.external_id_1
|
52
|
-
# #user.external_id_2
|
53
|
-
# #user.external_id_3
|
54
|
-
|
55
|
-
# if user.save
|
56
|
-
# puts "User #{user.full_name} saved (#{user.id})"
|
57
|
-
# else
|
58
|
-
# user.error_messages.each { |em| puts em }
|
59
|
-
# end
|
60
|
-
|
61
|
-
# user2 = TheCity::User.load_by_id(user.id)
|
62
|
-
# user2.email = 'somegirl@somewhere.org'
|
63
|
-
# user2.nickname = 'dog'
|
64
|
-
|
65
|
-
# if user2.save
|
66
|
-
# puts "User #{user2.full_name} updated (#{user2.id})"
|
67
|
-
# else
|
68
|
-
# user2.error_messages.each { |em| puts em }
|
69
|
-
# end
|
70
|
-
|
71
|
-
# if user.delete
|
72
|
-
# puts "User #{user.full_name} deleted (#{user.id})"
|
73
|
-
# else
|
74
|
-
# puts "Something bad happened"
|
75
|
-
# #user.error_messages.each { |em| puts em }
|
76
|
-
# end
|
77
|
-
|
78
|
-
|
79
|
-
# puts "-----------------------------"
|
80
|
-
|
81
|
-
# user_list = TheCity::UserList.new
|
82
|
-
|
83
|
-
# user = user_list[0]
|
84
|
-
# puts user.full_name
|
85
|
-
# user.first = 'Wes'
|
86
|
-
# puts user.full_name
|
87
|
-
# user.save
|
88
|
-
# puts user.id
|
89
|
-
|
90
|
-
# user2 = TheCity::User.load_by_id(user.id)
|
91
|
-
# puts user2.full_name
|
92
|
-
|
93
|
-
# puts "User has #{user.addresses.size} addresses"
|
94
|
-
# puts "User has #{user.family.size} family members"
|
95
|
-
# puts "User has #{user.notes.size} notes"
|
96
|
-
# puts "User has #{user.roles.size} roles"
|
97
|
-
# puts "User has #{user.skills.size} skills"
|
98
|
-
# #puts "User has #{user.processes.size} processes"
|
99
|
-
# puts "User has #{user.invitations.size} invitations"
|
100
|
-
# #puts "User has #{user.admin_privileges.size} admin_privileges"
|
101
|
-
|
102
|
-
|
103
|
-
# This is currenly returning a 404 if no family members are found
|
104
|
-
# puts user.family[0].name
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
# puts "-----------------------------"
|
109
|
-
|
110
|
-
# group_list = TheCity::GroupList.new
|
111
|
-
# group = group_list[0]
|
112
|
-
# puts group.name
|
113
|
-
# group.name = 'Wes Group'
|
114
|
-
# puts group.name
|
115
|
-
# group.save
|
116
|
-
# group2 = TheCity::Group.load_by_id(group.id)
|
117
|
-
# puts group2.name
|
118
|
-
|
119
|
-
|
120
|
-
# puts "-----------------------------"
|
121
|
-
# puts "##### GROUPS #######"
|
122
|
-
# puts "-----------------------------"
|
123
|
-
|
124
|
-
# group_list = TheCity::GroupList.new
|
125
|
-
|
126
|
-
# group = group_list[13]
|
127
|
-
# puts "Group Name: #{group.name} (#{group.id})"
|
128
|
-
|
129
|
-
# if group.roles.size == 0
|
130
|
-
# puts "No group roles found"
|
131
|
-
# else
|
132
|
-
# puts group.roles[0].title
|
133
|
-
# end
|
134
|
-
|
135
|
-
# if group.tags.size == 0
|
136
|
-
# puts "No group tags found"
|
137
|
-
# else
|
138
|
-
# puts group.tags[0].name
|
139
|
-
# end
|
140
|
-
|
141
|
-
# if group.invitations.size == 0
|
142
|
-
# puts "No group invitations found"
|
143
|
-
# else
|
144
|
-
# puts group.invitations[0].id
|
145
|
-
# end
|
146
18
|
|
19
|
+
done = false
|
20
|
+
page = 1
|
21
|
+
count = 0
|
147
22
|
|
148
|
-
|
149
|
-
|
150
|
-
puts "-----------------------------"
|
23
|
+
while !done
|
24
|
+
group_list = TheCity::GroupList.new({:page => page})
|
151
25
|
|
152
|
-
|
26
|
+
group_list.each do |group|
|
27
|
+
count += 1
|
28
|
+
puts "#{count}) #{group.name}"
|
29
|
+
end
|
153
30
|
|
154
|
-
|
155
|
-
|
31
|
+
if group_list.total_pages <= page
|
32
|
+
done = true
|
33
|
+
else
|
34
|
+
page += 1
|
35
|
+
end
|
156
36
|
end
|
157
37
|
|
data/lib/api/pledge.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module TheCity
|
2
|
+
|
3
|
+
class Pledge < ApiObject
|
4
|
+
tc_attr_accessor :id,
|
5
|
+
:user_id,
|
6
|
+
:fund_id,
|
7
|
+
:amount,
|
8
|
+
:pledge_date,
|
9
|
+
:created_at,
|
10
|
+
:updated_at
|
11
|
+
|
12
|
+
|
13
|
+
# Loads the pledge by the specified ID.
|
14
|
+
#
|
15
|
+
# @param pledge_id The ID of the pledge to load.
|
16
|
+
#
|
17
|
+
# Returns a new {Pledge} object.
|
18
|
+
def self.load_pledge_by_id(pledge_id)
|
19
|
+
pledge_reader = PledgeReader.new(Pledge_id)
|
20
|
+
self.new(Pledge_reader)
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
# Constructor.
|
26
|
+
#
|
27
|
+
# @param reader (optional) The object that has the data. This can be a {PledgeReader} or Hash object.
|
28
|
+
def initialize(reader = nil)
|
29
|
+
if reader.is_a?(PledgeReader)
|
30
|
+
initialize_from_json_object(reader.load_feed)
|
31
|
+
elsif reader.is_a?(Hash)
|
32
|
+
initialize_from_json_object(reader)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module TheCity
|
2
|
+
|
3
|
+
class PledgeList
|
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 pledge 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::PledgeListReader.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 pledges in the list.
|
38
|
+
#
|
39
|
+
# @return array of pledge names.
|
40
|
+
def all_names
|
41
|
+
@json_data['pledges'].collect { |pledge| pledge['id'] }
|
42
|
+
end
|
43
|
+
alias :names :all_names
|
44
|
+
|
45
|
+
|
46
|
+
# Get the specified pledge.
|
47
|
+
#
|
48
|
+
# @param index The index of the pledge to get.
|
49
|
+
#
|
50
|
+
# @return [pledge]
|
51
|
+
def [](index)
|
52
|
+
pledge.new( @json_data['pledges'][index] ) if @json_data['pledges'][index]
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
# This method is needed for Enumerable.
|
57
|
+
def each &block
|
58
|
+
@json_data['pledges'].each{ |pledge| yield( Pledge.new(pledge) )}
|
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['pledges'].empty?
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|