netgsm_sms 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 624acb6a716c208440d34cb7131d2e4699295ccc
4
- data.tar.gz: 53242c119596d6d9a0aa0a107eccfd91f0dd9ad1
3
+ metadata.gz: 54653881737e5287794db01e357f2c347bc0a0ba
4
+ data.tar.gz: 18252274fac58d607b9b67db4941899bd54cdcd2
5
5
  SHA512:
6
- metadata.gz: a4273cac3032e1f04723168a1b27a2eda245e2b00312584057f5f5415e60203c36ac751664f04e2ba445a548ce028002a290f0575e791df1415c8421eac975e1
7
- data.tar.gz: f98105caba5bc69368c5110ebcb62aa23c0cb9cf72810f7596c470c7b980f975f5e3266efca653ca702d85bf31bb9a3b26d8d7bad9940d814cf59f3281fa9f39
6
+ metadata.gz: f0d3594875bf6c02e97851c5553aad7dfc57590ee874307b958363ca52d699f7f2363690f21664a1ba8c3b4a5051c8c25de727b611e9642a92c0eac1e90b6950
7
+ data.tar.gz: 471ad01a2c5b1a8ad28e7b2018624cccaf4b0f56ec0e45cf9fbfb71a99053c58dd66d69aef63e6fff97c0ab324e442a1807111f31534075fa25cdbf1acd9bafe
@@ -0,0 +1,23 @@
1
+ module NetGSM
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
+
9
+ def initialize
10
+ @host = 'api.netgsm.com.tr'
11
+ @port = 80
12
+ end
13
+ end
14
+
15
+ class << self
16
+ attr_accessor :configuration
17
+ end
18
+
19
+ def self.configure
20
+ self.configuration ||= Configuration.new
21
+ yield configuration
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ module NetGSM
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,51 @@
1
+ module NetGSM
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 => NetGSM::DATE.now) unless valid_options[:start_date]
6
+ valid_options.merge!(:stop_date => NetGSM::DATE.n_hour_from_now(1)) unless valid_options[:stop_date]
7
+
8
+ body = NetGSM::XmlBody.send_sms_body(valid_options)
9
+
10
+ response = send_request(body)
11
+
12
+ result = parse_response(response)
13
+ "result = #{result}"
14
+ end
15
+
16
+ def sms_status
17
+ 'OK status'
18
+ end
19
+
20
+ def check_balance
21
+ 'OK Balance'
22
+ end
23
+
24
+ def initialize(auth_options={})
25
+ @auth_options = auth_options
26
+ end
27
+
28
+ def self.send_request(body)
29
+ header = {
30
+ "Content-Type" => "text/xml; charset=utf-8",
31
+ "Content-Length" => body.bytesize.to_s,
32
+ "Accept" => "*/*"
33
+ }
34
+
35
+ request = Net::HTTP::Post.new('/xmlbulkhttppost.asp', header)
36
+ request.body = body
37
+ #puts "Request #{@header} #{request.body} "
38
+ response = Net::HTTP.new(NetGSM.configuration.host, NetGSM.configuration.port).start {|http| http.request(request) }
39
+ #puts "Response #{response.code} #{response.message}: #{response.body}"
40
+
41
+ # parser = XMLRPC::XMLParser::REXMLStreamParser::StreamListener.new
42
+ # parser.parse(response.body)
43
+
44
+ return response.body
45
+ end
46
+
47
+ def self.parse_response(body)
48
+ body.split(" ")
49
+ end
50
+ end
51
+ end
data/lib/netgsm_sms.rb CHANGED
@@ -2,86 +2,14 @@ require 'net/http'
2
2
  require 'net/https'
3
3
  require 'core-ext/hash'
4
4
 
