Class: Skr::Jobs::FreshBooks::Retrieve
- Inherits:
-
Base
- Object
- Lanes::Job
- Base
- Skr::Jobs::FreshBooks::Retrieve
show all
- Defined in:
- lib/skr/jobs/fresh_books/retrieve.rb
Constant Summary
Constants inherited
from Base
Base::STEPS
Instance Attribute Summary
Attributes inherited from Base
#fb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#fetch_each, #process_each_type, #resp_data_for_req_type
Class Method Details
.from_request(req) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/skr/jobs/fresh_books/retrieve.rb', line 38
def self.from_request(req)
fb = ::FreshBooks::Client.new("#{req['domain']}.freshbooks.com", req['api_key'])
errors = nil
begin
resp = fb.client.list(per_page: 1)
errors = {access: resp['error']} if resp['error']
rescue SocketError
errors = {network: 'Unable to resolve account'}
end
if errors
return {success: false, data: {}, errors: errors}
else
job = self.perform_later(req['domain'], req['api_key'])
return {
success: true, message: 'Import Validation Started', data: {
job: Lanes::Job.status_for_id(job.job_id)
}
}
end
end
|
Instance Method Details
31
32
33
34
35
36
|
# File 'lib/skr/jobs/fresh_books/retrieve.rb', line 31
def perform(account, token)
process_each_type(account, token) do | output, index |
save_progress(output, (index+1).to_f / STEPS.length)
end
self
end
|
#process_client(rec) ⇒ Object
7
8
9
|
# File 'lib/skr/jobs/fresh_books/retrieve.rb', line 7
def process_client(rec)
rec.slice(*%w{ client_id organization first_name last_name})
end
|
#process_invoice(rec) ⇒ Object
15
16
17
|
# File 'lib/skr/jobs/fresh_books/retrieve.rb', line 15
def process_invoice(rec)
rec.slice(*%w{invoice_id client_id number amount po_number notes status})
end
|
#process_project(rec) ⇒ Object
11
12
13
|
# File 'lib/skr/jobs/fresh_books/retrieve.rb', line 11
def process_project(rec)
rec.slice(*%w{project_id name description})
end
|
#process_staff(r) ⇒ Object
27
28
29
|
# File 'lib/skr/jobs/fresh_books/retrieve.rb', line 27
def process_staff(r)
r.slice(*%w{staff_id username first_name last_name email})
end
|
#process_time_entry(rec) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/skr/jobs/fresh_books/retrieve.rb', line 19
def process_time_entry(rec)
if rec['billed'] == '1'
nil
else
rec.slice(*%w{ time_entry_id staff_id project_id hours date notes})
end
end
|