barabut_sms 0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 371c28ccf225c2992791465022a3a4c73e37b241
4
+ data.tar.gz: 508bdd203f4ab927b93b758192e221080d90b858
5
+ SHA512:
6
+ metadata.gz: 8f4310366dd4c942c24c933950a19f89002acb33537a760234a8b7b2fe64acc8332a3270a6cb7763cca437226daa0a2d36ee015408294cfc3985ce3d6158ce6b
7
+ data.tar.gz: 6806098df3acf60fc92461c6311bc45f0f3307193ecceb97056e0ca92bf7e3d58a7c24139c9d87d7b4c7e37a0d1af05b6d5455d561d33f5f340f359920807df6
@@ -0,0 +1,16 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'core-ext/hash'
4
+ require 'xmlsimple'
5
+
6
+ require 'barabut_sms/configuration'
7
+ require 'barabut_sms/sms'
8
+ require 'barabut_sms/date'
9
+ require 'barabut_sms/xml_body'
10
+
11
+ module Barabut
12
+ def self.root
13
+ File.expand_path('../..', __FILE__)
14
+ end
15
+ end
16
+
@@ -0,0 +1,23 @@
1
+ module Barabut
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 = 'gw.barabut.com'
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 Barabut
2
+ class DATE
3
+ def self.now
4
+ format_date(Time.now.utc)
5
+ end
6
+
7
+ def self.n_hour_from_now(duration)
8
+ format_date(Time.now.utc + duration*60*60)
9
+ end
10
+
11
+ def self.format_date(date)
12
+ date.strftime('%Y-%m-%dT%H:%M:%SZ')
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,54 @@
1
+ module Barabut
2
+ class SMS
3
+ def self.send_sms(recipient, message_text, opts={})
4
+ valid_options = opts.only(:from, :start_date, :stop_date, :turkish, :validity_period)
5
+ valid_options.merge!(:start_date => Barabut::DATE.now) unless valid_options[:start_date]
6
+ valid_options.merge!(:validity_period => 1440) unless valid_options[:validity_period]
7
+
8
+
9
+ body = Barabut::XmlBody.send_sms_body(recipient, message_text, valid_options)
10
+
11
+ response = send_request(body)
12
+
13
+ result = parse_response(response)
14
+ code = result["Response"].first["Status"].first["Code"].first rescue "500"
15
+ sms_id = result["Response"].first["MessageId"].first rescue nil
16
+ return {code: code, sms_id: sms_id}
17
+ end
18
+
19
+ def sms_status
20
+ 'OK status'
21
+ end
22
+
23
+ def check_balance
24
+ 'OK Balance'
25
+ end
26
+
27
+ def initialize(auth_options={})
28
+ @auth_options = auth_options
29
+ end
30
+
31
+ def self.send_request(body)
32
+ header = {
33
+ "Content-Type" => "text/xml; charset=utf-8",
34
+ "Content-Length" => body.bytesize.to_s,
35
+ "Accept" => "*/*"
36
+ }
37
+
38
+ request = Net::HTTP::Post.new('/v1/xml/syncreply/Submit', header)
39
+ request.body = body
40
+ #puts "Request #{@header} #{request.body} "
41
+ response = Net::HTTP.new(Barabut.configuration.host, Barabut.configuration.port).start {|http| http.request(request) }
42
+ #puts "Response #{response.code} #{response.message}: #{response.body}"
43
+
44
+ # parser = XMLRPC::XMLParser::REXMLStreamParser::StreamListener.new
45
+ # parser.parse(response.body)
46
+
47
+ return response.body
48
+ end
49
+
50
+ def self.parse_response(body)
51
+ data = XmlSimple.xml_in(body)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,21 @@
1
+ module Barabut
2
+ class XmlBody
3
+ def self.send_sms_body(recipient, message_text, valid_options)
4
+ "<?xml version='1.0'?>
5
+ <Submit xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='SmsApi'>
6
+ <Credential>
7
+ <Password>#{Barabut.configuration.password}</Password>
8
+ <Username>#{Barabut.configuration.usercode}</Username>
9
+ </Credential>
10
+ <DataCoding>Default</DataCoding>
11
+ <Header>
12
+ <From>#{valid_options[:from]}</From>
13
+ </Header>
14
+ <Message><![CDATA[#{message_text}]]></Message>
15
+ <To xmlns:d2p1='http://schemas.microsoft.com/2003/10/Serialization/Arrays'>
16
+ <d2p1:string>#{recipient}</d2p1:string>
17
+ </To>
18
+ </Submit>"
19
+ end
20
+ end
21
+ end
@@ -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
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: barabut_sms
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - IPOS - Huseyin Gomleksizoglu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: xml-simple
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: This gem is for sending SMS using Barabut.com services
28
+ email: huseyin.gomleksizoglu@ipos.com.tr
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/barabut_sms.rb
34
+ - lib/core-ext/hash.rb
35
+ - lib/barabut_sms/configuration.rb
36
+ - lib/barabut_sms/sms.rb
37
+ - lib/barabut_sms/date.rb
38
+ - lib/barabut_sms/xml_body.rb
39
+ homepage: http://rubygems.org/gems/barabut_sms
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.1.11
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: SMS sender for Turkey barabut.com!
63
+ test_files: []
64
+ has_rdoc: