tepco_usage_api 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,8 +8,13 @@ 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"
11
+ def at(arg)
12
+ path = case arg
13
+ when Date
14
+ "/#{arg.year}/#{arg.month}/#{arg.day}.json"
15
+ when Time
16
+ "/#{arg.year}/#{arg.month}/#{arg.day}/#{arg.hour}.json"
17
+ end
13
18
  response = request(path)
14
19
  JSON.parse(response.body)
15
20
  end
@@ -72,5 +72,45 @@ describe TepcoUsage do
72
72
  subject{TepcoUsage.at(Date.today)}
73
73
  it { should_not be_nil }
74
74
  end
75
+ context "Given Time object" do
76
+ before do
77
+ @now = Time.now
78
+ path = "/#{@now.year}/#{@now.month}/#{@now.day}/#{@now.hour}.json"
79
+ TepcoUsage.stub!(:request).with(path).and_return do
80
+ mock = mock(Object.new, :body => <<-JSON)
81
+ [
82
+ {
83
+ "saving": false,
84
+ "hour": 0,
85
+ "capacity_updated": "2011-03-25 16:05:00",
86
+ "month": 3,
87
+ "usage_updated": "2011-03-25 16:30:49",
88
+ "entryfor": "2011-03-25 15:00:00",
89
+ "capacity_peak_period": null,
90
+ "year": 2011,
91
+ "usage": 2889,
92
+ "capacity": 3750,
93
+ "day": 26
94
+ },
95
+ {
96
+ "saving": false,
97
+ "hour": 1,
98
+ "capacity_updated": "2011-03-25 16:05:00",
99
+ "month": 3,
100
+ "usage_updated": "2011-03-25 17:05:49",
101
+ "entryfor": "2011-03-25 16:00:00",
102
+ "capacity_peak_period": null,
103
+ "year": 2011,
104
+ "usage": 2758,
105
+ "capacity": 3750,
106
+ "day": 26
107
+ }
108
+ ]
109
+ JSON
110
+ end
111
+ end
112
+ subject{TepcoUsage.at(@now)}
113
+ it { should_not be_nil }
114
+ end
75
115
  end
76
116
  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.1.0
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Tatsuya Sato
@@ -54,6 +54,6 @@ rubyforge_project:
54
54
  rubygems_version: 1.5.2
55
55
  signing_key:
56
56
  specification_version: 3
57
- summary: The gem to talk with Yahoo! Web API.
57
+ summary: The gem to talk with Tepco Usage API.
58
58
  test_files: []
59
59