action_kit_api 0.3.12 → 0.4.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.
@@ -18,29 +18,39 @@ module ActionKitApi
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def save
|
21
|
-
if self.respond_to?('before_save')
|
22
|
-
self.send('before_save')
|
23
|
-
end
|
24
21
|
|
25
22
|
class_name = self.class.to_s.split("::").last
|
26
23
|
|
27
24
|
raise MissingRequiredAttributeException unless self.valid?
|
28
25
|
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
if self.id.nil?
|
27
|
+
if self.respond_to?('before_create')
|
28
|
+
self.send('before_create')
|
29
|
+
end
|
30
|
+
|
31
|
+
call = "#{class_name}.create"
|
32
|
+
response = ActionKitApi.connection.call(call, self.safe_hash)
|
33
|
+
|
34
|
+
if self.respond_to?('after_create')
|
35
|
+
self.send('after_create')
|
36
|
+
end
|
37
|
+
else
|
38
|
+
if self.respond_to?('before_save')
|
39
|
+
self.send('before_save')
|
40
|
+
end
|
41
|
+
|
42
|
+
call = "#{class_name}.save_or_create"
|
43
|
+
response = ActionKitApi.connection.call(call, self.safe_hash)
|
44
|
+
|
45
|
+
if self.respond_to?('after_save')
|
46
|
+
self.send('after_save')
|
47
|
+
end
|
32
48
|
end
|
33
49
|
|
34
|
-
call = "#{class_name}.save_or_create"
|
35
|
-
|
36
|
-
response = ActionKitApi.connection.call(call, attrs_hash)
|
37
50
|
|
38
51
|
# Update ourselves to include the data that the server populated
|
39
52
|
self.update(response)
|
40
53
|
|
41
|
-
if self.respond_to?('after_save')
|
42
|
-
self.send('after_save')
|
43
|
-
end
|
44
54
|
|
45
55
|
self
|
46
56
|
end
|
@@ -50,10 +60,6 @@ module ActionKitApi
|
|
50
60
|
# keys in the hash that is passed, and will not update/add non-existant
|
51
61
|
# attributes
|
52
62
|
def update(hash = {})
|
53
|
-
if self.respond_to?('before_update')
|
54
|
-
self.send('before_update')
|
55
|
-
end
|
56
|
-
|
57
63
|
hash.each do |k,v|
|
58
64
|
# The name of the setter for the value of k
|
59
65
|
setter = "#{k}="
|
@@ -65,10 +71,6 @@ module ActionKitApi
|
|
65
71
|
end
|
66
72
|
end
|
67
73
|
|
68
|
-
if self.respond_to?('after_update')
|
69
|
-
self.send('after_update')
|
70
|
-
end
|
71
|
-
|
72
74
|
self
|
73
75
|
end
|
74
76
|
|
@@ -98,6 +100,15 @@ module ActionKitApi
|
|
98
100
|
|
99
101
|
user_hash
|
100
102
|
end
|
103
|
+
|
104
|
+
def safe_hash
|
105
|
+
attrs_hash = self.to_hash
|
106
|
+
attrs_hash.delete_if do |k, v|
|
107
|
+
@read_only_attrs.include?(k)
|
108
|
+
end
|
109
|
+
|
110
|
+
attrs_hash
|
111
|
+
end
|
101
112
|
end
|
102
113
|
end
|
103
114
|
|
data/lib/action_kit_api/event.rb
CHANGED
@@ -18,7 +18,7 @@ module ActionKitApi
|
|
18
18
|
|
19
19
|
def initialize(*args)
|
20
20
|
@required_attrs = [:campaign_id, :creator_id]
|
21
|
-
@read_only_attrs = [:attendee_count]
|
21
|
+
@read_only_attrs = [:attendee_count, :host_is_confirmed, :is_full, :is_in_past, :is_open_for_signup, :status_summary]
|
22
22
|
|
23
23
|
super
|
24
24
|
end
|
@@ -26,49 +26,13 @@ module ActionKitApi
|
|
26
26
|
@show_address1 ||= true
|
27
27
|
end
|
28
28
|
|
29
|
-
#
|
30
|
-
# associated signup and hosting pages. These will follow the
|
31
|
-
# ActionKit convention to prevent them from getting wise. This
|
32
|
-
# is so we don't have to use that sketchy part of their API
|
33
|
-
def after_save
|
34
|
-
# Only continue if we have a valid id
|
35
|
-
if self.id.nil?
|
36
|
-
return
|
37
|
-
end
|
38
|
-
|
39
|
-
signup_page_name = "#{self.name}_signup"
|
40
|
-
create_page_name = "#{self.name}_create"
|
41
|
-
|
42
|
-
# These two calls trigger an exception EVEN IF THEY SUCCEED, since there
|
43
|
-
# won't be any events for them yet :-/
|
44
|
-
begin
|
45
|
-
if ActionKitApi::Page.find_by_name(signup_page_name).nil?
|
46
|
-
signup_page = ActionKitApi::EventSignupPage.new(:name => signup_page_name, :title => "{self.title} - Attend", :campaign_id => self.id)
|
47
|
-
signup_page.save
|
48
|
-
end
|
49
|
-
rescue
|
50
|
-
end
|
51
|
-
|
52
|
-
begin
|
53
|
-
if ActionKitApi::Page.find_by_name(create_page_name).nil?
|
54
|
-
create_page = ActionKitApi::EventCreatePage.new(:name => create_page_name, :title => "{self.title} - Host", :campaign_id => self.id)
|
55
|
-
create_page.save
|
56
|
-
end
|
57
|
-
rescue
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
29
|
+
# Requires at a minimum the creator_id
|
61
30
|
def create_event(*args)
|
62
31
|
raise "EventCampaign needs to be saved before Event creation" if self.id.nil?
|
63
32
|
|
64
|
-
(args[0]).merge(:campaign_id => self.id)
|
33
|
+
(args[0]).merge!(:campaign_id => self.id)
|
65
34
|
|
66
35
|
event = ActionKitApi::Event.new(*args)
|
67
|
-
event.save
|
68
|
-
|
69
|
-
result = ActionKitApi.connection.call("EventCreate.create", {:event_id => event.id})
|
70
|
-
|
71
|
-
event
|
72
36
|
end
|
73
37
|
|
74
38
|
# Uses public_search so is subject those limitations
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 4
|
8
|
+
- 0
|
9
|
+
version: 0.4.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sam Stelfox
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-03-
|
17
|
+
date: 2012-03-15 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|