Class: MrMurano::Services

Inherits:
SolutionBase show all
Defined in:
lib/MrMurano/Solution-ServiceConfig.rb

Overview

This is only used for debugging and deciphering APIs.

There was once a plan for using this to automagically map commands into services by reading their schema. That plan had too much magic and was too fragile for real use.

A much better UI/UX happens with human intervention. :nocov:

Constant Summary

Constants included from Verbose

Verbose::TABULARIZE_DATA_FORMAT_ERROR

Constants included from SolutionId

MrMurano::SolutionId::INVALID_API_ID, MrMurano::SolutionId::UNEXPECTED_TYPE_OR_ERROR_MSG

Constants included from AccountBase

AccountBase::LOGIN_ADVICE, AccountBase::LOGIN_NOTICE

Instance Attribute Summary

Attributes included from SolutionId

#sid, #valid_api_id

Instance Method Summary collapse

Methods inherited from SolutionBase

#==, #endpoint, #search

Methods included from SyncUpDown

#config_vars_decode, #config_vars_encode, #debug_print_localitems, #diff_download, #diff_item_write, #docmp, #download, #ignore?, #ignoring, #localitems, #locallist, #locallist_add_item, #locallist_complain_missing, #locallist_mark_seen, #location, #match, #remove, #remove_or_clear, #removelocal, #resolve_config_var_usage!, #resurrect_undeletables, #searchFor, #syncdown_after, #syncdown_before, #synckey, #syncup_after, #syncup_before, #to_remote_items, #tolocalname, #tolocalpath, #update_mtime, #upload

Methods included from Verbose

ask_yes_no, #ask_yes_no, #assert, assert, cmd_confirm_delete!, #cmd_confirm_delete!, debug, #debug, dump_file_json, dump_file_plain, dump_file_yaml, #dump_output_file, #error, error, #error_file_format!, fancy_ticks, #fancy_ticks, #load_file_json, #load_file_plain, #load_file_yaml, #load_input_file, outf, #outf, #outformat_engine, #pluralize?, pluralize?, #prepare_hash_csv, #read_hashf!, #tabularize, tabularize, verbose, #verbose, warning, #warning, #whirly_interject, whirly_interject, #whirly_linger, whirly_linger, #whirly_msg, whirly_msg, #whirly_pause, whirly_pause, #whirly_start, whirly_start, #whirly_stop, whirly_stop, #whirly_unpause, whirly_unpause

Methods included from SyncCore

#debug_selected, #dodiff, #dodiff_build_cmd, #dodiff_cull_tempfile_paths, #dodiff_do_diff, #dodiff_download_remote, #dodiff_flexible, #dodiff_header_aware, #dodiff_local_to_tempfile, #dodiff_prepare_local_and_diff, #dodiff_resolve_localname, #dodiff_tempfile_paths, #filter_solution, #init_mods_and_chgs_arrs, #item_dirty_set_status, #item_local_there_merged, #item_merged_diff_status, #item_merged_set_status, #item_select_selected!, #items_classify_and_find_duplicates, #items_cull_clashes!, #items_lists, #items_log_duplicates, #items_log_duplicates_there_local, #items_mods_and_chgs!, #items_new_and_old!, #select_selected!, #sort_by_name, #status, #sync_update_progress, #syncable_validate_api_id, #syncdown, #syncdown_item, #syncup, #syncup_item

Methods included from SyncAllowed

#download_item_allowed, #remove_item_allowed, #removelocal_item_allowed, #sync_item_allowed, #upload_item_allowed

Methods included from SolutionId

#affirm_valid, #api_id?, #endpoint, #init_api_id!, #valid_api_id?

Methods included from AccountBase

#add_headers, #ask_for_password!, #ask_for_user!, #cfg_clear_user_and_business, #credentials_reset, #get, #invalidate_token, #login_info, #logout, #must_prompt_if_logged_off!, #token, #token_reset, #verify_cfg_auth!, #verify_cfg_auth_persist, #verify_cfg_auth_scheme!, #verify_cfg_auth_ttl, #verify_set, warn_configfile_env_maybe

Methods included from Http

#add_headers, #curldebug, curldebug_after, curldebug_elapsed, curldebug_log, #delete, #endpoint, #get, #host, #http, #http_reset, #isJSON, #json_opts, #patch, #post, #postf, #put, #showHttpError, #user, #workit, #workit_response

Constructor Details

#initialize(api_id = nil) ⇒ Services

Returns a new instance of Services.



126
127
128
129
130
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 126

def initialize(api_id=nil)
  @solntype = 'application.id'
  super
  @uriparts << :service
end

Instance Method Details

#all_eventsObject



174
175
176
177
178
179
180
181
182
183
184
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 174

def all_events
  sevs = list
  ret = []
  sevs.each do |srv|
    scm = schema(srv[:id]) || {}
    (scm['x-events'.to_sym] || {}).each_pair do |event, _info|
      ret << [srv[:alias], event]
    end
  end
  ret
end

#api_idObject



138
139
140
141
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 138

def api_id
  return @api_id unless @api_id.nil?
  @api_id = api_id_for_name(@service_name)
end

#api_id_for_name(name) ⇒ Object



132
133
134
135
136
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 132

def api_id_for_name(name)
  name = name.to_s unless name.is_a? String
  scr = list.select { |i| i[:alias] == name }.first
  scr[:id]
end

#callable(id = api_id, all = false) ⇒ Object

Get list of call operations from a schema



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 158

def callable(id=api_id, all=false)
  scm = schema(id)
  calls = []
  scm[:paths].each do |path, methods|
    methods.each do |method, params|
      next unless params.is_a?(Hash)
      call = [method]
      call << path.to_s if all
      call << params[:operationId]
      call << (params['x-internal-use'.to_sym] || false) if all
      calls << call
    end
  end
  calls
end

#listObject



143
144
145
146
147
148
149
150
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 143

def list
  ret = get
  return [] unless ret.is_a?(Hash) && !ret.key?(:error)
  return [] unless ret.key?(:items)
  ret[:items]
  # MAYBE/2017-08-17:
  #   sort_by_name(ret[:items])
end

#schema(id = api_id) ⇒ Object



152
153
154
155
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 152

def schema(id=api_id)
  # TODO: cache schema in user dir?
  get("/#{id}/schema")
end