Class: Morpheus::AccountsInterface
- Inherits:
-
APIClient
- Object
- APIClient
- Morpheus::AccountsInterface
- Defined in:
- lib/morpheus/api/accounts_interface.rb
Instance Method Summary collapse
- #create(options) ⇒ Object
- #destroy(id) ⇒ Object
- #get(id) ⇒ Object
-
#initialize(access_token, refresh_token, expires_at = nil, base_url = nil) ⇒ AccountsInterface
constructor
A new instance of AccountsInterface.
- #list(options = {}) ⇒ Object
- #update(id, options) ⇒ Object
Constructor Details
#initialize(access_token, refresh_token, expires_at = nil, base_url = nil) ⇒ AccountsInterface
Returns a new instance of AccountsInterface.
5 6 7 8 9 10 |
# File 'lib/morpheus/api/accounts_interface.rb', line 5 def initialize(access_token, refresh_token,expires_at = nil, base_url=nil) @access_token = access_token @refresh_token = refresh_token @base_url = base_url @expires_at = expires_at end |
Instance Method Details
#create(options) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/morpheus/api/accounts_interface.rb', line 30 def create() url = "#{@base_url}/api/accounts" headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } payload = response = Morpheus::RestClient.execute(method: :post, url: url, timeout: 10, headers: headers, payload: payload.to_json) JSON.parse(response.to_s) end |
#destroy(id) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/morpheus/api/accounts_interface.rb', line 48 def destroy(id) url = "#{@base_url}/api/accounts/#{id}" headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } response = Morpheus::RestClient.execute(method: :delete, url: url, timeout: 10, headers: headers) JSON.parse(response.to_s) end |
#get(id) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/morpheus/api/accounts_interface.rb', line 12 def get(id) raise "#{self.class}.get() passed a blank id!" if id.to_s == '' url = "#{@base_url}/api/accounts/#{id}" headers = { params: {}, authorization: "Bearer #{@access_token}" } response = Morpheus::RestClient.execute(method: :get, url: url, timeout: 10, headers: headers) JSON.parse(response.to_s) end |
#list(options = {}) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/morpheus/api/accounts_interface.rb', line 21 def list(={}) url = "#{@base_url}/api/accounts" headers = { params: {}, authorization: "Bearer #{@access_token}" } headers[:params].merge!() response = Morpheus::RestClient.execute(method: :get, url: url, timeout: 10, headers: headers) JSON.parse(response.to_s) end |
#update(id, options) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/morpheus/api/accounts_interface.rb', line 39 def update(id, ) url = "#{@base_url}/api/accounts/#{id}" headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' } payload = response = Morpheus::RestClient.execute(method: :put, url: url, timeout: 10, headers: headers, payload: payload.to_json) JSON.parse(response.to_s) end |