Floppy-amee 0.1.5 → 0.2.1
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/README +1 -5
- data/examples/view_data_item.rb +1 -1
- data/lib/amee.rb +7 -1
- data/lib/amee/data_category.rb +68 -55
- data/lib/amee/data_item.rb +53 -7
- data/lib/amee/data_item_value.rb +38 -9
- data/lib/amee/profile.rb +1 -1
- data/lib/amee/shell.rb +1 -1
- data/lib/amee/version.rb +2 -2
- metadata +2 -2
data/README
CHANGED
@@ -23,11 +23,7 @@ examples/view_data_*.rb for simple usage examples. You can also get the list
|
|
23
23
|
of available Profiles. See examples/list_profiles.rb for details.
|
24
24
|
|
25
25
|
The gem will use the AMEE JSON API if the JSON gem is installed on the local
|
26
|
-
system. Otherwise the XML API will be used.
|
27
|
-
Profile lists are supported with JSON, so you can disable JSON support by setting
|
28
|
-
the fourth argument to AMEE::Connection.new() to false:
|
29
|
-
|
30
|
-
> AMEE::Connection.new($srv, $user, $pass, false) # last arg disables JSON support
|
26
|
+
system. Otherwise the XML API will be used.
|
31
27
|
|
32
28
|
== INTERACTIVE SHELL
|
33
29
|
|
data/examples/view_data_item.rb
CHANGED
@@ -17,7 +17,7 @@ OptionParser.new do |opts|
|
|
17
17
|
end.parse!
|
18
18
|
|
19
19
|
# Connect
|
20
|
-
connection = AMEE::Connection.new(options[:server], options[:username], options[:password]
|
20
|
+
connection = AMEE::Connection.new(options[:server], options[:username], options[:password])
|
21
21
|
|
22
22
|
# For each path in arg list, show details
|
23
23
|
ARGV.each do |path|
|
data/lib/amee.rb
CHANGED
@@ -7,6 +7,12 @@ rescue LoadError
|
|
7
7
|
nil
|
8
8
|
end
|
9
9
|
|
10
|
+
class String
|
11
|
+
def is_json?
|
12
|
+
slice(0,1) == '{'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
10
16
|
require 'amee/version'
|
11
17
|
require 'amee/exceptions'
|
12
18
|
require 'amee/connection'
|
@@ -14,4 +20,4 @@ require 'amee/object'
|
|
14
20
|
require 'amee/data_category'
|
15
21
|
require 'amee/data_item'
|
16
22
|
require 'amee/data_item_value'
|
17
|
-
require 'amee/profile'
|
23
|
+
require 'amee/profile'
|
data/lib/amee/data_category.rb
CHANGED
@@ -13,71 +13,84 @@ module AMEE
|
|
13
13
|
attr_reader :children
|
14
14
|
attr_reader :items
|
15
15
|
|
16
|
+
def self.from_json(json)
|
17
|
+
# Parse json
|
18
|
+
doc = JSON.parse(json)
|
19
|
+
data = {}
|
20
|
+
data[:uid] = doc['dataCategory']['uid']
|
21
|
+
data[:created] = DateTime.parse(doc['dataCategory']['created'])
|
22
|
+
data[:modified] = DateTime.parse(doc['dataCategory']['modified'])
|
23
|
+
data[:name] = doc['dataCategory']['name']
|
24
|
+
data[:path] = doc['path']
|
25
|
+
data[:children] = []
|
26
|
+
doc['children']['dataCategories'].each do |child|
|
27
|
+
category_data = {}
|
28
|
+
category_data[:name] = child['name']
|
29
|
+
category_data[:path] = child['path']
|
30
|
+
category_data[:uid] = child['uid']
|
31
|
+
data[:children] << category_data
|
32
|
+
end
|
33
|
+
data[:items] = []
|
34
|
+
if doc['children']['dataItems']['rows']
|
35
|
+
doc['children']['dataItems']['rows'].each do |item|
|
36
|
+
item_data = {}
|
37
|
+
item_data[:label] = item['label']
|
38
|
+
item_data[:path] = item['path']
|
39
|
+
item_data[:uid] = item['uid']
|
40
|
+
data[:items] << item_data
|
41
|
+
end
|
42
|
+
end
|
43
|
+
# Create object
|
44
|
+
Category.new(data)
|
45
|
+
rescue
|
46
|
+
raise AMEE::BadData.new("Couldn't load DataCategory from JSON data. Check that your URL is correct.")
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.from_xml(xml)
|
50
|
+
# Parse XML
|
51
|
+
doc = REXML::Document.new(xml)
|
52
|
+
data = {}
|
53
|
+
data[:uid] = REXML::XPath.first(doc, "/Resources/DataCategoryResource/DataCategory/@uid").to_s
|
54
|
+
data[:created] = DateTime.parse(REXML::XPath.first(doc, "/Resources/DataCategoryResource/DataCategory/@created").to_s)
|
55
|
+
data[:modified] = DateTime.parse(REXML::XPath.first(doc, "/Resources/DataCategoryResource/DataCategory/@modified").to_s)
|
56
|
+
data[:name] = REXML::XPath.first(doc, '/Resources/DataCategoryResource/DataCategory/Name').text
|
57
|
+
data[:path] = REXML::XPath.first(doc, '/Resources/DataCategoryResource/Path').text || ""
|
58
|
+
data[:children] = []
|
59
|
+
REXML::XPath.each(doc, '/Resources/DataCategoryResource/Children/DataCategories/DataCategory') do |child|
|
60
|
+
category_data = {}
|
61
|
+
category_data[:name] = child.elements['Name'].text
|
62
|
+
category_data[:path] = child.elements['Path'].text
|
63
|
+
category_data[:uid] = child.attributes['uid'].to_s
|
64
|
+
data[:children] << category_data
|
65
|
+
end
|
66
|
+
data[:items] = []
|
67
|
+
REXML::XPath.each(doc, '/Resources/DataCategoryResource/Children/DataItems/DataItem') do |item|
|
68
|
+
item_data = {}
|
69
|
+
item_data[:label] = item.elements['label'].text
|
70
|
+
item_data[:path] = item.elements['path'].text
|
71
|
+
item_data[:uid] = item.attributes['uid'].to_s
|
72
|
+
data[:items] << item_data
|
73
|
+
end
|
74
|
+
# Create object
|
75
|
+
Category.new(data)
|
76
|
+
rescue
|
77
|
+
raise AMEE::BadData.new("Couldn't load DataCategory from XML data. Check that your URL is correct.")
|
78
|
+
end
|
79
|
+
|
16
80
|
def self.get(connection, path)
|
17
81
|
# Load data from path
|
18
82
|
response = connection.get(path)
|
19
83
|
# Parse data from response
|
20
|
-
|
21
|
-
|
22
|
-
# Read JSON
|
23
|
-
doc = JSON.parse(response)
|
24
|
-
data = {}
|
25
|
-
data[:uid] = doc['dataCategory']['uid']
|
26
|
-
data[:created] = DateTime.parse(doc['dataCategory']['created'])
|
27
|
-
data[:modified] = DateTime.parse(doc['dataCategory']['modified'])
|
28
|
-
data[:name] = doc['dataCategory']['name']
|
29
|
-
data[:path] = doc['path']
|
30
|
-
data[:children] = []
|
31
|
-
doc['children']['dataCategories'].each do |child|
|
32
|
-
category_data = {}
|
33
|
-
category_data[:name] = child['name']
|
34
|
-
category_data[:path] = child['path']
|
35
|
-
category_data[:uid] = child['uid']
|
36
|
-
data[:children] << category_data
|
37
|
-
end
|
38
|
-
data[:items] = []
|
39
|
-
if doc['children']['dataItems']['rows']
|
40
|
-
doc['children']['dataItems']['rows'].each do |item|
|
41
|
-
item_data = {}
|
42
|
-
item_data[:label] = item['label']
|
43
|
-
item_data[:path] = item['path']
|
44
|
-
item_data[:uid] = item['uid']
|
45
|
-
data[:items] << item_data
|
46
|
-
end
|
47
|
-
end
|
84
|
+
if response.is_json?
|
85
|
+
cat = Category.from_json(response)
|
48
86
|
else
|
49
|
-
|
50
|
-
doc = REXML::Document.new(response)
|
51
|
-
data = {}
|
52
|
-
data[:uid] = REXML::XPath.first(doc, "/Resources/DataCategoryResource/DataCategory/@uid").to_s
|
53
|
-
data[:created] = DateTime.parse(REXML::XPath.first(doc, "/Resources/DataCategoryResource/DataCategory/@created").to_s)
|
54
|
-
data[:modified] = DateTime.parse(REXML::XPath.first(doc, "/Resources/DataCategoryResource/DataCategory/@modified").to_s)
|
55
|
-
data[:name] = REXML::XPath.first(doc, '/Resources/DataCategoryResource/DataCategory/Name').text
|
56
|
-
data[:path] = REXML::XPath.first(doc, '/Resources/DataCategoryResource/Path').text || ""
|
57
|
-
data[:children] = []
|
58
|
-
REXML::XPath.each(doc, '/Resources/DataCategoryResource/Children/DataCategories/DataCategory') do |child|
|
59
|
-
category_data = {}
|
60
|
-
category_data[:name] = child.elements['Name'].text
|
61
|
-
category_data[:path] = child.elements['Path'].text
|
62
|
-
category_data[:uid] = child.attributes['uid'].to_s
|
63
|
-
data[:children] << category_data
|
64
|
-
end
|
65
|
-
data[:items] = []
|
66
|
-
REXML::XPath.each(doc, '/Resources/DataCategoryResource/Children/DataItems/DataItem') do |item|
|
67
|
-
item_data = {}
|
68
|
-
item_data[:label] = item.elements['label'].text
|
69
|
-
item_data[:path] = item.elements['path'].text
|
70
|
-
item_data[:uid] = item.attributes['uid'].to_s
|
71
|
-
data[:items] << item_data
|
72
|
-
end
|
87
|
+
cat = Category.from_xml(response)
|
73
88
|
end
|
74
|
-
# Create category object
|
75
|
-
cat = Category.new(data)
|
76
89
|
# Store connection in object for future use
|
77
90
|
cat.connection = connection
|
78
91
|
# Done
|
79
92
|
return cat
|
80
|
-
rescue
|
93
|
+
rescue
|
81
94
|
raise AMEE::BadData.new("Couldn't load DataCategory. Check that your URL is correct.")
|
82
95
|
end
|
83
96
|
|
data/lib/amee/data_item.rb
CHANGED
@@ -13,11 +13,43 @@ module AMEE
|
|
13
13
|
attr_reader :choices
|
14
14
|
attr_reader :label
|
15
15
|
|
16
|
-
def self.
|
17
|
-
#
|
18
|
-
|
16
|
+
def self.from_json(json)
|
17
|
+
# Read JSON
|
18
|
+
doc = JSON.parse(json)
|
19
|
+
data = {}
|
20
|
+
data[:uid] = doc['dataItem']['uid']
|
21
|
+
data[:created] = DateTime.parse(doc['dataItem']['created'])
|
22
|
+
data[:modified] = DateTime.parse(doc['dataItem']['modified'])
|
23
|
+
data[:name] = doc['dataItem']['name']
|
24
|
+
data[:path] = doc['path']
|
25
|
+
data[:label] = doc['dataItem']['label']
|
26
|
+
# Get values
|
27
|
+
data[:values] = []
|
28
|
+
doc['dataItem']['itemValues'].each do |value|
|
29
|
+
value_data = {}
|
30
|
+
value_data[:name] = value['name']
|
31
|
+
value_data[:path] = value['path']
|
32
|
+
value_data[:value] = value['value']
|
33
|
+
value_data[:uid] = value['uid']
|
34
|
+
data[:values] << value_data
|
35
|
+
end
|
36
|
+
# Get choices
|
37
|
+
data[:choices] = []
|
38
|
+
doc['userValueChoices']['choices'].each do |choice|
|
39
|
+
choice_data = {}
|
40
|
+
choice_data[:name] = choice['name']
|
41
|
+
choice_data[:value] = choice['value']
|
42
|
+
data[:choices] << choice_data
|
43
|
+
end
|
44
|
+
# Create object
|
45
|
+
Item.new(data)
|
46
|
+
rescue
|
47
|
+
raise AMEE::BadData.new("Couldn't load DataItem from JSON. Check that your URL is correct.")
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.from_xml(xml)
|
19
51
|
# Parse data from response into hash
|
20
|
-
doc = REXML::Document.new(
|
52
|
+
doc = REXML::Document.new(xml)
|
21
53
|
data = {}
|
22
54
|
data[:uid] = REXML::XPath.first(doc, "/Resources/DataItemResource/DataItem/@uid").to_s
|
23
55
|
data[:created] = DateTime.parse(REXML::XPath.first(doc, "/Resources/DataItemResource/DataItem/@created").to_s)
|
@@ -40,11 +72,25 @@ module AMEE
|
|
40
72
|
REXML::XPath.each(doc, '/Resources/DataItemResource/Choices/Choices/Choice') do |choice|
|
41
73
|
choice_data = {}
|
42
74
|
choice_data[:name] = choice.elements['Name'].text
|
43
|
-
choice_data[:value] = choice.elements['Value'].text
|
75
|
+
choice_data[:value] = choice.elements['Value'].text || ""
|
44
76
|
data[:choices] << choice_data
|
45
77
|
end
|
46
|
-
# Create
|
47
|
-
|
78
|
+
# Create object
|
79
|
+
Item.new(data)
|
80
|
+
rescue
|
81
|
+
raise AMEE::BadData.new("Couldn't load DataItem from XML. Check that your URL is correct.")
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def self.get(connection, path)
|
86
|
+
# Load data from path
|
87
|
+
response = connection.get(path)
|
88
|
+
# Parse data from response
|
89
|
+
if response.is_json?
|
90
|
+
item = Item.from_json(response)
|
91
|
+
else
|
92
|
+
item = Item.from_xml(response)
|
93
|
+
end
|
48
94
|
# Store connection in object for future use
|
49
95
|
item.connection = connection
|
50
96
|
# Done
|
data/lib/amee/data_item_value.rb
CHANGED
@@ -29,11 +29,26 @@ module AMEE
|
|
29
29
|
@from_data
|
30
30
|
end
|
31
31
|
|
32
|
-
def self.
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
def self.from_json(json, path)
|
33
|
+
# Read JSON
|
34
|
+
doc = JSON.parse(json)['itemValue']
|
35
|
+
data = {}
|
36
|
+
data[:uid] = doc['uid']
|
37
|
+
data[:created] = DateTime.parse(doc['created'])
|
38
|
+
data[:modified] = DateTime.parse(doc['modified'])
|
39
|
+
data[:name] = doc['name']
|
40
|
+
data[:path] = path
|
41
|
+
data[:value] = doc['value']
|
42
|
+
data[:type] = doc['itemValueDefinition']['valueDefinition']['valueType']
|
43
|
+
# Create object
|
44
|
+
ItemValue.new(data)
|
45
|
+
rescue
|
46
|
+
raise AMEE::BadData.new("Couldn't load DataItemValue from JSON. Check that your URL is correct.")
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.from_xml(xml, path)
|
50
|
+
# Read XML
|
51
|
+
doc = REXML::Document.new(xml)
|
37
52
|
data = {}
|
38
53
|
data[:uid] = REXML::XPath.first(doc, "/Resources/DataItemValueResource/ItemValue/@uid").to_s
|
39
54
|
data[:created] = DateTime.parse(REXML::XPath.first(doc, "/Resources/DataItemValueResource/ItemValue/@Created").to_s)
|
@@ -44,12 +59,26 @@ module AMEE
|
|
44
59
|
data[:type] = REXML::XPath.first(doc, '/Resources/DataItemValueResource/ItemValue/ItemValueDefinition/ValueDefinition/ValueType').text
|
45
60
|
data[:from_profile] = REXML::XPath.first(doc, '/Resources/DataItemValueResource/ItemValue/ItemValueDefinition/FromProfile').text == "true" ? true : false
|
46
61
|
data[:from_data] = REXML::XPath.first(doc, '/Resources/DataItemValueResource/ItemValue/ItemValueDefinition/FromData').text == "true" ? true : false
|
47
|
-
# Create
|
48
|
-
|
62
|
+
# Create object
|
63
|
+
ItemValue.new(data)
|
64
|
+
rescue
|
65
|
+
raise AMEE::BadData.new("Couldn't load DataItemValue from XML. Check that your URL is correct.")
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.get(connection, path)
|
69
|
+
# Load data from path
|
70
|
+
response = connection.get(path)
|
71
|
+
# Parse data from response
|
72
|
+
data = {}
|
73
|
+
if response.is_json?
|
74
|
+
value = ItemValue.from_json(response, path)
|
75
|
+
else
|
76
|
+
value = ItemValue.from_xml(response, path)
|
77
|
+
end
|
49
78
|
# Store connection in object for future use
|
50
|
-
|
79
|
+
value.connection = connection
|
51
80
|
# Done
|
52
|
-
return
|
81
|
+
return value
|
53
82
|
rescue
|
54
83
|
raise AMEE::BadData.new("Couldn't load DataItemValue. Check that your URL is correct.")
|
55
84
|
end
|
data/lib/amee/profile.rb
CHANGED
data/lib/amee/shell.rb
CHANGED
@@ -60,7 +60,7 @@ require 'amee'
|
|
60
60
|
include AMEE::Shell
|
61
61
|
|
62
62
|
# Set up connection
|
63
|
-
$connection = AMEE::Connection.new(ENV['AMEE_SERVER'], ENV['AMEE_USERNAME'], ENV['AMEE_PASSWORD']
|
63
|
+
$connection = AMEE::Connection.new(ENV['AMEE_SERVER'], ENV['AMEE_USERNAME'], ENV['AMEE_PASSWORD'])
|
64
64
|
|
65
65
|
if $connection.valid?
|
66
66
|
# Change to root of data api to get going
|
data/lib/amee/version.rb
CHANGED
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.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Smith
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-08-01 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|