Module: LetsFreckle::ClientResource
Overview
ClientResource should be extended by resource classes in order to gain access to HTTP methods.
Instance Method Summary collapse
- #base_api_url ⇒ Object
- #get(resource, options = {}) ⇒ Object
- #post(resource, options = {}) ⇒ Object
- #relative_path_for(resource) ⇒ Object
Instance Method Details
#base_api_url ⇒ Object
21 22 23 |
# File 'lib/letsfreckle/client_resource.rb', line 21 def base_api_url "https://#{LetsFreckle.config.account_host}.letsfreckle.com" end |
#get(resource, options = {}) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/letsfreckle/client_resource.rb', line 6 def get(resource, = {}) response = client.get do |request| request.url relative_path_for(resource), end response.body.map { |mash| new(mash) } end |
#post(resource, options = {}) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/letsfreckle/client_resource.rb', line 13 def post(resource, = {}) client.post do |request| request.url relative_path_for(resource) request.headers['Content-Type'] = 'application/xml' request.body = end end |
#relative_path_for(resource) ⇒ Object
25 26 27 |
# File 'lib/letsfreckle/client_resource.rb', line 25 def relative_path_for(resource) "/api/#{resource}.xml?token=#{LetsFreckle.config.token}" end |