Class: Adash::Manager
- Inherits:
-
Object
- Object
- Adash::Manager
- Defined in:
- lib/adash.rb
Instance Method Summary collapse
-
#initialize ⇒ Manager
constructor
A new instance of Manager.
- #sub_deregistrate(name) ⇒ Object
- #sub_init(name, device_model, is_test) ⇒ Object
- #sub_list ⇒ Object
- #sub_list_slot(name) ⇒ Object
- #sub_replenish(name, slot_id) ⇒ Object
Constructor Details
#initialize ⇒ Manager
Returns a new instance of Manager.
11 12 |
# File 'lib/adash.rb', line 11 def initialize end |
Instance Method Details
#sub_deregistrate(name) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/adash.rb', line 62 def sub_deregistrate(name) device = get_device_by_name(name) unless device puts "Device #{name} not found" return 5 end client = create_client_from_device(device) resp = client.deregistrate_device save_credentials_without_device_model(device['device_model']) 0 end |
#sub_init(name, device_model, is_test) ⇒ Object
14 15 16 17 18 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 48 49 |
# File 'lib/adash.rb', line 14 def sub_init(name, device_model, is_test) serial = generate_serial(device_model) credentials = get_credentials = credentials['authorized_devices'] hit = &.find_index { |d| d['device_model'] == device_model } if hit puts "Adash knows device what is #{device_model}." return 3 end hit = &.find_index { |d| d['name'] == name } if hit puts "Adash knows device what is named #{name}." return 4 end wi = Adash::WaitIndefinitely.new(device_model, serial) Signal.trap(:INT){ wi.shutdown } code = wi.get_code FileUtils.mkdir_p(File.('..', Adash::Config.credentials_path)) new_device = { 'name' => name, 'device_model' => device_model, 'serial' => serial, 'authorization_code' => code, 'redirect_uri' => wi.redirect_uri } new_device['is_test'] = true if is_test if credentials['authorized_devices'] credentials['authorized_devices'] << new_device else credentials['authorized_devices'] = [new_device] end save_credentials(credentials) client = create_client_from_device(new_device) client.get_token 0 end |
#sub_list ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/adash.rb', line 51 def sub_list credentials = get_credentials credentials['authorized_devices'].each do |device| puts "---- name: #{device['name']}" puts "* device_model: #{device['device_model']}" puts " serial: #{device['serial']}" puts ' THIS DEVICE IS TEST PURCHASE MODE' if device['is_test'] end 0 end |
#sub_list_slot(name) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/adash.rb', line 74 def sub_list_slot(name) device = get_device_by_name(name) unless device puts "Device #{name} not found" return 5 end client = create_client_from_device(device) resp = client.subscription_info index = 0 resp.slots.each do |slot_id, available| puts "---- #{index}" puts "* slot_id: #{slot_id}" puts " available: #{available}" index =+ 1 end 0 end |
#sub_replenish(name, slot_id) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/adash.rb', line 92 def sub_replenish(name, slot_id) device = get_device_by_name(name) unless device puts "Device #{name} not found" return 5 end client = create_client_from_device(device) slot_id = select_slot_prompt(client) unless slot_id resp = client.replenish(slot_id) if resp.instance_of?(AmazonDrs::Replenish) puts "ERROR: #{resp.}" else case resp.detail_code when 'STANDARD_ORDER_PLACED' puts 'Succeeded to order.' when 'ORDER_INPROGRESS' puts 'The order is in progress.' end end 0 end |