Class: CS::Auth::OAuth

Inherits:
Object
  • Object
show all
Defined in:
lib/cs/auth/oauth.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(consumer_key, consumer_secret, access_token, access_token_secret, uri = nil) ⇒ OAuth

Returns a new instance of OAuth.


10
11
12
13
14
15
16
17
18
# File 'lib/cs/auth/oauth.rb', line 10

def initialize(consumer_key, consumer_secret, access_token, access_token_secret, uri=nil)
  @consumer_key = consumer_key
  @consumer_secret = consumer_secret
  @access_token = access_token
  @access_token_secret = access_token_secret
  oauth_base = ::OAuth::Consumer.new(consumer_key, consumer_secret, :site => uri)
  @oauth = ::OAuth::AccessToken.new(oauth_base, access_token, access_token_secret)
  reset
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token


7
8
9
# File 'lib/cs/auth/oauth.rb', line 7

def access_token
  @access_token
end

#access_token_secretObject

Returns the value of attribute access_token_secret


7
8
9
# File 'lib/cs/auth/oauth.rb', line 7

def access_token_secret
  @access_token_secret
end

#consumer_keyObject

Returns the value of attribute consumer_key


7
8
9
# File 'lib/cs/auth/oauth.rb', line 7

def consumer_key
  @consumer_key
end

#consumer_secretObject

Returns the value of attribute consumer_secret


7
8
9
# File 'lib/cs/auth/oauth.rb', line 7

def consumer_secret
  @consumer_secret
end

#errorsObject

Returns the value of attribute errors


7
8
9
# File 'lib/cs/auth/oauth.rb', line 7

def errors
  @errors
end

#loggerObject

Returns the value of attribute logger


7
8
9
# File 'lib/cs/auth/oauth.rb', line 7

def logger
  @logger
end

#request_bodyObject

Returns the value of attribute request_body


7
8
9
# File 'lib/cs/auth/oauth.rb', line 7

def request_body
  @request_body
end

#request_headersObject

Returns the value of attribute request_headers


7
8
9
# File 'lib/cs/auth/oauth.rb', line 7

def request_headers
  @request_headers
end

#response_bodyObject

Returns the value of attribute response_body


7
8
9
# File 'lib/cs/auth/oauth.rb', line 7

def response_body
  @response_body
end

#response_codeObject

Returns the value of attribute response_code


7
8
9
# File 'lib/cs/auth/oauth.rb', line 7

def response_code
  @response_code
end

#response_headersObject

Returns the value of attribute response_headers


7
8
9
# File 'lib/cs/auth/oauth.rb', line 7

def response_headers
  @response_headers
end

Instance Method Details

#base_uri=(uri = nil) ⇒ Object


70
71
72
# File 'lib/cs/auth/oauth.rb', line 70

def base_uri=(uri = nil)
  self.class.base_uri uri
end

#delete(path, query = {}, headers = {}) ⇒ Object


55
56
57
58
59
60
61
# File 'lib/cs/auth/oauth.rb', line 55

def delete(path, query={}, headers = {})
  execute do
    path += '?' + URI.encode_www_form(query) unless query.empty?
    @request_headers = default_headers.merge(headers)
    oauth.delete(path, headers)
  end
end

#execute(&block) ⇒ Object


24
25
26
27
28
29
# File 'lib/cs/auth/oauth.rb', line 24

def execute(&block)
  reset
  response = yield
  parse_response(response)
  @response_body
end

#get(path, query = {}, headers = {}) ⇒ Object


31
32
33
34
35
36
37
# File 'lib/cs/auth/oauth.rb', line 31

def get(path, query={}, headers = {})
  execute do
    path += '?' + URI.encode_www_form(query) unless query.empty?
    @request_headers = default_headers.merge(headers)
    oauth.get(path, headers)
  end
end

#head(path, headers = {}) ⇒ Object


63
64
65
66
67
68
# File 'lib/cs/auth/oauth.rb', line 63

def head(path, headers = {})
  execute do
    @request_headers = default_headers.merge(headers)
    oauth.head(path, headers)
  end
end

#oauthObject


20
21
22
# File 'lib/cs/auth/oauth.rb', line 20

def oauth
  @oauth
end

#post(path, body = '', headers = {}) ⇒ Object


39
40
41
42
43
44
45
# File 'lib/cs/auth/oauth.rb', line 39

def post(path, body = '', headers = {})
  execute do
    @request_headers = default_headers.merge(headers)
    @request_body = body.to_json
    oauth.post(path, @request_body, headers)
  end
end

#put(path, body = '', headers = {}) ⇒ Object


47
48
49
50
51
52
53
# File 'lib/cs/auth/oauth.rb', line 47

def put(path, body = '', headers = {})
  execute do
    @request_headers = default_headers.merge(headers)
    @request_body = body.to_json
    oauth.put(path, @request_body, headers)
  end
end