catapult-rails 0.0.1 → 0.0.2
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/README.md +40 -3
- data/lib/catapult.rb +1 -0
- data/lib/catapult/campaign.rb +17 -0
- data/lib/catapult/catapult_methods.rb +1 -1
- data/lib/catapult/subscription.rb +21 -4
- data/lib/catapult/version.rb +1 -1
- metadata +9 -2
data/README.md
CHANGED
@@ -16,23 +16,60 @@ Finally, add this to one of your initliazation files
|
|
16
16
|
Catapult.username = "c@apult.com"
|
17
17
|
Catapult.password = "MyShinyPassword"
|
18
18
|
|
19
|
-
##
|
19
|
+
## Methods
|
20
20
|
|
21
21
|
The gem should explicitly follow [the api](http://client.vibes.com/toolkit/api/update-subscriber.shtml).
|
22
22
|
|
23
|
-
For example under the subscription section we have a
|
23
|
+
For example under the subscription section we have a create_subscription method. To call this method use:
|
24
24
|
|
25
25
|
Catapult::Subscription.create_subscription(campaign_id, phone)
|
26
26
|
|
27
27
|
|
28
28
|
Finished:
|
29
29
|
|
30
|
+
* Campaign.list_campaigns(account_list=nil, status_filter=nil, type_filter=nil)
|
30
31
|
* Subscription.list_subscribers(campaign)
|
31
32
|
* Subscription.create_subscription(campaign, phone)
|
32
|
-
* Subscription.
|
33
|
+
* Subscription.read_subscription(campaign, phone)
|
34
|
+
* Subscription.delete_subscriber(campaign, phone, suppress_message=false)
|
33
35
|
* Subscription.update_subscriber(campaign, phone, opts = {})
|
34
36
|
|
37
|
+
opts in the update_subscriber call mirrors the api as well: {"first-name" => "Lisbeth"}
|
38
|
+
|
39
|
+
|
40
|
+
## Usage
|
41
|
+
One way to find a users subscriptions:
|
42
|
+
|
43
|
+
@campaigns = Hash.new
|
44
|
+
|
45
|
+
MyTextAlerts.all.each do |ta|
|
46
|
+
sub = Catapult::Subscription.read_subscription(ta.campaign_id, phone_number)
|
47
|
+
@campaigns[ta.campaign_id] = (sub['subscription'].blank? ? false : true)
|
48
|
+
end
|
49
|
+
|
50
|
+
puts @campaigns
|
51
|
+
=>
|
52
|
+
{
|
53
|
+
12345 => false,
|
54
|
+
23456 => true
|
55
|
+
}
|
56
|
+
|
57
|
+
Create a subscription:
|
58
|
+
|
59
|
+
Catapult::Subscription.create_subscription(campaign_id, phone_number)
|
60
|
+
=> true
|
61
|
+
|
62
|
+
Update a subscription:
|
63
|
+
|
64
|
+
As far as I can tell this does not create a subscription even though the docs imply that it does
|
65
|
+
|
66
|
+
Catapult::Subscription.update_subscriber(campaign_id, phone_number, options)
|
67
|
+
=> true
|
68
|
+
|
69
|
+
Delete a subscription:
|
35
70
|
|
71
|
+
Catapult::Subscription.delete_subscriber(campaign_id, phone_number)
|
72
|
+
=> true
|
36
73
|
|
37
74
|
## Contributing
|
38
75
|
|
data/lib/catapult.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
module Catapult
|
2
|
+
class Campaign
|
3
|
+
extend CatapultMethods
|
4
|
+
|
5
|
+
def self.list_campaigns(account_list=nil, status_filter=nil, type_filter=nil)
|
6
|
+
req_str = "/api/campaigns.xml?"
|
7
|
+
arr = {}
|
8
|
+
arr[:accounts] = account_list if account_list
|
9
|
+
arr[:status] = status_filter if status_filter
|
10
|
+
arr[:type] = type_filter if type_filter
|
11
|
+
http, request = build_request(req_str + arr.to_query)
|
12
|
+
response = http.request(request)
|
13
|
+
Hash.from_xml(response.body)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -8,6 +8,10 @@ module Catapult
|
|
8
8
|
Hash.from_xml(response.body)
|
9
9
|
end
|
10
10
|
|
11
|
+
# returns:
|
12
|
+
# true on success
|
13
|
+
# hash on false
|
14
|
+
#
|
11
15
|
def self.create_subscription(campaign, phone)
|
12
16
|
http, request = build_request("/api/subscription_campaigns/#{campaign}/subscriptions.xml", "POST")
|
13
17
|
xml = Nokogiri::XML::Builder.new do |x|
|
@@ -22,7 +26,20 @@ module Catapult
|
|
22
26
|
handle_response(response)
|
23
27
|
end
|
24
28
|
|
29
|
+
# returns:
|
30
|
+
# true on success
|
31
|
+
# hash on false
|
32
|
+
#
|
33
|
+
def self.read_subscription(campaign, phone)
|
34
|
+
http, request = build_request("/api/subscription_campaigns/#{campaign}/subscriptions/#{phone}.xml", "GET")
|
35
|
+
response = http.request(request)
|
36
|
+
handle_response(response)
|
37
|
+
end
|
25
38
|
|
39
|
+
# returns:
|
40
|
+
# true on success
|
41
|
+
# hash on false
|
42
|
+
#
|
26
43
|
def self.delete_subscriber(campaign, phone, suppress_message = false)
|
27
44
|
http, request = build_request("/api/subscription_campaigns/#{campaign}/subscriptions/#{phone}.xml?suppress_message=#{suppress_message}", "DELETE")
|
28
45
|
response = http.request(request)
|
@@ -30,10 +47,10 @@ module Catapult
|
|
30
47
|
end
|
31
48
|
|
32
49
|
# options = {
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
50
|
+
# 'birthday-on' => '02/18/1978',
|
51
|
+
# 'email' => 'fake@fake.co',
|
52
|
+
# 'gender' => "M"
|
53
|
+
# }
|
37
54
|
def self.update_subscriber(campaign, phone, options = {})
|
38
55
|
http, request = build_request("/api/subscription_campaigns/#{campaign}/subscriptions/#{phone}.xml", "PUT")
|
39
56
|
xml = Nokogiri::XML::Builder.new do |x|
|
data/lib/catapult/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: catapult-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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: 2013-08-
|
12
|
+
date: 2013-08-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- catapult-rails.gemspec
|
60
60
|
- lib/catapult.rb
|
61
61
|
- lib/catapult/.DS_Store
|
62
|
+
- lib/catapult/campaign.rb
|
62
63
|
- lib/catapult/catapult_methods.rb
|
63
64
|
- lib/catapult/subscription.rb
|
64
65
|
- lib/catapult/version.rb
|
@@ -75,12 +76,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
76
|
- - ! '>='
|
76
77
|
- !ruby/object:Gem::Version
|
77
78
|
version: '0'
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
hash: -2871894567716705260
|
78
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
83
|
none: false
|
80
84
|
requirements:
|
81
85
|
- - ! '>='
|
82
86
|
- !ruby/object:Gem::Version
|
83
87
|
version: '0'
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
hash: -2871894567716705260
|
84
91
|
requirements: []
|
85
92
|
rubyforge_project:
|
86
93
|
rubygems_version: 1.8.23
|