Floppy-amee 2.0.15 → 2.0.16

Sign up to get free protection for your applications and to get access to all the features.
data/lib/amee.rb CHANGED
@@ -40,6 +40,8 @@ require 'amee/profile_category'
40
40
  require 'amee/profile_item'
41
41
  require 'amee/profile_item_value'
42
42
  require 'amee/drill_down'
43
+ require 'amee/pager'
44
+ require 'amee/item_definition'
43
45
 
44
46
  class Date
45
47
  def amee1_date
@@ -0,0 +1,65 @@
1
+ module AMEE
2
+ module Admin
3
+ class ItemDefinition < AMEE::Object
4
+
5
+ def initialize(data = {})
6
+ @name = data[:name]
7
+ super
8
+ end
9
+
10
+ attr_reader :name
11
+
12
+ def self.from_json(json)
13
+ # Read JSON
14
+ doc = JSON.parse(json)
15
+ data = {}
16
+ data[:uid] = doc['itemDefinition']['uid']
17
+ data[:created] = DateTime.parse(doc['itemDefinition']['created'])
18
+ data[:modified] = DateTime.parse(doc['itemDefinition']['modified'])
19
+ data[:name] = doc['itemDefinition']['name']
20
+ # Create object
21
+ ItemDefinition.new(data)
22
+ rescue
23
+ raise AMEE::BadData.new("Couldn't load ItemDefinition from JSON. Check that your URL is correct.")
24
+ end
25
+
26
+ def self.from_xml(xml)
27
+ # Parse data from response into hash
28
+ doc = REXML::Document.new(xml)
29
+ data = {}
30
+ data[:uid] = REXML::XPath.first(doc, "/Resources/ItemDefinitionResource/ItemDefinition/@uid").to_s
31
+ data[:created] = DateTime.parse(REXML::XPath.first(doc, "/Resources/ItemDefinitionResource/ItemDefinition/@created").to_s)
32
+ data[:modified] = DateTime.parse(REXML::XPath.first(doc, "/Resources/ItemDefinitionResource/ItemDefinition/@modified").to_s)
33
+ data[:name] = REXML::XPath.first(doc, '/Resources/ItemDefinitionResource/ItemDefinition/Name').text
34
+ # Create object
35
+ ItemDefinition.new(data)
36
+ rescue
37
+ raise AMEE::BadData.new("Couldn't load ItemDefinition from XML. Check that your URL is correct.")
38
+ end
39
+
40
+ def self.get(connection, path, options = {})
41
+ # Load data from path
42
+ response = connection.get(path, options).body
43
+ # Parse data from response
44
+ if response.is_json?
45
+ item_definition = ItemDefinition.from_json(response)
46
+ else
47
+ item_definition = ItemDefinition.from_xml(response)
48
+ end
49
+ # Store connection in object for future use
50
+ item_definition.connection = connection
51
+ # Done
52
+ return item_definition
53
+ rescue
54
+ raise AMEE::BadData.new("Couldn't load ItemDefinition. Check that your URL is correct.")
55
+ end
56
+
57
+ def update(options = {})
58
+ response = connection.put(full_path, options).body
59
+ rescue
60
+ raise AMEE::BadData.new("Couldn't update ItemDefinition. Check that your information is correct.")
61
+ end
62
+
63
+ end
64
+ end
65
+ end
data/lib/amee/pager.rb ADDED
@@ -0,0 +1,59 @@
1
+ module AMEE
2
+ class Pager
3
+
4
+ def initialize(data)
5
+ @start = data[:start]
6
+ @from = data[:from]
7
+ @to = data[:to]
8
+ @items = data[:items]
9
+ @current_page = data[:current_page]
10
+ @requested_page = data[:requested_page]
11
+ @next_page = data[:next_page]
12
+ @previous_page = data[:previous_page]
13
+ @last_page = data[:last_page]
14
+ @items_per_page = data[:items_per_page]
15
+ @items_found = data[:items_found]
16
+ end
17
+
18
+ attr_reader :start
19
+ attr_reader :from
20
+ attr_reader :to
21
+ attr_reader :items
22
+ attr_reader :current_page
23
+ attr_reader :requested_page
24
+ attr_reader :next_page
25
+ attr_reader :previous_page
26
+ attr_reader :last_page
27
+ attr_reader :items_per_page
28
+ attr_reader :items_found
29
+
30
+ def self.from_xml(node)
31
+ return Pager.new({:start => node.elements["Start"].text.to_i,
32
+ :from => node.elements["From"].text.to_i,
33
+ :to => node.elements["To"].text.to_i,
34
+ :items => node.elements["Items"].text.to_i,
35
+ :current_page => node.elements["CurrentPage"].text.to_i,
36
+ :requested_page => node.elements["RequestedPage"].text.to_i,
37
+ :next_page => node.elements["NextPage"].text.to_i,
38
+ :previous_page => node.elements["PreviousPage"].text.to_i,
39
+ :last_page => node.elements["LastPage"].text.to_i,
40
+ :items_per_page => node.elements["ItemsPerPage"].text.to_i,
41
+ :items_found => node.elements["ItemsFound"].text.to_i})
42
+ end
43
+
44
+ def self.from_json(node)
45
+ return Pager.new({:start => node["start"],
46
+ :from => node["from"],
47
+ :to => node["to"],
48
+ :items => node["items"],
49
+ :current_page => node["currentPage"],
50
+ :requested_page => node["requestedPage"],
51
+ :next_page => node["nextPage"],
52
+ :previous_page => node["previousPage"],
53
+ :last_page => node["lastPage"],
54
+ :items_per_page => node["itemsPerPage"],
55
+ :items_found => node["itemsFound"]})
56
+ end
57
+
58
+ end
59
+ end
data/lib/amee/profile.rb CHANGED
@@ -1,15 +1,15 @@
1
1
  module AMEE
