Class: Bluepay::Request

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

Constant Summary collapse

HOST =
'secure.bluepay.com'.freeze
PORT =
443.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action) ⇒ Request

Returns a new instance of Request.



10
11
12
# File 'lib/bluepay/request.rb', line 10

def initialize(action)
  @action = action
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



8
9
10
# File 'lib/bluepay/request.rb', line 8

def action
  @action
end

Instance Method Details

#execute!Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bluepay/request.rb', line 14

def execute!
  uri = URI::HTTPS.build(
    host: HOST,
    path: action.path
  )

  req = Net::HTTP::Post.new(uri)
  req.set_form_data(action.data)
  req['User-Agent'] = 'BluepayRB Ruby Client'
  req['Content-Type'] = 'application/x-www-form-urlencoded'

  res = Net::HTTP.start(
    HOST, PORT,
    use_ssl: true,
  ) { |http| http.request(req) }

  Response.new(res)
end