Class: ActiveSmsgate::Gateway::Amegainform

Inherits:
Gateway
  • Object
show all
Defined in:
lib/active_smsgate/gateways/amegainform.rb

Overview

«Амега Информ» – amegainform.ru/

Defined Under Namespace

Modules: ResultSms

Constant Summary collapse

CLASS_ID =
'amegainform'
ALIAS =
'www.amegainform.ru'
SHORT_DESC =
'Шлюз sms рассылок www.amegainform.ru'
DESC =
"Описание шлюза"

Instance Attribute Summary

Attributes inherited from Gateway

#errors, #login, #password, #use_ssl

Instance Method Summary collapse

Methods inherited from Gateway

#uri, #use_of_backup_server?, #use_ssl?, #valid?

Constructor Details

#initialize(options = {}) ⇒ Amegainform

Адреса резервных серверов: service-r1.amegainform.ru и service-r2.amegainform.ru Создание нового шлюза AmegaInformGateway

  • :login – REQUIRED

  • :password – REQUIRED



61
62
63
64
# File 'lib/active_smsgate/gateways/amegainform.rb', line 61

def initialize(options = {})
  @options = options
  super
end

Instance Method Details

#balanceObject

Получение текущего баланса BALANCE [текущее состояние счёта] OVERDRAFT [максимальных уход в минус] PARENT_DEBT [задолженность]



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/active_smsgate/gateways/amegainform.rb', line 70

def balance
  response = self.class.post("#{uri}/sendsms",
                              :query => { :action => "balance"}.merge(auth_options))
  if response.code == 200
    xml = Zlib::GzipReader.new( StringIO.new( response ) ).read
    doc = Nokogiri::XML(xml)
    {
      :balance =>   (doc.at("//balance//AGT_BALANCE").inner_html rescue 0),
      :debt =>      (doc.at("//balance//PARENT_DEBT").inner_html rescue 0),
      :overdraft => (doc.at("//balance//OVERDRAFT").inner_html   rescue 0)
    }
  else
    raise
  end
rescue
  nil
end

#deliver_sms(options = { :sender => nil}) ⇒ Object

Возвращаемые параметры sms_id - ид в сервисе шлюза sms_count - сколько смс потрачено на отправку сообщения phone - номер куда было отправлено сообщение Если @errors не пустое то возвращает nil



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/active_smsgate/gateways/amegainform.rb', line 102

def deliver_sms(options = { :sender => nil})
  @options = {
    :action  => "post_sms", :message => options[:message],
    :target  => options[:phones], :sender  => options[:sender] }

  response = self.class.post("#{uri}/sendsms", :query => @options.merge(auth_options))
  xml = Zlib::GzipReader.new( StringIO.new( response ) ).read
  if response.code == 200
    parse(xml)[:sms]
  else
    raise
  end
rescue
  STDERR.puts  " #{$!.inspect} "
  STDERR.puts  " #{xml} " if xml
  nil
end

#reply_sms(sms_id, sms_type = :sms) ⇒ Object

Возвращаем hash где обязательно есть sms_id - ид в сервисе шлюза sms_count - кол-во смс потраченное на отправку сообщения phone - телефон



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/active_smsgate/gateways/amegainform.rb', line 132

def reply_sms(sms_id, sms_type = :sms)
  raise unless [:sms, :sms_group].include?(sms_type)

  @options = { :action => "status", :sendtype => "SENDSMS", "#{sms_type}_id".to_sym => sms_id }
  response = self.class.post("#{uri}/sendsms", :query => @options.merge(auth_options))
  xml = Zlib::GzipReader.new( StringIO.new( response ) ).read
  if response.code == 200
    parse(xml)[:messages]
  else
    raise
  end
rescue
  STDERR.puts  " #{$!.inspect} "
  STDERR.puts  " #{xml} " if xml
  false
end