active_smsgate 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -3,7 +3,7 @@
3
3
  Description goes here.
4
4
 
5
5
  == Note on Patches/Pull Requests
6
-
6
+
7
7
  * Fork the project.
8
8
  * Make your feature addition or bug fix.
9
9
  * Add tests for it. This is important so I don't break it in a
@@ -12,6 +12,4 @@ Description goes here.
12
12
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
13
  * Send me a pull request. Bonus points for topic branches.
14
14
 
15
- == Copyright
16
15
 
17
- Copyright (c) 2010 Pechnikov Maxim. See LICENSE for details.
@@ -42,9 +42,8 @@ module ActiveSmsgate #:nodoc:
42
42
  # в течение которого было установлено соединение для отправки сообщения.
43
43
  # SMS_DTMF_DIGITS - Что пользователь нажимал в сеансе разговора (для SENDVOICE (в разработке))
44
44
  # SMS_CLOSE_TIME - Время завершения работы по сообщению.
45
-
46
-
47
45
  =end
46
+
48
47
  class Amegainform < Gateway
49
48
 
50
49
  CLASS_ID = 'amegainform'
@@ -56,7 +55,6 @@ module ActiveSmsgate #:nodoc:
56
55
  base_uri 'http://service.amega-inform.ru'
57
56
 
58
57
  # Адреса резервных серверов: service-r1.amegainform.ru и service-r2.amegainform.ru
59
-
60
58
  # Создание нового шлюза AmegaInformGateway
61
59
  # * <tt>:login</tt> -- REQUIRED
62
60
  # * <tt>:password</tt> -- REQUIRED
@@ -111,9 +109,6 @@ module ActiveSmsgate #:nodoc:
111
109
  xml = Zlib::GzipReader.new( StringIO.new( response ) ).read
112
110
  if response.code == 200
113
111
  parse(xml)
114
- @sms.map{|x| x.merge({ :sms_group_id => x[:sms_group_id],
115
- :sms_id => x[:id], :phone => x[:phone], :sms_count => x[:sms_res_count] })}
116
-
117
112
  else
118
113
  raise
119
114
  end
@@ -143,13 +138,6 @@ module ActiveSmsgate #:nodoc:
143
138
  xml = Zlib::GzipReader.new( StringIO.new( response ) ).read
144
139
  if response.code == 200
145
140
  parse(xml)
146
- if sms_type == :sms
147
- @messages.map{ |msg| msg.merge({ :sms_id => msg[:sms_id],:sms_count => msg[:sms_res_count],
148
- :phone => msg[:sms_target] }) }.find{ |x| x[:sms_id] == sms_id.to_s }
149
- else
150
- @messages.map{ |msg| msg.merge({ :sms_id => msg[:sms_id],
151
- :sms_count => msg[:sms_res_count], :phone => msg[:sms_target] }) }
152
- end
153
141
  else
154
142
  raise
155
143
  end
@@ -159,27 +147,6 @@ module ActiveSmsgate #:nodoc:
159
147
  false
160
148
  end
161
149
 
162
- # Выполнение отправки смс завершено
163
- def complete_sms(sms_id)
164
- @message ||= reply_sms(sms_id)
165
- true if @message[:sms_closed].to_i == 1
166
- end
167
- alias :complete_sms? :complete_sms
168
-
169
- # Смс досталена
170
- def success_sms(sms_id)
171
- @message ||= reply_sms(sms_id)
172
- true if @message[:sms_sent].to_i == 1
173
- end
174
- alias :success_sms? :success_sms
175
-
176
- # Смс не доставлена
177
- def failure_sms(sms_id)
178
- @message ||= reply_sms(sms_id)
179
- true if @message[:sms_sent].to_i != 1
180
- end
181
- alias :failure_sms? :failure_sms
182
-
183
150
  private
184
151
 
185
152
  # Возвращает параметры для авторизации
