netgsm_sms 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/core-ext/hash.rb +16 -0
  3. data/lib/netgsm_sms.rb +87 -0
  4. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 624acb6a716c208440d34cb7131d2e4699295ccc
4
+ data.tar.gz: 53242c119596d6d9a0aa0a107eccfd91f0dd9ad1
5
+ SHA512:
6
+ metadata.gz: a4273cac3032e1f04723168a1b27a2eda245e2b00312584057f5f5415e60203c36ac751664f04e2ba445a548ce028002a290f0575e791df1415c8421eac975e1
7
+ data.tar.gz: f98105caba5bc69368c5110ebcb62aa23c0cb9cf72810f7596c470c7b980f975f5e3266efca653ca702d85bf31bb9a3b26d8d7bad9940d814cf59f3281fa9f39
@@ -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
data/lib/netgsm_sms.rb ADDED
@@ -0,0 +1,87 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'core-ext/hash'
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
45
+
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
82
+
83
+ def self.format_date(date)
84
+ date.strftime('%d%m%Y%H%M')
85
+ end
86
+ end
87
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: netgsm_sms
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - IPOS - Huseyin Gomleksizoglu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This gem is for sending SMS using NetGSM services
14
+ email: huseyin.gomleksizoglu@ipos.com.tr
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/netgsm_sms.rb
20
+ - lib/core-ext/hash.rb
21
+ homepage: http://rubygems.org/gems/netgsm_sms
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.0.3
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: SMS sender for Turkey NetGSM!
45
+ test_files: []