mind_meld 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c36f7bd086fb8cf7f5a125636870edbca927c7f2
4
- data.tar.gz: 63dd877a5c0916987285487006e21aa89d5d1644
3
+ metadata.gz: abbb5393c6f319e896e4f0b13ae040ed085255ca
4
+ data.tar.gz: d76a86d3865b2277663c9a6b2a35d01dd6d98cf7
5
5
  SHA512:
6
- metadata.gz: 293b8adbe092a8000b56134cfd5375a469f2b3e0c5816e8651577a385595eac1fd4c3fbed7a17a15f14b0b3c73aee771890b4669525311326c0ca16d9e4d44ef
7
- data.tar.gz: 7ff18a9c7664bf67e515d95b833427d2392fa588ce5a629f888343d076e1fd915f4100f5aab4f69ce0a13c3941d8d803c682a30d66dcfc99db0daeaf16ba2111
6
+ metadata.gz: c3800bfe361a6520b76d87acb11093afdf18115a92bf86ee3cf42136563a883bdef6cfdda1f4c6af80a430199cfd934c44a07d16a70c6f73e050f70299832a3a
7
+ data.tar.gz: 5179039aeb0d2ca6e2472e7921bf06adf8fe29399d364a54648b8d5535c814cd5a37d44a02e3a743ddf2d4df595adf1c9e36e3cd883cbf806543384d10d21f3f
data/bin/mind_meld CHANGED
@@ -36,8 +36,11 @@ class Parser
36
36
  device: { id: i }
37
37
  )
38
38
  end
39
- opts.on("-t TYPE") { |t| options.action_type = t }
40
- opts.on("-b BODY") { |b| options.body = b }
39
+ case type
40
+ when 'action'
41
+ opts.on("-t TYPE") { |t| options.action_type = t }
42
+ opts.on("-b BODY") { |b| options.body = b }
43
+ end
41
44
  end
42
45
 
43
46
  opt_parser.parse(opts)
@@ -73,6 +76,17 @@ when 'action'
73
76
  opts = Parser.parse 'action', ARGV
74
77
 
75
78
  opts[:connection].create_action( opts[:options].to_h )
79
+
80
+ when 'details'
81
+ opts = Parser.parse 'device', ARGV
82
+ dd = opts[:connection].device_details(view: 'simple')
83
+ puts "Id: #{dd['id']}"
84
+ puts "Name: #{dd['name']}"
85
+ puts "Model: #{dd['model_display_name']} (#{dd['model']})"
86
+ puts "Brand: #{dd['brand_display_name']} (#{dd['brand']})"
87
+ puts "Type: #{dd['device_type']}"
88
+ puts "Serial: #{dd['serial']}"
89
+ puts "Asset Id: #{dd['asset_id']}"
76
90
  when nil, /^-+/
77
91
  puts "Missing command"
78
92
  puts "(and missing help file)"
@@ -9,7 +9,7 @@ class MindMeld::Device < MindMeld
9
9
  @device = options[:device]
10
10
  # To trigger registration (is this needed?)
11
11
  @device_details = {}.with_indifferent_access
12
- device_details
12
+ device_details(view: 'simple')
13
13
  end
14
14
 
15
15
  def id
@@ -51,12 +51,21 @@ class MindMeld::Device < MindMeld
51
51
  response
52
52
  end
53
53
 
54
- def device_details(refresh = false)
54
+ def device_details(options = {refresh: false})
55
+ if options.is_a? Hash
56
+ refresh = options[:refresh] || false
57
+ view = options[:view] || 'full'
58
+ else
59
+ puts "[DEPRECATION WARNING] device_details(true) replaced by device_details(refresh: true) in Mind Meld"
60
+ refresh = options
61
+ view = 'full'
62
+ end
63
+
55
64
  if refresh || ! @device_details.has_key?(:id)
56
65
  if @device_details.has_key? :id
57
- @device_details = request :get, "devices/#{@device_details[:id]}"
66
+ @device_details = request :get, "devices/#{@device_details[:id]}", { view: view }
58
67
  elsif @device.has_key? :id
59
- @device_details = request :get, "devices/#{@device[:id]}"
68
+ @device_details = request :get, "devices/#{@device[:id]}", { view: view }
60
69
  else
61
70
  @device_details = register @device
62
71
  end
data/lib/mind_meld.rb CHANGED
@@ -28,12 +28,22 @@ class MindMeld
28
28
  def request type, call, params = {}
29
29
  if @http
30
30
  begin
31
+ path = "/api/#{call}.json"
32
+ params_query = params.to_query
33
+ # Apparently request_get is inconsistent with request_<everything else>
34
+ # (Great)
35
+ case type
36
+ when :get
37
+ response = @http.request_get("#{path}?#{params_query}")
38
+ else
39
+ response = @http.send(
40
+ "request_#{type}",
41
+ path,
42
+ params_query
43
+ )
44
+ end
31
45
  # Allow for 'array with indifferent access'
32
- { reply: JSON.parse(@http.send(
33
- "request_#{type}",
34
- "/api/#{call}.json",
35
- type == :get ? params : params.to_query
36
- ).body) }.with_indifferent_access[:reply]
46
+ { reply: JSON.parse(response.body) }.with_indifferent_access[:reply]
37
47
  rescue => e
38
48
  { error: e.message }.with_indifferent_access
39
49
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mind_meld
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Haig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-26 00:00:00.000000000 Z
11
+ date: 2016-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport