Floppy-amee 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/amee.rb CHANGED
@@ -25,3 +25,4 @@ require 'amee/data_item_value'
25
25
  require 'amee/profile'
26
26
  require 'amee/profile_category'
27
27
  require 'amee/profile_item'
28
+ require 'amee/drill_down'
@@ -101,7 +101,11 @@ module AMEE
101
101
  def child(child_path)
102
102
  AMEE::Data::Category.get(connection, "#{full_path}/#{child_path}")
103
103
  end
104
-
104
+
105
+ def drill
106
+ AMEE::Data::DrillDown.get(connection, "#{full_path}/drill")
107
+ end
108
+
105
109
  end
106
110
  end
107
111
  end
@@ -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
@@ -2,8 +2,8 @@ module AMEE
2
2
 
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 0
5
- MINOR = 3
6
- TINY = 1
5
+ MINOR = 4
6
+ TINY = 6
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
9
9
 
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.5
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-16 00:00:00 -07:00
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