Class: Dibuk::HttpRequest
- Inherits:
-
Object
- Object
- Dibuk::HttpRequest
- Extended by:
- Dry::Initializer::Mixin
- Defined in:
- lib/dibuk/http_request.rb
Constant Summary collapse
- ENDPOINT_URL =
'https://agregator.dibuk.eu/2_3/call.php'.freeze
- ENDPOINT_SANDBOX_URL =
'https://sandbox.dibuk.eu/agregator/2_3/call.php'.freeze
Instance Method Summary collapse
Instance Method Details
#body_sign ⇒ Object
38 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/dibuk/http_request.rb', line 38 def body_sign params = { :a => request.action, :v => ::Dibuk::API_VERSION, :did => seller_id } request.body.each do |key, value| params[key] = value end query = '' params.each do |key, value| query += '&' unless query == '' query += key.to_s query += '=' + CGI.escape(value) end #ph = Faraday::Utils::ParamsHash.new #ph.update(params) #puts ph.to_query wrong, changing order of keys params[:ch] = OpenSSL::HMAC.hexdigest("sha1", Base64.decode64(signature), query) params end |
#call ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dibuk/http_request.rb', line 15 def call # pr endpoint # pr body_sign uri = URI(endpoint) net_http = Net::HTTP.new(uri.host, uri.port) net_http.use_ssl=true request = Net::HTTP::Post.new(uri) net_http.start do |http| post_data = URI.encode_www_form(body_sign) http.request(request, post_data) end end |
#endpoint ⇒ Object
30 31 32 |
# File 'lib/dibuk/http_request.rb', line 30 def endpoint sandbox? ? ENDPOINT_SANDBOX_URL : ENDPOINT_URL end |
#sandbox? ⇒ Boolean
34 35 36 |
# File 'lib/dibuk/http_request.rb', line 34 def sandbox? sandbox end |