Class: Fireblocks::Request
- Inherits:
-
Object
- Object
- Fireblocks::Request
- Defined in:
- lib/fireblocks/api/request.rb
Overview
Interface to GET, POST, PUT
Constant Summary collapse
- Error =
Class.new(StandardError)
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
-
#uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
Instance Method Summary collapse
- #get(body) ⇒ Object
-
#initialize(path:) ⇒ Request
constructor
A new instance of Request.
- #post(body) ⇒ Object
- #put(body) ⇒ Object
Constructor Details
#initialize(path:) ⇒ Request
Returns a new instance of Request.
25 26 27 28 |
# File 'lib/fireblocks/api/request.rb', line 25 def initialize(path:) @path = path @uri = URI("#{Fireblocks.configuration.base_url}#{path}") end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
23 24 25 |
# File 'lib/fireblocks/api/request.rb', line 23 def path @path end |
#uri ⇒ Object
Returns the value of attribute uri.
23 24 25 |
# File 'lib/fireblocks/api/request.rb', line 23 def uri @uri end |
Class Method Details
.get(path:, body: '') ⇒ Object
10 11 12 |
# File 'lib/fireblocks/api/request.rb', line 10 def get(path:, body: '') new(path: path).get(body) end |
.post(path:, body:) ⇒ Object
18 19 20 |
# File 'lib/fireblocks/api/request.rb', line 18 def post(path:, body:) new(path: path).post(body) end |
.put(path:, body:) ⇒ Object
14 15 16 |
# File 'lib/fireblocks/api/request.rb', line 14 def put(path:, body:) new(path: path).put(body) end |
Instance Method Details
#get(body) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/fireblocks/api/request.rb', line 30 def get(body) req = Net::HTTP::Get.new(uri) request_headers(body).each { |rk, rv| req[rk] = rv } valid_response!(send_request(req)) end |
#post(body) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/fireblocks/api/request.rb', line 45 def post(body) req = Net::HTTP::Post.new(uri) request_headers(body).each { |rk, rv| req[rk] = rv } req.body = body.to_json valid_response!(send_request(req)) end |
#put(body) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/fireblocks/api/request.rb', line 37 def put(body) req = Net::HTTP::Put.new(uri) request_headers(body).each { |rk, rv| req[rk] = rv } req.body = body.to_json valid_response!(send_request(req)) end |