Floppy-amee 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,11 +29,19 @@ module AMEE
29
29
  !@auth_token.nil?
30
30
  end
31
31
 
32
- def get(path)
32
+ def get(path, data = {})
33
+ # Create URL parameters
34
+ params = []
35
+ data.each_pair do |key, value|
36
+ params << "#{key}=#{value}"
37
+ end
38
+ if params.size > 0
39
+ path += "?#{params.join('&')}"
40
+ end
33
41
  # Send request
34
- do_request(Net::HTTP::Get.new(path))
42
+ do_request Net::HTTP::Get.new(path)
35
43
  end
36
-
44
+
37
45
  def post(path, data = {})
38
46
  # Create POST request
39
47
  post = Net::HTTP::Post.new(path)
@@ -8,14 +8,12 @@ module AMEE
8
8
  @children = data ? data[:children] : []
9
9
  @items = data ? data[:items] : []
10
10
  @total_amount_per_month = data[:total_amount_per_month]
11
- @values = data[:values]
12
11
  super
13
12
  end
14
13
 
15
14
  attr_reader :children
16
15
  attr_reader :items
17
16
  attr_reader :total_amount_per_month
18
- attr_reader :values
19
17
 
20
18
  def self.from_json(json)
21
19
  # Parse json
@@ -109,10 +107,26 @@ module AMEE
109
107
  rescue
110
108
  raise AMEE::BadData.new("Couldn't load ProfileCategory from XML data. Check that your URL is correct.")
111
109
  end
112
-
113
- def self.get(connection, path)
110
+
111
+ def self.get_history(connection, path, num_months, end_date = Date.today)
112
+ month = end_date.month
113
+ year = end_date.year
114
+ history = []
115
+ num_months.times do
116
+ date = Date.new(year, month)
117
+ history << self.get(connection, path, date)
118
+ month -= 1
119
+ if (month == 0)
120
+ year -= 1
121
+ month = 12
122
+ end
123
+ end
124
+ return history.reverse
125
+ end
126
+
127
+ def self.get(connection, path, for_date = Date.today)
114
128
  # Load data from path
115
- response = connection.get(path)
129
+ response = connection.get(path, :profileDate => for_date.strftime("%Y%m"))
116
130
  # Parse data from response
117
131
  if response.is_json?
118
132
  cat = Category.from_json(response)
@@ -133,4 +147,4 @@ module AMEE
133
147
 
134
148
  end
135
149
  end
136
- end
150
+ end
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.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Smith