adash 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/exe/adash +17 -4
  3. data/lib/adash.rb +13 -10
  4. data/lib/adash/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 349b18112b944763dbcf5ba78c67a39a800a56f1
4
- data.tar.gz: d83c1b8f1b127287f96012a98f8c3cc1ef66c2e1
3
+ metadata.gz: c3bf354baae4874d47f0f6fd795da1a4663ad874
4
+ data.tar.gz: ce988ab6a88d3fc484d04a117f1ccac76270c22b
5
5
  SHA512:
6
- metadata.gz: f43f1d1a311a55a1fd8bcdfebf3137b555801e7a5174376db3e40039f4b17ed26855d92cce1e35556f8e36bc8c58a5e841ae502462fae5745b1103151fcf5195
7
- data.tar.gz: 67506f20e45900253a26bf85dd1634c158b97cb7fafa1a602c42061071af175e01787fc3133c4fce8615bae7fca4a6fb22a4db8bddf2bffd750ab762035a44e2
6
+ metadata.gz: 7ce593770dc9943926f45f597296cd1bc4cdbceeaaba6087f48cde0dda6d82eb75dca6f0dcf3f2c893571be64d525ea6b0bc0fbba7573fabf21bc45195289610
7
+ data.tar.gz: c0b143679b7536438aa40acd827067b7f5a508c25b58e0ccc223780054e116cba9be9b4a50e96a3b18af9becbd86b632537cc0f8c7729651a42e088b1dd9fd61
data/exe/adash CHANGED
@@ -54,18 +54,31 @@ def run_sub_command(adash, subcmd, argv)
54
54
  adash.sub_replenish(name, slot_id)
55
55
  end
56
56
  else
57
- $stderr.puts "no such subcommand: #{k}"
57
+ $stderr.puts "no such sub-command: #{subcmd}"
58
58
  2
59
59
  end
60
60
  end
61
61
 
62
+ def help
63
+ puts 'adash sub-command'
64
+ puts 'sub-commands:'
65
+ puts ' init'
66
+ puts ' list'
67
+ puts ' list-slot'
68
+ puts ' replenish'
69
+ end
70
+
62
71
  opt = OptionParser.new
63
- opt.on('-h', '--help') { puts 'help' }
72
+ opt.on('-h', '--help') {
73
+ help
74
+ }
64
75
 
65
- adash = Adash::Access.new
76
+ adash = Adash::Manager.new
66
77
 
67
78
  argv = opt.order(ARGV)
68
- unless argv.empty?
79
+ if argv.empty?
80
+ help
81
+ else
69
82
  subcmd = argv.shift
70
83
  ret = run_sub_command(adash, subcmd, argv)
71
84
  exit ret if ret != 0
@@ -6,9 +6,8 @@ require 'fileutils'
6
6
  require 'yaml'
7
7
  require 'amazon-drs'
8
8
 
9
- # TODO: Use each class for return
10
9
  module Adash
11
- class Access
10
+ class Manager
12
11
  def initialize
13
12
  end
14
13
 
@@ -16,12 +15,12 @@ module Adash
16
15
  serial = generate_serial(device_model)
17
16
  credentials = get_credentials
18
17
  authorized_devices = credentials['authorized_devices']
19
- hit = authorized_devices.find_index { |d| d['device_model'] == device_model }
18
+ hit = authorized_devices&.find_index { |d| d['device_model'] == device_model }
20
19
  if hit
21
20
  puts "Adash knows device what is #{device_model}."
22
21
  return 3
23
22
  end
24
- hit = authorized_devices.find_index { |d| d['name'] == name }
23
+ hit = authorized_devices&.find_index { |d| d['name'] == name }
25
24
  if hit
26
25
  puts "Adash knows device what is named #{name}."
27
26
  return 4
@@ -38,7 +37,11 @@ module Adash
38
37
  'redirect_uri' => wi.redirect_uri
39
38
  }
40
39
  new_device['is_test'] = true if is_test
41
- credentials['authorized_devices'] << new_device
40
+ if credentials['authorized_devices']
41
+ credentials['authorized_devices'] << new_device
42
+ else
43
+ credentials['authorized_devices'] = [new_device]
44
+ end
42
45
  save_credentials(credentials)
43
46
  client = create_client_from_device(new_device)
44
47
  client.get_token
@@ -77,7 +80,7 @@ module Adash
77
80
  client = create_client_from_device(device)
78
81
  resp = client.subscription_info
79
82
  index = 0
80
- resp.json['slotsSubscriptionStatus'].each do |slot_id, available|
83
+ resp.slots.each do |slot_id, available|
81
84
  puts "---- #{index}"
82
85
  puts "* slot_id: #{slot_id}"
83
86
  puts " available: #{available}"
@@ -95,10 +98,10 @@ module Adash
95
98
  client = create_client_from_device(device)
96
99
  slot_id = select_slot_prompt(client) unless slot_id
97
100
  resp = client.replenish(slot_id)
98
- if resp.json['message']
99
- puts "ERROR: #{resp.json['message']}"
101
+ if resp.instance_of?(AmazonDrs::Replenish)
102
+ puts "ERROR: #{resp.message}"
100
103
  else
101
- case resp.json['detailCode']
104
+ case resp.detail_code
102
105
  when 'STANDARD_ORDER_PLACED'
103
106
  puts 'Succeeded to order.'
104
107
  when 'ORDER_INPROGRESS'
@@ -207,7 +210,7 @@ module Adash
207
210
 
208
211
  def select_slot_prompt(client)
209
212
  resp = client.subscription_info
210
- slots = resp.json['slotsSubscriptionStatus'].select{ |k, v| v }
213
+ slots = resp.slots.select{ |k, v| v }
211
214
  if slots.size == 1
212
215
  return slots.keys.first
213
216
  end
@@ -1,3 +1,3 @@
1
1
  module Adash
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code Ass
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-30 00:00:00.000000000 Z
11
+ date: 2017-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler