Class: ParichkiBg::Request::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/parichki_bg/request/base.rb

Direct Known Subclasses

Query, Transaction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
# File 'lib/parichki_bg/request/base.rb', line 7

def initialize(attributes = {})
  @amount = attributes.fetch :amount
  @pin = attributes.fetch :pin
  @user_id = attributes.fetch :user_id
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



5
6
7
# File 'lib/parichki_bg/request/base.rb', line 5

def amount
  @amount
end

#pinObject (readonly)

Returns the value of attribute pin.



5
6
7
# File 'lib/parichki_bg/request/base.rb', line 5

def pin
  @pin
end

#user_idObject (readonly)

Returns the value of attribute user_id.



5
6
7
# File 'lib/parichki_bg/request/base.rb', line 5

def user_id
  @user_id
end

Instance Method Details

#checksumObject



28
29
30
# File 'lib/parichki_bg/request/base.rb', line 28

def checksum
  ParichkiBg.hmac to_json
end

#encoded_checksumObject



32
33
34
# File 'lib/parichki_bg/request/base.rb', line 32

def encoded_checksum
  Base64.strict_encode64 checksum
end

#encoded_dataObject



36
37
38
# File 'lib/parichki_bg/request/base.rb', line 36

def encoded_data
  Base64.strict_encode64 to_json
end

#httpsObject



13
14
15
16
17
18
# File 'lib/parichki_bg/request/base.rb', line 13

def https
  @http ||= Net::HTTP.new uri.host, uri.port
  @http.use_ssl = true
  @http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  @http
end

#resultObject



40
41
42
43
44
45
46
# File 'lib/parichki_bg/request/base.rb', line 40

def result
  if success?
    ActiveSupport::JSON.decode @response.body
  else
    {"error" => "UserNotFound"}
  end
end

#sendObject



20
21
22
# File 'lib/parichki_bg/request/base.rb', line 20

def send
  @response = https.get uri.request_uri
end

#signed_requestObject



24
25
26
# File 'lib/parichki_bg/request/base.rb', line 24

def signed_request
  encoded_checksum + "." + encoded_data
end