5
- module NetGSM
6
- class SMS
7
- attr_accessor :auth_options
8
-
9
- def send_sms(recipient, message_text, opts={})
10
- valid_options = opts.only(:from, :start_date, :stop_date, :turkish)
11
- valid_options.merge!(:start_date => NetGSM::DATE.now) unless valid_options[:start_date]
12
- valid_options.merge!(:stop_date => NetGSM::DATE.n_hour_from_now(1)) unless valid_options[:stop_date]
13
-
14
- body = "<?xml version='1.0'?>
15
- <mainbody>
16
- <header>
17
- <company #{"dil='TR'" if valid_options[:turkish] == true}>NETGSM</company>
18
- <usercode>#{@auth_options[:usercode]}</usercode>
19
- <password>#{@auth_options[:password]}</password>
20
- <startdate>#{valid_options[:start_date]}</startdate>
21
- <stopdate>#{valid_options[:stop_date]}</stopdate>
22
- <type>1:n</type>
23
- <msgheader>#{valid_options[:from]}</msgheader>
24
- </header>
25
- <body>
26
- <msg><![CDATA[#{message_text}]]></msg>
27
- <no>#{recipient}</no>
28
- </body>
29
- </mainbody>"
30
-
31
- # puts body
32
-
33
- send_request(body)
34
-
35
- "#{valid_options.inspect}"
36
- end
37
-
38
- def sms_status
39
- 'OK status'
40
- end
41
-
42
- def check_balance
43
- 'OK Balance'
44
- end
5
+ require 'netgsm_sms/configuration'
6
+ require 'netgsm_sms/sms'
7
+ require 'netgsm_sms/date'
8
+ require 'netgsm_sms/xml_body'
45
9
 
46
- def initialize(auth_options={})
47
- @auth_options = auth_options
48
- end
49
-
50
- def send_request(body)
51
- header = {
52
- "Content-Type" => "text/xml; charset=utf-8",
53
- "Content-Length" => body.bytesize.to_s,
54
- "Accept" => "*/*"
55
- }
56
-
57
- request = Net::HTTP::Post.new('/xmlbulkhttppost.asp', header)
58
- puts "request created. request = #{request.inspect}"
59
- request.body = body
60
- #puts "Request #{@header} #{request.body} "
61
- response = Net::HTTP.new('api.netgsm.com.tr', 80).start {|http| http.request(request) }
62
- puts "response created. response = #{response.inspect}"
63
- #puts "Response #{response.code} #{response.message}: #{response.body}"
64
-
65
- # parser = XMLRPC::XMLParser::REXMLStreamParser::StreamListener.new
66
- # parser.parse(response.body)
67
-
68
- puts "result parsed. result = #{response.body.inspect}"
69
-
70
- return 'OK'
71
- end
72
- end
73
-
74
- class DATE
75
- def self.now
76
- format_date(Time.now)
77
- end
78
-
79
- def self.n_hour_from_now(duration)
80
- format_date(Time.now + duration*60*60)
81
- end
10
+ module NetGSM
11
+ def self.root
12
+ File.expand_path('../..', __FILE__)
13
+ end
14
+ end
82
15
 
83
- def self.format_date(date)
84
- date.strftime('%d%m%Y%H%M')
85
- end
86
- end
87
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netgsm_sms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - IPOS - Huseyin Gomleksizoglu
@@ -18,6 +18,9 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - lib/netgsm_sms.rb
20
20
  - lib/core-ext/hash.rb
21
+ - lib/netgsm_sms/configuration.rb
22
+ - lib/netgsm_sms/sms.rb
23
+ - lib/netgsm_sms/date.rb
21
24
  homepage: http://rubygems.org/gems/netgsm_sms
22
25
  licenses:
23
26
  - MIT
@@ -38,7 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
41
  version: '0'
39
42
  requirements: []
40
43
  rubyforge_project:
41
- rubygems_version: 2.0.3
44
+ rubygems_version: 2.1.11
42
45
  signing_key:
43
46
  specification_version: 4
44
47
  summary: SMS sender for Turkey NetGSM!