Class: OAuthRubytter

Inherits:
Rubytter show all
Defined in:
lib/rubytter/oauth_rubytter.rb

Overview

must use oauth library.

Constant Summary

Constants inherited from Rubytter

Rubytter::VERSION

Instance Attribute Summary

Attributes inherited from Rubytter

#header, #host, #login, #path_prefix

Instance Method Summary collapse

Methods inherited from Rubytter

#__create_saved_search, #__update_status, api_settings, #create_request, #create_saved_search, #direct_message, #http_request, #search, #search_result_to_hash, #search_user, #setup, #structize, #to_param_str, #update, #update_status

Constructor Details

#initialize(access_token, options = {}) ⇒ OAuthRubytter

access_token: must be instance of OAuth::AccessToken



5
6
7
8
# File 'lib/rubytter/oauth_rubytter.rb', line 5

def initialize(access_token, options = {})
  super(nil, nil, options)
  @access_token = access_token
end

Instance Method Details

#delete(path, params = {}) ⇒ Object



27
28
29
30
31
32
# File 'lib/rubytter/oauth_rubytter.rb', line 27

def delete(path, params = {})
  path = path_prefix + path + '.json'
  param_str = to_param_str(params)
  path = path + '?' + param_str unless param_str.empty?
  parse_response(@access_token.delete(path, @header))
end

#get(path, params = {}) ⇒ Object



10
11
12
13
14
15
# File 'lib/rubytter/oauth_rubytter.rb', line 10

def get(path, params = {})
  path = path_prefix + path + '.json'
  param_str = to_param_str(params)
  path = path + '?' + param_str unless param_str.empty?
  parse_response(@access_token.get(path, @header))
end

#parse_response(res) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/rubytter/oauth_rubytter.rb', line 34

def parse_response(res)
  json_data = JSON.parse(res.body)
  case res.code
  when "200"
    structize(json_data)
  else
    raise APIError.new(json_data['error'], res)
  end
end

#post(path, params = {}) ⇒ Object



17
18
19
20
# File 'lib/rubytter/oauth_rubytter.rb', line 17

def post(path, params = {})
  path = path_prefix + path + '.json'
  parse_response(@access_token.post(path, params.stringify_keys, @header))
end

#put(path, params = {}) ⇒ Object



22
23
24
25
# File 'lib/rubytter/oauth_rubytter.rb', line 22

def put(path, params = {})
  path = path_prefix + path + '.json'
  parse_response(@access_token.put(path, params.stringify_keys, @header))
end