Class: Onena::Client
- Inherits:
-
Object
- Object
- Onena::Client
- Defined in:
- lib/onena/client.rb
Instance Method Summary collapse
- #float_client_names ⇒ Object
- #float_project_client_names ⇒ Object
- #float_project_names ⇒ Object
- #float_user_names ⇒ Object
-
#initialize(tock_api_key: nil, float_api_key: nil, tock_api_endpoint: nil) ⇒ Client
constructor
A new instance of Client.
- #possible_client_matches ⇒ Object
- #possible_project_client_matches ⇒ Object
- #possible_project_matches ⇒ Object
- #possible_user_matches ⇒ Object
- #print_possible_matches ⇒ Object
- #tagged_possible_matches ⇒ Object
- #tock_client_names ⇒ Object
- #tock_project_client_names ⇒ Object
- #tock_project_names ⇒ Object
- #tock_user_names ⇒ Object
Constructor Details
#initialize(tock_api_key: nil, float_api_key: nil, tock_api_endpoint: nil) ⇒ Client
Returns a new instance of Client.
6 7 8 9 10 11 |
# 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 |
Instance Method Details
#float_client_names ⇒ Object
33 34 35 36 37 |
# 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 ⇒ Object
45 46 47 48 49 |
# 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 ⇒ Object
23 24 25 26 |
# 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 ⇒ Object
13 14 15 16 |
# 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 ⇒ Object
65 66 67 |
# 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 ⇒ Object
69 70 71 |
# 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 ⇒ Object
61 62 63 |
# 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 ⇒ Object
57 58 59 |
# 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 ⇒ Object
82 83 84 |
# 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 ⇒ Object
73 74 75 76 77 78 79 80 |
# 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 ⇒ Object
39 40 41 42 43 |
# 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 ⇒ Object
51 52 53 54 55 |
# 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 ⇒ Object
28 29 30 31 |
# 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 ⇒ Object
18 19 20 21 |
# 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 |