Class: Paygent::Request
- Inherits:
-
Object
- Object
- Paygent::Request
- Defined in:
- lib/paygent/request.rb
Instance Attribute Summary collapse
-
#_params ⇒ Object
Returns the value of attribute _params.
-
#body_str ⇒ Object
Returns the value of attribute body_str.
-
#header_str ⇒ Object
Returns the value of attribute header_str.
-
#process_id ⇒ Object
Returns the value of attribute process_id.
-
#request ⇒ Object
Returns the value of attribute request.
-
#response_code ⇒ Object
Returns the value of attribute response_code.
Instance Method Summary collapse
- #body_hash ⇒ Object
-
#initialize(option = {}) ⇒ Request
constructor
A new instance of Request.
- #log(str) ⇒ Object
- #params ⇒ Object
- #params_str ⇒ Object
- #post ⇒ Object
- #replaceTelegramKana ⇒ Object
- #reqGet(key) ⇒ Object
- #reqPut(key, value) ⇒ Object
- #success_processed? ⇒ Boolean
- #success_response? ⇒ Boolean
- #valid? ⇒ Boolean
- #validateTelegramLengthCheck ⇒ Object
Constructor Details
#initialize(option = {}) ⇒ Request
8 9 10 11 12 13 |
# File 'lib/paygent/request.rb', line 8 def initialize(option={}) self._params ||= {} self._params.update(option) self.process_id = (rand * 100000000).to_i self end |
Instance Attribute Details
#_params ⇒ Object
Returns the value of attribute _params.
6 7 8 |
# File 'lib/paygent/request.rb', line 6 def _params @_params end |
#body_str ⇒ Object
Returns the value of attribute body_str.
6 7 8 |
# File 'lib/paygent/request.rb', line 6 def body_str @body_str end |
#header_str ⇒ Object
Returns the value of attribute header_str.
6 7 8 |
# File 'lib/paygent/request.rb', line 6 def header_str @header_str end |
#process_id ⇒ Object
Returns the value of attribute process_id.
6 7 8 |
# File 'lib/paygent/request.rb', line 6 def process_id @process_id end |
#request ⇒ Object
Returns the value of attribute request.
6 7 8 |
# File 'lib/paygent/request.rb', line 6 def request @request end |
#response_code ⇒ Object
Returns the value of attribute response_code.
6 7 8 |
# File 'lib/paygent/request.rb', line 6 def response_code @response_code end |
Instance Method Details
#body_hash ⇒ Object
97 98 99 100 101 |
# File 'lib/paygent/request.rb', line 97 def body_hash hash = {} body_str.scan(/\n(\w+)=(<!DOCTYPE.*?<\/HTML>|.*?)\r/m) { hash.update($1 => $2) } hash.with_indifferent_access end |
#log(str) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/paygent/request.rb', line 81 def log(str) if File.exist?(Paygent.log_output_path) File.open(Paygent.log_output_path, "a") do |file| file.puts "[#{process_id}][#{params[:trading_id]}] #{str}" end end end |
#params ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/paygent/request.rb', line 33 def params { :merchant_id => Paygent.merchant_id, :connect_id => Paygent.default_id, :connect_password => Paygent.default_password, :limit_count => Paygent.select_max_cnt, :telegram_version => Paygent.telegram_version, }.merge(_params || {}) end |
#params_str ⇒ Object
43 44 45 |
# File 'lib/paygent/request.rb', line 43 def params_str params.map{|f,k| "#{Curl::Easy.new.escape(f)}=#{Curl::Easy.new.escape(k)}"}.join('&') end |
#post ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/paygent/request.rb', line 47 def post telegram_kind = params[:telegram_kind] base_url = Paygent::Service.get_url_with_telegram_kind(telegram_kind) log("Can't found related paygent URL with #{telegram_kind}") unless base_url url = "#{base_url}?#{params_str}" c = Curl::Easy.new(url) c.cacert = Paygent.ca_file_path c.cert = Paygent.client_file_path c.certpassword = Paygent.cert_password c.connect_timeout = Paygent.timeout c.verbose = true c.ssl_verify_host = false c.multipart_form_post = true c.headers["Content-Type"] = "application/x-www-form-urlencoded" c.headers["charset"] = "Windows-31J" c.headers["User-Agent"] = "curl_php" c.http_post() self.response_code = c.response_code self.body_str = Iconv.conv('utf-8','Windows-31J', c.body_str) self.header_str = c.header_str self.request = c log("URL: #{url}") log("ResponseCode: #{response_code}") log("BODY: #{body_str}") log("HEAD: #{header_str}\n\n") return self end |
#replaceTelegramKana ⇒ Object
18 19 |
# File 'lib/paygent/request.rb', line 18 def replaceTelegramKana end |
#reqGet(key) ⇒ Object
29 30 31 |
# File 'lib/paygent/request.rb', line 29 def reqGet(key) params[key.to_sym] end |
#reqPut(key, value) ⇒ Object
24 25 26 27 |
# File 'lib/paygent/request.rb', line 24 def reqPut(key, value) _params ||= {} _params[key.to_sym] = value end |
#success_processed? ⇒ Boolean
93 94 95 |
# File 'lib/paygent/request.rb', line 93 def success_processed? body_hash[:result].to_i != 1 end |
#success_response? ⇒ Boolean
89 90 91 |
# File 'lib/paygent/request.rb', line 89 def success_response? response_code.to_i == 200 end |
#valid? ⇒ Boolean
15 16 |
# File 'lib/paygent/request.rb', line 15 def valid? end |
#validateTelegramLengthCheck ⇒ Object
21 22 |
# File 'lib/paygent/request.rb', line 21 def validateTelegramLengthCheck end |