shado_puppet 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/shado_puppet/configuration.rb +31 -0
- data/lib/shado_puppet/message.rb +73 -0
- data/lib/shado_puppet/version.rb +5 -0
- data/lib/shado_puppet.rb +6 -0
- data/shado_puppet.gemspec +58 -0
- data/test/helper.rb +10 -0
- data/test/test_shado_puppet.rb +7 -0
- metadata +88 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Steve Richert
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= shado_puppet
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Steve Richert. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "shado_puppet"
|
8
|
+
gem.summary = %Q{A Ruby interface for the Moonshado SMS delivery API.}
|
9
|
+
gem.description = %Q{A Ruby interface for the Moonshado SMS delivery API.}
|
10
|
+
gem.email = "steve.richert@gmail.com"
|
11
|
+
gem.homepage = "http://moonshado.com/"
|
12
|
+
gem.authors = ["Steve Richert"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake/testtask'
|
22
|
+
Rake::TestTask.new(:test) do |test|
|
23
|
+
test.libs << 'lib' << 'test'
|
24
|
+
test.pattern = 'test/**/test_*.rb'
|
25
|
+
test.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require 'rcov/rcovtask'
|
30
|
+
Rcov::RcovTask.new do |test|
|
31
|
+
test.libs << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
task :rcov do
|
37
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
task :test => :check_dependencies
|
42
|
+
|
43
|
+
task :default => :test
|
44
|
+
|
45
|
+
require 'rake/rdoctask'
|
46
|
+
Rake::RDocTask.new do |rdoc|
|
47
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
48
|
+
|
49
|
+
rdoc.rdoc_dir = 'rdoc'
|
50
|
+
rdoc.title = "shado_puppet #{version}"
|
51
|
+
rdoc.rdoc_files.include('README*')
|
52
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
53
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "lib", "shado_puppet")
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ShadoPuppet
|
2
|
+
module Configuration
|
3
|
+
def configure(&block)
|
4
|
+
block.bind(Configuration).call
|
5
|
+
end
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def options
|
9
|
+
@options ||= {
|
10
|
+
:ssl => true,
|
11
|
+
:domain => "api.moonshado.com",
|
12
|
+
:message => {}
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing(symbol, *args)
|
17
|
+
if args.empty?
|
18
|
+
options.key?(symbol) ? options[symbol] : super
|
19
|
+
else
|
20
|
+
value = args.first
|
21
|
+
value.symbolize_keys! if value.is_a?(Hash)
|
22
|
+
options[symbol] = value
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def site
|
27
|
+
(ssl ? "https://" : "http://") + domain + "/"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module ShadoPuppet
|
2
|
+
class Message < ActiveRecord::Base
|
3
|
+
MAXIMUM_CONTENT_LENGTH = 160
|
4
|
+
|
5
|
+
def self.columns
|
6
|
+
@columns ||= []
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.column(name, type, options = {})
|
10
|
+
options.reverse_merge(:null => true, :default => nil)
|
11
|
+
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, options[:default], type.to_s, options[:null])
|
12
|
+
end
|
13
|
+
|
14
|
+
column :originating_address, :string
|
15
|
+
column :device_address, :string
|
16
|
+
column :subject, :string
|
17
|
+
column :body, :text
|
18
|
+
column :reporting_key, :string
|
19
|
+
column :ttl, :datetime
|
20
|
+
column :shorten, :string
|
21
|
+
column :keyword, :string
|
22
|
+
|
23
|
+
validates_presence_of :originating_address, :device_address, :body
|
24
|
+
validates_format_of :device_address, :with => /^1\d{10}$/, :allow_nil => true
|
25
|
+
validates_inclusion_of :shorten, :in => %w(split truncate), :allow_nil => true
|
26
|
+
validate :content_length_must_be_valid
|
27
|
+
|
28
|
+
def self.uri
|
29
|
+
@uri ||= URI.parse(Configuration.site + "gateway/sms")
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize_with_configuration(attrs = nil)
|
33
|
+
initialize_without_configuration(attrs) do
|
34
|
+
attribute_names = attrs ? attrs.keys.map(&:to_sym) : []
|
35
|
+
default_attribute_values = Configuration.message.except(*attribute_names)
|
36
|
+
|
37
|
+
default_attribute_values.each do |attribute, value|
|
38
|
+
__send__("#{attribute}=", value)
|
39
|
+
end
|
40
|
+
|
41
|
+
yield self if block_given?
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
alias_method_chain :initialize, :configuration
|
46
|
+
|
47
|
+
def device_address=(value)
|
48
|
+
number = value.gsub(/\D/, "").sub(/^([^1])/, '1\1')
|
49
|
+
write_attribute(:device_address, number.blank? ? nil : number)
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
def create
|
54
|
+
message = attributes.symbolize_keys
|
55
|
+
message[:ttl] &&= message[:ttl].strftime("%Y-%m-%d %H:%M:%S %Z")
|
56
|
+
|
57
|
+
response = RestClient.post(self.class.uri.to_s, :api_key => Configuration.api_key, :message => message)
|
58
|
+
code = Hash.from_xml(response.body)["status"]["code"].to_i
|
59
|
+
code == 10
|
60
|
+
rescue
|
61
|
+
false
|
62
|
+
end
|
63
|
+
|
64
|
+
def content_length_must_be_valid
|
65
|
+
content_length = [subject, body].compact.map(&:length).sum
|
66
|
+
|
67
|
+
if content_length > MAXIMUM_CONTENT_LENGTH
|
68
|
+
errors.add(:subject, "and body together must add up to #{MAXIMUM_CONTENT_LENGTH} characters")
|
69
|
+
errors.add(:body, "and subject together must add up to #{MAXIMUM_CONTENT_LENGTH} characters")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/shado_puppet.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{shado_puppet}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Steve Richert"]
|
12
|
+
s.date = %q{2010-04-22}
|
13
|
+
s.description = %q{A Ruby interface for the Moonshado SMS delivery API.}
|
14
|
+
s.email = %q{steve.richert@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"init.rb",
|
27
|
+
"lib/shado_puppet.rb",
|
28
|
+
"lib/shado_puppet/configuration.rb",
|
29
|
+
"lib/shado_puppet/message.rb",
|
30
|
+
"lib/shado_puppet/version.rb",
|
31
|
+
"shado_puppet.gemspec",
|
32
|
+
"test/helper.rb",
|
33
|
+
"test/test_shado_puppet.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://moonshado.com/}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.6}
|
39
|
+
s.summary = %q{A Ruby interface for the Moonshado SMS delivery API.}
|
40
|
+
s.test_files = [
|
41
|
+
"test/helper.rb",
|
42
|
+
"test/test_shado_puppet.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
53
|
+
end
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shado_puppet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Steve Richert
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-04-22 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: thoughtbot-shoulda
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
description: A Ruby interface for the Moonshado SMS delivery API.
|
33
|
+
email: steve.richert@gmail.com
|
34
|
+
executables: []
|
35
|
+
|
36
|
+
extensions: []
|
37
|
+
|
38
|
+
extra_rdoc_files:
|
39
|
+
- LICENSE
|
40
|
+
- README.rdoc
|
41
|
+
files:
|
42
|
+
- .document
|
43
|
+
- .gitignore
|
44
|
+
- LICENSE
|
45
|
+
- README.rdoc
|
46
|
+
- Rakefile
|
47
|
+
- VERSION
|
48
|
+
- init.rb
|
49
|
+
- lib/shado_puppet.rb
|
50
|
+
- lib/shado_puppet/configuration.rb
|
51
|
+
- lib/shado_puppet/message.rb
|
52
|
+
- lib/shado_puppet/version.rb
|
53
|
+
- shado_puppet.gemspec
|
54
|
+
- test/helper.rb
|
55
|
+
- test/test_shado_puppet.rb
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: http://moonshado.com/
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options:
|
62
|
+
- --charset=UTF-8
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
segments:
|
77
|
+
- 0
|
78
|
+
version: "0"
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.3.6
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: A Ruby interface for the Moonshado SMS delivery API.
|
86
|
+
test_files:
|
87
|
+
- test/helper.rb
|
88
|
+
- test/test_shado_puppet.rb
|