amee 2.0.35 → 2.2.0

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/object.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module AMEE
2
2
  class Object
3
-
3
+ include ParseHelper
4
+ extend ParseHelper # because sometimes things parse themselves in class methdos
4
5
  def initialize(data = nil)
5
6
  @uid = data ? data[:uid] : nil
6
7
  @created = data ? data[:created] : Time.now
@@ -9,13 +10,13 @@ module AMEE
9
10
  @name = data ? data[:name] : nil
10
11
  @connection = data ? data[:connection] : nil
11
12
  end
12
-
13
+
13
14
  attr_accessor :connection
14
15
  attr_reader :uid
15
16
  attr_reader :created
16
17
  attr_reader :modified
17
18
  attr_reader :path
18
19
  attr_reader :name
19
-
20
+
20
21
  end
21
22
  end
data/lib/amee/pager.rb CHANGED
@@ -56,6 +56,49 @@ module AMEE
56
56
  :items_per_page => node["itemsPerPage"],
57
57
  :items_found => node["itemsFound"]})
58
58
  end
59
+ def more?
60
+ current_page<=last_page
61
+ end
62
+ def next!
63
+ @current_page+=1
64
+ more?
65
+ end
66
+ def page_fragment
67
+ "?page=#{current_page}"
68
+ end
69
+ def options
70
+ {:page => current_page}
71
+ end
72
+ end
59
73
 
74
+ class Limiter
75
+ extend ParseHelper
76
+ def initialize(data)
77
+ @offset=data[:resultStart] || 0
78
+ @limit=data[:resultLimit] || 10
79
+ @truncated=data[:truncated] || false
80
+ end
81
+ attr_reader :offset,:limit,:truncated
82
+ def more?
83
+ truncated
84
+ end
85
+ def next!
86
+ @offset+=limit
87
+ more?
88
+ end
89
+ def page_fragment
90
+ "?resultStart=#{offset}&resultLimit=#{limit}"
91
+ end
92
+ def options
93
+ {:resultStart=>offset,:resultLimit=>limit}
94
+ end
95
+ def self.from_json(doc,options={})
96
+ raise AMEE::NotSupported
97
+ end
98
+ def self.from_xml(node,options={})
99
+ t=x('@truncated',:doc=>node)
100
+ options[:truncated] = (t=='true') if t
101
+ Limiter.new options
102
+ end
60
103
  end
61
104
  end
@@ -0,0 +1,29 @@
1
+ module ParseHelper
2
+ def x(xpath,options = {})
3
+ doc = options[:doc] || @doc
4
+ preamble = options[:meta] == true ? metaxmlpathpreamble : xmlpathpreamble
5
+ nodes=REXML::XPath.match(doc,"#{preamble}#{xpath}")
6
+ if nodes.length==1
7
+ if nodes.first.respond_to?(:text)
8
+ return nodes.first.text
9
+ elsif nodes.first.respond_to?(:to_s)
10
+ return nodes.first.to_s
11
+ end
12
+ end
13
+
14
+ if nodes.length>1
15
+ if nodes.first.respond_to?(:text)
16
+ return nodes.map{|x| x.text}
17
+ elsif nodes.first.respond_to?(:to_s)
18
+ return nodes.map{|x| x.to_s}
19
+ end
20
+ end
21
+ return nil
22
+
23
+ end
24
+ def xmlpathpreamble
25
+ ''
26
+ end
27
+ private :x
28
+
29
+ end
@@ -9,6 +9,8 @@ module AMEE
9
9
  @items = data ? data[:items] : []
10
10
  @total_amount = data[:total_amount]
11
11
  @total_amount_unit = data[:total_amount_unit]
12
+ @amounts = data[:amounts] || []
13
+ @notes = data[:notes] || []
12
14
  @start_date = data[:start_date]
13
15
  @end_date = data[:end_date]
14
16
  @pager = data[:pager]
@@ -19,6 +21,8 @@ module AMEE
19
21
  attr_reader :items
20
22
  attr_reader :total_amount
21
23
  attr_reader :total_amount_unit
24
+ attr_reader :amounts
25
+ attr_reader :notes
22
26
  attr_reader :pager
23
27
 
24
28
  def start_date
@@ -59,7 +63,27 @@ module AMEE
59
63
  item_data[:amount] = value['value'].to_f
60
64
  item_data[:amount_unit] = value['unit']
61
65
  when 'amounts'
