Class: Eport
- Inherits:
-
Object
- Object
- Eport
- Defined in:
- lib/eport.rb
Instance Method Summary collapse
- #get_balance ⇒ Object
- #get_catalog ⇒ Object
-
#initialize ⇒ Eport
constructor
A new instance of Eport.
- #refill_operation(operation_name, operation_id, product_id, value, account) ⇒ Object
Constructor Details
#initialize ⇒ Eport
Returns a new instance of Eport.
6 7 8 9 |
# File 'lib/eport.rb', line 6 def initialize config_file = File.join(RAILS_ROOT, 'config', 'eport.yml') @config = YAML.load(IO.read(config_file)) end |
Instance Method Details
#get_balance ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/eport.rb', line 26 def get_balance req = Request.new do |r| r.point = @config[:eport][:point] r.private_key_path = "#{RAILS_ROOT}/#{@config[:eport][:private_key_path]}" r.host = @config[:eport][:host] r.path = "/cp/bal" r.body = "" end ic = Iconv.new('UTF-8', 'WINDOWS-1251') ic.iconv(req.confirm) end |
#get_catalog ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/eport.rb', line 11 def get_catalog req = Request.new do |r| r.point = @config[:eport][:point] r.private_key_path = "#{RAILS_ROOT}/#{@config[:eport][:private_key_path]}" r.host = @config[:eport][:host] r.path = "/cp/dir" r.body = "" end data = req.confirm cp = CatalogParser.new cp.new_catalog(data) end |
#refill_operation(operation_name, operation_id, product_id, value, account) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/eport.rb', line 39 def refill_operation(operation_name, operation_id, product_id, value, account) req = Request.new do |r| r.point = @config[:eport][:point] r.private_key_path = "#{RAILS_ROOT}/#{@config[:eport][:private_key_path]}" r.host = @config[:eport][:host] r.path = "/cp/fe" req = EportRequestPlainText.new req.operation_type = operation_name.to_s.upcase if [:operation, :confirm, :check, :cancel].include?(operation_name) req.operation_id = operation_id req.product_id = product_id req.value = value req.account = account r.body = req.body end ic = Iconv.new('UTF-8', 'WINDOWS-1251') res = ic.iconv(req.confirm).split("RESULT\r\n")[1..-1].collect{|o| Hash[o.split("\r\n").collect{|o| o.split("=")}].symbolize_keys} res.inject({}){|h,o| h = o if o[:id] == operation_id.to_s ;h} end |