2
2
  module Profile
3
- class Profile < AMEE::Profile::Object
4
-
5
- def self.list(connection)
3
+ class ProfileList < Array
4
+
5
+ def initialize(connection, options = {})
6
6
  # Load data from path
7
- response = connection.get('/profiles').body
7
+ response = connection.get('/profiles', options).body
8
8
  # Parse data from response
9
- profiles = []
10
9
  if response.is_json?
11
10
  # Read JSON
12
11
  doc = JSON.parse(response)
12
+ @pager = AMEE::Pager.from_json(doc['pager'])
13
13
  doc['profiles'].each do |p|
14
14
  data = {}
15
15
  data[:uid] = p['uid']
@@ -20,11 +20,12 @@ module AMEE
20
20
  # Create profile
21
21
  profile = Profile.new(data)
22
22
  # Store in array
23
- profiles << profile
23
+ self << profile
24
24
  end
25
25
  else
26
26
  # Read XML
27
27
  doc = REXML::Document.new(response)
28
+ @pager = AMEE::Pager.from_xml(REXML::XPath.first(doc, '/Resources/ProfilesResource/Pager'))
28
29
  REXML::XPath.each(doc, '/Resources/ProfilesResource/Profiles/Profile') do |p|
29
30
  data = {}
30
31
  data[:uid] = p.attributes['uid'].to_s
@@ -37,14 +38,23 @@ module AMEE
37
38
  # Store connection in profile object
38
39
  profile.connection = connection
39
40
  # Store in array
40
- profiles << profile
41
+ self << profile
41
42
  end
42
43
  end
43
- # Done
44
- return profiles
45
44
  rescue
46
45
  raise AMEE::BadData.new("Couldn't load Profile list.")
47
46
  end
47
+
48
+ attr_reader :pager
49
+
50
+ end
51
+
52
+ class Profile < AMEE::Profile::Object
53
+
54
+ # backwards compatibility
55
+ def self.list(connection)
56
+ ProfileList.new(connection)
57
+ end
48
58
 
49
59
  def self.create(connection)
50
60
  # Create new profile
@@ -283,15 +283,17 @@ module AMEE
283
283
  raise AMEE::BadData.new("Couldn't create ProfileItem. Check that your information is correct.")
284
284
  end
285
285
 
286
- def self.create_batch(category, items)
286
+ def self.create_batch(category, items, options = {})
287
287
  create_batch_without_category(category.connection, category.full_path, items)
288
288
  end
289
289
 
290
- def self.create_batch_without_category(connection, category_path, items)
290
+ def self.create_batch_without_category(connection, category_path, items, options = {})
291
291
  if connection.format == :json
292
- post_data = ({:profileItems => items}).to_json
292
+ options.merge! :profileItems => items
293
+ post_data = options.to_json
293
294
  else
294
- post_data = ({:ProfileItems => items}).to_xml(:root => "ProfileCategory", :skip_types => true, :skip_nil => true)
295
+ options.merge!({:ProfileItems => items})
296
+ post_data = options.to_xml(:root => "ProfileCategory", :skip_types => true, :skip_nil => true)
295
297
  end
296
298
  # Post to category
297
299
  response = connection.raw_post(category_path, post_data).body
data/lib/amee/version.rb CHANGED
@@ -3,7 +3,7 @@ module AMEE
3
3
  module VERSION #:nodoc:
4
4
  MAJOR = 2
5
5
  MINOR = 0
6
- TINY = 15
6
+ TINY = 16
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: 2.0.15
4
+ version: 2.0.16
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: 2009-05-01 00:00:00 -07:00
12
+ date: 2009-05-12 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -60,6 +60,8 @@ files:
60
60
  - lib/amee/shell.rb
61
61
  - lib/amee/drill_down.rb
62
62
  - lib/amee/rails.rb
63
+ - lib/amee/pager.rb
64
+ - lib/amee/item_definition.rb
63
65
  - bin/ameesh
64
66
  - examples/list_profiles.rb
65
67
  - examples/create_profile.rb