62
- # add new code per COM-69 here.
66
+ item_data[:amounts] = []
67
+ if value['amount']
68
+ value['amount'].each do |x|
69
+ d = {}
70
+ d[:type] = x['type']
71
+ d[:value] = x['value'].to_f
72
+ d[:unit] = x['unit']
73
+ d[:per_unit] = x['perUnit']
74
+ d[:default] = x['default'] == 'true'
75
+ item_data[:amounts] << d
76
+ end
77
+ end
78
+ item_data[:notes] = []
79
+ if value['note']
80
+ value['note'].each do |x|
81
+ d = {}
82
+ d[:type] = x['type']
83
+ d[:value] = x['value']
84
+ item_data[:notes] << d
85
+ end
86
+ end
63
87
  when 'itemValues'
64
88
  value.each do |itemval|
65
89
  path = itemval['path'].to_sym
@@ -295,7 +319,25 @@ module AMEE
295
319
  item_data[:amount] = element.text.to_f
296
320
  item_data[:amount_unit] = element.attributes['unit'].to_s
297
321
  when 'amounts'
298
- # add new code per COM-69 here.
322
+ element.elements.each do |x|
323
+ case x.name
324
+ when 'Amount'
325
+ item_data[:amounts] ||= []
326
+ d = {}
327
+ d[:type] = x.attributes['type'].to_s
328
+ d[:value] = x.text.to_f
329
+ d[:unit] = x.attributes['unit'].to_s
330
+ d[:per_unit] = x.attributes['perUnit'].to_s if x.attributes['perUnit']
331
+ d[:default] = x.attributes['default'] == 'true'
332
+ item_data[:amounts] << d
333
+ when 'Note'
334
+ item_data[:notes] ||= []
335
+ d = {}
336
+ d[:type] = x.attributes['type'].to_s
337
+ d[:value] = x.text
338
+ item_data[:notes] << d
339
+ end
340
+ end
299
341
  when 'itemvalues'
300
342
  element.elements.each do |itemvalue|
301
343
  path = itemvalue.elements['Path'].text
@@ -6,6 +6,8 @@ module AMEE
6
6
  @values = data ? data[:values] : []
7
7
  @total_amount = data[:total_amount]
8
8
  @total_amount_unit = data[:total_amount_unit]
9
+ @amounts = data[:amounts] || []
10
+ @notes = data[:notes] || []
9
11
  @start_date = data[:start_date] || data[:valid_from]
10
12
  @end_date = data[:end_date] || (data[:end] == true ? @start_date : nil )
11
13
  @data_item_uid = data[:data_item_uid]
@@ -15,6 +17,8 @@ module AMEE
15
17
  attr_reader :values
16
18
  attr_reader :total_amount
17
19
  attr_reader :total_amount_unit
20
+ attr_reader :amounts
21
+ attr_reader :notes
18
22
  attr_reader :start_date
19
23
  attr_reader :end_date
20
24
  attr_reader :data_item_uid
@@ -87,6 +91,27 @@ module AMEE
87
91
  end
88
92
  data[:values] << value_data
89
93
  end
94
+ if doc['profileItem']['amounts']
95
+ if doc['profileItem']['amounts']['amount']
96
+ data[:amounts] = doc['profileItem']['amounts']['amount'].map do |item|
97
+ {
98
+ :type => item['type'],
99
+ :value => item['value'].to_f,
100
+ :unit => item['unit'],
101
+ :per_unit => item['perUnit'],
102
+ :default => (item['default'] == 'true'),
103
+ }
104
+ end
105
+ end
106
+ if doc['profileItem']['amounts']['note']
107
+ data[:notes] = doc['profileItem']['amounts']['note'].map do |item|
108
+ {
109
+ :type => item['type'],
110
+ :value => item['value'],
111
+ }
112
+ end
113
+ end
114
+ end
90
115
  # Create object
91
116
  Item.new(data)
92
117
  rescue
@@ -114,7 +139,7 @@ module AMEE
114
139
  value = element.text
115
140
  case key
116
141
  when 'Name', 'Path', 'Value'
117
- value_data[key.downcase.to_sym] = value
142
+ value_data[key.downcase.to_sym] = value
118
143
  end
119
144
  end
120
145
  value_data[:uid] = item.attributes['uid'].to_s
@@ -155,6 +180,22 @@ module AMEE
155
180
  value_data[:uid] = item.attributes['uid'].to_s
156
181
  data[:values] << value_data
157
182
  end
183
+ data[:amounts] = REXML::XPath.each(doc, '/Resources/ProfileItemResource/ProfileItem/Amounts/Amount').map do |item|
184
+ x = {
185
+ :type => item.attribute('type').value,
186
+ :value => item.text.to_f,
187
+ :unit => item.attribute('unit').value,
188
+ }
189
+ x[:per_unit] = item.attribute('perUnit').value if item.attribute('perUnit')
190
+ x[:default] = (item.attribute('default').value == 'true') if item.attribute('default')
191
+ x
192
+ end
193
+ data[:notes] = REXML::XPath.each(doc, '/Resources/ProfileItemResource/ProfileItem/Amounts/Note').map do |item|
194
+ {
195
+ :type => item.attribute('type').value,
196
+ :value => item.text,
197
+ }
198
+ end
158
199
  # Create object
