Class: EmergeCLI::Network
- Inherits:
-
Object
- Object
- EmergeCLI::Network
- Defined in:
- lib/utils/network.rb
Constant Summary collapse
- EMERGE_API_PROD_URL =
'api.emergetools.com'.freeze
- RETRY_DELAY =
5
- MAX_RETRIES =
3
Instance Method Summary collapse
- #close ⇒ Object
- #get(path:, headers: {}, max_retries: MAX_RETRIES) ⇒ Object
-
#initialize(api_token: nil, base_url: EMERGE_API_PROD_URL) ⇒ Network
constructor
A new instance of Network.
- #post(path:, body:, headers: {}, query: nil, max_retries: MAX_RETRIES) ⇒ Object
- #put(path:, body:, headers: {}, max_retries: MAX_RETRIES) ⇒ Object
Constructor Details
#initialize(api_token: nil, base_url: EMERGE_API_PROD_URL) ⇒ Network
Returns a new instance of Network.
14 15 16 17 18 |
# File 'lib/utils/network.rb', line 14 def initialize(api_token: nil, base_url: EMERGE_API_PROD_URL) @base_url = base_url @api_token = api_token @internet = Async::HTTP::Internet.new end |
Instance Method Details
#close ⇒ Object
32 33 34 |
# File 'lib/utils/network.rb', line 32 def close @internet.close end |
#get(path:, headers: {}, max_retries: MAX_RETRIES) ⇒ Object
20 21 22 |
# File 'lib/utils/network.rb', line 20 def get(path:, headers: {}, max_retries: MAX_RETRIES) request(:get, path, nil, headers, nil, max_retries) end |
#post(path:, body:, headers: {}, query: nil, max_retries: MAX_RETRIES) ⇒ Object
24 25 26 |
# File 'lib/utils/network.rb', line 24 def post(path:, body:, headers: {}, query: nil, max_retries: MAX_RETRIES) request(:post, path, body, headers, query, max_retries) end |
#put(path:, body:, headers: {}, max_retries: MAX_RETRIES) ⇒ Object
28 29 30 |
# File 'lib/utils/network.rb', line 28 def put(path:, body:, headers: {}, max_retries: MAX_RETRIES) request(:put, path, body, headers, nil, max_retries) end |