@@ -189,23 +156,24 @@ module ActiveSmsgate #:nodoc:
189
156
  def parse(xml)
190
157
  doc = Nokogiri::XML(xml)
191
158
  @sms, @messages, @errors = nil, nil, nil
159
+
192
160
  # Ответ от отправка смс
193
161
  @sms = doc.at("//output//result") && doc.at("//output//result").
194
162
  children.search("//sms").map {|x|
195
- _x ={}
196
- doc.at("//output//result").each { |v,l| _x[v.downcase.to_sym] = l }
197
- x.each { |v,l| _x[v.downcase.to_sym] = l }
198
- _x[:text] = x.inner_html
199
- _x
163
+ hash = { }
164
+ doc.at("//output//result").each { |v,l| hash[v.downcase.to_sym] = l }
165
+ x.each { |v,l| hash[v.downcase.to_sym] = l }
166
+ hash[:text] = x.inner_html
167
+ ::ResultSms::Result.new(hash.merge({ :sms_id => hash[:id], :sms_count => x[:sms_res_count]}))
200
168
  }
201
169
 
202
170
  # Сообщения о доставках смс
203
171
  @messages = doc.at("//output//MESSAGES") && doc.at("//output//MESSAGES").
204
172
  children.search("//MESSAGE").map { |x|
205
- _x = { }
206
- x.each { |v,l| _x[v.downcase.to_sym] = l }
207
- x.children.each {|n| _x[n.name.downcase.to_sym] = n.inner_html unless n.blank? }
208
- _x
173
+ hash = { }
174
+ x.each { |v,l| hash[v.downcase.to_sym] = l }
175
+ x.children.each {|n| hash[n.name.downcase.to_sym] = n.inner_html unless n.blank? }
176
+ ::ResultSms::Message.new(hash.merge({ :phone => hash[:sms_target], :sms_count => hash[:sms_res_count] }))
209
177
  }
210
178
 
211
179
  # Сообщения об ошибках
@@ -214,6 +182,26 @@ module ActiveSmsgate #:nodoc:
214
182
 
215
183
  { :sms => @sms, :messages => @messages, :errors => @errors}
216
184
  end
185
+
186
+ module ResultSms
187
+ class Message < OpenStruct
188
+ def complete; true if sms_closed.to_i == 1; end
189
+ alias :complete? :complete
190
+
191
+ def success; true if sms_sent.to_i == 1; end
192
+ alias :success? :success
193
+
194
+ def failure; true unless success?; end
195
+ alias :failure? :failure
196
+ define_method(:id){ @table[:id] || object_id}
197
+ end
198
+ class Result < OpenStruct;
199
+ define_method(:id){ @table[:id] || object_id}
200
+ end
201
+ end
202
+
217
203
  end
218
204
  end
219
205
  end
206
+
207
+
@@ -7,6 +7,7 @@ require 'nokogiri'
7
7
  require 'digest'
8
8
  require "zlib"
9
9
  require 'active_resource'
10
+ require 'ostruct'
10
11
 
11
12
  require "active_smsgate/gateway"
12
13
  Dir[File.join(File.dirname(__FILE__), 'active_smsgate','gateways','**','*.rb')].each { |gw| require gw }
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Pechnikov Maxim
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-13 00:00:00 +06:00
17
+ date: 2010-05-14 00:00:00 +06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -78,13 +78,11 @@ executables: []
78
78
  extensions: []
79
79
 
80
80
  extra_rdoc_files:
81
- - LICENSE
82
81
  - README.rdoc
83
82
  files:
84
83
  - lib/active_smsgate.rb
85
84
  - lib/active_smsgate/gateway.rb
86
85
  - lib/active_smsgate/gateways/amegainform.rb
87
- - LICENSE
88
86
  - README.rdoc
89
87
  has_rdoc: true
90
88
  homepage: http://github.com/pronix/active_smsgate
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Copyright (c) 2009 Pechnikov Maxim
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.