Class: MrMurano::Account
- Inherits:
-
Object
- Object
- MrMurano::Account
- Includes:
- AccountBase, Verbose
- Defined in:
- lib/MrMurano/Account.rb
Constant Summary
Constants included from Verbose
Verbose::TABULARIZE_DATA_FORMAT_ERROR
Constants included from AccountBase
MrMurano::AccountBase::LOGIN_ADVICE, MrMurano::AccountBase::LOGIN_NOTICE
Instance Method Summary collapse
- #accept_account(token, password) ⇒ Object
-
#add_business_details(bizes, detailed: nil, networks: nil) ⇒ Object
———————————————————————.
- #businesses(bid: nil, name: nil, fuzzy: nil, detailed: nil, networks: nil) ⇒ Object
- #classify_business_by_network(biz, bizes_in_network, bizes_unconfigured, bizes_without_network) ⇒ Object
- #delete_business(id) ⇒ Object
-
#match_bid_name_fuzzy!(bizes, bid, name, fuzzy) ⇒ Object
Filter Businesses (e.g., used by the ‘business find` command).
-
#new_account(email, name, company = '') ⇒ Object
2017-07-05: [lb] notes that the remaining methods are not called.
-
#new_business(name) ⇒ Object
———————————————————————.
- #reset_account(email) ⇒ Object
-
#sort_by_networks(bizes) ⇒ Object
———————————————————————.
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 AccountBase
#add_headers, #ask_for_password!, #ask_for_user!, #cfg_clear_user_and_business, #credentials_reset, #get, #initialize, #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
Instance Method Details
#accept_account(token, password) ⇒ Object
135 136 137 138 139 |
# File 'lib/MrMurano/Account.rb', line 135 def accept_account(token, password) # this is a kludge. If we're gonna support this, do it better. token_reset post("key/#{token}", password: password) end |
#add_business_details(bizes, detailed: nil, networks: nil) ⇒ Object
89 90 91 92 93 |
# File 'lib/MrMurano/Account.rb', line 89 def add_business_details(bizes, detailed: nil, networks: nil) bizes.each do |biz| biz.overview(detailed: detailed, networks: networks) end end |
#businesses(bid: nil, name: nil, fuzzy: nil, detailed: nil, networks: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/MrMurano/Account.rb', line 19 def businesses(bid: nil, name: nil, fuzzy: nil, detailed: nil, networks: nil) # Ask user for name and password, if not saved to config and password files. login_info if user.empty? raise 'Missing user?!' if user.empty? MrMurano::Verbose.whirly_start 'Fetching Businesses...' # (lb): FIXME: This endpoint should be moved to class User eventually # (when User is finally implemented). bizes = get('user/' + user + '/membership/') MrMurano::Verbose.whirly_stop return [] unless bizes.is_a?(Array) && bizes.any? # 2017-06-30: The data for each message contains a :bizid, :role, and :name. # :role is probably generally "owner". match_bid_name_fuzzy!(bizes, bid, name, fuzzy) if detailed || networks bizes = add_business_details(bizes, detailed: detailed, networks: networks) end if networks # Sort results by network status, then name. sort_by_networks(bizes) else # Sort results by name. bizes.sort_by!(&:name) end end |
#classify_business_by_network(biz, bizes_in_network, bizes_unconfigured, bizes_without_network) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/MrMurano/Account.rb', line 70 def classify_business_by_network( biz, bizes_in_network, bizes_unconfigured, bizes_without_network ) case biz.network_status when :parent_configured bizes_in_network.push(biz) when :parent_unconfigured bizes_unconfigured.push(biz) when :child_configured bizes_in_network.push(biz) when :child_unconfigured bizes_without_network.push(biz) else assert(false) end end |
#delete_business(id) ⇒ Object
148 149 150 151 |
# File 'lib/MrMurano/Account.rb', line 148 def delete_business(id) assert(False) # Not called. delete("business/#{id}") end |
#match_bid_name_fuzzy!(bizes, bid, name, fuzzy) ⇒ Object
Filter Businesses (e.g., used by the ‘business find` command).
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/MrMurano/Account.rb', line 98 def match_bid_name_fuzzy!(bizes, bid, name, fuzzy) match_bid = ensure_array(bid) match_name = ensure_array(name) match_fuzzy = ensure_array(fuzzy) if match_bid.any? || match_name.any? || match_fuzzy.any? bizes.select! do |biz| ( match_bid.include?(biz[:bizid]) || match_name.include?(biz[:name]) || match_fuzzy.any? do |term| ( (biz[:name] =~ /#{Regexp.escape(term)}/i) || (biz[:bizid] =~ /#{Regexp.escape(term)}/i) ) end ) end end bizes.map! { || MrMurano::Business.new() } end |
#new_account(email, name, company = '') ⇒ Object
2017-07-05: [lb] notes that the remaining methods are not called.
(Tilstra might be calling these via the _qb plugin.)
125 126 127 128 129 |
# File 'lib/MrMurano/Account.rb', line 125 def new_account(email, name, company='') # this is a kludge. If we're gonna support this, do it better. token_reset post('key/', email: email, name: name, company: company, source: 'signup') end |
#new_business(name) ⇒ Object
143 144 145 146 |
# File 'lib/MrMurano/Account.rb', line 143 def new_business(name) assert(False) # Not called. post('business/', name: name) end |
#reset_account(email) ⇒ Object
131 132 133 |
# File 'lib/MrMurano/Account.rb', line 131 def reset_account(email) post('key/', email: email, source: 'reset') end |
#sort_by_networks(bizes) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/MrMurano/Account.rb', line 51 def sort_by_networks(bizes) bizes_in_network = [] bizes_unconfigured = [] bizes_without_network = [] bizes.each do |biz| classify_business_by_network( biz, bizes_in_network, bizes_unconfigured, bizes_without_network ) end # Assemble the master list so that confgured networks are on top, followed # by unconfigured networks, followed by non-network businesses all_bizes = [] all_bizes.concat(bizes_in_network.sort_by! { |biz| biz.[:network_name] }) all_bizes.concat(bizes_unconfigured.sort_by!(&:name)) all_bizes.concat(bizes_without_network.sort_by!(&:name)) end |