the-city-admin 0.3.0 → 0.3.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/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/index.rb +91 -26
- data/lib/api/group.rb +29 -13
- data/lib/api/group_export.rb +20 -3
- data/lib/readers/group_export_reader.rb +25 -0
- data/lib/writers/api_writer.rb +10 -0
- data/lib/writers/group_export_writer.rb +25 -0
- data/thecity_admin_api.gemspec +2 -2
- metadata +8 -6
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/index.rb
CHANGED
@@ -5,45 +5,89 @@
|
|
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
|
+
# TCA_ENV = 'development'
|
9
|
+
# THE_CITY_ADMIN_PATH = 'http://api.devthecity.org:9292'
|
10
|
+
# key = 'Dev Key'
|
11
|
+
# token = 'dev token'
|
10
12
|
|
13
|
+
key = 'YOUR KEY'
|
14
|
+
token = 'YOUR TOKEN'
|
15
|
+
|
16
|
+
require 'open-uri'
|
17
|
+
require 'csv'
|
11
18
|
require 'ruby-debug'
|
12
19
|
require File.dirname(__FILE__) + '/lib/the_city_admin.rb'
|
13
20
|
|
14
|
-
|
15
|
-
|
21
|
+
TheCity::AdminApi.connect(key, token)
|
22
|
+
|
23
|
+
# group_export = TheCity::GroupExport.new
|
24
|
+
# group_export.group_id = 73608
|
25
|
+
# if group_export.save
|
26
|
+
# puts "Export created"
|
27
|
+
# else
|
28
|
+
# puts "Export failed: #{group_export.error_messages.join(', ')}"
|
29
|
+
# end
|
16
30
|
|
17
|
-
key = 'cf2903151e3213e66fd8080c7d8b65b1d6ccdd31'
|
18
|
-
token = '5c88b32edda7653c'
|
19
31
|
|
20
|
-
|
32
|
+
# done = false
|
33
|
+
# page = 1
|
34
|
+
# count = 0
|
35
|
+
|
36
|
+
# while !done
|
37
|
+
# export_list = TheCity::GroupExportList.new({:page => page, :group_id => 73608})
|
38
|
+
|
39
|
+
# export_list.each do |export|
|
40
|
+
# count += 1
|
41
|
+
# puts "#{count}) #{export.id} :: #{export.state}"
|
42
|
+
# end
|
43
|
+
|
44
|
+
# if export_list.total_pages <= page
|
45
|
+
# done = true
|
46
|
+
# else
|
47
|
+
# page += 1
|
48
|
+
# end
|
49
|
+
# end
|
50
|
+
|
51
|
+
# export_list = TheCity::GroupExportList.new({:page => page, :group_id => 73608})
|
52
|
+
# group_export = export_list[0]
|
53
|
+
# puts group_export.inspect
|
21
54
|
|
22
55
|
|
23
|
-
puts "-----------------------------"
|
24
|
-
puts "##### Web Hooks #######"
|
25
|
-
puts "-----------------------------"
|
26
56
|
|
27
|
-
|
28
|
-
|
29
|
-
|
57
|
+
group_export = TheCity::GroupExport.load_by_id(100996, {:group_id => 73608})
|
58
|
+
path = group_export.authenticated_s3_url
|
59
|
+
|
60
|
+
data = open(path).read()
|
61
|
+
|
62
|
+
CSV.parse(data, {:headers => true}).each do |row|
|
63
|
+
puts [row[2], row[4]].join(' ')
|
30
64
|
end
|
31
65
|
|
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
66
|
|
36
|
-
|
37
|
-
|
38
|
-
|
67
|
+
# puts "-----------------------------"
|
68
|
+
# puts "##### Web Hooks #######"
|
69
|
+
# puts "-----------------------------"
|
70
|
+
|
71
|
+
# web_hooks = TheCity::WebHookList.new({:page => 1})
|
72
|
+
# web_hooks.each do |hook|
|
73
|
+
# puts hook.inspect
|
74
|
+
# end
|
75
|
+
|
76
|
+
# web_hook1 = TheCity::WebHook.new({:callback_uri => 'https://www.somedomain.com/city/callbacks/fund/create',
|
77
|
+
# :object => TheCity::WebHook::Objects[:fund],
|
78
|
+
# :event => TheCity::WebHook::Events[:create]})
|
79
|
+
|
80
|
+
# web_hook2 = TheCity::WebHook.new({:callback_uri => 'https://www.somedomain.com/city/callbacks/pledge/create',
|
81
|
+
# :object => TheCity::WebHook::Objects[:pledge],
|
82
|
+
# :event => TheCity::WebHook::Events[:create]})
|
39
83
|
|
40
|
-
web_hook3 = TheCity::WebHook.new({:callback_uri => 'https://www.somedomain.com/city/callbacks/donation/create',
|
41
|
-
|
42
|
-
|
84
|
+
# web_hook3 = TheCity::WebHook.new({:callback_uri => 'https://www.somedomain.com/city/callbacks/donation/create',
|
85
|
+
# :object => TheCity::WebHook::Objects[:donation],
|
86
|
+
# :event => TheCity::WebHook::Events[:create]})
|
43
87
|
|
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'
|
88
|
+
# puts web_hook1.save ? 'Web Hook saved' : 'Web Hook failed'
|
89
|
+
# puts web_hook2.save ? 'Web Hook saved' : 'Web Hook failed'
|
90
|
+
# puts web_hook3.save ? 'Web Hook saved' : 'Web Hook failed'
|
47
91
|
|
48
92
|
# web_hooks = TheCity::WebHookList.new({:page => 1})
|
49
93
|
# web_hooks.each do |hook|
|
@@ -93,7 +137,7 @@ puts web_hook3.save ? 'Web Hook saved' : 'Web Hook failed'
|
|
93
137
|
|
94
138
|
# group_list.each do |group|
|
95
139
|
# count += 1
|
96
|
-
# puts "#{count}) #{group.name}"
|
140
|
+
# puts "#{count}) #{group.name} [#{group.group_type}]"
|
97
141
|
# end
|
98
142
|
|
99
143
|
# if group_list.total_pages <= page
|
@@ -123,6 +167,17 @@ puts web_hook3.save ? 'Web Hook saved' : 'Web Hook failed'
|
|
123
167
|
# end
|
124
168
|
# end
|
125
169
|
|
170
|
+
# tag_list = TheCity::TagList.new({:page => page})
|
171
|
+
# tag = tag_list[0]
|
172
|
+
|
173
|
+
# puts tag.name
|
174
|
+
# tag.name = "Wes Hays #{Random.rand(99999)}"
|
175
|
+
# if tag.save
|
176
|
+
# puts "TAG SAVED"
|
177
|
+
# else
|
178
|
+
# puts "TAG FAILED TO SAVE: #{tag.error_messages}"
|
179
|
+
# end
|
180
|
+
|
126
181
|
|
127
182
|
|
128
183
|
|
@@ -132,6 +187,16 @@ puts web_hook3.save ? 'Web Hook saved' : 'Web Hook failed'
|
|
132
187
|
# puts "-----------------------------"
|
133
188
|
|
134
189
|
|
190
|
+
# wes = TheCity::User.load_by_id(746076)
|
191
|
+
|
192
|
+
# wes.first = "Jim"
|
193
|
+
# if wes.save
|
194
|
+
# puts "Wes Saved"
|
195
|
+
# else
|
196
|
+
# puts "WES FAILED TO SAVE: #{wes.error_messages}"
|
197
|
+
# end
|
198
|
+
|
199
|
+
|
135
200
|
# user_list = TheCity::UserList.new
|
136
201
|
|
137
202
|
# user_list.each do |u|
|
data/lib/api/group.rb
CHANGED
@@ -1,20 +1,36 @@
|
|
1
1
|
module TheCity
|
2
2
|
|
3
3
|
class Group < ApiObject
|
4
|
-
tc_attr_accessor :
|
5
|
-
:
|
6
|
-
:
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
4
|
+
tc_attr_accessor :campus_name,
|
5
|
+
:last_engaged,
|
6
|
+
:default_invitation_custom_message,
|
7
|
+
:archive_scheduled,
|
8
|
+
:time_zone,
|
9
|
+
:campus_id,
|
10
|
+
:group_type,
|
11
|
+
:parent_id,
|
12
|
+
:target_size,
|
13
|
+
:nearest_neighborhood_name,
|
14
|
+
:admin_url,
|
15
|
+
:deletion_scheduled,
|
16
|
+
:plaza_url,
|
17
|
+
:updated_at,
|
18
|
+
:external_description,
|
19
|
+
:nickname,
|
16
20
|
:started_as_seed,
|
17
|
-
:
|
21
|
+
:unlisted,
|
22
|
+
:created_at,
|
23
|
+
:api_url,
|
24
|
+
:profile_pic,
|
25
|
+
:inactive,
|
26
|
+
:internal_url,
|
27
|
+
:secure,
|
28
|
+
:nearest_neighborhood_id,
|
29
|
+
:name,
|
30
|
+
:auto_approve_invites,
|
31
|
+
:id,
|
32
|
+
:external_id,
|
33
|
+
:user_ids
|
18
34
|
|
19
35
|
|
20
36
|
# Loads the group by the specified ID.
|
data/lib/api/group_export.rb
CHANGED
@@ -3,16 +3,33 @@ module TheCity
|
|
3
3
|
class GroupExport < ApiObject
|
4
4
|
|
5
5
|
tc_attr_accessor :id,
|
6
|
+
:group_id,
|
6
7
|
:state,
|
7
8
|
:authenticated_s3_url,
|
8
9
|
:created_at
|
9
10
|
|
10
11
|
|
12
|
+
# Loads the group export by the specified ID.
|
13
|
+
#
|
14
|
+
# @param group_export_id The ID of the group export to load.
|
15
|
+
# @param options A hash of options for requesting data from the server.
|
16
|
+
# :: group_id is required
|
17
|
+
#
|
18
|
+
# Returns a new {GroupExport} object.
|
19
|
+
def self.load_by_id(group_export_id, options = {})
|
20
|
+
group_reader = GroupExportReader.new(group_export_id, options)
|
21
|
+
self.new(group_reader.load_feed)
|
22
|
+
rescue
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
|
11
27
|
# Constructor.
|
12
28
|
#
|
13
|
-
# @param json_data JSON data of the group export.
|
14
|
-
def initialize(json_data)
|
15
|
-
|
29
|
+
# @param json_data (optional) JSON data of the group export.
|
30
|
+
def initialize(json_data = nil)
|
31
|
+
@writer_object = GroupExportWriter
|
32
|
+
initialize_from_json_object(json_data) unless json_data.nil?
|
16
33
|
end
|
17
34
|
|
18
35
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module TheCity
|
2
|
+
|
3
|
+
class GroupExportReader < ApiReader
|
4
|
+
|
5
|
+
# Constructor.
|
6
|
+
#
|
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
|
+
# :: group_id is required
|
10
|
+
# @param cacher (optional) The CacheAdapter cacher to be used to cache data.
|
11
|
+
def initialize(group_export_id, options = {}, cacher = nil)
|
12
|
+
group_id = options[:group_id]
|
13
|
+
#@class_key = "group_export_#{group_id}"
|
14
|
+
@url_data_path = "/groups/#{group_id}/exports/#{group_export_id}"
|
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
|
24
|
+
|
25
|
+
|
data/lib/writers/api_writer.rb
CHANGED
@@ -11,6 +11,11 @@ module TheCity
|
|
11
11
|
@url_data_params ||= {}
|
12
12
|
success = true
|
13
13
|
|
14
|
+
if @url_data_path.nil?
|
15
|
+
@error_messages = ["#{@url_action.to_s.upcase} not implemented for #{self.class.to_s}"]
|
16
|
+
return false
|
17
|
+
end
|
18
|
+
|
14
19
|
if @updatable_fields and !@updatable_fields.empty?
|
15
20
|
fields_to_remove = @url_data_params.keys - @updatable_fields
|
16
21
|
fields_to_remove.each { |ftr| @url_data_params.delete(ftr) }
|
@@ -36,6 +41,11 @@ module TheCity
|
|
36
41
|
def delete_object
|
37
42
|
success = true
|
38
43
|
|
44
|
+
if @url_data_delete_path.nil?
|
45
|
+
@error_messages = ["DELETE not implemented for #{self.class.to_s}"]
|
46
|
+
return false
|
47
|
+
end
|
48
|
+
|
39
49
|
begin
|
40
50
|
# @url_data_path should be the same as :put if this object is already
|
41
51
|
# setup and mapped to an object that exists
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module TheCity
|
2
|
+
|
3
|
+
class GroupExportWriter < 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 = "/groups/#{data[:group_id]}/exports"
|
15
|
+
end
|
16
|
+
@url_data_delete_path = nil # not implemented
|
17
|
+
|
18
|
+
@url_data_params = data
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
|
data/thecity_admin_api.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
PROJECT_GEM = 'the-city-admin'
|
3
|
-
PROJECT_GEM_VERSION = '0.3.
|
3
|
+
PROJECT_GEM_VERSION = '0.3.1'
|
4
4
|
|
5
5
|
s.name = PROJECT_GEM
|
6
6
|
s.version = PROJECT_GEM_VERSION
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.summary = 'Ruby gem/plugin to interact with The City Admin API (https://api.OnTheCity.org).'
|
16
16
|
s.description = 'Ruby gem/plugin to interact with The City Admin API (https://api.OnTheCity.org). Checkout the project on github for more detail.'
|
17
17
|
|
18
|
-
s.add_dependency('typhoeus')
|
18
|
+
s.add_dependency('typhoeus', '0.4.2')
|
19
19
|
|
20
20
|
|
21
21
|
s.files = `git ls-files`.split("\n")
|
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: typhoeus
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - '='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
21
|
+
version: 0.4.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - '='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 0.4.2
|
30
30
|
description: Ruby gem/plugin to interact with The City Admin API (https://api.OnTheCity.org).
|
31
31
|
Checkout the project on github for more detail.
|
32
32
|
email: wes@onthecity.org
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- lib/readers/group_checkin_list_reader.rb
|
151
151
|
- lib/readers/group_event_attendance_list_reader.rb
|
152
152
|
- lib/readers/group_export_list_reader.rb
|
153
|
+
- lib/readers/group_export_reader.rb
|
153
154
|
- lib/readers/group_invitation_list_reader.rb
|
154
155
|
- lib/readers/group_list_reader.rb
|
155
156
|
- lib/readers/group_reader.rb
|
@@ -188,6 +189,7 @@ files:
|
|
188
189
|
- lib/writers/api_writer.rb
|
189
190
|
- lib/writers/family_writer.rb
|
190
191
|
- lib/writers/group_address_writer.rb
|
192
|
+
- lib/writers/group_export_writer.rb
|
191
193
|
- lib/writers/group_writer.rb
|
192
194
|
- lib/writers/metric_measurement_writer.rb
|
193
195
|
- lib/writers/metric_writer.rb
|