turatel_sms 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6044fbd74cf587765d35a08662697cac9e7562ee
4
+ data.tar.gz: 916467d954bd515a8c1a45b0eec7754126a66a8d
5
+ SHA512:
6
+ metadata.gz: 1bdd9bfb0ea5c90d3d79b3cce8bf2b9bbe774cc2d3dcd3a19eb6e229064c7d8456ff289fd66c1f1d441003159ee9c87a89c738dc3ef8080acee0587cc8bd26fe
7
+ data.tar.gz: dfc7a6ab24965765e4c3f6c6044a304e21846bb3ddf356553d12c9653984909d9a859a2ecd3373a1e41a7755839e72706b5703e65add9f89ae15c335d2eb69c8
@@ -0,0 +1,16 @@
1
+ class Hash
2
+ # https://raw.github.com/lukeredpath/clickatell/master/lib/core-ext/hash.rb
3
+ # Returns a new hash containing only the keys specified
4
+ # that exist in the current hash.
5
+ #
6
+ # {:a => '1', :b => '2', :c => '3'}.only(:a, :c)
7
+ # # => {:a => '1', :c => '3'}
8
+ #
9
+ # Keys that do not exist in the original hash are ignored.
10
+ def only(*keys)
11
+ inject( {} ) do |new_hash, (key, value)|
12
+ new_hash[key] = value if keys.include?(key)
13
+ new_hash
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ module TuraTEL
2
+ # Used to set up and modify settings for the notifier.
3
+ class Configuration
4
+ attr_accessor :host
5
+ attr_accessor :port
6
+ attr_accessor :usercode
7
+ attr_accessor :password
8
+ attr_accessor :channel_code
9
+ attr_accessor :debug
10
+
11
+ def initialize
12
+ @host = 'processor.smsorigin.com'
13
+ @port = 80
14
+ end
15
+ end
16
+
17
+ class << self
18
+ attr_accessor :configuration
19
+ end
20
+
21
+ def self.configure
22
+ self.configuration ||= Configuration.new
23
+ yield configuration
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ module TuraTEL
2
+ class DATE
3
+ def self.now
4
+ format_date(Time.now)
5
+ end
6
+
7
+ def self.n_hour_from_now(duration)
8
+ format_date(Time.now + duration*60*60)
9
+ end
10
+
11
+ def self.format_date(date)
12
+ date.strftime('%d%m%Y%H%M')
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,53 @@
1
+ module TuraTEL
2
+ class SMS
3
+ def self.send_sms(recipient, message_text, opts={})
4
+ valid_options = opts.only(:from, :start_date, :stop_date, :turkish)
5
+ valid_options.merge!(:start_date => TuraTEL::DATE.now) unless valid_options[:start_date]
6
+ valid_options.merge!(:stop_date => TuraTEL::DATE.n_hour_from_now(1)) unless valid_options[:stop_date]
7
+
8
+ body = TuraTEL::XmlBody.send_sms_body(recipient, message_text, valid_options)
9
+
10
+ puts body if TuraTEL.configuration.debug
11
+
12
+ response = send_request(body)
13
+
14
+ result = parse_response(response)
15
+ "result = #{result}"
16
+ end
17
+
18
+ def sms_status
19
+ 'OK status'
20
+ end
21
+
22
+ def check_balance
23
+ 'OK Balance'
24
+ end
25
+
26
+ def initialize(auth_options={})
27
+ @auth_options = auth_options
28
+ end
29
+
30
+ def self.send_request(body)
31
+ header = {
32
+ "Content-Type" => "text/xml; charset=utf-8",
33
+ "Content-Length" => body.bytesize.to_s,
34
+ "Accept" => "*/*"
35
+ }
36
+
37
+ request = Net::HTTP::Post.new('/xml/process.aspx', header)
38
+ request.body = body
39
+ #puts "Request #{@header} #{request.body} "
40
+ response = Net::HTTP.new(TuraTEL.configuration.host, TuraTEL.configuration.port).start {|http| http.request(request) }
41
+ #puts "Response #{response.code} #{response.message}: #{response.body}"
42
+
43
+ # parser = XMLRPC::XMLParser::REXMLStreamParser::StreamListener.new
44
+ # parser.parse(response.body)
45
+
46
+ return response.body
47
+ end
48
+
49
+ def self.parse_response(body)
50
+ body.split(" ")
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,7 @@
1
+ module TuraTEL
2
+ class XmlBody
3
+ def self.send_sms_body(recipient, message_text, valid_options)
4
+ "<MainmsgBody><Command>0</Command><PlatformID>1</PlatformID><ChannelCode>#{TuraTEL.configuration.channel_code}</ChannelCode><UserName>#{TuraTEL.configuration.usercode}</UserName><PassWord>#{TuraTEL.configuration.password}</PassWord><Mesgbody>#{message_text}</Mesgbody><Numbers>#{recipient}</Numbers><Type>1</Type><Originator>#{valid_options[:from]}</Originator></MainmsgBody>"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'core-ext/hash'
4
+
5
+ require 'turatel_sms/configuration'
6
+ require 'turatel_sms/sms'
7
+ require 'turatel_sms/date'
8
+ require 'turatel_sms/xml_body'
9
+
10
+ module NetGSM
11
+ def self.root
12
+ File.expand_path('../..', __FILE__)
13
+ end
14
+ end
15
+
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: turatel_sms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - IPOS - Huseyin Gomleksizoglu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This gem is for sending SMS using TuraTEL services
14
+ email: huseyin.gomleksizoglu@ipos.com.tr
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/turatel_sms.rb
20
+ - lib/core-ext/hash.rb
21
+ - lib/turatel_sms/configuration.rb
22
+ - lib/turatel_sms/sms.rb
23
+ - lib/turatel_sms/date.rb
24
+ - lib/turatel_sms/xml_body.rb
25
+ homepage: http://rubygems.org/gems/turatel_sms
26
+ licenses:
27
+ - MIT
28
+ metadata: {}
29
+ post_install_message:
30
+ rdoc_options: []
31
+ require_paths:
32
+ - lib
33
+ required_ruby_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ required_rubygems_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 2.1.11
46
+ signing_key:
47
+ specification_version: 4
48
+ summary: SMS sender for Turkey TuraTEL!
49
+ test_files: []