Floppy-amee 2.0.20 → 2.0.21

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
+ @start_date = data[:start_date]
13
+ @end_date = data[:end_date]
12
14
  super
13
15
  end
14
16
 
@@ -17,6 +19,14 @@ module AMEE
17
19
  attr_reader :total_amount
18
20
  attr_reader :total_amount_unit
19
21
 
22
+ def start_date
23
+ @start_date || profile_date
24
+ end
25
+
26
+ def end_date
27
+ @end_date
28
+ end
29
+
20
30
  def self.parse_json_profile_item(item)
21
31
  item_data = {}
22
32
  item_data[:values] = {}
@@ -123,7 +133,8 @@ module AMEE
123
133
  doc = JSON.parse(json)
124
134
  data = {}
125
135
  data[:profile_uid] = doc['profile']['uid']
126
- data[:profile_date] = options[:start_date]
136
+ data[:start_date] = options[:start_date]
137
+ data[:end_date] = options[:end_date]
127
138
  data[:name] = doc['dataCategory']['name']
128
139
  data[:path] = doc['path']
129
140
  data[:total_amount] = doc['totalAmount']['value'].to_f rescue nil
@@ -301,7 +312,8 @@ module AMEE
301
312
  doc = REXML::Document.new(xml)
302
313
  data = {}
303
314
  data[:profile_uid] = REXML::XPath.first(doc, "/Resources/ProfileCategoryResource/Profile/@uid").to_s
304
- data[:profile_date] = options[:start_date]
315
+ data[:start_date] = options[:start_date]
316
+ data[:end_date] = options[:end_date]
305
317
  data[:name] = REXML::XPath.first(doc, '/Resources/ProfileCategoryResource/DataCategory/Name').text
306
318
  data[:path] = REXML::XPath.first(doc, '/Resources/ProfileCategoryResource/Path').text || ""
307
319
  data[:total_amount] = REXML::XPath.first(doc, '/Resources/ProfileCategoryResource/TotalAmount').text.to_f rescue nil
@@ -351,7 +363,8 @@ module AMEE
351
363
  doc = REXML::Document.new(response)
352
364
  data = {}
353
365
  data[:profile_uid] = REXML::XPath.first(doc, "/feed/@xml:base").to_s.match("/profiles/(.*?)/")[1]
354
- data[:profile_date] = options[:start_date]
366
+ data[:start_date] = options[:start_date]
367
+ data[:end_date] = options[:end_date]
355
368
  data[:name] = REXML::XPath.first(doc, '/feed/amee:name').text
356
369
  data[:path] = REXML::XPath.first(doc, "/feed/@xml:base").to_s.match("/profiles/.*?(/.*)")[1]
357
370
  data[:total_amount] = REXML::XPath.first(doc, '/feed/amee:totalAmount').text.to_f rescue nil
@@ -455,25 +468,28 @@ module AMEE
455
468
  end
456
469
  end
457
470
 
458
- def self.get(connection, path, options = {})
459
- unless options.is_a?(Hash)
471
+ def self.get(connection, path, orig_options = {})
472
+ unless orig_options.is_a?(Hash)
460
473
  raise AMEE::ArgumentError.new("Third argument must be a hash of options!")
461
474
  end
462
475
  # Convert to AMEE options
476
+ options = orig_options.clone
463
477
  if options[:start_date] && connection.version < 2
464
478
  options[:profileDate] = options[:start_date].amee1_month
465
479
  elsif options[:start_date] && connection.version >= 2
466
480
  options[:startDate] = options[:start_date].xmlschema
467
481
  end
482
+ options.delete(:start_date)
468
483
  if options[:end_date] && connection.version >= 2
469
484
  options[:endDate] = options[:end_date].xmlschema
470
485
  end
486
+ options.delete(:end_date)
471
487
  if options[:duration] && connection.version >= 2
472
488
  options[:duration] = "PT#{options[:duration] * 86400}S"
473
489
  end
474
490
  # Load data from path
475
491
  response = connection.get(path, options).body
476
- return Category.parse(connection, response, options)
492
+ return Category.parse(connection, response, orig_options)
477
493
  rescue
478
494
  raise AMEE::BadData.new("Couldn't load ProfileCategory. Check that your URL is correct.\n#{response}")
479
495
  end
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 = 20
6
+ TINY = 21
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.20
4
+ version: 2.0.21
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-07-24 00:00:00 -07:00
12
+ date: 2009-08-05 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -72,6 +72,7 @@ files:
72
72
  - rails/init.rb
73
73
  has_rdoc: true
74
74
  homepage: http://github.com/Floppy/amee-ruby
75
+ licenses:
75
76
  post_install_message:
76
77
  rdoc_options: []
77
78
 
@@ -92,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
93
  requirements: []
93
94
 
94
95
  rubyforge_project:
95
- rubygems_version: 1.2.0
96
+ rubygems_version: 1.3.5
96
97
  signing_key:
97
98
  specification_version: 2
98
99
  summary: Ruby interface to the AMEE carbon calculator