Skip to content

Commit

Permalink
Cleanup Part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Anil V committed Aug 4, 2011
1 parent c9a87e3 commit 0eb40b8
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/rdio_api/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ module RdioApi
module Api

def method_missing(method_sym, *arguments)
if UNAUTHENTICATED.include?(method_sym)
unauthenticated_request(method_sym, *arguments)
elsif AUTHENTICATED.include?(method_sym)
authenticated_request(method_sym, *arguments)
end
if UNAUTHENTICATED.include?(method_sym)
unauthenticated_request(method_sym, *arguments)
elsif AUTHENTICATED.include?(method_sym)
authenticated_request(method_sym, *arguments)
end
end

def respond_to?(method)
AUTHENTICATED.include?(method.to_sym) || UNAUTHENTICATED.include?(method.to_sym) ? true : false
end

private

def unauthenticated_request(method_sym, *arguments)
response = unauthenticated_connection.post do |request|
request.body = {:method => method_sym.to_s}.merge!(Hash[*arguments.flatten])
Expand All @@ -28,11 +28,11 @@ def unauthenticated_request(method_sym, *arguments)

def authenticated_request(method_sym, *arguments)
if authenticated_connection
response = MultiJson.decode(authenticated_connection.post(api_url,
{:method => method_sym.to_s}.merge!(Hash[*arguments.flatten])).body)['result']
response.is_a?(Hash) ? Hashie::Mash.new(response) : response
response = MultiJson.decode(authenticated_connection.post(api_url,
{:method => method_sym.to_s}.merge!(Hash[*arguments.flatten])).body)['result']
response.is_a?(Hash) ? Hashie::Mash.new(response) : response
else
"Set access token at initialization or the client's access_token instance variable"
"Set access token at initialization or the client's access_token instance variable"
end
end

Expand Down

0 comments on commit 0eb40b8

Please sign in to comment.