module Sfctl::Starfish::Client
Public Class Methods
account_assignments(endpoint, all, token)
click to toggle source
# 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)
click to toggle source
# File lib/sfctl/starfish/client.rb, line 29 def self.account_info(endpoint, token) response = conn(endpoint, token).get('profile') parsed_response(response) end
conn(endpoint, token)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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