truesenses 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,40 @@
1
1
  = truesenses
2
2
 
3
- Description goes here.
3
+ A implementation of the truesenses HTTP/HTTPS API for sending SMS.
4
+ Register at truesenses.com and buy some credits.
5
+
6
+ == Install
7
+ gem install truesenses
8
+
9
+ == Notes
10
+ Not all API methods are implemented (i.e. delivery reports)
11
+ Multiple recipients are not supported (to allow for better error reports)
12
+
13
+ == How to use
14
+
15
+ require 'rubygems'
16
+ require 'truesenses'
17
+
18
+ include Truesenses
19
+ # you need a config which specifies at least username/password
20
+ config = Config.new(:username => 'ABCDE', :password => 'defgh', :prototcol => :http, :deliver => false)
21
+ # or
22
+ config = Config.load(File.join(RAILS_ROOT, 'config', 'truesenses.yml'), RAILS_ENV)
23
+
24
+ # then you can create the gateway object
25
+ gateway = SMSGateway.new(config)
26
+
27
+ # you can query the remaining credits
28
+ gateway.credits_left
29
+
30
+ # or send text messages (of course...)
31
+ # all response codes but 01 will trigger an exception
32
+ id = gateway.send_text_message('Your message', '+41987654321', :origin => 'ABCD')
33
+
34
+
4
35
 
5
36
  == Note on Patches/Pull Requests
6
-
37
+
7
38
  * Fork the project.
8
39
  * Make your feature addition or bug fix.
9
40
  * Add tests for it. This is important so I don't break it in a
@@ -14,4 +45,4 @@ Description goes here.
14
45
 
15
46
  == Copyright
16
47
 
17
- Copyright (c) 2010 pascalbetz. See LICENSE for details.
48
+ Copyright (c) 2010 simplificator. See LICENSE for details.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ begin
5
5
  require 'jeweler'
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "truesenses"
8
- gem.summary = %Q{implementation of the http api for truesenses.com SMS gateway}
8
+ gem.summary = %Q{implementation of the api for truesenses.com SMS gateway}
9
9
  gem.description = %Q{implementation of the http/https api for truesenses.com SMS gateway}
10
10
  gem.email = "info@simplificator.com"
11
11
  gem.homepage = "http://github.com/simplificator/truesenses"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -1,6 +1,12 @@
1
1
  module Truesenses
2
2
  class Config
3
3
  attr_reader :password, :username, :protocol, :origin, :deliver
4
+
5
+ # :username
6
+ # :password
7
+ # :protocol :http or :https, defaults to :http
8
+ # :origin default origin ID of text message
9
+ # :deliver true|false, false turns on the TEST mode of truesenses API
4
10
  def initialize(options)
5
11
  options = options.stringify_keys
6
12
  @password = options['password']
@@ -10,7 +16,10 @@ module Truesenses
10
16
  @deliver = options.has_key?('deliver') ? options['deliver'] : true
11
17
  verify!
12
18
  end
13
-
19
+
20
+ # Load config from a YAML file
21
+ # if root is specified, then this root key is used (useful when you store different configurations
22
+ # in one YAML file: Config.load('somefile.yml', RAILS_ENV))
14
23
  def self.load(filename, root = nil)
15
24
  data = YAML.load_file(filename)
16
25
  Config.new(root ? data[root] : data)
@@ -7,29 +7,37 @@ module Truesenses
7
7
  include HTTParty
8
8
 
9
9
  attr_reader :config
10
+
11
+
12
+
10
13
  def initialize(config)
11
14
  @config = config
12
15
  end
13
16
 
17
+ #
14
18
  def credits_left
15
- post_request('CHECKCREDITS')
19
+ post_request('CHECKCREDITS').to_i
16
20
  end
17
21
 
22
+ # Send a text message
23
+ #
24
+ # Available options are:
18
25
  # :origin: if nil, do not transmit origin even if specified in config
19
26
  # :flash: true|false (defaults to false)
20
27
  # :test: true|false (defaults to false)
28
+ #
29
+ # returns the ID of the message in the YYMMDDHHMMSS format (strange, i know...)
21
30
  def send_text_message(message, receipient, options = {})
22
31
  params = {'NUMBER' => receipient, 'MESSAGE' => message}
23
- if !(options.has_key?(:origin) && options[:origin].nil?) && options[:origin] || self.config.origin
32
+ if options.has_key?(:origin) && options[:origin].nil?
33
+ # ignore origin, even if it's in config
34
+ elsif options[:origin] || self.config.origin
35
+ # set origin override config is specified in options
24
36
  params['ORIGIN'] = options[:origin] || self.config.origin
25
37
  end
26
38
  params['FLASH'] = 'ON' if options[:flash]
27
- params['TEST'] = 'ON' if options[:test]
28
- if self.config.deliver
29
- post_request('SENDMESSAGE', params)
30
- else
31
- puts "Fake Delivery: #{message} to #{receipient}"
32
- end
39
+ params['TEST'] = 'ON' if options[:test] || (self.config.deliver == false)
40
+ post_request('SENDMESSAGE', params)
33
41
  end
34
42
 
35
43
 
@@ -0,0 +1,12 @@
1
+ production:
2
+ username: ABCDE
3
+ password: something
4
+ protocol: :https
5
+ origin: XYZ
6
+ deliver: true
7
+ test:
8
+ username: ABCDE
9
+ password: something
10
+ protocol: :https
11
+ origin: XYZ
12
+ deliver: false
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: truesenses
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - pascalbetz
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-06 00:00:00 +02:00
18
+ date: 2010-09-07 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -55,6 +55,7 @@ files:
55
55
  - lib/truesenses/hash.rb
56
56
  - lib/truesenses/sms_gateway.rb
57
57
  - lib/truesenses/sms_gateway_error.rb
58
+ - sample.yml
58
59
  - test/helper.rb
59
60
  - test/test_truesenses.rb
60
61
  has_rdoc: true
@@ -90,7 +91,7 @@ rubyforge_project:
90
91
  rubygems_version: 1.3.7
91
92
  signing_key:
92
93
  specification_version: 3
93
- summary: implementation of the http api for truesenses.com SMS gateway
94
+ summary: implementation of the api for truesenses.com SMS gateway
94
95
  test_files:
95
96
  - test/helper.rb
96
97
  - test/test_truesenses.rb