truesenses 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
@@ -1,11 +1,12 @@
1
1
  module Truesenses
2
2
  class Config
3
- attr_reader :password, :username, :protocol
3
+ attr_reader :password, :username, :protocol, :origin
4
4
  def initialize(options)
5
5
  options = options.stringify_keys
6
6
  @password = options['password']
7
7
  @username = options['username']
8
8
  @protocol = options['protocol'] || :http
9
+ @origin = options['origin']
9
10
  verify!
10
11
  end
11
12
 
@@ -2,7 +2,7 @@ module Truesenses
2
2
  class SMSGateway
3
3
  RESPONSE_FORMAT = /(\d{2}) (.*)/
4
4
  SUCCESS = 1
5
- HTTP_BASE = 'http://www.truesenses.com/cgi-bin/smsgateway.cgi'
5
+ HTTP_BASE = 'http://truesenses.com/cgi-bin/smsgateway.cgi'
6
6
  HTTPS_BASE = 'https://secure.simmcomm.ch/cgi-bin/smsgateway.cgi'
7
7
  include HTTParty
8
8
 
@@ -12,16 +12,20 @@ module Truesenses
12
12
  end
13
13
 
14
14
  def credits_left
15
- raise "not yet implemented"
16
- post_request({'CMD' => 'CHECKCREDITS'})
15
+ post_request('CHECKCREDITS')
17
16
  end
18
17
 
19
- def send_text_message(message, receipient)
20
- get_request({
21
- 'CMD' => 'SENDMESSAGE',
22
- 'NUMBER' => receipient,
23
- 'MESSAGE' => message
24
- })
18
+ # :origin: if nil, do not transmit origin even if specified in config
19
+ # :flash: true|false (defaults to false)
20
+ # :test: true|false (defaults to false)
21
+ def send_text_message(message, receipient, options = {})
22
+ params = {'NUMBER' => receipient, 'MESSAGE' => message}
23
+ if !(options.has_key?(:origin) && options[:origin].nil?) && options[:origin] || self.config.origin
24
+ params['ORIGIN'] = options[:origin] || self.config.origin
25
+ end
26
+ params['FLASH'] = 'ON' if options[:flash]
27
+ params['TEST'] = 'ON' if options[:test]
28
+ post_request('SENDMESSAGE', params)
25
29
  end
26
30
 
27
31
 
@@ -29,12 +33,8 @@ module Truesenses
29
33
 
30
34
  private
31
35
 
32
- def get_request(options = {})
33
- parse_response!(SMSGateway.get(base_url, :query => options.merge(default_options)))
34
- end
35
-
36
- def post_request(options = {})
37
- parse_response!(SMSGateway.post(base_url, :query => options.merge(default_options)))
36
+ def post_request(command, options = {})
37
+ parse_response!(SMSGateway.post(base_url, :body => options.merge(default_options).merge({'CMD' => command})))
38
38
  end
39
39
 
40
40
  def parse_response!(response)
@@ -55,7 +55,6 @@ module Truesenses
55
55
  }
56
56
  end
57
57
 
58
-
59
58
  def base_url
60
59
  self.config.protocol == :http ? HTTP_BASE : HTTPS_BASE
61
60
  end
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: 31
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 0.0.0
10
+ version: 0.1.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-05 00:00:00 +02:00
18
+ date: 2010-09-06 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency