moonshado-sms 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -10
- data/Rakefile +1 -0
- data/VERSION.yml +2 -2
- data/lib/moonshado/sms.rb +14 -22
- metadata +12 -2
data/README.rdoc
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
= moonshado-sms
|
2
2
|
|
3
|
-
|
3
|
+
Moonshado SMS Gem
|
4
4
|
|
5
|
-
==
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
== Usage
|
6
|
+
|
7
|
+
Put this in Development and Test environment so no real SMS are sent out:
|
8
|
+
Moonshado::Sms.config = {
|
9
|
+
:test_env => true,
|
10
|
+
:sms_api_url => nil
|
11
|
+
}
|
12
|
+
|
13
|
+
Production environment config:
|
14
|
+
Moonshado::Sms.config = {
|
15
|
+
:sms_api_url => ENV['MOONSHADOSMS_URL']
|
16
|
+
}
|
14
17
|
|
15
18
|
== Copyright
|
16
19
|
|
data/Rakefile
CHANGED
@@ -12,6 +12,7 @@ begin
|
|
12
12
|
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
13
13
|
gem.add_runtime_dependency "rest-client"
|
14
14
|
gem.add_runtime_dependency "json"
|
15
|
+
gem.add_runtime_dependency "active_support"
|
15
16
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
17
|
end
|
17
18
|
Jeweler::GemcutterTasks.new
|
data/VERSION.yml
CHANGED
data/lib/moonshado/sms.rb
CHANGED
@@ -1,29 +1,17 @@
|
|
1
|
+
require 'active_support'
|
1
2
|
require 'rest_client'
|
2
3
|
require 'json'
|
3
4
|
|
4
5
|
module Moonshado
|
5
6
|
class Sms
|
6
|
-
|
7
|
-
:test_env => false,
|
8
|
-
:sms_api_url => ENV['MOONSHADOSMS_URL']
|
9
|
-
}
|
10
|
-
|
7
|
+
cattr_accessor :config
|
11
8
|
attr_accessor :number, :message
|
12
9
|
|
13
|
-
def self.config
|
14
|
-
@@config
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.config=(config)
|
18
|
-
raise MoonshadoSMSException.new("config is not a hash")
|
19
|
-
@@config = config
|
20
|
-
end
|
21
|
-
|
22
10
|
def self.find(id)
|
23
|
-
if
|
11
|
+
if config[:test_env] == true
|
24
12
|
{:sms => {:id => id, :reports => '[{"update_date":"2010-01-03T22:56:45-08:00","status_info":"test"}]'}, :stat => "ok"}
|
25
13
|
else
|
26
|
-
response = RestClient.get("#{
|
14
|
+
response = RestClient.get("#{config[:sms_api_url]}/#{id}")
|
27
15
|
JSON.parse(response.body)
|
28
16
|
end
|
29
17
|
end
|
@@ -34,14 +22,18 @@ module Moonshado
|
|
34
22
|
end
|
35
23
|
|
36
24
|
def deliver_sms
|
37
|
-
raise MoonshadoSMSException.new("Invalid message")
|
25
|
+
raise MoonshadoSMSException.new("Invalid message") unless is_message_valid?(@message)
|
38
26
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
27
|
+
if config[:test_env] == true
|
28
|
+
{:stat => 'ok', :id => Digest::SHA1.hexdigest(Time.now.to_s + rand(12341234).to_s)[1..16]}
|
29
|
+
else
|
30
|
+
response = RestClient.post(
|
31
|
+
config[:sms_api_url],
|
32
|
+
{:sms => {:device_address => format_number(@number), :message => @message}}
|
33
|
+
)
|
43
34
|
|
44
|
-
|
35
|
+
JSON.parse(response.body)
|
36
|
+
end
|
45
37
|
rescue MoonshadoSMSException => exception
|
46
38
|
raise exception
|
47
39
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moonshado-sms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Patel
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-04-
|
12
|
+
date: 2010-04-12 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -42,6 +42,16 @@ dependencies:
|
|
42
42
|
- !ruby/object:Gem::Version
|
43
43
|
version: "0"
|
44
44
|
version:
|
45
|
+
- !ruby/object:Gem::Dependency
|
46
|
+
name: active_support
|
47
|
+
type: :runtime
|
48
|
+
version_requirement:
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
45
55
|
description:
|
46
56
|
email: tech@moonshado.com
|
47
57
|
executables: []
|