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

#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



68
69
70
# File 'lib/cs/auth/oauth.rb', line 68

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

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



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

def delete(path, query={}, headers = {})
  execute do
    path += '?' + URI.encode_www_form(query) unless query.empty?
    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?
    headers = default_headers.merge(headers)
    oauth.get(path, headers)
  end
end

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



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

def head(path, headers = {})
  execute do
    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
# File 'lib/cs/auth/oauth.rb', line 39

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

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



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

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