Class: Weibo2::Interface::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/weibo2/interface/base.rb

Overview

The Base class of API

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Base

Returns a new instance of Base.



6
7
8
# File 'lib/weibo2/interface/base.rb', line 6

def initialize(client)
  @client = client
end

Instance Method Details

#get(path, opts = {}, &block) ⇒ Object



22
23
24
# File 'lib/weibo2/interface/base.rb', line 22

def get(path, opts={}, &block)
  request(:get, path, opts, &block)
end

#post(path, opts = {}, &block) ⇒ Object



26
27
28
# File 'lib/weibo2/interface/base.rb', line 26

def post(path, opts={}, &block)
  request(:post, path, opts, &block)
end

#request(verb, path, opts = {}, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/weibo2/interface/base.rb', line 10

def request(verb, path, opts={}, &block)
  unless @client.is_authorized?
    raise "I can't find a valid access_token. Forgot to get it or expired?"
  end
  
  response = @client.token.request(verb, path, opts, &block)
  if response.error
    raise Error.new(response)
  end
  response
end