esendex4soap 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/Gemfile +6 -5
  2. data/VERSION +1 -1
  3. data/esendex4soap.gemspec +20 -20
  4. data/lib/esendex4soap.rb +85 -54
  5. metadata +9 -9
data/Gemfile CHANGED
@@ -2,10 +2,11 @@ source "http://rubygems.org"
2
2
  gem 'jruby-openssl', :platform => :jruby
3
3
  gem 'savon', '~> 0.9.7'
4
4
  gem 'log4r'
5
- gem 'wtf_lang'
5
+ gem 'wtf_lang', '~> 0.3.1'
6
+
6
7
  group :development do
7
- gem "shoulda", ">= 0"
8
- gem "bundler", "~> 1.0.0"
9
- gem "jeweler", "~> 1.6.4"
10
- gem "rcov", ">= 0"
8
+ gem "shoulda" #, ">= 0"
9
+ gem "bundler" #, "~> 1.0.0"
10
+ gem "jeweler" #, "~> 1.6.4"
11
+ gem "rcov" #, ">= 0"
11
12
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.4
1
+ 0.6.0
data/esendex4soap.gemspec CHANGED
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{esendex4soap}
8
- s.version = "0.5.4"
7
+ s.name = "esendex4soap"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Voip Scout}]
12
- s.date = %q{2011-12-02}
13
- s.description = %q{thanks to savon library}
14
- s.email = %q{voipscout@gmail.com}
11
+ s.authors = ["Voip Scout"]
12
+ s.date = "2012-02-26"
13
+ s.description = "thanks to savon library"
14
+ s.email = "voipscout@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.rdoc"
@@ -28,11 +28,11 @@ Gem::Specification.new do |s|
28
28
  "test/helper.rb",
29
29
  "test/test_esendex4soap.rb"
30
30
  ]
