Class: Soundcloud::PublicOAuthAccessToken

Inherits:
OAuthActiveResource::FakeOAuthAccessToken
  • Object
show all
Defined in:
lib/soundcloud/public_oauth_access_token.rb

Overview

Subclass to force API users to pass a consumer key with each request.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ PublicOAuthAccessToken

Returns a new instance of PublicOAuthAccessToken



7
8
9
10
11
12
13
14
# File 'lib/soundcloud/public_oauth_access_token.rb', line 7

def initialize(key)
  @key    = key
  @token = "public #{key}"
  @secret = 'Anonymous'
  
  # ensure that keys are symbols
  @options = @@default_options    
end

Instance Attribute Details

#secretObject

Returns the value of attribute secret



6
7
8
# File 'lib/soundcloud/public_oauth_access_token.rb', line 6

def secret
  @secret
end

#tokenObject

Returns the value of attribute token



6
7
8
# File 'lib/soundcloud/public_oauth_access_token.rb', line 6

def token
  @token
end

Instance Method Details

#request(http_method, path, token = nil, request_options = {}, *arguments) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/soundcloud/public_oauth_access_token.rb', line 15

def request(http_method, path, token = nil, request_options = {}, *arguments)
  # Force a relative path from an absolute path
  if path !~ /^\//
    @http = create_http(path)
  end
  _uri = URI.parse(path)
  
  # Append the consumer key to the request
  if _uri.query.nil?
    _uri.query = "consumer_key=#{@key}"
  else
    _uri.query += "&consumer_key=#{@key}"
  end
  
  path = "#{_uri.path}#{_uri.query ? "?#{_uri.query}" : ""}"
  rsp = http.request(create_http_request(http_method, path, token, request_options, *arguments ))
  
  rsp
end