Class: Hatena::API::Auth

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

Constant Summary collapse

BASE_URI =
'http://auth.hatena.ne.jp/'
PATH =
{
  :auth => '/auth',
  :json => '/api/auth.json'
}.freeze
VERSION =
'0.1.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Auth

Returns a new instance of Auth.



28
29
30
31
# File 'lib/hatena/api/auth.rb', line 28

def initialize(options = {})
  @api_key = options[:api_key]
  @secret  = options[:secret]
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



27
28
29
# File 'lib/hatena/api/auth.rb', line 27

def api_key
  @api_key
end

#secretObject

Returns the value of attribute secret.



27
28
29
# File 'lib/hatena/api/auth.rb', line 27

def secret
  @secret
end

Instance Method Details

#login(cert) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/hatena/api/auth.rb', line 40

def (cert)
  result = JSON.parse open(
             uri_to_authcheck(cert),
             'User-Agent' => "#{self.class}/#{VERSION} - Ruby"
           ).read

  if result['has_error']
    raise AuthError.new(result['error']['message'])
  else
    result['user']
  end
end

#uri_to_loginObject



33
34
35
36
37
38
# File 'lib/hatena/api/auth.rb', line 33

def 
  uri = URI.parse BASE_URI
  uri.path = PATH[:auth]
  uri.query = query_with_api_sig
  uri
end