Module: Sfctl::Starfish::Client
- Defined in:
- lib/sfctl/starfish/client.rb
Class Method Summary collapse
- .account_assignments(endpoint, all, token) ⇒ Object
- .account_info(endpoint, token) ⇒ Object
- .check_authorization(endpoint, token) ⇒ Object
- .conn(endpoint, token) ⇒ Object
- .next_report(endpoint, token, assignment_id) ⇒ Object
- .parsed_response(response) ⇒ Object
- .update_next_report(endpoint, token, assignment_id, items) ⇒ Object
Class Method Details
.account_assignments(endpoint, all, token) ⇒ Object
34 35 36 37 38 |
# File 'lib/sfctl/starfish/client.rb', line 34 def self.account_assignments(endpoint, all, token) api_conn = conn(endpoint, token) response = all ? api_conn.get('assignments?all=1') : api_conn.get('assignments') parsed_response(response) end |
.account_info(endpoint, token) ⇒ Object
29 30 31 32 |
# File 'lib/sfctl/starfish/client.rb', line 29 def self.account_info(endpoint, token) response = conn(endpoint, token).get('profile') parsed_response(response) end |
.check_authorization(endpoint, token) ⇒ Object
24 25 26 27 |
# File 'lib/sfctl/starfish/client.rb', line 24 def self.(endpoint, token) response = conn(endpoint, token).get('profile') response.status == 200 end |
.conn(endpoint, token) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/sfctl/starfish/client.rb', line 7 def self.conn(endpoint, token) raise 'Before continue please pass endpoint and token.' if endpoint.nil? || token.nil? headers = { 'Content-Type' => 'application/json', 'X-Starfish-Auth' => token } Faraday.new(url: "#{endpoint}/api/v1", headers: headers) do |builder| builder.request :retry builder.adapter :net_http end end |
.next_report(endpoint, token, assignment_id) ⇒ Object
40 41 42 43 44 |
# File 'lib/sfctl/starfish/client.rb', line 40 def self.next_report(endpoint, token, assignment_id) api_conn = conn(endpoint, token) response = api_conn.get("assignments/#{assignment_id}/next_report") parsed_response(response) end |
.parsed_response(response) ⇒ Object
20 21 22 |
# File 'lib/sfctl/starfish/client.rb', line 20 def self.parsed_response(response) [response.status == 200, JSON.parse(response.body)] end |
.update_next_report(endpoint, token, assignment_id, items) ⇒ Object
46 47 48 49 50 |
# File 'lib/sfctl/starfish/client.rb', line 46 def self.update_next_report(endpoint, token, assignment_id, items) api_conn = conn(endpoint, token) response = api_conn.put("assignments/#{assignment_id}/next_report", JSON.generate(items: items)) response.status == 204 end |