catapult-rails 0.0.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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in catapult-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 caleb bron
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Caleb Bron
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # catapult-rails
2
+
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'catapult-rails', :require => "catapult"
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Finally, add this to one of your initliazation files
15
+
16
+ Catapult.username = "c@apult.com"
17
+ Catapult.password = "MyShinyPassword"
18
+
19
+ ## Usage
20
+
21
+ The gem should explicitly follow [the api](http://client.vibes.com/toolkit/api/update-subscriber.shtml).
22
+
23
+ For example under the subscription section we have a create subscription method.To call this method use:
24
+
25
+ Catapult::Subscription.create_subscription(campaign_id, phone)
26
+
27
+
28
+ Finished:
29
+
30
+ * Subscription.list_subscribers(campaign)
31
+ * Subscription.create_subscription(campaign, phone)
32
+ * Subscription.delete_subscriber(campaign, phone, suppress_message)
33
+ * Subscription.update_subscriber(campaign, phone, opts = {})
34
+
35
+
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'catapult/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "catapult-rails"
8
+ spec.version = Catapult::VERSION
9
+ spec.authors = ["cbron"]
10
+ spec.email = ["x@x.com"]
11
+ spec.description = %q{Ruby wrapper for the Vibes Catapult api}
12
+ spec.summary = %q{Wraps the catapult api, which is used for marketing, such as text message subscriptions.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ # spec.add_development_dependency "nokogiri"
24
+ end
@@ -0,0 +1,11 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require 'catapult/catapult_methods'
4
+ require 'catapult/subscription'
5
+ require 'catapult/version'
6
+
7
+
8
+ module Catapult
9
+ mattr_accessor :username, :password
10
+ BaseUrl = "http://www.vibescm.com"
11
+ end
Binary file
@@ -0,0 +1,32 @@
1
+ module Catapult
2
+ module CatapultMethods
3
+
4
+ def build_request(url, method = "GET")
5
+ uri = URI.parse(BaseUrl+ url)
6
+ http = Net::HTTP.new(uri.host, uri.port)
7
+ c_type = {'Content-Type' =>'application/xml'}
8
+
9
+ request = case method
10
+ when "GET"
11
+ Net::HTTP::Get.new(uri.request_uri, c_type)
12
+ when "POST"
13
+ Net::HTTP::Post.new(uri.request_uri, c_type)
14
+ when "DELETE"
15
+ Net::HTTP::Delete.new(uri.request_uri, c_type)
16
+ when "PUT"
17
+ Net::HTTP::Put.new(uri.request_uri, c_type)
18
+ end
19
+ request.basic_auth(Catapult.username, Catapult.password)
20
+ return http, request
21
+ end
22
+
23
+ def handle_response(response)
24
+ if response.code.to_i == 200
25
+ return true
26
+ else
27
+ return Hash.from_xml(response.body)
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,59 @@
1
+ module Catapult
2
+ class Subscription
3
+ extend CatapultMethods
4
+
5
+ def self.list_subscribers(campaign)
6
+ http, request = build_request("/api/subscription_campaigns/#{campaign}/subscriptions.xml")
7
+ response = http.request(request)
8
+ Hash.from_xml(response.body)
9
+ end
10
+
11
+ def self.create_subscription(campaign, phone)
12
+ http, request = build_request("/api/subscription_campaigns/#{campaign}/subscriptions.xml", "POST")
13
+ xml = Nokogiri::XML::Builder.new do |x|
14
+ x.subscription{
15
+ x.user{
16
+ x.send(:'mobile-phone', phone)
17
+ }
18
+ }
19
+ end
20
+ request.body = xml.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION).strip
21
+ response = http.request(request)
22
+ handle_response(response)
23
+ end
24
+
25
+
26
+ def self.delete_subscriber(campaign, phone, suppress_message = false)
27
+ http, request = build_request("/api/subscription_campaigns/#{campaign}/subscriptions/#{phone}.xml?suppress_message=#{suppress_message}", "DELETE")
28
+ response = http.request(request)
29
+ handle_response(response)
30
+ end
31
+
32
+ # options = {
33
+ # 'birthday-on' => '02/18/1978',
34
+ # 'email' => 'fake@fake.co',
35
+ # 'gender' => "M"
36
+ # }
37
+ def self.update_subscriber(campaign, phone, options = {})
38
+ http, request = build_request("/api/subscription_campaigns/#{campaign}/subscriptions/#{phone}.xml", "PUT")
39
+ xml = Nokogiri::XML::Builder.new do |x|
40
+ x.subscription{
41
+ x.user{
42
+ x.send(:'mobile-phone', phone)
43
+ x.send(:'carrier_id', options['carrier_id']) if options['carrier_id']
44
+ x.send(:'first-name', options['first-name']) if options['first-name']
45
+ x.send(:'last-name', options['last-name']) if options['last-name']
46
+ x.send(:'birthday-on', options['birthday-on']) if options['birthday-on']
47
+ x.send(:'email', options['email']) if options['email']
48
+ x.send(:'gender', options['gender']) if options['gender']
49
+ x.send(:'postal-code', options['postal-code']) if options['postal-code']
50
+ x.send(:'timezone-id', options['timezone-id']) if options['timezone-id']
51
+ }
52
+ }
53
+ end
54
+ request.body = xml.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::AS_XML | Nokogiri::XML::Node::SaveOptions::NO_DECLARATION).strip
55
+ response = http.request(request)
56
+ handle_response(response)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ module Catapult
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: catapult-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - cbron
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Ruby wrapper for the Vibes Catapult api
47
+ email:
48
+ - x@x.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - catapult-rails.gemspec
60
+ - lib/catapult.rb
61
+ - lib/catapult/.DS_Store
62
+ - lib/catapult/catapult_methods.rb
63
+ - lib/catapult/subscription.rb
64
+ - lib/catapult/version.rb
65
+ homepage: ''
66
+ licenses:
67
+ - MIT
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ none: false
80
+ requirements:
81
+ - - ! '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 1.8.23
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Wraps the catapult api, which is used for marketing, such as text message
90
+ subscriptions.
91
+ test_files: []