class Onena::Client
Public Class Methods
new(tock_api_key: nil, float_api_key: nil, tock_api_endpoint: nil)
click to toggle source
# File lib/onena/client.rb, line 6 def initialize(tock_api_key: nil, float_api_key: nil, tock_api_endpoint: nil) @tock_api_key = tock_api_key || ENV['TOCK_API_KEY'] @float_api_key = float_api_key || ENV['FLOAT_API_KEY'] @tock_api_endpoint = tock_api_endpoint || ENV['TOCK_API_ENDPOINT'] || Onena::Protocol::TOCK_API_BASE_URL fail Onena::Error::ArgumentMissing, 'Float API key is missing' if @float_api_key.nil? end
Public Instance Methods
float_client_names()
click to toggle source
# File lib/onena/client.rb, line 33 def float_client_names float_projects = get_float_projects clients = float_projects['projects'].map { |project| project['client_name'] } clients.uniq.compact end
float_project_client_names()
click to toggle source
# File lib/onena/client.rb, line 45 def float_project_client_names float_projects = get_float_projects project_clients = float_projects['projects'].map { |project| "#{project['project_name']} -> #{project['client_name']}" } project_clients.uniq.compact end
float_project_names()
click to toggle source
# File lib/onena/client.rb, line 23 def float_project_names float_projects = get_float_projects float_projects['projects'].map { |project| project['project_name'] } end
float_user_names()
click to toggle source
# File lib/onena/client.rb, line 13 def float_user_names float_users = get_float_users float_users['people'].map { |user| user['name'] } end
possible_client_matches()
click to toggle source
# File lib/onena/client.rb, line 65 def possible_client_matches Onena::Util.matches(tock_list: tock_client_names, float_list: float_client_names) end
possible_project_client_matches()
click to toggle source
# File lib/onena/client.rb, line 69 def possible_project_client_matches Onena::Util.matches(tock_list: tock_project_client_names, float_list: float_project_client_names) end
possible_project_matches()
click to toggle source
# File lib/onena/client.rb, line 61 def possible_project_matches Onena::Util.matches(tock_list: tock_project_names, float_list: float_project_names) end
possible_user_matches()
click to toggle source
# File lib/onena/client.rb, line 57 def possible_user_matches Onena::Util.matches(tock_list: tock_user_names, float_list: float_user_names) end
print_possible_matches()
click to toggle source
# File lib/onena/client.rb, line 82 def print_possible_matches tagged_possible_matches.each { |match| $stdout.puts match.to_json } end
tagged_possible_matches()
click to toggle source
# File lib/onena/client.rb, line 73 def tagged_possible_matches [tag_matches(matches: possible_user_matches, type: :user), tag_matches(matches: possible_project_matches, type: :project), tag_matches(matches: possible_client_matches, type: :client), tag_matches(matches: possible_project_client_matches, type: :"project-client")] .flatten .compact end
tock_client_names()
click to toggle source
# File lib/onena/client.rb, line 39 def tock_client_names tock_projects = get_tock_projects clients = tock_projects['results'].map { |project| project['client'] } clients.uniq end
tock_project_client_names()
click to toggle source
# File lib/onena/client.rb, line 51 def tock_project_client_names tock_projects = get_tock_projects project_clients = tock_projects['results'].map { |project| "#{project['name']} -> #{project['client']}" } project_clients.uniq end
tock_project_names()
click to toggle source
# File lib/onena/client.rb, line 28 def tock_project_names tock_projects = get_tock_projects tock_projects['results'].map { |project| project['name'] } end
tock_user_names()
click to toggle source
# File lib/onena/client.rb, line 18 def tock_user_names tock_users = get_tock_users tock_users['results'].map { |user| [user['first_name'], user['last_name']].join(' ').strip } end
Private Instance Methods
fetch_float_projects()
click to toggle source
# File lib/onena/client.rb, line 134 def fetch_float_projects url = Onena::Protocol.float_projects_url Curl.get(url) do |http| http.headers['Authorization'] = @float_api_key end end
fetch_float_users()
click to toggle source
# File lib/onena/client.rb, line 122 def fetch_float_users url = Onena::Protocol.float_users_url Curl.get(url) do |http| http.headers['Authorization'] = @float_api_key end end
fetch_tock_projects()
click to toggle source
# File lib/onena/client.rb, line 129 def fetch_tock_projects url = Onena::Protocol.tock_projects_url(endpoint: @tock_api_endpoint) tock_request(url) end
fetch_tock_users()
click to toggle source
# File lib/onena/client.rb, line 117 def fetch_tock_users url = Onena::Protocol.tock_users_url(endpoint: @tock_api_endpoint) tock_request(url) end
get_float_projects()
click to toggle source
# File lib/onena/client.rb, line 98 def get_float_projects response = fetch_float_projects JSON.parse(response.body_str) end
get_float_users()
click to toggle source
# File lib/onena/client.rb, line 88 def get_float_users response = fetch_float_users JSON.parse(response.body_str) end
get_tock_projects()
click to toggle source
# File lib/onena/client.rb, line 103 def get_tock_projects response = fetch_tock_projects JSON.parse(response.body_str) end
get_tock_users()
click to toggle source
# File lib/onena/client.rb, line 93 def get_tock_users response = fetch_tock_users JSON.parse(response.body_str) end
tag_matches(matches: [], type: nil)
click to toggle source
# File lib/onena/client.rb, line 141 def tag_matches(matches: [], type: nil) matches.map { |match| match.merge(type: type) } end
tock_request(url)
click to toggle source
# File lib/onena/client.rb, line 108 def tock_request(url) Curl.get(url) do |http| # Authentication is done against production endpoint, # https://tock.18f.gov/api/, by copying the cookie generated by # oauth2_proxy http.headers['Cookie'] = '_oauth2_proxy=' + @tock_api_key unless @tock_api_key.nil? end end