moonshado-sms 0.0.3 → 0.1.0

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.
Files changed (5) hide show
  1. data/README.rdoc +13 -10
  2. data/Rakefile +1 -0
  3. data/VERSION.yml +2 -2
  4. data/lib/moonshado/sms.rb +14 -22
  5. metadata +12 -2
data/README.rdoc CHANGED
@@ -1,16 +1,19 @@
1
1
  = moonshado-sms
2
2
 
3
- Description goes here.
3
+ Moonshado SMS Gem
4
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.
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
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 0
3
+ :minor: 1
4
4
  :build:
5
- :patch: 3
5
+ :patch: 0
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
- @@config = {
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 @@config_env[:test_env]
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("#{@@config[:sms_api_url]}/#{id}")
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") if is_message_valid?(@message)
25
+ raise MoonshadoSMSException.new("Invalid message") unless is_message_valid?(@message)
38
26
 
39
- response = RestClient.post(
40
- @@config[:sms_api_url],
41
- {:sms => {:device_address => format_number(@number), :message => @message}}
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
- JSON.parse(response.body)
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.3
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-08 00:00:00 -07:00
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: []