159
200
  Item.new(data)
160
201
  rescue
@@ -255,7 +296,7 @@ module AMEE
255
296
  end
256
297
  if options[:end_date] && connection.version >= 2
257
298
  options[:endDate] = options[:end_date].xmlschema
258
- end
299
+ end
259
300
  if options[:duration] && connection.version >= 2
260
301
  options[:duration] = "PT#{options[:duration] * 86400}S"
261
302
  end
@@ -263,7 +304,7 @@ module AMEE
263
304
  options.merge! :dataItemUid => data_item_uid
264
305
  response = connection.post(path, options)
265
306
  if response['Location']
266
- location = response['Location'].match("http://.*?(/.*)")[1]
307
+ location = response['Location'].match("https??://.*?(/.*)")[1]
267
308
  else
268
309
  category = Category.parse(connection, response.body, nil)
269
310
  location = category.full_path + "/" + category.items[0][:path]
@@ -316,7 +357,7 @@ module AMEE
316
357
  options.delete(:start_date)
317
358
  if options[:end_date] && connection.version >= 2
318
359
  options[:endDate] = options[:end_date].xmlschema
319
- end
360
+ end
320
361
  options.delete(:end_date)
321
362
  if options[:duration] && connection.version >= 2
322
363
  options[:duration] = "PT#{options[:duration] * 86400}S"
data/lib/amee/rails.rb CHANGED
@@ -9,6 +9,9 @@ module AMEE
9
9
  def self.global(options = {})
10
10
  unless @connection
11
11
  $AMEE_CONFIG ||= {} # Make default values nil
12
+ if $AMEE_CONFIG['ssl'] == false
13
+ options.merge! :ssl => false
14
+ end
12
15
  @connection = self.connect($AMEE_CONFIG['server'], $AMEE_CONFIG['username'], $AMEE_CONFIG['password'], options)
13
16
  # Also store as $amee for backwards compatibility, though this is now deprecated
14
17
  $amee = @connection
@@ -25,6 +28,7 @@ module AMEE
25
28
 
26
29
  def self.included(base)
27
30
  base.extend ClassMethods
31
+ AMEE::Logger.to(::Rails.logger) if defined? ::Rails
28
32
  end
29
33
 
30
34
  module ClassMethods
@@ -36,7 +40,7 @@ module AMEE
36
40
  alias_method_chain :save, :amee
37
41
  before_destroy :amee_destroy
38
42
  # Check that this object has an AMEE profile UID when saving
39
- validates_presence_of :amee_profile
43
+ validates_presence_of :amee_profile
40
44
  end
41
45
  end
42
46
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amee
3
3
  version: !ruby/object:Gem::Version
4
- hash: 73
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
+ - 2
8
9
  - 0
9
- - 35
10
- version: 2.0.35
10
+ version: 2.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Smith
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-15 00:00:00 +01:00
18
+ date: 2010-07-21 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -62,6 +62,20 @@ dependencies:
62
62
  version: "0"
63
63
  type: :runtime
64
64
  version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: log4r
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :runtime
78
+ version_requirements: *id004
65
79
  description:
66
80
  email: james@floppy.org.uk
67
81
  executables:
@@ -73,6 +87,7 @@ extra_rdoc_files: []
73
87
  files:
74
88
  - README
75
89
  - COPYING
90
+ - CHANGELOG
76
91
  - lib/amee.rb
77
92
  - lib/amee/connection.rb
78
93
  - lib/amee/data_item.rb
@@ -93,7 +108,11 @@ files:
93
108
  - lib/amee/rails.rb
94
109
  - lib/amee/pager.rb
95
110
  - lib/amee/item_definition.rb
111
+ - lib/amee/item_value_definition.rb
96
112
  - lib/amee/user.rb
113
+ - lib/amee/collection.rb
114
+ - lib/amee/parse_helper.rb
115
+ - lib/amee/logger.rb
97
116
  - bin/ameesh
98
117
  - examples/list_profiles.rb
99
118
  - examples/create_profile.rb
@@ -103,6 +122,7 @@ files:
103
122
  - init.rb
104
123
  - rails/init.rb
105
124
  - amee.example.yml
125
+ - cacert.pem
106
126
  has_rdoc: true
107
127
  homepage: http://github.com/Floppy/amee-ruby
108
128
  licenses: []