the-city-admin 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/city_keys.rb +2 -2
- data/examples/donation_export.rb +63 -0
- data/lib/api/donation_export.rb +38 -0
- data/lib/api/donation_export_list.rb +63 -0
- data/lib/api/fund.rb +1 -0
- data/lib/common.rb +2 -2
- data/lib/readers/donation_export_list_reader.rb +23 -0
- data/lib/readers/donation_export_reader.rb +23 -0
- data/lib/the_city_admin.rb +7 -21
- data/lib/writers/donation_export_writer.rb +25 -0
- data/lib/writers/fund_writer.rb +25 -0
- data/thecity_admin_api.gemspec +1 -1
- metadata +9 -2
data/examples/city_keys.rb
CHANGED
@@ -0,0 +1,63 @@
|
|
1
|
+
# *******************************************
|
2
|
+
# This is a demo file to show usage.
|
3
|
+
#
|
4
|
+
# @package TheCity::Admin
|
5
|
+
# @authors Robbie Lieb <robbie@onthecity.org>, Wes Hays <wes@onthecity.org>
|
6
|
+
# *******************************************
|
7
|
+
|
8
|
+
TCA_ENV = 'development'
|
9
|
+
THE_CITY_ADMIN_PATH = 'http://api.devthecity.org:9292'
|
10
|
+
key = '66c59e2ee24553e7237259e30b4c17365681b95c'
|
11
|
+
token = 'a9ae4af3c3e80102'
|
12
|
+
|
13
|
+
|
14
|
+
require 'ruby-debug'
|
15
|
+
require File.dirname(__FILE__) + '/../lib/the_city_admin.rb'
|
16
|
+
|
17
|
+
require File.dirname(__FILE__) + '/city_keys.rb'
|
18
|
+
include CityKeys
|
19
|
+
|
20
|
+
TheCity::AdminApi.connect(KEY, TOKEN)
|
21
|
+
|
22
|
+
|
23
|
+
de_list = TheCity::DonationExportList.new
|
24
|
+
de_list.each do |item|
|
25
|
+
puts "DonationExport: #{item.inspect}"
|
26
|
+
end
|
27
|
+
|
28
|
+
# de_list = TheCity::DonationExportList.new
|
29
|
+
# de_list.each do |item|
|
30
|
+
# if item.delete
|
31
|
+
# puts "DonationExport #{item.id} deleted"
|
32
|
+
# else
|
33
|
+
# puts "Unable to delete donation export #{item.id}: #{item.error_messages.join(', ')}"
|
34
|
+
# end
|
35
|
+
# end
|
36
|
+
|
37
|
+
# de_list = TheCity::DonationExportList.new
|
38
|
+
# if de_list.empty?
|
39
|
+
# puts "No donation exports found"
|
40
|
+
# else
|
41
|
+
# puts "Donation exports found"
|
42
|
+
# end
|
43
|
+
|
44
|
+
# donation_export = TheCity::DonationExport.new
|
45
|
+
# if donation_export.save
|
46
|
+
# puts "Donation export created"
|
47
|
+
# else
|
48
|
+
# puts "Failed to create donation export"
|
49
|
+
# end
|
50
|
+
|
51
|
+
|
52
|
+
# de_list = TheCity::DonationExportList.new
|
53
|
+
# if de_list.empty?
|
54
|
+
# puts "No donation exports found"
|
55
|
+
# else
|
56
|
+
# puts "Donation exports found"
|
57
|
+
# end
|
58
|
+
|
59
|
+
puts "------------------------------------"
|
60
|
+
|
61
|
+
puts "####################################"
|
62
|
+
|
63
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module TheCity
|
2
|
+
|
3
|
+
class DonationExport < ApiObject
|
4
|
+
|
5
|
+
tc_attr_accessor :id,
|
6
|
+
:state,
|
7
|
+
:authenticated_s3_url,
|
8
|
+
:created_at
|
9
|
+
|
10
|
+
|
11
|
+
# Loads the donation export by the specified ID.
|
12
|
+
#
|
13
|
+
# @param donation_export_id The ID of the donation export to load.
|
14
|
+
# @param options A hash of options for requesting data from the server.
|
15
|
+
# :: donation_id is required
|
16
|
+
#
|
17
|
+
# Returns a new {DonationExport} object.
|
18
|
+
def self.load_by_id(donation_export_id, options = {})
|
19
|
+
donation_reader = DonationExportReader.new(donation_export_id, options)
|
20
|
+
self.new(donation_reader.load_feed)
|
21
|
+
rescue
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
# Constructor.
|
27
|
+
#
|
28
|
+
# @param json_data (optional) JSON data of the donation export.
|
29
|
+
def initialize(json_data = nil)
|
30
|
+
@writer_object = DonationExportWriter
|
31
|
+
initialize_from_json_object(json_data) unless json_data.nil?
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module TheCity
|
2
|
+
|
3
|
+
class DonationExportList
|
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
|
+
# :donation_id - The ID of the donation to load the addresses for. (required)
|
15
|
+
# :page - The page number to get.
|
16
|
+
# :reader - The Reader to use to load the data.
|
17
|
+
#
|
18
|
+
#
|
19
|
+
# Examples:
|
20
|
+
# DonationExportList.new({:donation_id => 12345})
|
21
|
+
#
|
22
|
+
# DonationExportList.new({:donation_id => 12345, :page => 2})
|
23
|
+
#
|
24
|
+
def initialize(options = {})
|
25
|
+
reader = options[:reader] || TheCity::DonationExportListReader.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 note.
|
36
|
+
#
|
37
|
+
# @param index The index of the note to get.
|
38
|
+
#
|
39
|
+
# @return [DonationExport]
|
40
|
+
def [](index)
|
41
|
+
DonationExport.new( @json_data['exports'][index] ) if @json_data['exports'][index]
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
# This method is needed for Enumerable.
|
46
|
+
def each &block
|
47
|
+
@json_data['exports'].each{ |export| yield( DonationExport.new(export) )}
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
# Alias the count method
|
52
|
+
alias :size :count
|
53
|
+
|
54
|
+
# Checks if the list is empty.
|
55
|
+
#
|
56
|
+
# @return True on empty, false otherwise.
|
57
|
+
def empty?
|
58
|
+
@json_data['exports'].empty?
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/lib/api/fund.rb
CHANGED
data/lib/common.rb
CHANGED
@@ -50,12 +50,12 @@ module TheCity
|
|
50
50
|
current_time = Time.now.to_i.to_s
|
51
51
|
string_to_sign = current_time.to_s + method_request + url
|
52
52
|
|
53
|
-
unencoded_hmac = OpenSSL::HMAC.digest('sha256', TheCity::AdminApi
|
53
|
+
unencoded_hmac = OpenSSL::HMAC.digest('sha256', TheCity::AdminApi.api_key, string_to_sign)
|
54
54
|
unescaped_hmac = Base64.encode64(unencoded_hmac).chomp
|
55
55
|
hmac_signature = CGI.escape(unescaped_hmac)
|
56
56
|
|
57
57
|
{'X-City-Sig' => hmac_signature,
|
58
|
-
'X-City-User-Token' => TheCity::AdminApi
|
58
|
+
'X-City-User-Token' => TheCity::AdminApi.api_token,
|
59
59
|
'X-City-Time' => current_time,
|
60
60
|
'Accept' => 'application/vnd.thecity.admin.v1+json',
|
61
61
|
'Content-Type' => 'application/json',
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module TheCity
|
2
|
+
|
3
|
+
class DonationExportListReader < 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 = "groups_#{group_id}_exports"
|
12
|
+
@url_data_path = "/donations/exports"
|
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
|
22
|
+
|
23
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module TheCity
|
2
|
+
|
3
|
+
class DonationExportReader < ApiReader
|
4
|
+
|
5
|
+
# Constructor.
|
6
|
+
#
|
7
|
+
# @param donation_export_id The ID of the donation export to load.
|
8
|
+
# @param options A hash of options for requesting data from the server.
|
9
|
+
# @param cacher (optional) The CacheAdapter cacher to be used to cache data.
|
10
|
+
def initialize(donation_export_id, options = {}, cacher = nil)
|
11
|
+
#@class_key = "donation_export_#{donation_export_id}"
|
12
|
+
@url_data_path = "/donations/exports/#{donation_export_id}"
|
13
|
+
@url_data_params = options
|
14
|
+
|
15
|
+
# The object to store and load the cache.
|
16
|
+
@cacher = cacher unless cacher.nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
|
data/lib/the_city_admin.rb
CHANGED
@@ -28,28 +28,14 @@ require File.dirname(__FILE__) + '/common.rb'
|
|
28
28
|
module TheCity
|
29
29
|
|
30
30
|
class AdminApi
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
# Alias for calling the *new* method.
|
36
|
-
def self.connect(api_key, api_token)
|
37
|
-
self.new(api_key, api_token)
|
31
|
+
class << self
|
32
|
+
attr_reader :api_key, :api_token
|
38
33
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
# @param api_token The API token for the church.
|
45
|
-
def initialize(api_key, api_token)
|
46
|
-
raise TheCityExceptions::UnableToConnectToTheCity.new('Key and Token cannot be nil.') if api_key.nil? or api_token.nil?
|
47
|
-
|
48
|
-
# Create a constant for the churches API key.
|
49
|
-
TheCity::AdminApi::const_set(:API_KEY, api_key) unless defined?(API_KEY)
|
50
|
-
|
51
|
-
# Create a constant for the churches API Token.
|
52
|
-
TheCity::AdminApi::const_set(:API_TOKEN, api_token) unless defined?(API_TOKEN)
|
34
|
+
|
35
|
+
def self.connect(admin_api_key, admin_api_token)
|
36
|
+
raise TheCityExceptions::UnableToConnectToTheCity.new('Key and Token cannot be nil.') if admin_api_key.nil? or admin_api_token.nil?
|
37
|
+
@api_key = admin_api_key
|
38
|
+
@api_token = admin_api_token
|
53
39
|
end
|
54
40
|
|
55
41
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module TheCity
|
2
|
+
|
3
|
+
class DonationExportWriter < ApiWriter
|
4
|
+
|
5
|
+
# Constructor.
|
6
|
+
#
|
7
|
+
# @param data The json data to save.
|
8
|
+
def initialize(data)
|
9
|
+
if data[:id]
|
10
|
+
@url_action = :put
|
11
|
+
@url_data_path = nil # not implemented
|
12
|
+
else
|
13
|
+
@url_action = :post
|
14
|
+
@url_data_path = '/donations/exports'
|
15
|
+
end
|
16
|
+
@url_data_delete_path = "/donations/exports/#{data[:id]}"
|
17
|
+
|
18
|
+
@url_data_params = data
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module TheCity
|
2
|
+
|
3
|
+
class FundWriter < ApiWriter
|
4
|
+
|
5
|
+
# Constructor.
|
6
|
+
#
|
7
|
+
# @param data The json data to save.
|
8
|
+
def initialize(data)
|
9
|
+
if data[:id]
|
10
|
+
@url_action = :put
|
11
|
+
@url_data_path = "/funds/#{data[:id]}"
|
12
|
+
else
|
13
|
+
@url_action = :post
|
14
|
+
@url_data_path = "/funds"
|
15
|
+
end
|
16
|
+
@url_data_delete_path = "/funds/#{data[:id]}"
|
17
|
+
|
18
|
+
@url_data_params = data
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
data/thecity_admin_api.gemspec
CHANGED
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.
|
4
|
+
version: 0.5.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:
|
12
|
+
date: 2013-01-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: typhoeus
|
@@ -49,6 +49,7 @@ files:
|
|
49
49
|
- examples/addresses.rb
|
50
50
|
- examples/barcodes_checkins.rb
|
51
51
|
- examples/city_keys.rb
|
52
|
+
- examples/donation_export.rb
|
52
53
|
- examples/familes.rb
|
53
54
|
- examples/groups.rb
|
54
55
|
- examples/metrics.rb
|
@@ -66,6 +67,8 @@ files:
|
|
66
67
|
- lib/api/checkin.rb
|
67
68
|
- lib/api/checkin_list.rb
|
68
69
|
- lib/api/donation.rb
|
70
|
+
- lib/api/donation_export.rb
|
71
|
+
- lib/api/donation_export_list.rb
|
69
72
|
- lib/api/donation_list.rb
|
70
73
|
- lib/api/family.rb
|
71
74
|
- lib/api/family_member.rb
|
@@ -140,6 +143,8 @@ files:
|
|
140
143
|
- lib/readers/api_reader.rb
|
141
144
|
- lib/readers/checkin_list_reader.rb
|
142
145
|
- lib/readers/checkin_reader.rb
|
146
|
+
- lib/readers/donation_export_list_reader.rb
|
147
|
+
- lib/readers/donation_export_reader.rb
|
143
148
|
- lib/readers/donation_list_reader.rb
|
144
149
|
- lib/readers/donation_reader.rb
|
145
150
|
- lib/readers/family_reader.rb
|
@@ -187,7 +192,9 @@ files:
|
|
187
192
|
- lib/readers/web_hook_list_reader.rb
|
188
193
|
- lib/the_city_admin.rb
|
189
194
|
- lib/writers/api_writer.rb
|
195
|
+
- lib/writers/donation_export_writer.rb
|
190
196
|
- lib/writers/family_writer.rb
|
197
|
+
- lib/writers/fund_writer.rb
|
191
198
|
- lib/writers/group_address_writer.rb
|
192
199
|
- lib/writers/group_export_writer.rb
|
193
200
|
- lib/writers/group_writer.rb
|