short_message 0.0.2 → 0.0.3

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 CHANGED
@@ -30,3 +30,21 @@ Create a message and deliver it:
30
30
  @sms = ShortMessage::Message.new(:sender => "0041791234567", :recipient => "0041799876543", :text => "Hello World!")
31
31
  @sms.deliver
32
32
  ```
33
+ ## Customization ##
34
+ ### Status Codes ##
35
+ If you need to customize the status response codes simply edit the internationalization files in config/locales
36
+
37
+ ### Params ###
38
+ To override the params string add this to an initializer file (or put it into config/initializers/short_message.rb)
39
+ ```ruby
40
+ ShortMessage::Message.module_eval do
41
+ private
42
+ def build_deliver_params_string
43
+ # your code here
44
+ end
45
+
46
+ def build_recharge_params_string amount
47
+ # your code here
48
+ end
49
+ end
50
+ ```
@@ -10,7 +10,9 @@ module ShortMessage
10
10
  end
11
11
 
12
12
  def deliver
13
- unless self.sender.blank? and self.recipient.blank? and self.text.blank?
13
+ self.sender = ShortMessage.config.default_sms_sender if self.sender.blank?
14
+
15
+ unless self.recipient.blank? and self.text.blank?
14
16
  http = Net::HTTP.new(ShortMessage.config.gateway_server)
15
17
  response, data = http.post(ShortMessage.config.send_file_path, build_deliver_params_string)
16
18
 
@@ -38,25 +40,27 @@ module ShortMessage
38
40
  end
39
41
 
40
42
  def recharge amount = ShortMessage.config.default_reload_amount
41
- http = Net::HTTP.new(ShortMessage.config.gateway_server)
42
- response, body = http.post(ShortMessage.config.account_functions_path, build_recharge_params_string(amount))
43
+ unless ShortMessage.config.account_functions_path.blank?
44
+ http = Net::HTTP.new(ShortMessage.config.gateway_server)
45
+ response, body = http.post(ShortMessage.config.account_functions_path, build_recharge_params_string(amount))
43
46
 
44
- if response.code == "200"
45
- # returns something like 0:Successful
46
- result_set = response.body.split(":")
47
+ if response.code == "200"
48
+ # returns something like 0:Successful
49
+ result_set = response.body.split(":")
47
50
 
48
- if result_set[0] == "0"
49
- logger.info "SMS account successfully charged with #{amount} sms."
50
- Mailer.recharge_notification(amount).deliver unless ShortMessage.config.reload_notification_email.blank?
51
- Mailer.voucher_notification(amount).deliver unless ShortMessage.config.voucher_notification_email.blank?
52
- true
53
- else
54
- logger.warn "SMS account could not be recharged with #{amount} sms. Error: #{body}"
55
- Mailer.recharge_failed_notification(amount, body).deliver unless ShortMessage.config.reload_notification_email.blank?
56
- false
51
+ if result_set[0] == "0"
52
+ logger.info "SMS account successfully charged with #{amount} sms."
53
+ Mailer.recharge_notification(amount).deliver unless ShortMessage.config.reload_notification_email.blank?
54
+ Mailer.voucher_notification(amount).deliver unless ShortMessage.config.voucher_notification_email.blank?
55
+ true
56
+ else
57
+ logger.warn "SMS account could not be recharged with #{amount} sms. Error: #{body}"
58
+ Mailer.recharge_failed_notification(amount, body).deliver unless ShortMessage.config.reload_notification_email.blank?
59
+ false
60
+ end
61
+ else
62
+ "#{response.code} #{response.message}"
57
63
  end
58
- else
59
- "#{response.code} #{response.message}"
60
64
  end
61
65
  end
62
66
 
@@ -9,10 +9,13 @@ ShortMessage.configure do |config|
9
9
  config.user_id = ""
10
10
  config.ccu_id = ""
11
11
  config.id_string = ""
12
-
12
+
13
13
  config.default_reload_amount = 1000
14
14
 
15
15
  config.default_mail_sender = "webmaster@your-domain.com"
16
16
  config.reload_notification_email = "webmaster@your-domain.com"
17
- config.voucher_notification_email = "give-me-money@your-domain.com"
17
+ config.voucher_notification_email = "give-me-money@your-domain.com" # set nil to disable voucher mailing
18
+
19
+ # set a default sms sender (used if no sender is present)
20
+ # config.default_sms_sender = ""
18
21
  end
@@ -20,6 +20,7 @@ module ShortMessage
20
20
  config_accessor :ccu_id
21
21
  config_accessor :id_string
22
22
 
23
+ config_accessor :default_sms_sender
23
24
  config_accessor :default_reload_amount
24
25
  config_accessor :reload_notification_email
25
26
  config_accessor :voucher_notification_email
@@ -1,3 +1,3 @@
1
1
  module ShortMessage
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: short_message
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: