Class: Sina::Base
- Inherits:
-
Object
- Object
- Sina::Base
- Defined in:
- lib/sina/base.rb
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #call_method(type, function = "users/show", params) ⇒ Object
-
#initialize(access_token) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(access_token) ⇒ Base
Returns a new instance of Base.
13 14 15 |
# File 'lib/sina/base.rb', line 13 def initialize(access_token) @access_token = access_token end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
11 12 13 |
# File 'lib/sina/base.rb', line 11 def params @params end |
Instance Method Details
#call_method(type, function = "users/show", params) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sina/base.rb', line 17 def call_method(type, function = "users/show", params) url = URI.parse("https://api.weibo.com/2/#{function}.json") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true if url.scheme == 'https' if type == "get" request = Net::HTTP::Get.new("#{url.path}?access_token=#{@access_token}&#{params_to_string(params)}") elsif type == "post" request = Net::HTTP::Post.new("#{url.path}?access_token=#{@access_token}") request.set_form_data(params) end MultiJson.decode(http.request(request).body) end |