tepco_usage_api 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,12 @@ class TepcoUsage
8
8
  JSON.parse(response.body)
9
9
  end
10
10
 
11
+ def at(date)
12
+ path = "/#{date.year}/#{date.month}/#{date.day}.json"
13
+ response = request(path)
14
+ JSON.parse(response.body)
15
+ end
16
+
11
17
  private
12
18
  def request(path)
13
19
  http.request_get(path)
@@ -1,5 +1,6 @@
1
1
  require File.expand_path(File.join(
2
2
  File.dirname(__FILE__), 'spec_helper'))
3
+ require 'date'
3
4
 
4
5
  describe TepcoUsage do
5
6
  describe "#latest" do
@@ -30,4 +31,46 @@ describe TepcoUsage do
30
31
  end
31
32
 
32
33
  end
34
+ describe "#at" do
35
+ context "Given Date object" do
36
+ before do
37
+ today = Date.today
38
+ path = "/#{today.year}/#{today.month}/#{today.day}.json"
39
+ TepcoUsage.stub!(:request).with(path).and_return do
40
+ mock = mock(Object.new, :body => <<-JSON)
41
+ [
42
+ {
43
+ "saving": false,
44
+ "hour": 0,
45
+ "capacity_updated": "2011-03-25 16:05:00",
46
+ "month": 3,
47
+ "usage_updated": "2011-03-25 16:30:49",
48
+ "entryfor": "2011-03-25 15:00:00",
49
+ "capacity_peak_period": null,
50
+ "year": 2011,
51
+ "usage": 2889,
52
+ "capacity": 3750,
53
+ "day": 26
54
+ },
55
+ {
56
+ "saving": false,
57
+ "hour": 1,
58
+ "capacity_updated": "2011-03-25 16:05:00",
59
+ "month": 3,
60
+ "usage_updated": "2011-03-25 17:05:49",
61
+ "entryfor": "2011-03-25 16:00:00",
62
+ "capacity_peak_period": null,
63
+ "year": 2011,
64
+ "usage": 2758,
65
+ "capacity": 3750,
66
+ "day": 26
67
+ }
68
+ ]
69
+ JSON
70
+ end
71
+ end
72
+ subject{TepcoUsage.at(Date.today)}
73
+ it { should_not be_nil }
74
+ end
75
+ end
33
76
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: tepco_usage_api
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tatsuya Sato