31
- s.homepage = %q{http://github.com/voipscout/esendex4soap}
32
- s.licenses = [%q{MIT}]
33
- s.require_paths = [%q{lib}]
34
- s.rubygems_version = %q{1.8.9}
35
- s.summary = %q{esendex SOAP-XML-API for ruby}
31
+ s.homepage = "http://github.com/voipscout/esendex4soap"
32
+ s.licenses = ["MIT"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = "1.8.15"
35
+ s.summary = "esendex SOAP-XML-API for ruby"
36
36
 
37
37
  if s.respond_to? :specification_version then
38
38
  s.specification_version = 3
@@ -41,29 +41,29 @@ Gem::Specification.new do |s|
41
41
  s.add_runtime_dependency(%q<jruby-openssl>, [">= 0"])
42
42
  s.add_runtime_dependency(%q<savon>, ["~> 0.9.7"])
43
43
  s.add_runtime_dependency(%q<log4r>, [">= 0"])
44
- s.add_runtime_dependency(%q<wtf_lang>, [">= 0"])
44
+ s.add_runtime_dependency(%q<wtf_lang>, ["~> 0.3.1"])
45
45
  s.add_development_dependency(%q<shoulda>, [">= 0"])
46
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
47
- s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
46
+ s.add_development_dependency(%q<bundler>, [">= 0"])
47
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
48
48
  s.add_development_dependency(%q<rcov>, [">= 0"])
49
49
  else
50
50
  s.add_dependency(%q<jruby-openssl>, [">= 0"])
51
51
  s.add_dependency(%q<savon>, ["~> 0.9.7"])
52
52
  s.add_dependency(%q<log4r>, [">= 0"])
53
- s.add_dependency(%q<wtf_lang>, [">= 0"])
53
+ s.add_dependency(%q<wtf_lang>, ["~> 0.3.1"])
54
54
  s.add_dependency(%q<shoulda>, [">= 0"])
55
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
56
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
55
+ s.add_dependency(%q<bundler>, [">= 0"])
56
+ s.add_dependency(%q<jeweler>, [">= 0"])
57
57
  s.add_dependency(%q<rcov>, [">= 0"])
58
58
  end
59
59
  else
60
60
  s.add_dependency(%q<jruby-openssl>, [">= 0"])
61
61
  s.add_dependency(%q<savon>, ["~> 0.9.7"])
62
62
  s.add_dependency(%q<log4r>, [">= 0"])
63
- s.add_dependency(%q<wtf_lang>, [">= 0"])
63
+ s.add_dependency(%q<wtf_lang>, ["~> 0.3.1"])
64
64
  s.add_dependency(%q<shoulda>, [">= 0"])
65
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66
- s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
65
+ s.add_dependency(%q<bundler>, [">= 0"])
66
+ s.add_dependency(%q<jeweler>, [">= 0"])
67
67
  s.add_dependency(%q<rcov>, [">= 0"])
68
68
  end
69
69
  end
data/lib/esendex4soap.rb CHANGED
@@ -6,74 +6,105 @@ require 'wtf_lang'
6
6
  module Esendex
7
7
  class Client
8
8
  include Log4r
9
- INBOX_SERVICE_WSDL = 'https://www.esendex.com/secure/messenger/soap/InboxService.asmx?wsdl'
10
- SEND_SERVICE_WSDL = 'https://www.esendex.com/secure/messenger/soap/SendService.asmx?wsdl'
11
-
12
- attr_accessor :username, :password, :account_reference
13
- attr_reader :sent_message_ids
14
-
15
- def initialize(*args)
16
- @username = args.shift
17
- @password = args.shift
18
- @account_reference = args.shift
19
- @sent_message_ids = []
20
-
21
- Savon.configure do |config|
9
+ INBOX_SERVICE_WSDL = 'https://www.esendex.com/secure/messenger/soap/InboxService.asmx?wsdl'
10
+ SEND_SERVICE_WSDL = 'https://www.esendex.com/secure/messenger/soap/SendService.asmx?wsdl'
11
+ ACCOUNT_SERVICE_WSDL = 'https://www.esendex.com/secure/messenger/soap/AccountService.asmx?wsdl'
12
+
13
+ attr_accessor :username, :password, :account_reference
14
+ attr_reader :sent_message_ids, :sent_message_statuses
15
+
16
+ def initialize(*args)
17
+ @username = args.shift
18
+ @password = args.shift
19
+ @account_reference = args.shift
20
+ @sent_message_ids, @sent_message_statuses = [], {}
21
+
22
+ Savon.configure do |config|
22
23
  config.raise_errors = true
23
24
  config.log = false
24
25
  config.log_level = :error
25
26
  HTTPI.log = false
26
- end
27
+ end
27
28
 
28
- @log = Logger.new "#{self.class.name}"
29
- @log.outputters = Outputter.stdout
30
- @log.level = ERROR
29
+ @log = Logger.new "#{self.class.name}"
30
+ @log.outputters = Outputter.stdout
31
+ @log.level = ERROR
31
32
 
32
- @message_kind = String.new
33
+ @message_kind = String.new
33
34
 
34
- end
35
+ end
35
36
 
36
- def send_message(recipient, text, originator, validityperiod)
37
- @log.debug "TO:#{recipient} text size:#{text.size} in #{text.full_lang} language"
38
- #TODO: handle other languages as well
39
- unless text.full_lang == 'russian'
40
- sms_parts = text.scan(/.{610}/mu)
41
- sms_parts << text[sms_parts.to_s.size..text.size]
42
- @message_kind = 'Text'
43
- @log.debug "#{@message_kind}:#{text.scan(/./mu)} = #{text.size}. #{sms_parts.size} part/s."
44
- sms(recipient, sms_parts, originator, validityperiod)
45
- else
46
- sms_parts = text.scan(/.{70}/mu)
47
- sms_parts << text[sms_parts.to_s.size..text.size]
48
- @message_kind = 'Unicode'
49
- @log.debug "#{@message_kind}:#{text.scan(/./mu)} != #{text.size}. #{sms_parts.size} part/s."
50
- sms(recipient, sms_parts, originator, validityperiod)
51
- end
37
+ def send_message(recipient, text, originator, validityperiod)
38
+ @log.debug "TO:#{recipient} text size:#{text.size} in #{text.full_lang} language"
39
+ #TODO: handle other languages as well
40
+ unless text.full_lang == 'russian'
41
+ sms_parts = text.scan(/.{610}/mu)
42
+ sms_parts << text[sms_parts.to_s.size..text.size]
43
+ @message_kind = 'Text'
44
+ @log.debug "#{@message_kind}:#{text.scan(/./mu)} = #{text.size}. #{sms_parts.size} part/s."
45
+ sms(recipient, sms_parts, originator, validityperiod)
46
+ else
47
+ sms_parts = text.scan(/.{70}/mu)
48
+ sms_parts << text[sms_parts.to_s.size..text.size]
49
+ @message_kind = 'Unicode'
50
+ @log.debug "#{@message_kind}:#{text.scan(/./mu)} != #{text.size}. #{sms_parts.size} part/s."
51
+ sms(recipient, sms_parts, originator, validityperiod)
52
52
  end
53
-
54
- private
55
- def connect
56
- @client = Savon::Client.new(SEND_SERVICE_WSDL)
57
- #http://jira.codehaus.org/browse/JRUBY-5529 - jruby-openssl in --1.9 jruby mode
58
- @client.http.auth.ssl.verify_mode=(:none)
53
+ end
54
+
55
+ def get_credit
56
+ client = Savon::Client.new(ACCOUNT_SERVICE_WSDL)
57
+ #http://jira.codehaus.org/browse/JRUBY-5529 - jruby-openssl in --1.9 jruby mode
58
+ client.http.auth.ssl.verify_mode=(:none)
59
+ resp = client.request :com, :get_message_limit do |soap|
60
+ soap.header["com:MessengerHeader"] = {"com:Username" => @username, "com:Password" => @password, "com:Account" => @account_reference}
59
61
  end
60
-
61
- def sms(recipient, messages, originator, validityperiod)
62
- @log.debug "#{@message_kind}:#{messages.size} parts."
63
- connect
64
- messages.each do |message|
65
- @log.debug "#{@message_kind}:#{message.size} bytes. Sending..."
66
- resp = @client.request :com, :send_message_full do |soap|
62
+ resp.to_hash[:get_message_limit_response][:get_message_limit_result].to_i
63
+ end
64
+
65
+ def get_status(*message_id)
66
+ connect unless @client
67
+
68
+ if message_id.size > 1
69
+ message_id.each do |id|
70
+ resp = @client.request :com, :get_message_status do |soap|
67
71
  soap.header["com:MessengerHeader"] = {"com:Username" => @username, "com:Password" => @password, "com:Account" => @account_reference}
68
- soap.body = {"com:recipient" => recipient, "com:body" => message, "com:type" => @message_kind, "com:originator" => originator, "com:validityperiod" => validityperiod}
72
+ soap.body = {"com:id" => id.to_s}
69
73
  end
70
- @log.debug "Sent #{@message_kind}:#{recipient}:#{message.size} bytes"
71
- @sent_message_ids << resp.to_hash[:send_message_full_response][:send_message_full_result]
74
+ @sent_message_statuses << resp.to_hash[:get_message_status_response][:get_message_status_result]
75
+ end
76
+ else
77
+ resp = @client.request :com, :get_message_status do |soap|
78
+ soap.header["com:MessengerHeader"] = {"com:Username" => @username, "com:Password" => @password, "com:Account" => @account_reference}
79
+ soap.body = {"com:id" => message_id.first}
80
+ end
81
+ resp.to_hash[:get_message_status_response][:get_message_status_result]
82
+ end
83
+ end
84
+
85
+ private
86
+ def connect
87
+ @client = Savon::Client.new(SEND_SERVICE_WSDL)
88
+ #http://jira.codehaus.org/browse/JRUBY-5529 - jruby-openssl in --1.9 jruby mode
89
+ @client.http.auth.ssl.verify_mode=(:none)
90
+ end
91
+
92
+ def sms(recipient, messages, originator, validityperiod)
93
+ @log.debug "#{@message_kind}:#{messages.size} parts."
94
+ connect
95
+ messages.each do |message|
96
+ @log.debug "#{@message_kind}:#{message.size} bytes. Sending..."
97
+ resp = @client.request :com, :send_message_full do |soap|
98
+ soap.header["com:MessengerHeader"] = {"com:Username" => @username, "com:Password" => @password, "com:Account" => @account_reference}
99
+ soap.body = {"com:recipient" => recipient, "com:body" => message, "com:type" => @message_kind, "com:originator" => originator, "com:validityperiod" => validityperiod}
72
100
  end
73
- @log.debug "-=| #{messages.join(' + ')} |=-"
74
- @log.debug "-----"
101
+ @log.debug "Sent #{@message_kind}:#{recipient}:#{message.size} bytes"
102
+ @sent_message_ids << resp.to_hash[:send_message_full_response][:send_message_full_result]
75
103
  end
76
-
104
+ @log.debug "-=| #{messages.join(' + ')} |=-"
105
+ @log.debug "-----"
106
+ end
107
+
77
108
  end #module Client
78
109
 
79
110
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: esendex4soap
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.4
5
+ version: 0.6.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Voip Scout
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-12-02 00:00:00 Z
13
+ date: 2012-02-26 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: jruby-openssl
@@ -50,9 +50,9 @@ dependencies:
50
50
  version_requirements: &id004 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
- - - ">="
53
+ - - ~>
54
54
  - !ruby/object:Gem::Version
55
- version: "0"
55
+ version: 0.3.1
56
56
  requirement: *id004
57
57
  prerelease: false
58
58
  type: :runtime
@@ -72,9 +72,9 @@ dependencies:
72
72
  version_requirements: &id006 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
- - - ~>
75
+ - - ">="
76
76
  - !ruby/object:Gem::Version
77
- version: 1.0.0
77
+ version: "0"
78
78
  requirement: *id006
79
79
  prerelease: false
80
80
  type: :development
@@ -83,9 +83,9 @@ dependencies:
83
83
  version_requirements: &id007 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
- - - ~>
86
+ - - ">="
87
87
  - !ruby/object:Gem::Version
88
- version: 1.6.4
88
+ version: "0"
89
89
  requirement: *id007
90
90
  prerelease: false
91
91
  type: :development
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
146
  requirements: []
147
147
 
148
148
  rubyforge_project:
149
- rubygems_version: 1.8.9
149
+ rubygems_version: 1.8.15
150
150
  signing_key:
151
151
  specification_version: 3
152
152
  summary: esendex SOAP-XML-API for ruby