Class: HCl::TimesheetResource
- Inherits:
-
Object
- Object
- HCl::TimesheetResource
show all
- Defined in:
- lib/hcl/timesheet_resource.rb
Defined Under Namespace
Classes: Failure
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of TimesheetResource.
27
28
29
|
# File 'lib/hcl/timesheet_resource.rb', line 27
def initialize params
@data = params
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/hcl/timesheet_resource.rb', line 59
def method_missing method, *args
if @data.key? method.to_sym
@data[method]
else
super
end
end
|
Class Method Details
5
6
7
8
9
10
11
12
13
|
# File 'lib/hcl/timesheet_resource.rb', line 5
def self.configure opts = nil
if opts
self.login = opts['login']
self.password = opts['password']
self.subdomain = opts['subdomain']
else
yield self
end
end
|
.get(action) ⇒ Object
31
32
33
|
# File 'lib/hcl/timesheet_resource.rb', line 31
def self.get action
https_do Net::HTTP::Get, action
end
|
.https_do(method_class, action, data = nil) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/hcl/timesheet_resource.rb', line 39
def self.https_do method_class, action, data = nil
https = Net::HTTP.new "#{subdomain}.harvestapp.com", 443
request = method_class.new "/#{action}"
https.use_ssl = true
request.basic_auth login, password
request.content_type = 'application/xml'
request['Accept'] = 'application/xml'
response = https.request request, data
return response.body
if response.kind_of? Net::HTTPSuccess
response.body
else
raise 'failure'
end
end
|
.post(action, data) ⇒ Object
35
36
37
|
# File 'lib/hcl/timesheet_resource.rb', line 35
def self.post action, data
https_do Net::HTTP::Post, action, data
end
|
.xml_to_hash(elem) ⇒ Object
67
68
69
70
71
72
|
# File 'lib/hcl/timesheet_resource.rb', line 67
def self.xml_to_hash elem
elem.elements.map { |e| e.name }.inject({}) do |a, f|
a[f.to_sym] = elem.elements[f].text if elem.elements[f]
a
end
end
|
Instance Method Details
#id ⇒ Object
55
56
57
|
# File 'lib/hcl/timesheet_resource.rb', line 55
def id
@data[:id]
end
|