action_kit_api 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,6 +17,10 @@ module ActionKitApi
17
17
  end
18
18
 
19
19
  def save
20
+ if self.respond_to?('before_save')
21
+ self.send('before_save')
22
+ end
23
+
20
24
  class_name = self.class.to_s.split("::").last
21
25
 
22
26
  raise MissingRequiredAttributeException unless self.valid?
@@ -28,13 +32,16 @@ module ActionKitApi
28
32
 
29
33
  call = "#{class_name}.save_or_create"
30
34
 
31
- puts call
32
- puts attrs_hash
33
-
34
35
  response = ActionKitApi.connection.call(call, attrs_hash)
35
36
 
36
37
  # Update ourselves to include the data that the server populated
37
38
  self.update(response)
39
+
40
+ if self.respond_to?('after_save')
41
+ self.send('after_save')
42
+ end
43
+
44
+ self
38
45
  end
39
46
 
40
47
  # Updates all the instance variables in our local object with
@@ -42,6 +49,10 @@ module ActionKitApi
42
49
  # keys in the hash that is passed, and will not update/add non-existant
43
50
  # attributes
44
51
  def update(hash = {})
52
+ if self.respond_to?('before_update')
53
+ self.send('before_update')
54
+ end
55
+
45
56
  hash.each do |k,v|
46
57
  # The name of the setter for the value of k
47
58
  setter = "#{k}="
@@ -52,6 +63,12 @@ module ActionKitApi
52
63
  self.send(setter, v)
53
64
  end
54
65
  end
66
+
67
+ if self.respond_to?('after_update')
68
+ self.send('after_update')
69
+ end
70
+
71
+ self
55
72
  end
56
73
 
57
74
  def valid?
@@ -29,9 +29,10 @@ module ActionKitApi
29
29
  def create_event(*args)
30
30
  raise "EventCampaign needs to be saved before Event creation" if self.id.nil?
31
31
 
32
- args[0][:campaign] = self.id
32
+ args[:campaign] = self.id
33
+ args[:title] ||= self.default_title
33
34
 
34
- Event.new(args)
35
+ ActionKitApi::Event.new(args)
35
36
  end
36
37
 
37
38
  # Uses public_search so is subject those limitations
@@ -1,3 +1,3 @@
1
1
  module ActionKitApi
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 6
9
- version: 0.3.6
8
+ - 7
9
+ version: 0.3.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Sam Stelfox