Floppy-amee 0.4.5 → 0.4.6
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/lib/amee.rb +1 -0
- data/lib/amee/data_category.rb +5 -1
- data/lib/amee/drill_down.rb +87 -0
- data/lib/amee/version.rb +2 -2
- metadata +3 -2
data/lib/amee.rb
CHANGED
data/lib/amee/data_category.rb
CHANGED
@@ -0,0 +1,87 @@
|
|
1
|
+
module AMEE
|
2
|
+
module Data
|
3
|
+
class DrillDown < AMEE::Data::Object
|
4
|
+
|
5
|
+
def initialize(data = {})
|
6
|
+
@choices = data ? data[:choices] : []
|
7
|
+
@choice_name = data[:choice_name]
|
8
|
+
@selections = data ? data[:selections] : []
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :choices
|
13
|
+
attr_reader :choice_name
|
14
|
+
attr_reader :selections
|
15
|
+
|
16
|
+
def path=(path)
|
17
|
+
@path = path
|
18
|
+
end
|
19
|
+
|
20
|
+
def data_item_uid
|
21
|
+
return nil if @choice_name != 'uid' || @choices.size != 1
|
22
|
+
@choices[0]
|
23
|
+
end
|
24
|
+
|
25
|
+
def choose(choice)
|
26
|
+
options = []
|
27
|
+
@selections.each_pair do |key, value|
|
28
|
+
options << "#{key}=#{value}"
|
29
|
+
end
|
30
|
+
options << "#{@choice_name}=#{choice}"
|
31
|
+
query_string = options.join "&"
|
32
|
+
DrillDown.get(connection, "#{full_path}?#{query_string}")
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.from_json(json)
|
36
|
+
# Parse json
|
37
|
+
doc = JSON.parse(json)
|
38
|
+
data = {}
|
39
|
+
# Create object
|
40
|
+
DrillDown.new(data)
|
41
|
+
rescue
|
42
|
+
raise AMEE::BadData.new("Couldn't load DrillDown resource from JSON data. Check that your URL is correct.")
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.from_xml(xml)
|
46
|
+
# Parse XML
|
47
|
+
doc = REXML::Document.new(xml)
|
48
|
+
data = {}
|
49
|
+
data[:choice_name] = REXML::XPath.first(doc, "/Resources/DrillDownResource/Choices/Name").text
|
50
|
+
choices = []
|
51
|
+
REXML::XPath.each(doc, "/Resources/DrillDownResource/Choices/Choices/Choice") do |c|
|
52
|
+
choices << c.elements['Value'].text
|
53
|
+
end
|
54
|
+
data[:choices] = choices
|
55
|
+
selections = {}
|
56
|
+
REXML::XPath.each(doc, "/Resources/DrillDownResource/Selections/Choice") do |c|
|
57
|
+
selections[c.elements['Name'].text] = c.elements['Value'].text
|
58
|
+
end
|
59
|
+
data[:selections] = selections
|
60
|
+
# Create object
|
61
|
+
DrillDown.new(data)
|
62
|
+
rescue
|
63
|
+
raise AMEE::BadData.new("Couldn't load DrillDown resource from XML data. Check that your URL is correct.")
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.get(connection, path)
|
67
|
+
# Load data from path
|
68
|
+
response = connection.get(path)
|
69
|
+
# Parse data from response
|
70
|
+
if response.is_json?
|
71
|
+
drill = DrillDown.from_json(response)
|
72
|
+
else
|
73
|
+
drill = DrillDown.from_xml(response)
|
74
|
+
end
|
75
|
+
# Store path in drill object - response does not include it
|
76
|
+
drill.path = path.split('?')[0].gsub(/^\/data/, '')
|
77
|
+
# Store connection in object for future use
|
78
|
+
drill.connection = connection
|
79
|
+
# Done
|
80
|
+
return drill
|
81
|
+
rescue
|
82
|
+
raise AMEE::BadData.new("Couldn't load DrillDown resource. Check that your URL is correct.")
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
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.4.
|
4
|
+
version: 0.4.6
|
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-09-
|
12
|
+
date: 2008-09-23 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -38,6 +38,7 @@ files:
|
|
38
38
|
- lib/amee/data_object.rb
|
39
39
|
- lib/amee/object.rb
|
40
40
|
- lib/amee/shell.rb
|
41
|
+
- lib/amee/drill_down.rb
|
41
42
|
- bin/ameesh
|
42
43
|
- examples/list_profiles.rb
|
43
44
|
- examples/create_profile.rb
|