Class: Hatena::API::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/hatena/api/graph.rb

Constant Summary collapse

DATE_FORMAT =
'%Y-%m-%d'
GRAPH_API_URI =
URI.parse 'http://graph.hatena.ne.jp/api/post'

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ Graph

Returns a new instance of Graph.



16
17
18
19
# File 'lib/hatena/api/graph.rb', line 16

def initialize(username, password)
  @username = username
  @password = password
end

Instance Method Details

#post(graphname, date, value) ⇒ Object

Raises:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/hatena/api/graph.rb', line 21

def post(graphname, date, value)
  value = value.to_f
  date = date.strftime DATE_FORMAT
  headers = {
    'Access' => 'application/x.atom+xml, application/xml, text/xml, */*',
    'X-WSSE' => wsse(@username, @password),
  }
  params = {
    :graphname => graphname,
    :date => date,
    :value => value,
  }
  res = http_post GRAPH_API_URI, params, headers
  raise GraphError.new("request not successed: #{res}") if res.code != '201'
  res
end