Skip to content

Commit

Permalink
Refactor resource and memoize url generation
Browse files Browse the repository at this point in the history
  • Loading branch information
mloughran committed Nov 12, 2012
1 parent 456ac9e commit 8baac27
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/pusher/resource.rb
Expand Up @@ -6,21 +6,31 @@ def initialize(client, path)
end

def get(params)
Request.new(:get, @client.url(@path), params, nil, nil, @client).send_sync
create_request(:get, params).send_sync
end

def get_async(params)
Request.new(:get, @client.url(@path), params, nil, nil, @client).send_async
create_request(:get, params).send_async
end

def post(params)
body = MultiJson.encode(params)
Request.new(:post, @client.url(@path), {}, body, nil, @client).send_sync
create_request(:post, {}, body).send_sync
end

def post_async(params)
body = MultiJson.encode(params)
Request.new(:post, @client.url(@path), {}, body, nil, @client).send_async
create_request(:post, {}, body).send_async
end

private

def create_request(verb, params, body = nil)
Request.new(verb, url, params, body, nil, @client)
end

def url
@_url ||= @client.url(@path)
end
end
end

0 comments on commit 8baac27

Please sign in to comment.