Class: TepcoUsage

Inherits:
Object
  • Object
show all
Defined in:
lib/tepco_usage_api.rb

Constant Summary collapse

@@default_options =
{
  :proxy => nil
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ TepcoUsage

Returns a new instance of TepcoUsage.



9
10
11
12
13
14
# File 'lib/tepco_usage_api.rb', line 9

def initialize(options = {})
  @options = @@default_options.merge(options.inject({}) do |opts, (key, value)|
    opts[key.to_sym] = value
    opts
  end)
end

Class Method Details

.at(arg) ⇒ Object



67
68
69
# File 'lib/tepco_usage_api.rb', line 67

def at(arg)
  tepco.at(arg)
end

.in(arg) ⇒ Object



71
72
73
# File 'lib/tepco_usage_api.rb', line 71

def in(arg)
  tepco.in(arg)
end

.latestObject



63
64
65
# File 'lib/tepco_usage_api.rb', line 63

def latest
  tepco.latest
end

Instance Method Details

#at(arg) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/tepco_usage_api.rb', line 21

def at(arg)
  path = case arg
         when Date
           "/#{arg.year}/#{arg.month}/#{arg.day}.json"
         when Time
           "/#{arg.year}/#{arg.month}/#{arg.day}/#{arg.hour}.json"
         end
  response = request(path)
  JSON.parse(response.body)
end

#in(arg) ⇒ Object



32
33
34
35
36
# File 'lib/tepco_usage_api.rb', line 32

def in(arg)
  path = "/#{arg.year}/#{arg.month}.json"
  response = request(path)
  JSON.parse(response.body)
end

#latestObject



16
17
18
19
# File 'lib/tepco_usage_api.rb', line 16

def latest
  response = request('/latest.json')
  JSON.parse(response.body)
end