Floppy-amee 0.0.4 → 0.0.5

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.
data/bin/ameesh ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ irb_name = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb'
4
+
5
+ exec "#{irb_name} -r rubygems -r amee/shell --simple-prompt"
data/lib/amee.rb CHANGED
@@ -11,7 +11,7 @@ module AMEE
11
11
  module VERSION #:nodoc:
12
12
  MAJOR = 0
13
13
  MINOR = 0
14
- TINY = 4
14
+ TINY = 5
15
15
  STRING = [MAJOR, MINOR, TINY].join('.')
16
16
  end
17
17
 
@@ -4,10 +4,30 @@ module AMEE
4
4
 
5
5
  def initialize(data = {})
6
6
  @value = data ? data[:value] : nil
7
+ @type = data ? data[:type] : nil
8
+ @from_profile = data ? data[:from_profile] : nil
9
+ @from_data = data ? data[:from_data] : nil
7
10
  super
8
11
  end
9
12
 
10
- attr_reader :value
13
+ attr_reader :type
14
+
15
+ def value
16
+ case type
17
+ when "DECIMAL"
18
+ @value.to_f
19
+ else
20
+ @value
21
+ end
22
+ end
23
+
24
+ def from_profile?
25
+ @from_profile
26
+ end
27
+
28
+ def from_data?
29
+ @from_data
30
+ end
11
31
 
12
32
  def self.get(connection, path)
13
33
  # Load data from path
@@ -21,6 +41,9 @@ module AMEE
21
41
  data[:name] = REXML::XPath.first(doc, '/Resources/DataItemValueResource/ItemValue/Name').text
22
42
  data[:path] = path
23
43
  data[:value] = REXML::XPath.first(doc, '/Resources/DataItemValueResource/ItemValue/Value').text
44
+ data[:type] = REXML::XPath.first(doc, '/Resources/DataItemValueResource/ItemValue/ItemValueDefinition/ValueDefinition/ValueType').text
45
+ data[:from_profile] = REXML::XPath.first(doc, '/Resources/DataItemValueResource/ItemValue/ItemValueDefinition/FromProfile').text == "true" ? true : false
46
+ data[:from_data] = REXML::XPath.first(doc, '/Resources/DataItemValueResource/ItemValue/ItemValueDefinition/FromData').text == "true" ? true : false
24
47
  # Create item object
25
48
  item = ItemValue.new(data)
26
49
  # Store connection in object for future use
data/lib/amee/shell.rb ADDED
@@ -0,0 +1,68 @@
1
+ module AMEE
2
+ module Shell
3
+
4
+ def amee_help
5
+ puts "AMEE shell - version #{AMEE::VERSION::STRING}"
6
+ puts "--------------------------"
7
+ puts "Commands:"
8
+ puts " ls - display contents of current category."
9
+ puts " cd 'path' - change category. Path must be a quoted string. You can use things like '/data', '..', or 'subcategory'."
10
+ puts " pwd - display current category path."
11
+ puts " cat 'name' - display contents of data item called 'name' within the current category."
12
+ puts " amee_help - display this help text."
13
+ end
14
+
15
+ def ls
16
+ "listing contents of #{@@category}"
17
+ end
18
+
19
+ def pwd
20
+ @@category
21
+ end
22
+
23
+ def cd(path)
24
+ if path == '..'
25
+ path_components = @@category.split('/')
26
+ path = path_components.first(path_components.size - 1).join('/')
27
+ elsif !path.match /^\/.*/
28
+ path = @@category + '/' + path
29
+ end
30
+ @@category = path
31
+ end
32
+
33
+ def cat(object)
34
+ "displaying contents of #{@@category}/#{object}"
35
+ end
36
+
37
+ end
38
+ end
39
+
40
+ require 'amee'
41
+ require 'optparse'
42
+ include AMEE::Shell
43
+
44
+ # Command-line options - get username, password, and server
45
+ options = {}
46
+ OptionParser.new do |opts|
47
+ opts.on("-u", "--username USERNAME", "AMEE username") do |u|
48
+ options[:username] = u
49
+ end
50
+ opts.on("-p", "--password PASSWORD", "AMEE password") do |p|
51
+ options[:password] = p
52
+ end
53
+ opts.on("-s", "--server SERVER", "AMEE server") do |s|
54
+ options[:server] = s
55
+ end
56
+ end.parse!
57
+
58
+ # Connect
59
+ connection = AMEE::Connection.new(options[:server], options[:username], options[:password])
60
+
61
+ if connection.valid?
62
+ # Change to root of data api to get going
63
+ cd '/data'
64
+ # Display AMEE details
65
+ amee_help
66
+ else
67
+ puts "Can't connect to AMEE - please check details"
68
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Floppy-amee
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
  - James Smith
@@ -24,6 +24,7 @@ extra_rdoc_files: []
24
24
  files:
25
25
  - README
26
26
  - COPYING
27
+ - bin/ameesh
27
28
  - lib/amee.rb
28
29
  - lib/amee/connection.rb
29
30
  - lib/amee/data_category.rb
@@ -31,6 +32,7 @@ files:
31
32
  - lib/amee/data_item_value.rb
32
33
  - lib/amee/exceptions.rb
33
34
  - lib/amee/object.rb
35
+ - lib/amee/shell.rb
34
36
  - examples/view_data_category.rb
35
37
  - examples/view_data_item.rb
36
38
  has_rdoc: false