Class: RogIQ::HttpApi
- Inherits:
-
Object
- Object
- RogIQ::HttpApi
- Defined in:
- lib/rogiq/http_api.rb
Defined Under Namespace
Classes: Error
Class Method Summary collapse
Instance Method Summary collapse
- #get(path, query = {}) ⇒ Object
-
#initialize(base:, token:, account_id: nil) ⇒ HttpApi
constructor
A new instance of HttpApi.
- #post(path, body = nil, query: {}) ⇒ Object
Constructor Details
#initialize(base:, token:, account_id: nil) ⇒ HttpApi
Returns a new instance of HttpApi.
27 28 29 30 31 |
# File 'lib/rogiq/http_api.rb', line 27 def initialize(base:, token:, account_id: nil) @base = base.to_s.chomp("/") @token = token @account_id = account_id end |
Class Method Details
.from_config! ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/rogiq/http_api.rb', line 19 def self.from_config! base = RogIQ::ConfigStore.api_base_url token = RogIQ::ConfigStore.token raise Error, "Not logged in. Run: rogiq login" if base.nil? || token.nil? new(base: base, token: token, account_id: RogIQ::ConfigStore.account_id) end |
Instance Method Details
#get(path, query = {}) ⇒ Object
33 34 35 |
# File 'lib/rogiq/http_api.rb', line 33 def get(path, query = {}) request(Net::HTTP::Get, path, query: query) end |
#post(path, body = nil, query: {}) ⇒ Object
37 38 39 |
# File 'lib/rogiq/http_api.rb', line 37 def post(path, body = nil, query: {}) request(Net::HTTP::Post, path, query: query, body: body) end |