Module: LetsFreckle::ClientResource

Included in:
Entry, Project, Tag, User
Defined in:
lib/letsfreckle/client_resource.rb

Overview

ClientResource should be extended by resource classes in order to gain access to HTTP methods.

Instance Method Summary collapse

Instance Method Details

#base_api_urlObject



21
22
23
# File 'lib/letsfreckle/client_resource.rb', line 21

def base_api_url
  "https://#{LetsFreckle.config.}.letsfreckle.com"
end

#get(resource, options = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/letsfreckle/client_resource.rb', line 6

def get(resource, options = {})
  response = client.get do |request|
    request.url relative_path_for(resource), options
  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, options = {})
  client.post do |request|
    request.url relative_path_for(resource)
    request.headers['Content-Type'] = 'application/xml'
    request.body = options
  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