Class: Weibo::Request

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/weibo/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, method, path, options = {}) ⇒ Request

Returns a new instance of Request.



25
26
27
28
# File 'lib/weibo/request.rb', line 25

def initialize(client, method, path, options={})
  @client, @method, @path, @options = client, method, path, {:mash => true, :query => {:source => Weibo::Config.api_key}}.merge(options)
  # puts @options.inspect
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



22
23
24
# File 'lib/weibo/request.rb', line 22

def client
  @client
end

#methodObject (readonly)

Returns the value of attribute method.



22
23
24
# File 'lib/weibo/request.rb', line 22

def method
  @method
end

#optionsObject (readonly)

Returns the value of attribute options.



22
23
24
# File 'lib/weibo/request.rb', line 22

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



22
23
24
# File 'lib/weibo/request.rb', line 22

def path
  @path
end

Class Method Details

.delete(client, path, options = {}) ⇒ Object



18
19
20
# File 'lib/weibo/request.rb', line 18

def self.delete(client, path, options={})
  new(client, :delete, path, options).perform
end

.get(client, path, options = {}) ⇒ Object



6
7
8
# File 'lib/weibo/request.rb', line 6

def self.get(client, path, options={})
  new(client, :get, path, options).perform
end

.post(client, path, options = {}) ⇒ Object



10
11
12
# File 'lib/weibo/request.rb', line 10

def self.post(client, path, options={})
  new(client, :post, path, options).perform
end

.put(client, path, options = {}) ⇒ Object



14
15
16
# File 'lib/weibo/request.rb', line 14

def self.put(client, path, options={})
  new(client, :put, path, options).perform
end

Instance Method Details

#performObject



43
44
45
# File 'lib/weibo/request.rb', line 43

def perform
  make_friendly(send("perform_#{method}"))
end

#uriObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/weibo/request.rb', line 31

def uri
  @uri ||= begin
    uri = URI.parse(path)
    if options[:query] && options[:query] != {}
      uri.query = to_query(options[:query])
      options[:query]
    end

    uri.to_s
  end
end