pswincom 0.1.0

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.
data/LICENSE ADDED
File without changes
data/README.md ADDED
File without changes
data/lib/pswincom.rb ADDED
@@ -0,0 +1,7 @@
1
+ require File.join(File.dirname(__FILE__), 'pswincom/api')
2
+
3
+ module PSWinCom
4
+ def self.debug label, value
5
+ puts "#{label}: #{value}" if PSWinCom::API.debug_mode
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ %w( request
2
+ httpsender
3
+ ).each do |lib|
4
+ require File.join(File.dirname(__FILE__), lib)
5
+ end
6
+
7
+ module PSWinCom
8
+ class API
9
+ class << self
10
+ attr_accessor :test_mode
11
+ attr_accessor :debug_mode
12
+ attr_accessor :api_host, :api_port
13
+ end
14
+
15
+ self.test_mode = false;
16
+ self.debug_mode = false;
17
+
18
+ def initialize user, password
19
+ @user, @password = user, password
20
+ end
21
+
22
+ def send_sms to, text, args={}
23
+ request = create_request to, text, args
24
+ sender = HttpSender.new
25
+ PSWinCom.debug "Request", request.xml
26
+ result = sender.send(request) unless self.class.test_mode
27
+ PSWinCom.debug "Result", result
28
+ return result
29
+ end
30
+
31
+ def create_request to, text, args
32
+ request = Request.new :user => @user, :passwd => @password
33
+ request.add({:text => text, :receiver => to }.merge(args))
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,25 @@
1
+ require 'uri'
2
+ require 'socket'
3
+
4
+ module PSWinCom
5
+ class HttpSender
6
+ API_HOST = 'gw2-fro.pswin.com'
7
+ API_PORT = 1111
8
+
9
+ def initialize
10
+ @host = PSWinCom::API.api_host.nil? ? API_HOST : PSWinCom::API.api_host
11
+ @port = PSWinCom::API.api_port.nil? ? API_PORT : PSWinCom::API.api_port
12
+
13
+ PSWinCom.debug "Host", @host
14
+ PSWinCom.debug "Port", @port
15
+ end
16
+
17
+ def send request
18
+ session = TCPSocket.new(@host, @port)
19
+ session.write request.xml
20
+ result = session.read
21
+ session.close
22
+ result
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ require 'rubygems'
2
+ require 'builder'
3
+
4
+ module PSWinCom
5
+ class Request
6
+ TIME_FORMAT = "%Y%m%d%H%M"
7
+ def initialize args
8
+ @user, @passwd = args[:user], args[:passwd]
9
+ @messages = []
10
+ end
11
+ def add args
12
+ @messages << args
13
+ self
14
+ end
15
+ def xml
16
+ builder = Builder::XmlMarkup.new
17
+ "<?xml version=\"1.0\"?>\r\n" +
18
+ builder.SESSION { |s| s.CLIENT(@user); s.PW(@passwd); s.MSGLST { |lst| constr_msglst(lst) }; }
19
+ end
20
+ private
21
+ def constr_msglst lst
22
+ @messages.each_with_index do |args, id|
23
+ lst.MSG { |m| constr_msg(m, args, id) }
24
+ end
25
+ end
26
+ def constr_msg m, args, id
27
+ m.ID id+1
28
+ m.TEXT args[:text]
29
+ m.RCV args[:receiver]
30
+ m.SND args[:sender] if args[:sender]
31
+ m.TTL args[:TTL] if args[:TTL]
32
+ m.DELIVERYTIME args[:deliverytime].strftime(TIME_FORMAT) if args.include? :deliverytime
33
+ end
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pswincom
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors: []
13
+
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-07 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email:
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/pswincom/api.rb
32
+ - lib/pswincom/httpsender.rb
33
+ - lib/pswincom/request.rb
34
+ - lib/pswincom.rb
35
+ - LICENSE
36
+ - README.md
37
+ has_rdoc: true
38
+ homepage:
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.5.0
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: An easy to use API for the PSWinCom SMS Gateway
71
+ test_files: []
72
+