Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor resource and memoize url generation

  • Loading branch information...
commit 8baac27bb0b781bbec00db5e8861afe2650715c4 1 parent 456ac9e
@mloughran mloughran authored
Showing with 14 additions and 4 deletions.
  1. +14 −4 lib/pusher/resource.rb
View
18 lib/pusher/resource.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.