This repository has been archived by the owner on Dec 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-harvest-deprecated-api.php
764 lines (655 loc) · 19.8 KB
/
wp-harvest-deprecated-api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
<?php
/**
* WP Harvest API
*
* @link http://help.getharvest.com/api/ API Docs
* @package WP-API-Libraries\WP-Harvest-API
*/
/* Exit if accessed directly. */
if ( ! defined( 'ABSPATH' ) ) { exit; }
/* Check if class exists. */
if ( ! class_exists( 'HarvestAPI' ) ) {
/**
* Harvest API Class.
*
* @link http://help.getharvest.com/api/ API Docs
*/
class HarvestAPI {
/**
* HTTP request arguments.
*
* (default value: array())
*
* @var array
* @access protected
*/
private $args = array();
/**
* Output.
*
* @var string
*/
static private $output;
/**
* Account
*
* @var string
*/
static private $account;
/**
* BaseAPI Endpoint
*
* @var string
* @access protected
*/
protected $base_uri;
/**
* __construct function.
*
* @access public
* @param mixed $account Account.
* @param mixed $email Email.
* @param mixed $password Password.
* @param string $output (default: 'json') Output.
* @return void
*/
public function __construct( $account, $email, $password, $output = 'json' ) {
static::$account = $account;
static::$output = $account;
$this->base_uri = 'https://' . $account . '.harvestapp.com';
$secret_key = base64_encode( $email . ':' . $password );
$this->args['headers'] = array(
'Content-Type' => 'application/json',
'Accept' => 'application/json',
'Authorization' => 'Basic ' . $secret_key,
);
}
/**
* Fetch the request from the API.
*
* @access private
* @param mixed $request Request URL.
* @return $body Body.
*/
private function fetch( $request ) {
$response = wp_remote_request( $request, $this->args );
$code = wp_remote_retrieve_response_code( $response );
if ( 200 !== $code ) {
return new WP_Error( 'response-error', sprintf( __( 'Server response code: %d', 'wp-harvest-api' ), $code ) );
}
$body = wp_remote_retrieve_body( $response );
return json_decode( $body );
}
/* ACCOUNT. */
/**
* Who Am I?
*
* @access public
* @return void
*/
public function who_am_i() {
$request = $this->base_uri . '/account/who_am_i?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Get Rate Limit Status.
*
* @access public
* @return void
*/
public function get_rate_limit_status() {
$request = $this->base_uri . '/account/rate_limit_status?output=' . static::$output;
return $this->fetch( $request );
}
/* CLIENTS. */
/**
* Get all Clients
*
* @access public
* @return void
*/
public function get_all_clients() {
$request = $this->base_uri . '/clients?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Get Client.
*
* @access public
* @param mixed $client_id Client ID.
* @return void
*/
public function get_client( $client_id ) {
$request = $this->base_uri . '/clients/' . $client_id . '?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Create Client.
*
* @access public
* @param mixed $name Name.
* @param mixed $currency Currency.
* @param mixed $curreny_symbol Currency Symbol.
* @param mixed $active Active.
* @param mixed $details Details.
* @param mixed $highrise_id HighRise ID.
* @return void
*/
public function create_client( $name, $currency, $curreny_symbol, $active, $details, $highrise_id ) {
$request = $this->base_uri . '/clients?name=' . $name . '&active=' . $active . '¤cy=' . $currency . '¤cy_symbol=' . $curreny_symbol . '&detail=' . $details . '&highrise_id=' . $highrise_id . 'output=' . static::$output;
return $this->fetch( $request );
}
/**
* Update Client.
*
* @access public
* @param mixed $name Name.
* @param mixed $currency Currency.
* @param mixed $curreny_symbol Currency Symbol.
* @param mixed $active Active.
* @param mixed $details Details.
* @param mixed $highrise_id HighRise ID.
* @return void
*/
public function update_client( $name, $currency, $curreny_symbol, $active, $details, $highrise_id ) {
$request = $this->base_uri . '/clients?name=' . $name . '&active=' . $active . '¤cy=' . $currency . '¤cy_symbol=' . $curreny_symbol . '&detail=' . $details . '&highrise_id=' . $highrise_id . 'output=' . static::$output;
return $this->fetch( $request );
}
/**
* Toggle Client.
*
* @access public
* @param mixed $client_id
* @return void
*/
public function toggle_client( $client_id ) {
$request = $this->base_uri . '/clients/' . $client_id . '/toggle?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Delete Client.
*
* @access public
* @param mixed $client_id Client ID.
* @return void
*/
public function delete_client( $client_id ) {
$request = $this->base_uri . '/clients/' . $client_id . '?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Get All Contacts.
*
* @access public
* @param string $updated_since (default: '') Updated Since.
* @return void
*/
public function get_all_contacts( $updated_since = '' ) {
$request = $this->base_uri . '/contacts?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Get All Contacts For A Client.
*
* @access public
* @param mixed $client_id Client ID.
* @param string $updated_since (default: '') Updated Since.
* @return void
*/
public function get_all_client_contacts( $client_id, $updated_since = '' ) {
$request = $this->base_uri . '/clients/contacts?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Get Client Contact.
*
* @access public
* @param mixed $contact_id Contact ID.
* @return void
*/
public function get_client_contact( $contact_id ) {
$request = $this->base_uri . '/contacts/' . $contact_id . '?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Add Contact.
*
* @access public
* @param mixed $client_id Client ID.
* @param mixed $first_name First Name.
* @param mixed $last_name Last Name.
* @return void
*/
public function add_contact( $client_id, $first_name, $last_name ) {
$request = $this->base_uri . '/contacts/' . $contact_id . '?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Update Contact.
*
* @access public
* @param mixed $client_id Client ID.
* @param mixed $first_name First Name.
* @param mixed $last_name Last Name.
* @return void
*/
public function update_contact( $client_id, $first_name, $last_name ) {
$request = $this->base_uri . '/contacts/' . $contact_id . '?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Delete Contact.
*
* @access public
* @param mixed $contact_id Contact ID.
* @return void
*/
public function delete_contact( $contact_id ) {
$request = $this->base_uri . '/contacts/' . $contact_id . '?output=' . static::$output;
return $this->fetch( $request );
}
/* INVOICES & ESTIMATES. */
/**
* Add Invoice.
*
* @access public
* @param mixed $due_at_human_format Due at Human Format.
* @param mixed $client_id Client ID.
* @param mixed $currency Currency.
* @param mixed $discount Discount.
* @param mixed $issued_at Issued At.
* @param mixed $subject Subject.
* @param mixed $notes Notes.
* @param mixed $number Number.
* @param mixed $kind Kind.
* @param mixed $projects_to_invoice Projects to Invoice.
* @param mixed $import_hours Import Hours.
* @param mixed $import_expenses Import Expenses.
* @param mixed $expense_summary_type Expense Summary Type.
* @param mixed $period_start Period Start.
* @param mixed $period_end Period End.
* @param mixed $expense_period_start Expense Period Start.
* @param mixed $expense_period_end Expense Period End.
* @param mixed $csv_line_items CSV Line Items.
* @param mixed $tax Tax.
* @param mixed $tax2 Tax 2.
* @param mixed $purchase_order Purchase Order.
* @return void
*/
public function add_invoice( $due_at_human_format, $client_id, $currency, $discount, $issued_at, $subject, $notes, $number, $kind, $projects_to_invoice, $import_hours, $import_expenses, $expense_summary_type, $period_start, $period_end, $expense_period_start, $expense_period_end, $csv_line_items, $tax, $tax2, $purchase_order ) {
$request = $this->base_uri . '/invoices?output=' . static::$output;
return $this->fetch( $request );
}
/* EXPENSES. */
/**
* Get Expense.
*
* @access public
* @param mixed $expense_id Expense ID.
* @param string $of_user (default: '') Of User.
* @return void
*/
public function get_expense( $expense_id, $of_user = '' ) {
$request = $this->base_uri . '/expenses?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Delete Expense.
*
* @access public
* @param mixed $expense_id Expense ID.
* @return void
*/
public function delete_expense( $expense_id ) {
$request = $this->base_uri . '/expenses/' . $expense_id . '?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Attach Receipt Image to Expense.
*
* @access public
* @param mixed $expense_id Expense ID.
* @return void
*/
public function attach_receipt_image_to_expense( $expense_id ) {
$request = $this->base_uri . '/expenses/' . $expense_id . '/receipt?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Get Receipt Image from Expense.
*
* @access public
* @param mixed $expense_id Expense ID.
* @return void
*/
public function get_receipt_image_from_expense( $expense_id ) {
$request = $this->base_uri . '/expenses/' . $expense_id . '/receipt?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Add Expense.
*
* @access public
* @param mixed $notes Notes.
* @param mixed $total_cost Total Cost.
* @param mixed $project_id Project ID.
* @param mixed $expense_category_id Expense Category ID.
* @param mixed $billable Billable.
* @param mixed $spent_at Spent At.
* @param mixed $units Units.
* @return void
*/
public function add_expense( $notes, $total_cost, $project_id, $expense_category_id, $billable, $spent_at, $units ) {
}
/**
* Update Expense.
*
* @access public
* @param mixed $notes Notes.
* @param mixed $total_cost Total Cost.
* @param mixed $project_id Project ID.
* @param mixed $expense_category_id Expense Category ID.
* @param mixed $billable Billable.
* @param mixed $spent_at Spent At.
* @param mixed $units Units.
* @return void
*/
public function update_expense( $notes, $total_cost, $project_id, $expense_category_id, $billable, $spent_at, $units ) {
}
/* TIMESHEETS. */
/**
* Add Time Entry.
*
* @access public
* @param mixed $hours Hours.
* @param mixed $notes Notes.
* @param mixed $project_id Project ID.
* @param mixed $task_id Task ID.
* @param mixed $spent_at Spent At.
* @param mixed $client_id Client ID.
* @param mixed $user_id User ID.
* @param mixed $is_billed Is Billed.
* @param mixed $is_closed Is closed.
* @param mixed $timer_started_at Timer Started At.
* @param mixed $hours_with_timer Hours with Timer.
* @param mixed $hours_without_timer Hours without Timer.
* @param mixed $started_at Started At.
* @param mixed $ended_at Ended At.
* @param mixed $updated_at Updated At.
* @param $created_at $of_user Of User.
* @return void
*/
public function add_time_entry( $project_id, $task_id, $hours = null, $notes, $spent_at, $started_at = null, $ended_at = null, $client_id = null, $user_id = null, $is_billed = null, $is_closed = null, $timer_started_at = null, $hours_with_timer = null, $hours_without_timer = null, $updated_at = null, $of_user = null ) {
$request = $this->base_uri . '/daily/add?project_id=' . $project_id . '&task_id=' . $task_id . '&hours=' . $hours . '¬es=' . $notes . '&spent_at=' . $spent_at;
return $this->fetch( $request );
}
/**
* Toggle Timer.
*
* @access public
* @param mixed $day_entry_id Day Entry ID.
* @param mixed $of_user Of User.
* @return void
*/
public function toggle_timer( $day_entry_id, $of_user ) {
}
/**
* Delete Time Entry.
*
* @access public
* @param mixed $day_entry_id Day Entry ID.
* @param mixed $of_user Of User.
* @return void
*/
public function delete_time_entry( $day_entry_id, $of_user ) {
}
/**
* Update Time Entry.
*
* @access public
* @param mixed $day_entry_id Day Entry ID.
* @param mixed $of_user Of User.
* @return void
*/
public function update_time_entry( $day_entry_id, $of_user ) {
}
/* PROJECTS. */
/**
* Get All Projects.
*
* @access public
* @return void
*/
public function get_projects( $client_id = '', $updated_since = '' ) {
$request = $this->base_uri . '/projects?client=' . $client_id . '&updated_since=' . $updated_since . '&output=' . static::$output;
return $this->fetch( $request );
}
/**
* Get a Project.
*
* @access public
* @param mixed $project_id Project ID.
* @return void
*/
public function get_project( $project_id ) {
$request = $this->base_uri . '/projects/' . $project_id;
return $this->fetch( $request );
}
/**
* Create Project.
*
* @access public
* @param mixed $name Name.
* @param mixed $active Active.
* @param mixed $bill_by Bill By.
* @param mixed $client_id Client ID.
* @return void
*/
public function create_project( $name, $active, $bill_by, $client_id ) {
$request = $this->base_uri . '/projects?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Update Project.
*
* @access public
* @param mixed $project_id Project ID.
* @return void
*/
public function update_project( $project_id ) {
$request = $this->base_uri . '/projects/' . $project_id . '?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Toggle Project.
*
* @access public
* @param mixed $project_id Project ID.
* @return void
*/
public function toggle_project( $project_id ) {
$request = $this->base_uri . '/projects/' . $project_id . '/toggle?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Delete Project.
*
* @access public
* @param mixed $project_id Project ID.
* @return void
*/
public function delete_project( $project_id ) {
$request = $this->base_uri . '/projects/' . $project_id . '?output=' . static::$output;
return $this->fetch( $request );
}
/* REPORTS. */
/**
* Get Entries for project timeline.
*
* @access public
* @param mixed $project_id Project ID.
* @param mixed $tf_start_date Time Frame Start Date.
* @param mixed $tf_end_date Time Frame End Date.
* @return void
*/
public function get_entries_for_project_timeframe( $project_id, $tf_start_date, $tf_end_date ) {
}
/**
* Get Entries by user for Timeline.
*
* @access public
* @param mixed $user_id User ID.
* @param mixed $billable Billable.
* @param mixed $only_billed Only Billed.
* @param mixed $only_unbilled Only Unbilled.
* @param mixed $is_closed Is Closed.
* @param mixed $updated_since Updated Since.
* @return void
*/
public function get_entries_by_user_for_timeframe( $user_id, $billable, $only_billed, $only_unbilled, $is_closed, $updated_since ) {
}
/* TASKS. */
/**
* Get all Tasks.
*
* @access public
* @param string $updated_since (default: '') Updated Since.
* @return void
*/
public function get_all_tasks( $updated_since = '' ) {
$request = $this->base_uri . '/tasks/?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Get Task.
*
* @access public
* @param mixed $task_id Task ID.
* @return void
*/
public function get_task( $task_id ) {
$request = $this->base_uri . '/tasks/' . $task_id . '?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Add Task.
*
* @access public
* @return void
*/
public function add_task() {
$request = $this->base_uri . '/tasks/?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Archive Delete Task.
*
* @access public
* @param mixed $task_id Task ID.
* @return void
*/
public function archive_delete_task( $task_id ) {
$request = $this->base_uri . '/tasks/' . $task_id . '?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Update Task.
*
* @access public
* @param mixed $task_id Task ID.
* @return void
*/
public function update_task( $task_id ) {
$request = $this->base_uri . '/tasks/' . $task_id . '?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Reactivate Task.
*
* @access public
* @param mixed $task_id Task ID.
* @return void
*/
public function reactivate_task( $task_id ) {
$request = $this->base_uri . '/tasks/' . $task_id . '/activate?output=' . static::$output;
return $this->fetch( $request );
}
/* USERS. */
/**
* Get All Users.
*
* @access public
* @return void
*/
public function get_all_users() {
$request = $this->base_uri . '/people?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Add User.
*
* @access public
* @param mixed $email Email.
* @param mixed $first_name First Name.
* @param mixed $last_name Last Name.
* @param string $is_admin (default: '') Is Admin.
* @param mixed $timezone TimeZone.
* @param mixed $is_contractor Is Contractor.
* @param mixed $telephone Telephone.
* @param mixed $is_active Is Active.
* @param mixed $has_access_to_all_future_projects Has access to all future Projects.
* @param mixed $default_hourly_rate Default Hourly Rate.
* @param mixed $department Department.
* @param mixed $cost_rate Cost Rate.
* @return void
*/
public function add_user( $email, $first_name, $last_name, $is_admin = '', $timezone, $is_contractor, $telephone, $is_active, $has_access_to_all_future_projects, $default_hourly_rate, $department, $cost_rate ) {
$request = $this->base_uri . '/people?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Update User.
*
* @access public
* @param mixed $email Email.
* @param mixed $first_name First Name.
* @param mixed $last_name Last Name.
* @param string $is_admin (default: '') Is Admin.
* @param mixed $timezone TimeZone.
* @param mixed $is_contractor Is Contractor.
* @param mixed $telephone Telephone.
* @param mixed $is_active Is Active.
* @param mixed $has_access_to_all_future_projects Has access to all future Projects.
* @param mixed $default_hourly_rate Default Hourly Rate.
* @param mixed $department Department.
* @param mixed $cost_rate Cost Rate.
* @return void
*/
public function update_user( $email, $first_name, $last_name, $is_admin = '', $timezone, $is_contractor, $telephone, $is_active, $has_access_to_all_future_projects, $default_hourly_rate, $department, $cost_rate ) {
$request = $this->base_uri . '/people/' . $user_id . '?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Delete A User.
*
* @access public
* @param mixed $user_id User ID.
* @return void
*/
public function delete_user( $user_id ) {
$request = $this->base_uri . '/people/' . $user_id . '?output=' . static::$output;
return $this->fetch( $request );
}
/**
* Toggle An Existing User.
*
* @access public
* @param mixed $user_id User ID.
* @return void
*/
public function toggle_user( $user_id ) {
$request = $this->base_uri . '/people/' . $user_id . '/toggle?output=' . static::$output;
return $this->fetch( $request );
}
}
}