the-city-admin 0.2.0 → 0.2.1
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/index.rb +53 -11
- data/lib/api/group.rb +5 -3
- data/lib/api/invitation.rb +31 -0
- data/lib/api/invitation_list.rb +62 -0
- data/lib/api/web_hook.rb +6 -6
- data/lib/readers/api_reader.rb +1 -1
- data/lib/readers/group_list_reader.rb +1 -2
- data/lib/readers/group_reader.rb +5 -3
- data/lib/readers/invitation_list_reader.rb +22 -0
- data/thecity_admin_api.gemspec +1 -1
- metadata +5 -2
data/index.rb
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
# @authors Robbie Lieb <robbie@onthecity.org>, Wes Hays <wes@onthecity.org>
|
|
6
6
|
# *******************************************
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
TCA_ENV = 'development'
|
|
9
|
+
THE_CITY_ADMIN_PATH = 'http://api.devthecity.org:9292'
|
|
10
10
|
|
|
11
11
|
require 'ruby-debug'
|
|
12
12
|
require File.dirname(__FILE__) + '/lib/the_city_admin.rb'
|
|
@@ -14,16 +14,58 @@ require File.dirname(__FILE__) + '/lib/the_city_admin.rb'
|
|
|
14
14
|
# key = '66c59e2ee24553e7237259e30b4c17365681b95c'
|
|
15
15
|
# token = 'a9ae4af3c3e80102'
|
|
16
16
|
|
|
17
|
-
key = '
|
|
18
|
-
token = '
|
|
17
|
+
key = 'cf2903151e3213e66fd8080c7d8b65b1d6ccdd31'
|
|
18
|
+
token = '5c88b32edda7653c'
|
|
19
19
|
|
|
20
20
|
TheCity::AdminApi.connect(key, token)
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
puts "-----------------------------"
|
|
24
|
-
puts "#####
|
|
24
|
+
puts "##### Web Hooks #######"
|
|
25
25
|
puts "-----------------------------"
|
|
26
26
|
|
|
27
|
+
web_hooks = TheCity::WebHookList.new({:page => 1})
|
|
28
|
+
web_hooks.each do |hook|
|
|
29
|
+
puts hook.inspect
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
web_hook1 = TheCity::WebHook.new({:callback_uri => 'https://www.somedomain.com/city/callbacks/fund/create',
|
|
33
|
+
:object => TheCity::WebHook::Objects[:fund],
|
|
34
|
+
:event => TheCity::WebHook::Events[:create]})
|
|
35
|
+
|
|
36
|
+
web_hook2 = TheCity::WebHook.new({:callback_uri => 'https://www.somedomain.com/city/callbacks/pledge/create',
|
|
37
|
+
:object => TheCity::WebHook::Objects[:pledge],
|
|
38
|
+
:event => TheCity::WebHook::Events[:create]})
|
|
39
|
+
|
|
40
|
+
web_hook3 = TheCity::WebHook.new({:callback_uri => 'https://www.somedomain.com/city/callbacks/donation/create',
|
|
41
|
+
:object => TheCity::WebHook::Objects[:donation],
|
|
42
|
+
:event => TheCity::WebHook::Events[:create]})
|
|
43
|
+
|
|
44
|
+
puts web_hook1.save ? 'Web Hook saved' : 'Web Hook failed'
|
|
45
|
+
puts web_hook2.save ? 'Web Hook saved' : 'Web Hook failed'
|
|
46
|
+
puts web_hook3.save ? 'Web Hook saved' : 'Web Hook failed'
|
|
47
|
+
|
|
48
|
+
# web_hooks = TheCity::WebHookList.new({:page => 1})
|
|
49
|
+
# web_hooks.each do |hook|
|
|
50
|
+
# puts hook.inspect
|
|
51
|
+
# puts hook.delete
|
|
52
|
+
# end
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# puts "-----------------------------"
|
|
56
|
+
# puts "##### Invitations #######"
|
|
57
|
+
# puts "-----------------------------"
|
|
58
|
+
|
|
59
|
+
# invitation_list = TheCity::InvitationList.new({:page => 1})
|
|
60
|
+
|
|
61
|
+
# invitation_list.each do |invitation|
|
|
62
|
+
# puts invitation.inspect
|
|
63
|
+
# end
|
|
64
|
+
|
|
65
|
+
# puts "-----------------------------"
|
|
66
|
+
# puts "##### FUNDS / DONATIONS / PLEDGES #######"
|
|
67
|
+
# puts "-----------------------------"
|
|
68
|
+
|
|
27
69
|
|
|
28
70
|
# donation_list = TheCity::DonationList.new({:page => 1, :include_details => 1, :start_date => '2012-09-01', :end_date => '2012-09-30'})
|
|
29
71
|
|
|
@@ -32,15 +74,15 @@ puts "-----------------------------"
|
|
|
32
74
|
# end
|
|
33
75
|
|
|
34
76
|
|
|
35
|
-
fund_list = TheCity::FundList.new({:page => 1})
|
|
77
|
+
# fund_list = TheCity::FundList.new({:page => 1})
|
|
36
78
|
|
|
37
|
-
fund_list.each do |fund|
|
|
38
|
-
|
|
39
|
-
end
|
|
79
|
+
# fund_list.each do |fund|
|
|
80
|
+
# puts [fund.id, fund.name].join(' :: ')
|
|
81
|
+
# end
|
|
40
82
|
|
|
41
|
-
sfund = TheCity::Fund.load_fund_by_id(fund_list.first.id)
|
|
83
|
+
# sfund = TheCity::Fund.load_fund_by_id(fund_list.first.id)
|
|
42
84
|
|
|
43
|
-
puts [sfund.id, sfund.name].join(' :-: ')
|
|
85
|
+
# puts [sfund.id, sfund.name].join(' :-: ')
|
|
44
86
|
|
|
45
87
|
# done = false
|
|
46
88
|
# page = 1
|
data/lib/api/group.rb
CHANGED
|
@@ -13,16 +13,18 @@ module TheCity
|
|
|
13
13
|
:parent_id,
|
|
14
14
|
:plaza_url,
|
|
15
15
|
:smart_large_profile_pic,
|
|
16
|
-
:started_as_seed
|
|
16
|
+
:started_as_seed,
|
|
17
|
+
:user_ids
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
# Loads the group by the specified ID.
|
|
20
21
|
#
|
|
21
22
|
# @param group_id The ID of the group to load.
|
|
23
|
+
# @param options A hash of options for requesting data from the server.
|
|
22
24
|
#
|
|
23
25
|
# Returns a new {Group} object.
|
|
24
|
-
def self.load_group_by_id(group_id)
|
|
25
|
-
group_reader = GroupReader.new(group_id)
|
|
26
|
+
def self.load_group_by_id(group_id, options = {})
|
|
27
|
+
group_reader = GroupReader.new(group_id, options)
|
|
26
28
|
self.new(group_reader)
|
|
27
29
|
end
|
|
28
30
|
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module TheCity
|
|
2
|
+
|
|
3
|
+
class Invitation < ApiObject
|
|
4
|
+
|
|
5
|
+
tc_attr_accessor :created_at,
|
|
6
|
+
:pending_approval,
|
|
7
|
+
:id,
|
|
8
|
+
:group_id,
|
|
9
|
+
:user_id,
|
|
10
|
+
:custom_message,
|
|
11
|
+
:source,
|
|
12
|
+
:email,
|
|
13
|
+
:title,
|
|
14
|
+
:name,
|
|
15
|
+
:external_id_1,
|
|
16
|
+
:external_id_2,
|
|
17
|
+
:external_id_3,
|
|
18
|
+
:member_since
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# Constructor.
|
|
22
|
+
#
|
|
23
|
+
# @param json_data JSON data of the invitation.
|
|
24
|
+
def initialize(json_data)
|
|
25
|
+
initialize_from_json_object(json_data)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module TheCity
|
|
2
|
+
|
|
3
|
+
class InvitationList
|
|
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
|
+
# :group_id - The ID of the group to load the roles for. (required)
|
|
15
|
+
# :page - The page number to get.
|
|
16
|
+
# :reader - The Reader to use to load the data.
|
|
17
|
+
#
|
|
18
|
+
#
|
|
19
|
+
# Examples:
|
|
20
|
+
# InvitationList.new({:group_id => 12345})
|
|
21
|
+
#
|
|
22
|
+
# InvitationList.new({:group_id => 12345, :page => 2})
|
|
23
|
+
#
|
|
24
|
+
def initialize(options = {})
|
|
25
|
+
reader = options[:reader] || TheCity::InvitationListReader.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 group invitation.
|
|
36
|
+
#
|
|
37
|
+
# @param index The index of the group invitation to get.
|
|
38
|
+
#
|
|
39
|
+
# @return [Invitation]
|
|
40
|
+
def [](index)
|
|
41
|
+
Invitation.new( @json_data['invitations'][index] ) if @json_data['invitations'][index]
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# This method is needed for Enumerable.
|
|
46
|
+
def each &block
|
|
47
|
+
@json_data['invitations'].each{ |invitation| yield( Invitation.new(invitation) )}
|
|
48
|
+
end
|
|
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['invitations'].empty?
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
end
|
data/lib/api/web_hook.rb
CHANGED
|
@@ -2,17 +2,17 @@ module TheCity
|
|
|
2
2
|
|
|
3
3
|
class WebHook < ApiObject
|
|
4
4
|
|
|
5
|
-
Objects = {:user => 'User', :group => 'Group', :invitation => 'Invitation',
|
|
6
|
-
:privilege => 'Privilege', :checkin => 'Checkin', :address => 'Address'}
|
|
7
|
-
|
|
8
|
-
Events = {:create => 'create', :update => 'update', :destroy => 'destroy', :expire => 'expire'}
|
|
9
|
-
|
|
10
|
-
|
|
11
5
|
tc_attr_accessor :id,
|
|
12
6
|
:callback_uri,
|
|
13
7
|
:event,
|
|
14
8
|
:object
|
|
15
9
|
|
|
10
|
+
Objects = {:user => 'user', :group => 'group', :invitation => 'invitation',
|
|
11
|
+
:privilege => 'privilege', :checkin => 'checkin', :address => 'address',
|
|
12
|
+
:group_tag => 'group_tag', :fund => 'fund', :pledge => 'pledge', :donation => 'donation'}
|
|
13
|
+
|
|
14
|
+
Events = {:create => 'create', :update => 'update', :destroy => 'destroy', :expire => 'expire'}
|
|
15
|
+
|
|
16
16
|
# Constructor.
|
|
17
17
|
#
|
|
18
18
|
# @param json_data (optional) JSON data of the web hook.
|
data/lib/readers/api_reader.rb
CHANGED
|
@@ -16,7 +16,7 @@ module TheCity
|
|
|
16
16
|
# else
|
|
17
17
|
@url_data_params ||= {}
|
|
18
18
|
response = TheCity::admin_request(:get, @url_data_path, @url_data_params)
|
|
19
|
-
data = JSON.parse(response.body)
|
|
19
|
+
data = JSON.parse(response.body)
|
|
20
20
|
@cacher.save_data(@class_key, data) unless @cacher.nil?
|
|
21
21
|
#end
|
|
22
22
|
|
|
@@ -4,8 +4,7 @@ module TheCity
|
|
|
4
4
|
|
|
5
5
|
# Constructor.
|
|
6
6
|
#
|
|
7
|
-
# @param
|
|
8
|
-
# @param options A hash of options for requesting data from the server.
|
|
7
|
+
# @param options A hash of options for requesting data from the server. Adds default of page 1 if page not set.
|
|
9
8
|
# @param [CacheAdapter] cacher (optional) The cacher to be used to cache data.
|
|
10
9
|
def initialize(options = {}, cacher = nil)
|
|
11
10
|
options[:page] ||= 1
|
data/lib/readers/group_reader.rb
CHANGED
|
@@ -4,11 +4,13 @@ module TheCity
|
|
|
4
4
|
|
|
5
5
|
# Constructor.
|
|
6
6
|
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
|
|
7
|
+
# @param group_id The ID of the group 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(group_id, options = {}, cacher = nil)
|
|
10
11
|
#@class_key = "groups_#{group_id}"
|
|
11
12
|
@url_data_path = "/groups/#{group_id}"
|
|
13
|
+
@url_data_params = options
|
|
12
14
|
|
|
13
15
|
# The object to store and load the cache.
|
|
14
16
|
@cacher = cacher unless cacher.nil?
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module TheCity
|
|
2
|
+
|
|
3
|
+
class InvitationListReader < ApiReader
|
|
4
|
+
|
|
5
|
+
# Constructor.
|
|
6
|
+
#
|
|
7
|
+
# @param options A hash of options for requesting data from the server.
|
|
8
|
+
# :: group_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
|
+
#@class_key = "invitations_#{page}"
|
|
13
|
+
@url_data_path = "/invitations"
|
|
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
|
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.2.
|
|
4
|
+
version: 0.2.1
|
|
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-
|
|
12
|
+
date: 2012-10-24 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: typhoeus
|
|
@@ -88,6 +88,8 @@ files:
|
|
|
88
88
|
- lib/api/group_role_list.rb
|
|
89
89
|
- lib/api/group_tag.rb
|
|
90
90
|
- lib/api/group_tag_list.rb
|
|
91
|
+
- lib/api/invitation.rb
|
|
92
|
+
- lib/api/invitation_list.rb
|
|
91
93
|
- lib/api/metric.rb
|
|
92
94
|
- lib/api/metric_list.rb
|
|
93
95
|
- lib/api/metric_measurement.rb
|
|
@@ -153,6 +155,7 @@ files:
|
|
|
153
155
|
- lib/readers/group_reader.rb
|
|
154
156
|
- lib/readers/group_role_list_reader.rb
|
|
155
157
|
- lib/readers/group_tag_list_reader.rb
|
|
158
|
+
- lib/readers/invitation_list_reader.rb
|
|
156
159
|
- lib/readers/metric_list_reader.rb
|
|
157
160
|
- lib/readers/metric_measurement_list_reader.rb
|
|
158
161
|
- lib/readers/metric_measurement_reader.rb
|