├── .editorconfig ├── .gitignore ├── .travis.yml ├── LICENCE.md ├── composer.json ├── phpcs.xml ├── readme.md └── src ├── TogglApi.php └── TogglReportsApi.php /.editorconfig: -------------------------------------------------------------------------------- 1 | # This file is for unifying the coding style for different editors and IDEs 2 | # editorconfig.org 3 | 4 | # PHP PSR-2 Coding Standards 5 | # http://www.php-fig.org/psr/psr-2/ 6 | 7 | root = true 8 | 9 | ; Unix-style newlines 10 | [*] 11 | end_of_line = LF 12 | 13 | [*.php] 14 | charset = utf-8 15 | end_of_line = lf 16 | insert_final_newline = true 17 | trim_trailing_whitespace = true 18 | indent_style = space 19 | indent_size = 4 20 | 21 | ; top-most EditorConfig file 22 | root = true 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | .env 3 | test.php 4 | .idea -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | sudo: false 3 | php: 4 | - 5.6 5 | - 7.0 6 | - 7.1 7 | before_install: 8 | - composer self-update 9 | install: 10 | - composer install 11 | script: 12 | - ./vendor/bin/phpcs 13 | -------------------------------------------------------------------------------- /LICENCE.md: -------------------------------------------------------------------------------- 1 | GNU General Public License 2 | ========================== 3 | 4 | _Version 3, 29 June 2007_ 5 | _Copyright © 2007 Free Software Foundation, Inc. <>_ 6 | 7 | Everyone is permitted to copy and distribute verbatim copies of this license 8 | document, but changing it is not allowed. 9 | 10 | ## Preamble 11 | 12 | The GNU General Public License is a free, copyleft license for software and other 13 | kinds of works. 14 | 15 | The licenses for most software and other practical works are designed to take away 16 | your freedom to share and change the works. By contrast, the GNU General Public 17 | License is intended to guarantee your freedom to share and change all versions of a 18 | program--to make sure it remains free software for all its users. We, the Free 19 | Software Foundation, use the GNU General Public License for most of our software; it 20 | applies also to any other work released this way by its authors. You can apply it to 21 | your programs, too. 22 | 23 | When we speak of free software, we are referring to freedom, not price. Our General 24 | Public Licenses are designed to make sure that you have the freedom to distribute 25 | copies of free software (and charge for them if you wish), that you receive source 26 | code or can get it if you want it, that you can change the software or use pieces of 27 | it in new free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you these rights or 30 | asking you to surrender the rights. Therefore, you have certain responsibilities if 31 | you distribute copies of the software, or if you modify it: responsibilities to 32 | respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether gratis or for a fee, 35 | you must pass on to the recipients the same freedoms that you received. You must make 36 | sure that they, too, receive or can get the source code. And you must show them these 37 | terms so they know their rights. 38 | 39 | Developers that use the GNU GPL protect your rights with two steps: **(1)** assert 40 | copyright on the software, and **(2)** offer you this License giving you legal permission 41 | to copy, distribute and/or modify it. 42 | 43 | For the developers' and authors' protection, the GPL clearly explains that there is 44 | no warranty for this free software. For both users' and authors' sake, the GPL 45 | requires that modified versions be marked as changed, so that their problems will not 46 | be attributed erroneously to authors of previous versions. 47 | 48 | Some devices are designed to deny users access to install or run modified versions of 49 | the software inside them, although the manufacturer can do so. This is fundamentally 50 | incompatible with the aim of protecting users' freedom to change the software. The 51 | systematic pattern of such abuse occurs in the area of products for individuals to 52 | use, which is precisely where it is most unacceptable. Therefore, we have designed 53 | this version of the GPL to prohibit the practice for those products. If such problems 54 | arise substantially in other domains, we stand ready to extend this provision to 55 | those domains in future versions of the GPL, as needed to protect the freedom of 56 | users. 57 | 58 | Finally, every program is threatened constantly by software patents. States should 59 | not allow patents to restrict development and use of software on general-purpose 60 | computers, but in those that do, we wish to avoid the special danger that patents 61 | applied to a free program could make it effectively proprietary. To prevent this, the 62 | GPL assures that patents cannot be used to render the program non-free. 63 | 64 | The precise terms and conditions for copying, distribution and modification follow. 65 | 66 | ## TERMS AND CONDITIONS 67 | 68 | ### 0. Definitions 69 | 70 | “This License” refers to version 3 of the GNU General Public License. 71 | 72 | “Copyright” also means copyright-like laws that apply to other kinds of 73 | works, such as semiconductor masks. 74 | 75 | “The Program” refers to any copyrightable work licensed under this 76 | License. Each licensee is addressed as “you”. “Licensees” and 77 | “recipients” may be individuals or organizations. 78 | 79 | To “modify” a work means to copy from or adapt all or part of the work in 80 | a fashion requiring copyright permission, other than the making of an exact copy. The 81 | resulting work is called a “modified version” of the earlier work or a 82 | work “based on” the earlier work. 83 | 84 | A “covered work” means either the unmodified Program or a work based on 85 | the Program. 86 | 87 | To “propagate” a work means to do anything with it that, without 88 | permission, would make you directly or secondarily liable for infringement under 89 | applicable copyright law, except executing it on a computer or modifying a private 90 | copy. Propagation includes copying, distribution (with or without modification), 91 | making available to the public, and in some countries other activities as well. 92 | 93 | To “convey” a work means any kind of propagation that enables other 94 | parties to make or receive copies. Mere interaction with a user through a computer 95 | network, with no transfer of a copy, is not conveying. 96 | 97 | An interactive user interface displays “Appropriate Legal Notices” to the 98 | extent that it includes a convenient and prominently visible feature that **(1)** 99 | displays an appropriate copyright notice, and **(2)** tells the user that there is no 100 | warranty for the work (except to the extent that warranties are provided), that 101 | licensees may convey the work under this License, and how to view a copy of this 102 | License. If the interface presents a list of user commands or options, such as a 103 | menu, a prominent item in the list meets this criterion. 104 | 105 | ### 1. Source Code 106 | 107 | The “source code” for a work means the preferred form of the work for 108 | making modifications to it. “Object code” means any non-source form of a 109 | work. 110 | 111 | A “Standard Interface” means an interface that either is an official 112 | standard defined by a recognized standards body, or, in the case of interfaces 113 | specified for a particular programming language, one that is widely used among 114 | developers working in that language. 115 | 116 | The “System Libraries” of an executable work include anything, other than 117 | the work as a whole, that **(a)** is included in the normal form of packaging a Major 118 | Component, but which is not part of that Major Component, and **(b)** serves only to 119 | enable use of the work with that Major Component, or to implement a Standard 120 | Interface for which an implementation is available to the public in source code form. 121 | A “Major Component”, in this context, means a major essential component 122 | (kernel, window system, and so on) of the specific operating system (if any) on which 123 | the executable work runs, or a compiler used to produce the work, or an object code 124 | interpreter used to run it. 125 | 126 | The “Corresponding Source” for a work in object code form means all the 127 | source code needed to generate, install, and (for an executable work) run the object 128 | code and to modify the work, including scripts to control those activities. However, 129 | it does not include the work's System Libraries, or general-purpose tools or 130 | generally available free programs which are used unmodified in performing those 131 | activities but which are not part of the work. For example, Corresponding Source 132 | includes interface definition files associated with source files for the work, and 133 | the source code for shared libraries and dynamically linked subprograms that the work 134 | is specifically designed to require, such as by intimate data communication or 135 | control flow between those subprograms and other parts of the work. 136 | 137 | The Corresponding Source need not include anything that users can regenerate 138 | automatically from other parts of the Corresponding Source. 139 | 140 | The Corresponding Source for a work in source code form is that same work. 141 | 142 | ### 2. Basic Permissions 143 | 144 | All rights granted under this License are granted for the term of copyright on the 145 | Program, and are irrevocable provided the stated conditions are met. This License 146 | explicitly affirms your unlimited permission to run the unmodified Program. The 147 | output from running a covered work is covered by this License only if the output, 148 | given its content, constitutes a covered work. This License acknowledges your rights 149 | of fair use or other equivalent, as provided by copyright law. 150 | 151 | You may make, run and propagate covered works that you do not convey, without 152 | conditions so long as your license otherwise remains in force. You may convey covered 153 | works to others for the sole purpose of having them make modifications exclusively 154 | for you, or provide you with facilities for running those works, provided that you 155 | comply with the terms of this License in conveying all material for which you do not 156 | control copyright. Those thus making or running the covered works for you must do so 157 | exclusively on your behalf, under your direction and control, on terms that prohibit 158 | them from making any copies of your copyrighted material outside their relationship 159 | with you. 160 | 161 | Conveying under any other circumstances is permitted solely under the conditions 162 | stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 163 | 164 | ### 3. Protecting Users' Legal Rights From Anti-Circumvention Law 165 | 166 | No covered work shall be deemed part of an effective technological measure under any 167 | applicable law fulfilling obligations under article 11 of the WIPO copyright treaty 168 | adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention 169 | of such measures. 170 | 171 | When you convey a covered work, you waive any legal power to forbid circumvention of 172 | technological measures to the extent such circumvention is effected by exercising 173 | rights under this License with respect to the covered work, and you disclaim any 174 | intention to limit operation or modification of the work as a means of enforcing, 175 | against the work's users, your or third parties' legal rights to forbid circumvention 176 | of technological measures. 177 | 178 | ### 4. Conveying Verbatim Copies 179 | 180 | You may convey verbatim copies of the Program's source code as you receive it, in any 181 | medium, provided that you conspicuously and appropriately publish on each copy an 182 | appropriate copyright notice; keep intact all notices stating that this License and 183 | any non-permissive terms added in accord with section 7 apply to the code; keep 184 | intact all notices of the absence of any warranty; and give all recipients a copy of 185 | this License along with the Program. 186 | 187 | You may charge any price or no price for each copy that you convey, and you may offer 188 | support or warranty protection for a fee. 189 | 190 | ### 5. Conveying Modified Source Versions 191 | 192 | You may convey a work based on the Program, or the modifications to produce it from 193 | the Program, in the form of source code under the terms of section 4, provided that 194 | you also meet all of these conditions: 195 | 196 | * **a)** The work must carry prominent notices stating that you modified it, and giving a 197 | relevant date. 198 | * **b)** The work must carry prominent notices stating that it is released under this 199 | License and any conditions added under section 7. This requirement modifies the 200 | requirement in section 4 to “keep intact all notices”. 201 | * **c)** You must license the entire work, as a whole, under this License to anyone who 202 | comes into possession of a copy. This License will therefore apply, along with any 203 | applicable section 7 additional terms, to the whole of the work, and all its parts, 204 | regardless of how they are packaged. This License gives no permission to license the 205 | work in any other way, but it does not invalidate such permission if you have 206 | separately received it. 207 | * **d)** If the work has interactive user interfaces, each must display Appropriate Legal 208 | Notices; however, if the Program has interactive interfaces that do not display 209 | Appropriate Legal Notices, your work need not make them do so. 210 | 211 | A compilation of a covered work with other separate and independent works, which are 212 | not by their nature extensions of the covered work, and which are not combined with 213 | it such as to form a larger program, in or on a volume of a storage or distribution 214 | medium, is called an “aggregate” if the compilation and its resulting 215 | copyright are not used to limit the access or legal rights of the compilation's users 216 | beyond what the individual works permit. Inclusion of a covered work in an aggregate 217 | does not cause this License to apply to the other parts of the aggregate. 218 | 219 | ### 6. Conveying Non-Source Forms 220 | 221 | You may convey a covered work in object code form under the terms of sections 4 and 222 | 5, provided that you also convey the machine-readable Corresponding Source under the 223 | terms of this License, in one of these ways: 224 | 225 | * **a)** Convey the object code in, or embodied in, a physical product (including a 226 | physical distribution medium), accompanied by the Corresponding Source fixed on a 227 | durable physical medium customarily used for software interchange. 228 | * **b)** Convey the object code in, or embodied in, a physical product (including a 229 | physical distribution medium), accompanied by a written offer, valid for at least 230 | three years and valid for as long as you offer spare parts or customer support for 231 | that product model, to give anyone who possesses the object code either **(1)** a copy of 232 | the Corresponding Source for all the software in the product that is covered by this 233 | License, on a durable physical medium customarily used for software interchange, for 234 | a price no more than your reasonable cost of physically performing this conveying of 235 | source, or **(2)** access to copy the Corresponding Source from a network server at no 236 | charge. 237 | * **c)** Convey individual copies of the object code with a copy of the written offer to 238 | provide the Corresponding Source. This alternative is allowed only occasionally and 239 | noncommercially, and only if you received the object code with such an offer, in 240 | accord with subsection 6b. 241 | * **d)** Convey the object code by offering access from a designated place (gratis or for 242 | a charge), and offer equivalent access to the Corresponding Source in the same way 243 | through the same place at no further charge. You need not require recipients to copy 244 | the Corresponding Source along with the object code. If the place to copy the object 245 | code is a network server, the Corresponding Source may be on a different server 246 | (operated by you or a third party) that supports equivalent copying facilities, 247 | provided you maintain clear directions next to the object code saying where to find 248 | the Corresponding Source. Regardless of what server hosts the Corresponding Source, 249 | you remain obligated to ensure that it is available for as long as needed to satisfy 250 | these requirements. 251 | * **e)** Convey the object code using peer-to-peer transmission, provided you inform 252 | other peers where the object code and Corresponding Source of the work are being 253 | offered to the general public at no charge under subsection 6d. 254 | 255 | A separable portion of the object code, whose source code is excluded from the 256 | Corresponding Source as a System Library, need not be included in conveying the 257 | object code work. 258 | 259 | A “User Product” is either **(1)** a “consumer product”, which 260 | means any tangible personal property which is normally used for personal, family, or 261 | household purposes, or **(2)** anything designed or sold for incorporation into a 262 | dwelling. In determining whether a product is a consumer product, doubtful cases 263 | shall be resolved in favor of coverage. For a particular product received by a 264 | particular user, “normally used” refers to a typical or common use of 265 | that class of product, regardless of the status of the particular user or of the way 266 | in which the particular user actually uses, or expects or is expected to use, the 267 | product. A product is a consumer product regardless of whether the product has 268 | substantial commercial, industrial or non-consumer uses, unless such uses represent 269 | the only significant mode of use of the product. 270 | 271 | “Installation Information” for a User Product means any methods, 272 | procedures, authorization keys, or other information required to install and execute 273 | modified versions of a covered work in that User Product from a modified version of 274 | its Corresponding Source. The information must suffice to ensure that the continued 275 | functioning of the modified object code is in no case prevented or interfered with 276 | solely because modification has been made. 277 | 278 | If you convey an object code work under this section in, or with, or specifically for 279 | use in, a User Product, and the conveying occurs as part of a transaction in which 280 | the right of possession and use of the User Product is transferred to the recipient 281 | in perpetuity or for a fixed term (regardless of how the transaction is 282 | characterized), the Corresponding Source conveyed under this section must be 283 | accompanied by the Installation Information. But this requirement does not apply if 284 | neither you nor any third party retains the ability to install modified object code 285 | on the User Product (for example, the work has been installed in ROM). 286 | 287 | The requirement to provide Installation Information does not include a requirement to 288 | continue to provide support service, warranty, or updates for a work that has been 289 | modified or installed by the recipient, or for the User Product in which it has been 290 | modified or installed. Access to a network may be denied when the modification itself 291 | materially and adversely affects the operation of the network or violates the rules 292 | and protocols for communication across the network. 293 | 294 | Corresponding Source conveyed, and Installation Information provided, in accord with 295 | this section must be in a format that is publicly documented (and with an 296 | implementation available to the public in source code form), and must require no 297 | special password or key for unpacking, reading or copying. 298 | 299 | ### 7. Additional Terms 300 | 301 | “Additional permissions” are terms that supplement the terms of this 302 | License by making exceptions from one or more of its conditions. Additional 303 | permissions that are applicable to the entire Program shall be treated as though they 304 | were included in this License, to the extent that they are valid under applicable 305 | law. If additional permissions apply only to part of the Program, that part may be 306 | used separately under those permissions, but the entire Program remains governed by 307 | this License without regard to the additional permissions. 308 | 309 | When you convey a copy of a covered work, you may at your option remove any 310 | additional permissions from that copy, or from any part of it. (Additional 311 | permissions may be written to require their own removal in certain cases when you 312 | modify the work.) You may place additional permissions on material, added by you to a 313 | covered work, for which you have or can give appropriate copyright permission. 314 | 315 | Notwithstanding any other provision of this License, for material you add to a 316 | covered work, you may (if authorized by the copyright holders of that material) 317 | supplement the terms of this License with terms: 318 | 319 | * **a)** Disclaiming warranty or limiting liability differently from the terms of 320 | sections 15 and 16 of this License; or 321 | * **b)** Requiring preservation of specified reasonable legal notices or author 322 | attributions in that material or in the Appropriate Legal Notices displayed by works 323 | containing it; or 324 | * **c)** Prohibiting misrepresentation of the origin of that material, or requiring that 325 | modified versions of such material be marked in reasonable ways as different from the 326 | original version; or 327 | * **d)** Limiting the use for publicity purposes of names of licensors or authors of the 328 | material; or 329 | * **e)** Declining to grant rights under trademark law for use of some trade names, 330 | trademarks, or service marks; or 331 | * **f)** Requiring indemnification of licensors and authors of that material by anyone 332 | who conveys the material (or modified versions of it) with contractual assumptions of 333 | liability to the recipient, for any liability that these contractual assumptions 334 | directly impose on those licensors and authors. 335 | 336 | All other non-permissive additional terms are considered “further 337 | restrictions” within the meaning of section 10. If the Program as you received 338 | it, or any part of it, contains a notice stating that it is governed by this License 339 | along with a term that is a further restriction, you may remove that term. If a 340 | license document contains a further restriction but permits relicensing or conveying 341 | under this License, you may add to a covered work material governed by the terms of 342 | that license document, provided that the further restriction does not survive such 343 | relicensing or conveying. 344 | 345 | If you add terms to a covered work in accord with this section, you must place, in 346 | the relevant source files, a statement of the additional terms that apply to those 347 | files, or a notice indicating where to find the applicable terms. 348 | 349 | Additional terms, permissive or non-permissive, may be stated in the form of a 350 | separately written license, or stated as exceptions; the above requirements apply 351 | either way. 352 | 353 | ### 8. Termination 354 | 355 | You may not propagate or modify a covered work except as expressly provided under 356 | this License. Any attempt otherwise to propagate or modify it is void, and will 357 | automatically terminate your rights under this License (including any patent licenses 358 | granted under the third paragraph of section 11). 359 | 360 | However, if you cease all violation of this License, then your license from a 361 | particular copyright holder is reinstated **(a)** provisionally, unless and until the 362 | copyright holder explicitly and finally terminates your license, and **(b)** permanently, 363 | if the copyright holder fails to notify you of the violation by some reasonable means 364 | prior to 60 days after the cessation. 365 | 366 | Moreover, your license from a particular copyright holder is reinstated permanently 367 | if the copyright holder notifies you of the violation by some reasonable means, this 368 | is the first time you have received notice of violation of this License (for any 369 | work) from that copyright holder, and you cure the violation prior to 30 days after 370 | your receipt of the notice. 371 | 372 | Termination of your rights under this section does not terminate the licenses of 373 | parties who have received copies or rights from you under this License. If your 374 | rights have been terminated and not permanently reinstated, you do not qualify to 375 | receive new licenses for the same material under section 10. 376 | 377 | ### 9. Acceptance Not Required for Having Copies 378 | 379 | You are not required to accept this License in order to receive or run a copy of the 380 | Program. Ancillary propagation of a covered work occurring solely as a consequence of 381 | using peer-to-peer transmission to receive a copy likewise does not require 382 | acceptance. However, nothing other than this License grants you permission to 383 | propagate or modify any covered work. These actions infringe copyright if you do not 384 | accept this License. Therefore, by modifying or propagating a covered work, you 385 | indicate your acceptance of this License to do so. 386 | 387 | ### 10. Automatic Licensing of Downstream Recipients 388 | 389 | Each time you convey a covered work, the recipient automatically receives a license 390 | from the original licensors, to run, modify and propagate that work, subject to this 391 | License. You are not responsible for enforcing compliance by third parties with this 392 | License. 393 | 394 | An “entity transaction” is a transaction transferring control of an 395 | organization, or substantially all assets of one, or subdividing an organization, or 396 | merging organizations. If propagation of a covered work results from an entity 397 | transaction, each party to that transaction who receives a copy of the work also 398 | receives whatever licenses to the work the party's predecessor in interest had or 399 | could give under the previous paragraph, plus a right to possession of the 400 | Corresponding Source of the work from the predecessor in interest, if the predecessor 401 | has it or can get it with reasonable efforts. 402 | 403 | You may not impose any further restrictions on the exercise of the rights granted or 404 | affirmed under this License. For example, you may not impose a license fee, royalty, 405 | or other charge for exercise of rights granted under this License, and you may not 406 | initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging 407 | that any patent claim is infringed by making, using, selling, offering for sale, or 408 | importing the Program or any portion of it. 409 | 410 | ### 11. Patents 411 | 412 | A “contributor” is a copyright holder who authorizes use under this 413 | License of the Program or a work on which the Program is based. The work thus 414 | licensed is called the contributor's “contributor version”. 415 | 416 | A contributor's “essential patent claims” are all patent claims owned or 417 | controlled by the contributor, whether already acquired or hereafter acquired, that 418 | would be infringed by some manner, permitted by this License, of making, using, or 419 | selling its contributor version, but do not include claims that would be infringed 420 | only as a consequence of further modification of the contributor version. For 421 | purposes of this definition, “control” includes the right to grant patent 422 | sublicenses in a manner consistent with the requirements of this License. 423 | 424 | Each contributor grants you a non-exclusive, worldwide, royalty-free patent license 425 | under the contributor's essential patent claims, to make, use, sell, offer for sale, 426 | import and otherwise run, modify and propagate the contents of its contributor 427 | version. 428 | 429 | In the following three paragraphs, a “patent license” is any express 430 | agreement or commitment, however denominated, not to enforce a patent (such as an 431 | express permission to practice a patent or covenant not to sue for patent 432 | infringement). To “grant” such a patent license to a party means to make 433 | such an agreement or commitment not to enforce a patent against the party. 434 | 435 | If you convey a covered work, knowingly relying on a patent license, and the 436 | Corresponding Source of the work is not available for anyone to copy, free of charge 437 | and under the terms of this License, through a publicly available network server or 438 | other readily accessible means, then you must either **(1)** cause the Corresponding 439 | Source to be so available, or **(2)** arrange to deprive yourself of the benefit of the 440 | patent license for this particular work, or **(3)** arrange, in a manner consistent with 441 | the requirements of this License, to extend the patent license to downstream 442 | recipients. “Knowingly relying” means you have actual knowledge that, but 443 | for the patent license, your conveying the covered work in a country, or your 444 | recipient's use of the covered work in a country, would infringe one or more 445 | identifiable patents in that country that you have reason to believe are valid. 446 | 447 | If, pursuant to or in connection with a single transaction or arrangement, you 448 | convey, or propagate by procuring conveyance of, a covered work, and grant a patent 449 | license to some of the parties receiving the covered work authorizing them to use, 450 | propagate, modify or convey a specific copy of the covered work, then the patent 451 | license you grant is automatically extended to all recipients of the covered work and 452 | works based on it. 453 | 454 | A patent license is “discriminatory” if it does not include within the 455 | scope of its coverage, prohibits the exercise of, or is conditioned on the 456 | non-exercise of one or more of the rights that are specifically granted under this 457 | License. You may not convey a covered work if you are a party to an arrangement with 458 | a third party that is in the business of distributing software, under which you make 459 | payment to the third party based on the extent of your activity of conveying the 460 | work, and under which the third party grants, to any of the parties who would receive 461 | the covered work from you, a discriminatory patent license **(a)** in connection with 462 | copies of the covered work conveyed by you (or copies made from those copies), or **(b)** 463 | primarily for and in connection with specific products or compilations that contain 464 | the covered work, unless you entered into that arrangement, or that patent license 465 | was granted, prior to 28 March 2007. 466 | 467 | Nothing in this License shall be construed as excluding or limiting any implied 468 | license or other defenses to infringement that may otherwise be available to you 469 | under applicable patent law. 470 | 471 | ### 12. No Surrender of Others' Freedom 472 | 473 | If conditions are imposed on you (whether by court order, agreement or otherwise) 474 | that contradict the conditions of this License, they do not excuse you from the 475 | conditions of this License. If you cannot convey a covered work so as to satisfy 476 | simultaneously your obligations under this License and any other pertinent 477 | obligations, then as a consequence you may not convey it at all. For example, if you 478 | agree to terms that obligate you to collect a royalty for further conveying from 479 | those to whom you convey the Program, the only way you could satisfy both those terms 480 | and this License would be to refrain entirely from conveying the Program. 481 | 482 | ### 13. Use with the GNU Affero General Public License 483 | 484 | Notwithstanding any other provision of this License, you have permission to link or 485 | combine any covered work with a work licensed under version 3 of the GNU Affero 486 | General Public License into a single combined work, and to convey the resulting work. 487 | The terms of this License will continue to apply to the part which is the covered 488 | work, but the special requirements of the GNU Affero General Public License, section 489 | 13, concerning interaction through a network will apply to the combination as such. 490 | 491 | ### 14. Revised Versions of this License 492 | 493 | The Free Software Foundation may publish revised and/or new versions of the GNU 494 | General Public License from time to time. Such new versions will be similar in spirit 495 | to the present version, but may differ in detail to address new problems or concerns. 496 | 497 | Each version is given a distinguishing version number. If the Program specifies that 498 | a certain numbered version of the GNU General Public License “or any later 499 | version” applies to it, you have the option of following the terms and 500 | conditions either of that numbered version or of any later version published by the 501 | Free Software Foundation. If the Program does not specify a version number of the GNU 502 | General Public License, you may choose any version ever published by the Free 503 | Software Foundation. 504 | 505 | If the Program specifies that a proxy can decide which future versions of the GNU 506 | General Public License can be used, that proxy's public statement of acceptance of a 507 | version permanently authorizes you to choose that version for the Program. 508 | 509 | Later license versions may give you additional or different permissions. However, no 510 | additional obligations are imposed on any author or copyright holder as a result of 511 | your choosing to follow a later version. 512 | 513 | ### 15. Disclaimer of Warranty 514 | 515 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 516 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 517 | PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER 518 | EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 519 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE 520 | QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE 521 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 522 | 523 | ### 16. Limitation of Liability 524 | 525 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY 526 | COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS 527 | PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, 528 | INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 529 | PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE 530 | OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE 531 | WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 532 | POSSIBILITY OF SUCH DAMAGES. 533 | 534 | ### 17. Interpretation of Sections 15 and 16 535 | 536 | If the disclaimer of warranty and limitation of liability provided above cannot be 537 | given local legal effect according to their terms, reviewing courts shall apply local 538 | law that most closely approximates an absolute waiver of all civil liability in 539 | connection with the Program, unless a warranty or assumption of liability accompanies 540 | a copy of the Program in return for a fee. 541 | 542 | _END OF TERMS AND CONDITIONS_ 543 | 544 | ## How to Apply These Terms to Your New Programs 545 | 546 | If you develop a new program, and you want it to be of the greatest possible use to 547 | the public, the best way to achieve this is to make it free software which everyone 548 | can redistribute and change under these terms. 549 | 550 | To do so, attach the following notices to the program. It is safest to attach them 551 | to the start of each source file to most effectively state the exclusion of warranty; 552 | and each file should have at least the “copyright” line and a pointer to 553 | where the full notice is found. 554 | 555 | 556 | Copyright (C) 557 | 558 | This program is free software: you can redistribute it and/or modify 559 | it under the terms of the GNU General Public License as published by 560 | the Free Software Foundation, either version 3 of the License, or 561 | (at your option) any later version. 562 | 563 | This program is distributed in the hope that it will be useful, 564 | but WITHOUT ANY WARRANTY; without even the implied warranty of 565 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 566 | GNU General Public License for more details. 567 | 568 | You should have received a copy of the GNU General Public License 569 | along with this program. If not, see . 570 | 571 | Also add information on how to contact you by electronic and paper mail. 572 | 573 | If the program does terminal interaction, make it output a short notice like this 574 | when it starts in an interactive mode: 575 | 576 | Copyright (C) 577 | This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. 578 | This is free software, and you are welcome to redistribute it 579 | under certain conditions; type 'show c' for details. 580 | 581 | The hypothetical commands `show w` and `show c` should show the appropriate parts of 582 | the General Public License. Of course, your program's commands might be different; 583 | for a GUI interface, you would use an “about box”. 584 | 585 | You should also get your employer (if you work as a programmer) or school, if any, to 586 | sign a “copyright disclaimer” for the program, if necessary. For more 587 | information on this, and how to apply and follow the GNU GPL, see 588 | <>. 589 | 590 | The GNU General Public License does not permit incorporating your program into 591 | proprietary programs. If your program is a subroutine library, you may consider it 592 | more useful to permit linking proprietary applications with the library. If this is 593 | what you want to do, use the GNU Lesser General Public License instead of this 594 | License. But first, please read 595 | <>. 596 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "morningtrain/toggl-api", 3 | "type": "library", 4 | "description": "A complete native php wrapper for the Toggl API", 5 | "keywords": ["toggl","api", "php"], 6 | "homepage": "http://morningtrain.dk/", 7 | "license": "GNU General Public License v3.0", 8 | "authors": [ 9 | { 10 | "name": "Bjarne Bonde", 11 | "email": "bb@morningtain.dk", 12 | "homepage": "http://morningtrain.dk/", 13 | "role": "Developer" 14 | } 15 | ], 16 | "autoload": { 17 | "psr-4": { 18 | "MorningTrain\\TogglApi\\": "src/" 19 | } 20 | }, 21 | "require": { 22 | "guzzlehttp/guzzle": "^6.3|^7.0" 23 | }, 24 | "require-dev": { 25 | "squizlabs/php_codesniffer": "2.*", 26 | "escapestudios/symfony2-coding-standard": "2.*" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /phpcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | The coding standard for Morningtrain Toggl API. 4 | src 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | PHP class to connect with the Toggl API. 4 | 5 | This was coded on an early http://morningtrain.dk 6 | 7 | # Installation 8 | 9 | It can be installed with composer 10 | 11 | ``` 12 | composer require morningtrain/toggl-api 13 | ``` 14 | 15 | # Dependencies 16 | 17 | It depends on guzzlehttp/guzzle ver.6. 18 | 19 | Guzzle can be added with the following composer snippet: 20 | (or automatically when installing through composer) 21 | 22 | ``` 23 | { 24 | "require": { 25 | "guzzlehttp/guzzle": "^6.0" 26 | } 27 | } 28 | ``` 29 | 30 | # Changelog 31 | ### 14/06/2021 32 | - Added methods for some of the undocumented project_group endpoints. This will make it possible to assign, update or remove groups from private projects. 33 | 34 | ### 30/06/17 35 | - Changed function name from getDashboadForWorkspace to getDashboardForWorkspace, if your system is using getDashboadForWorkspace please change it to getDashboardForWorkspace. 36 | 37 | # Examples 38 | 39 | For details about the different objects required in the Toggl Api, take a look at their documentation: 40 | https://github.com/toggl/toggl_api_docs 41 | 42 | ## Toggl API 43 | 44 | ### Initialization 45 | 46 | ``` 47 | $toggl = new MorningTrain\TogglApi\TogglApi('my-api-token'); 48 | ``` 49 | 50 | ### Get available endpoints 51 | 52 | ``` 53 | $toggl->getAvailableEndpoints(); 54 | ``` 55 | 56 | ### Clients 57 | 58 | https://github.com/toggl/toggl_api_docs/blob/master/chapters/clients.md 59 | 60 | #### Creating a client 61 | 62 | ``` 63 | $toggl->createClient($clientObject); 64 | ``` 65 | 66 | #### Updating a client 67 | 68 | ``` 69 | $toggl->updateClient($clientId, $clientObject); 70 | ``` 71 | 72 | #### Deleting a client 73 | 74 | ``` 75 | $toggl->deleteClient($clientId); 76 | ``` 77 | 78 | #### Get all clients 79 | 80 | ``` 81 | $toggl->getClients(); 82 | ``` 83 | 84 | #### Get all projects for a client 85 | 86 | ``` 87 | $toggl->getClientProjects($clientId); 88 | ``` 89 | 90 | #### Get all active projects for a client 91 | 92 | ``` 93 | $toggl->getActiveClientProjects($clientId); 94 | ``` 95 | 96 | #### Get all inactive projects for a client 97 | 98 | ``` 99 | $toggl->getInactiveClientProjects($clientId); 100 | ``` 101 | 102 | #### Get both active and inactive projects for a client 103 | 104 | ``` 105 | $toggl->getAllClientProjects($clientId); 106 | ``` 107 | 108 | #### Get client by id 109 | 110 | ``` 111 | $toggl->getClientById($clientId); 112 | ``` 113 | 114 | ### Project users 115 | 116 | https://github.com/toggl/toggl_api_docs/blob/master/chapters/project_users.md 117 | 118 | #### Create project user 119 | 120 | ``` 121 | $toggl->createProjectUser($projectUserObject); 122 | ``` 123 | 124 | #### Create project users 125 | 126 | ``` 127 | $toggl->createProjectUsers($projectUserObject); 128 | ``` 129 | 130 | #### Update project user 131 | 132 | ``` 133 | $toggl->updateProjectUser($projectUserId, $projectUserObject); 134 | ``` 135 | 136 | #### Update project users 137 | 138 | ``` 139 | $toggl->updateProjectUsers($projectUserIds, $projectUserObject); 140 | ``` 141 | 142 | #### Create project users 143 | 144 | ``` 145 | $toggl->deleteProjectUser($projectUserId); 146 | ``` 147 | 148 | #### Create project users 149 | 150 | ``` 151 | $toggl->deleteProjectUsers($projectUserIds); 152 | ``` 153 | 154 | ### Projects 155 | https://github.com/toggl/toggl_api_docs/blob/master/chapters/projects.md 156 | 157 | #### Create project 158 | 159 | ``` 160 | $toggl->createProject($projectObject); 161 | ``` 162 | 163 | #### Update project 164 | 165 | ``` 166 | $toggl->updateProject($projectId, $projectObject); 167 | ``` 168 | 169 | #### Delete project 170 | 171 | ``` 172 | $toggl->deleteProject($projectId); 173 | ``` 174 | 175 | #### Delete projects 176 | 177 | ``` 178 | $toggl->deleteProjects($projectIds); 179 | ``` 180 | 181 | #### Get users for project 182 | 183 | ``` 184 | $toggl->getProjectUserRelations($projectId); 185 | ``` 186 | 187 | #### Get project tasks 188 | 189 | ``` 190 | $toggl->getProjectTasks($projectId); 191 | ``` 192 | 193 | #### Get project by ID 194 | 195 | ``` 196 | $toggl->getProject($projectId); 197 | ``` 198 | 199 | ### Dashboard 200 | https://github.com/toggl/toggl_api_docs/blob/master/chapters/dashboard.md 201 | 202 | #### Get dashboard for workspace 203 | 204 | ``` 205 | $toggl->getDashboardForWorkspace($workspaceId); 206 | ``` 207 | 208 | ### Users 209 | https://github.com/toggl/toggl_api_docs/blob/master/chapters/users.md 210 | 211 | #### Get me 212 | $related defaults to false. Set it to true, to get related data 213 | ``` 214 | $toggl->getMe($related); 215 | ``` 216 | 217 | #### Update me 218 | ``` 219 | $toggl->updateMe($userObject); 220 | ``` 221 | 222 | #### Sign up 223 | ``` 224 | $toggl->signup($userObject); 225 | ``` 226 | 227 | #### Reset API Token 228 | ``` 229 | $toggl->resetApiToken(); 230 | ``` 231 | 232 | ### Workspaces 233 | https://github.com/toggl/toggl_api_docs/blob/master/chapters/workspaces.md 234 | 235 | #### Get workspaces 236 | ``` 237 | $toggl->getWorkspaces(); 238 | ``` 239 | 240 | #### Get workspace by ID 241 | ``` 242 | $toggl->getWorkspace($workspaceId); 243 | ``` 244 | 245 | #### Update workspace 246 | ``` 247 | $toggl->updateWorkspace($workspaceId, $workspaceObject); 248 | ``` 249 | 250 | #### Get workspace users 251 | ``` 252 | $toggl->getWorkspaceUsers($workspaceId); 253 | ``` 254 | 255 | #### Get workspace clients 256 | ``` 257 | $toggl->getWorkspaceClients($workspaceId); 258 | ``` 259 | 260 | #### Get workspace projects 261 | ``` 262 | $toggl->getWorkspaceProjects($workspaceId); 263 | ``` 264 | 265 | #### Get workspace tasks 266 | ``` 267 | $toggl->getWorkspaceTasks($workspaceId); 268 | ``` 269 | 270 | #### Get workspace tags 271 | ``` 272 | $toggl->getWorkspaceTags($workspaceId); 273 | ``` 274 | 275 | ### Workspace users 276 | https://github.com/toggl/toggl_api_docs/blob/master/chapters/workspace_users.md 277 | 278 | #### Invite users to workspace 279 | ``` 280 | $toggl->inviteUsersToWorkspace($workspaceId, $emails); 281 | ``` 282 | 283 | #### Update workspace user 284 | ``` 285 | $toggl->updateWorkspaceUser($workspaceUserId, $userObject); 286 | ``` 287 | 288 | #### Delete workspace user 289 | ``` 290 | $toggl->deleteWorkspaceUser($workspaceUserId); 291 | ``` 292 | 293 | #### Get workspace users for workspace 294 | ``` 295 | $toggl->getWorkspaceUserRelations($workspaceId); 296 | ``` 297 | 298 | ### Tags 299 | https://github.com/toggl/toggl_api_docs/blob/master/chapters/tags.md 300 | 301 | #### Create tag 302 | ``` 303 | $toggl->createTag($tagObject); 304 | ``` 305 | 306 | #### Update tag 307 | ``` 308 | $toggl->updateTag($tagId, $tagObject); 309 | ``` 310 | 311 | #### Delete tag 312 | ``` 313 | $toggl->deleteTag($tagId); 314 | ``` 315 | 316 | ### Tasks 317 | https://github.com/toggl/toggl_api_docs/blob/master/chapters/tags.md 318 | 319 | #### Get task 320 | ``` 321 | $toggl->getTask($taskId); 322 | ``` 323 | 324 | #### Create task 325 | ``` 326 | $toggl->createTask($taskObject); 327 | ``` 328 | 329 | #### Update task 330 | ``` 331 | $toggl->updateTask($taskId, $taskObject); 332 | ``` 333 | 334 | #### Update tasks 335 | ``` 336 | $toggl->updateTasks($taskId, $taskObject); 337 | ``` 338 | 339 | #### Delete task 340 | ``` 341 | $toggl->deleteTask($taskId); 342 | ``` 343 | 344 | #### Delete tasks 345 | ``` 346 | $toggl->deleteTasks($taskIds); 347 | ``` 348 | 349 | ### Time entries 350 | https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md 351 | 352 | #### Create time entry 353 | ``` 354 | $toggl->createTimeEntry($timeEntryObject); 355 | ``` 356 | 357 | #### Start time entry 358 | ``` 359 | $toggl->startTimeEntry($timeEntryObject); 360 | ``` 361 | 362 | #### Stop time entry 363 | ``` 364 | $toggl->stopTimeEntry($timeEntryIds); 365 | ``` 366 | 367 | #### Get time entry 368 | ``` 369 | $toggl->getTimeEntry($timeEntryIds); 370 | ``` 371 | 372 | #### Get running time entry 373 | ``` 374 | $toggl->getRunningTimeEntry(); 375 | ``` 376 | 377 | #### Get time entries 378 | ``` 379 | $toggl->getTimeEntries(); 380 | ``` 381 | 382 | #### Get time entries in range 383 | ``` 384 | $toggl->getTimeEntriesInRange($start, $end); 385 | ``` 386 | 387 | #### Update tags for time entries 388 | ``` 389 | $toggl->updateTagsForTimeEntries($timeEntryIds, $timeEntryObject); 390 | ``` 391 | 392 | #### Update time entry 393 | ``` 394 | $toggl->updateTimeEntry($timeEntryIds, $timeEntryObject); 395 | ``` 396 | 397 | #### Delete time entry 398 | ``` 399 | $toggl->deleteTimeEntry($timeEntryIds); 400 | ``` 401 | 402 | ## Reports API 403 | https://github.com/toggl/toggl_api_docs/blob/master/reports.md 404 | 405 | ### Initialization 406 | 407 | ``` 408 | $toggl = new MorningTrain\TogglApi\TogglReportsApi('my-api-token'); 409 | ``` 410 | 411 | ### Get available endpoints 412 | 413 | ``` 414 | $toggl->getAvailableEndpoints(); 415 | ``` 416 | 417 | ### Methods 418 | 419 | #### Get project report 420 | ``` 421 | $toggl->getProjectReport($query); 422 | ``` 423 | 424 | #### Get summary report 425 | ``` 426 | $toggl->getSummaryReport($query); 427 | ``` 428 | 429 | #### Get details report 430 | ``` 431 | $toggl->getDetailsReport($query); 432 | ``` 433 | 434 | #### Get weekly report 435 | ``` 436 | $toggl->getWeeklyReport($query); 437 | ``` 438 | -------------------------------------------------------------------------------- /src/TogglApi.php: -------------------------------------------------------------------------------- 1 | apiToken = $apiToken; 37 | $this->workspaceId = $workspaceId; 38 | $this->client = new Client([ 39 | 'base_uri' => 'https://api.track.toggl.com/api/v9/', 40 | 'auth' => [$this->apiToken, 'api_token'], 41 | ]); 42 | } 43 | 44 | /** 45 | * Get available endpoints. 46 | * 47 | * @return bool|mixed|object 48 | */ 49 | public function getAvailableEndpoints() 50 | { 51 | return $this->get(''); 52 | } 53 | 54 | /** 55 | * Create client. 56 | * 57 | * @param array $client 58 | * 59 | * Client has the following properties 60 | * 61 | * - name: The name of the client (string, required, unique in workspace) 62 | * - wid: workspace ID, where the client will be used (integer, required) 63 | * - notes: Notes for the client (string, not required) 64 | * - hrate: The hourly rate for this client (float, not required, available only for pro workspaces) 65 | * - cur: The name of the client's currency (string, not required, available only for pro workspaces) 66 | * - at: timestamp that is sent in the response, indicates the time client was last updated 67 | * 68 | * @return bool|mixed|object 69 | * 70 | * @see https://github.com/toggl/toggl_api_docs/blob/master/chapters/clients.md 71 | */ 72 | public function createClient($client) 73 | { 74 | return $this->POST("workspaces/{$this->workspaceId}/clients", ['client' => $client]); 75 | } 76 | 77 | /** 78 | * Update client. 79 | * 80 | * @param int $clientId 81 | * @param array $client 82 | * 83 | * @return bool|mixed|object 84 | */ 85 | public function updateClient($clientId, $client) 86 | { 87 | return $this->PUT('clients/'.$clientId, ['client' => $client]); 88 | } 89 | 90 | /** 91 | * Delete client. 92 | * 93 | * @param int $clientId 94 | * 95 | * @return bool|mixed|object 96 | */ 97 | public function deleteClient($clientId) 98 | { 99 | return $this->DELETE('clients/'.$clientId); 100 | } 101 | 102 | /** 103 | * Get clients. 104 | * 105 | * @return bool|mixed|object 106 | */ 107 | public function getClients() 108 | { 109 | return $this->GET('clients'); 110 | } 111 | 112 | /** 113 | * Get client projects. 114 | * 115 | * @param int $clientId 116 | * 117 | * @return bool|mixed|object 118 | */ 119 | public function getClientProjects($clientId) 120 | { 121 | return $this->GET('clients/'.$clientId.'/projects'); 122 | } 123 | 124 | /** 125 | * Get active client projects. 126 | * 127 | * @param int $clientId 128 | * 129 | * @return bool|mixed|object 130 | */ 131 | public function getActiveClientProjects($clientId) 132 | { 133 | return $this->GET('clients/'.$clientId.'/projects?active=true'); 134 | } 135 | 136 | /** 137 | * Get inactive client projects. 138 | * 139 | * @param int $clientId 140 | * 141 | * @return bool|mixed|object 142 | */ 143 | public function getInactiveClientProjects($clientId) 144 | { 145 | return $this->GET('clients/'.$clientId.'/projects?active=false'); 146 | } 147 | 148 | /** 149 | * Get all client projects. 150 | * 151 | * @param int $clientId 152 | * 153 | * @return bool|mixed|object 154 | */ 155 | public function getAllClientProjects($clientId) 156 | { 157 | return $this->GET('clients/'.$clientId.'/projects?active=both'); 158 | } 159 | 160 | /** 161 | * Get client by ID. 162 | * 163 | * @param int $clientId 164 | * 165 | * @return bool|mixed|object 166 | */ 167 | public function getClientById($clientId) 168 | { 169 | return $this->GET("workspaces/{$this->workspaceId}/clients/{$clientId}"); 170 | } 171 | 172 | /** 173 | * Create project user relation. 174 | * 175 | * @param array $user 176 | * 177 | * Project user has the following properties 178 | * 179 | * - pid: project ID (integer, required) 180 | * - uid: user ID, who is added to the project (integer, required) 181 | * - wid: workspace ID, where the project belongs to (integer, not-required, project's workspace id is used) 182 | * - manager: admin rights for this project (boolean, default false) 183 | * - rate: hourly rate for the project user (float, not-required, only for pro workspaces) in the currency of the project's client or in workspace default currency. 184 | * - at: timestamp that is sent in the response, indicates when the project user was last updated 185 | * 186 | * Workspace id (wid), project id (pid) and user id (uid) can't be changed on update. 187 | * 188 | * @return bool|mixed|object 189 | * 190 | * @see https://github.com/toggl/toggl_api_docs/blob/master/chapters/project_users.md 191 | */ 192 | public function createProjectUser($user) 193 | { 194 | return $this->POST('project_users', ['project_user' => $user]); 195 | } 196 | 197 | /** 198 | * Create multiple project user relations. 199 | * 200 | * @param array $user 201 | * 202 | * @return bool|mixed|object 203 | */ 204 | public function createProjectUsers($user) 205 | { 206 | return $this->POST('project_users', ['project_user' => $user]); 207 | } 208 | 209 | /** 210 | * Update project user relations. 211 | * 212 | * @param int $projectUserId 213 | * @param array $user 214 | * 215 | * @return bool|mixed|object 216 | */ 217 | public function updateProjectUser($projectUserId, $user) 218 | { 219 | return $this->PUT('project_users/'.$projectUserId, ['project_user' => $user]); 220 | } 221 | 222 | /** 223 | * Update multiple project user relations. 224 | * 225 | * @param array $projectUserIds 226 | * @param array $user 227 | * 228 | * @return bool|mixed|object 229 | */ 230 | public function updateProjectUsers($projectUserIds, $user) 231 | { 232 | return $this->PUT('project_users/'.implode(',', $projectUserIds), ['project_user' => $user]); 233 | } 234 | 235 | /** 236 | * Delete project user relation. 237 | * 238 | * @param int $projectUserId 239 | * 240 | * @return bool|mixed|object 241 | */ 242 | public function deleteProjectUser($projectUserId) 243 | { 244 | return $this->DELETE('project_users/'.$projectUserId); 245 | } 246 | 247 | /** 248 | * Delete multiple project user relations. 249 | * 250 | * @param array $projectUserIds 251 | * 252 | * @return bool|mixed|object 253 | */ 254 | public function deleteProjectUsers($projectUserIds) 255 | { 256 | return $this->DELETE('project_users/'.implode(',', $projectUserIds)); 257 | } 258 | 259 | /** 260 | * Create project group relation. 261 | * 262 | * @param array $group 263 | * 264 | * Project user has the following properties 265 | * 266 | * - pid: project ID (integer, required) 267 | * - uid: user ID, who is added to the project (integer, required) 268 | * - wid: workspace ID, where the project belongs to (integer, not-required, project's workspace id is used) 269 | * - manager: admin rights for this project (boolean, default false) 270 | * - rate: hourly rate for the project user (float, not-required, only for pro workspaces) in the currency of the project's client or in workspace default currency. 271 | * - at: timestamp that is sent in the response, indicates when the project user was last updated 272 | * 273 | * Workspace id (wid), project id (pid) and user id (uid) can't be changed on update. 274 | * 275 | * @return bool|mixed|object 276 | * 277 | * @see https://github.com/toggl/toggl_api_docs/blob/master/chapters/project_users.md 278 | */ 279 | public function createProjectGroup($project_id, $group_id, $data = []) 280 | { 281 | $data = [ 282 | 'project_group' => array_merge( 283 | [ 284 | 'pid' => $project_id, 285 | 'group_ids' => [$group_id] 286 | ], 287 | $data 288 | ), 289 | ]; 290 | 291 | return $this->POST('project_groups', $data); 292 | } 293 | 294 | /** 295 | * Update project user relations. 296 | * 297 | * @param int $projectGroupId 298 | * @param array $data 299 | * 300 | * @return bool|mixed|object 301 | */ 302 | public function updateProjectGroup($projectGroupId, $data = []) 303 | { 304 | return $this->PUT('project_groups/'.$projectGroupId, ['project_group' => $data]); 305 | } 306 | 307 | /** 308 | * Delete project group relation. 309 | * 310 | * @param int $projectGroupId 311 | * 312 | * @return bool|mixed|object 313 | */ 314 | public function deleteProjectGroup($projectGroupId) 315 | { 316 | return $this->DELETE('project_groups/'.$projectGroupId); 317 | } 318 | 319 | /** 320 | * Delete multiple project user relations. 321 | * 322 | * @param array $projectGroupIds 323 | * 324 | * @return bool|mixed|object 325 | */ 326 | public function deleteProjectGroups($projectGroupIds) 327 | { 328 | return $this->DELETE('project_groups/'.implode(',', $projectGroupIds)); 329 | } 330 | 331 | /** 332 | * Create Project. 333 | * 334 | * @param array $project 335 | * 336 | * Project has the following properties: 337 | * - name: The name of the project (string, required, unique for client and workspace) 338 | * - wid: workspace ID, where the project will be saved (integer, required) 339 | * - cid: client ID (integer, not required) 340 | * - active: whether the project is archived or not (boolean, by default true) 341 | * - is_private: whether project is accessible for only project users or for all workspace users (boolean, default true) 342 | * - template: whether the project can be used as a template (boolean, not required) 343 | * - template_id: id of the template project used on current project's creation 344 | * - billable: whether the project is billable or not (boolean, default true, available only for pro workspaces) 345 | * - auto_estimates: whether the estimated hours is calculated based on task estimations or is fixed manually (boolean, default false, not required, premium functionality) 346 | * - estimated_hours: if auto_estimates is true then the sum of task estimations is returned, otherwise user inserted hours (integer, not required, premium functionality) 347 | * - at: timestamp that is sent in the response for PUT, indicates the time task was last updated (read-only) 348 | * - color: id of the color selected for the project 349 | * - rate: hourly rate of the project (float, not required, premium functionality) 350 | * - created_at: timestamp indicating when the project was created (UTC time), read-only 351 | * 352 | * @return bool|mixed|object 353 | * 354 | * @see https://github.com/toggl/toggl_api_docs/blob/master/chapters/projects.md 355 | */ 356 | public function createProject($project) 357 | { 358 | return $this->POST("workspaces/{$this->workspaceId}/projects", ['project' => $project]); 359 | } 360 | 361 | /** 362 | * Update a project. 363 | * 364 | * @param int $projectId 365 | * @param array $project 366 | * 367 | * @return bool|mixed|object 368 | */ 369 | public function updateProject($projectId, $project) 370 | { 371 | return $this->PUT("workspaces/{$this->workspaceId}/projects/{$projectId}", ['project' => $project]); 372 | } 373 | 374 | /** 375 | * Delete project. 376 | * 377 | * @param int $projectId 378 | * 379 | * @return bool|mixed|object 380 | */ 381 | public function deleteProject($projectId) 382 | { 383 | return $this->DELETE('projects/'.$projectId); 384 | } 385 | 386 | /** 387 | * Delete multiple projects. 388 | * 389 | * @param array $projectIds 390 | * 391 | * @return bool|mixed|object 392 | */ 393 | public function deleteProjects($projectIds) 394 | { 395 | return $this->DELETE('projects/'.implode(',', $projectIds)); 396 | } 397 | 398 | /** 399 | * Get project user relations. 400 | * 401 | * @param int $projectId 402 | * 403 | * @return bool|mixed|object 404 | */ 405 | public function getProjectUserRelations($projectId) 406 | { 407 | return $this->GET('projects/'.$projectId.'/project_users'); 408 | } 409 | 410 | /** 411 | * Get project group relations. 412 | * 413 | * @param int $projectId 414 | * 415 | * @return bool|mixed|object 416 | */ 417 | public function getProjectGroupRelations($projectId) 418 | { 419 | return $this->GET('projects/'.$projectId.'/project_groups'); 420 | } 421 | 422 | /** 423 | * Get project tasks. 424 | * 425 | * @param int $projectId 426 | * 427 | * @return bool|mixed|object 428 | */ 429 | public function getProjectTasks($projectId) 430 | { 431 | return $this->GET('projects/'.$projectId.'/tasks'); 432 | } 433 | 434 | /** 435 | * Get project. 436 | * 437 | * @param int $projectId 438 | * 439 | * @return bool|mixed|object 440 | */ 441 | public function getProject($projectId) 442 | { 443 | return $this->GET("workspaces/{$this->workspaceId}/projects/{$projectId}"); 444 | } 445 | 446 | /** 447 | * Get dashboard for workspace. 448 | * 449 | * @param int $workspaceId 450 | * 451 | * @return bool|mixed|object 452 | * 453 | * Dashboard's main purpose is to give an overview of what users in the workspace are doing and have been doing. 454 | * Dashboard request returns two objects: 455 | * - `activity`: Activity 456 | * - `most_active_user`: Most active user 457 | * 458 | * The activity object holds the data of 10 latest actions in the workspace. 459 | *Activity object has the following properties 460 | * 461 | * - user_id: user ID 462 | * - project_id: project ID (ID is 0 if time entry doesn'y have project connected to it) 463 | * - duration: time entry duration in seconds. If the time entry is currently running, the duration attribute contains a negative value, denoting the start of the time entry in seconds since epoch (Jan 1 1970). The correct duration can be calculated as current_time + duration, where current_time is the current time in seconds since epoch. 464 | * - description: (Description property is not present if time entry description is empty) 465 | * - stop: time entry stop time (ISO 8601 date and time. Stop property is not present when time entry is still running) 466 | * - tid: task id, if applicable 467 | * 468 | * The most active user object holds the data of the top 5 users who have tracked the most time during last 7 days. 469 | * Most active user object has the following properties 470 | * - user_id: user ID 471 | * - duration: Sum of time entry durations that have been created during last 7 days 472 | * 473 | * @see https://github.com/toggl/toggl_api_docs/blob/master/chapters/dashboard.md) 474 | */ 475 | public function getDashboardForWorkspace($workspaceId) 476 | { 477 | return $this->GET('dashboard/'.$workspaceId); 478 | } 479 | 480 | /** 481 | * Get current user. 482 | * 483 | * @param bool $related 484 | * 485 | * @return bool|mixed|object 486 | * 487 | * User has the following properties: 488 | * - api_token: (string) 489 | * - default_wid: default workspace id (integer) 490 | * - email: (string) 491 | * - jquery_timeofday_format: (string) 492 | * - jquery_date_format:(string) 493 | * - timeofday_format: (string) 494 | * - date_format: (string) 495 | * - store_start_and_stop_time: whether start and stop time are saved on time entry (boolean) 496 | * - beginning_of_week: (integer 0-6, Sunday=0) 497 | * - language: user's language (string) 498 | * - image_url: url with the user's profile picture(string) 499 | * - sidebar_piechart: should a piechart be shown on the sidebar (boolean) 500 | * - at: timestamp of last changes 501 | * - new_blog_post: an object with toggl blog post title and link 502 | * - send_product_emails: (boolean) Toggl can send newsletters over e-mail to the user 503 | * - send_weekly_report: (boolean) if user receives weekly report 504 | * - send_timer_notifications: (boolean) email user about long-running (more than 8 hours) tasks 505 | * - openid_enabled: (boolean) google signin enabled 506 | * - timezone: (string) timezone user has set on the "My profile" page ( IANA TZ timezones ) 507 | * 508 | * @see https://github.com/toggl/toggl_api_docs/blob/master/chapters/users.md 509 | */ 510 | public function getMe($related = false) 511 | { 512 | return $this->GET('me', ['with_related_data' => $related]); 513 | } 514 | 515 | /** 516 | * Update current user. 517 | * 518 | * @param array $user 519 | * 520 | * @return bool|mixed|object 521 | */ 522 | public function updateMe($user) 523 | { 524 | return $this->PUT('me', ['user' => $user]); 525 | } 526 | 527 | /** 528 | * Signup user. 529 | * 530 | * @param array $user 531 | * 532 | * @return bool|mixed|object 533 | */ 534 | public function signup($user) 535 | { 536 | return $this->POST('signups', ['user' => $user]); 537 | } 538 | 539 | /** 540 | * Reset API Token for current user. 541 | * 542 | * @return bool|mixed|object 543 | */ 544 | public function resetApiToken() 545 | { 546 | return $this->POST('reset_token'); 547 | } 548 | 549 | /** 550 | * Get available workspaces for the user. 551 | * 552 | * Workspace has the following properties: 553 | * - name: the name of the workspace (string) 554 | * - premium: If it's a pro workspace or not. Shows if someone is paying for the workspace or not (boolean) 555 | * - admin: shows whether currently requesting user has admin access to the workspace (boolean) 556 | * - default_hourly_rate: default hourly rate for workspace, won't be shown to non-admins if the only_admins_see_billable_rates flag is set to true (float) 557 | * - default_currency: default currency for workspace (string) 558 | * - only_admins_may_create_projects: whether only the admins can create projects or everybody (boolean) 559 | * - only_admins_see_billable_rates: whether only the admins can see billable rates or everybody (boolean) 560 | * - rounding: type of rounding (integer) 561 | * - rounding_minutes: round up to nearest minute (integer) 562 | * - at: timestamp that indicates the time workspace was last updated 563 | * - logo_url: URL pointing to the logo (if set, otherwise omited) (string) 564 | * 565 | * @return bool|mixed|object 566 | * 567 | * @see https://github.com/toggl/toggl_api_docs/blob/master/chapters/workspaces.md 568 | */ 569 | public function getWorkspaces() 570 | { 571 | return $this->GET('workspaces'); 572 | } 573 | 574 | /** 575 | * Get single workspace. 576 | * 577 | * @param int $wid 578 | * 579 | * @return bool|mixed|object 580 | */ 581 | public function getWorkspace($wid) 582 | { 583 | return $this->GET('workspaces/'.$wid); 584 | } 585 | 586 | /** 587 | * Update workspace. 588 | * 589 | * @param int $wid 590 | * @param array $workspace 591 | * 592 | * @return bool|mixed|object 593 | */ 594 | public function updateWorkspace($wid, $workspace) 595 | { 596 | return $this->PUT('workspaces/'.$wid, ['workspace' => $workspace]); 597 | } 598 | 599 | /** 600 | * Get workspaces users. 601 | * 602 | * @param int $wid 603 | * 604 | * @return bool|mixed|object 605 | */ 606 | public function getWorkspaceUsers($wid) 607 | { 608 | return $this->GET('workspaces/'.$wid.'/users'); 609 | } 610 | 611 | /** 612 | * Get workspace clients. 613 | * 614 | * @param int $wid 615 | * 616 | * @return bool|mixed|object 617 | */ 618 | public function getWorkspaceClients($wid) 619 | { 620 | return $this->GET('workspaces/'.$wid.'/clients'); 621 | } 622 | 623 | /** 624 | * Get workspace projects. 625 | * 626 | * @param int $workspaceId 627 | * @param array $options 628 | * 629 | * @return bool|mixed|object 630 | */ 631 | public function getWorkspaceProjects($workspaceId, $options = []) 632 | { 633 | return $this->GET("workspaces/{$workspaceId}/projects", $options); 634 | } 635 | 636 | /** 637 | * Get projects. 638 | * 639 | * @param array $options 640 | * 641 | * @return bool|mixed|object 642 | */ 643 | public function getProjects($options = []) 644 | { 645 | return $this->GET("workspaces/{$this->workspaceId}/projects", $options); 646 | } 647 | 648 | /** 649 | * Get projects. 650 | * 651 | * @param int $workspaceId 652 | * @param array $options 653 | * 654 | * @return bool|mixed|object 655 | */ 656 | public function getProjects($options = []) 657 | { 658 | return $this->GET("workspaces/{$this->workspaceId}/projects", $options); 659 | } 660 | 661 | /** 662 | * Get workspace tasks. 663 | * 664 | * @param int $wid 665 | * @param array $options 666 | * 667 | * @return bool|mixed|object 668 | */ 669 | public function getWorkspaceTasks($wid, $options = []) 670 | { 671 | return $this->GET('workspaces/'.$wid.'/tasks', $options); 672 | } 673 | 674 | /** 675 | * Get workspace tags. 676 | * 677 | * @param int $wid 678 | * 679 | * @return bool|mixed|object 680 | */ 681 | public function getWorkspaceTags($wid) 682 | { 683 | return $this->GET('workspaces/'.$wid.'/tags'); 684 | } 685 | 686 | /** 687 | * Invite users to workspace. 688 | * 689 | * @param int $wid 690 | * @param string $emails 691 | * 692 | * @return bool|mixed|object 693 | * 694 | */ 695 | public function inviteUsersToWorkspace($wid, $emails) 696 | { 697 | return $this->POST('workspaces/'.$wid.'/invite', ['emails' => $emails]); 698 | } 699 | 700 | /** 701 | * Update workspace user. 702 | * 703 | * @param int $workspaceUserId 704 | * @param array $user 705 | * 706 | * Workspace user has the following properties: 707 | * - id: workspace user id (integer) 708 | * - uid: user id of the workspace user (integer) 709 | * - admin: if user is workspace admin (boolean) 710 | * - active: if the workspace user has accepted the invitation to this workspace (boolean) 711 | * - invite_url: if user has not accepted the invitation the url for accepting his/her invitation is sent when the request is made by workspace_admin 712 | * 713 | * @return bool|mixed|object 714 | * 715 | * @see https://github.com/toggl/toggl_api_docs/blob/master/chapters/workspace_users.md 716 | */ 717 | public function updateWorkspaceUser($workspaceUserId, $user) 718 | { 719 | return $this->PUT('workspace_users/'.$workspaceUserId, ['workspace_user' => $user]); 720 | } 721 | 722 | /** 723 | * Delete worksapce user. 724 | * 725 | * @param int $workspaceUserId 726 | * 727 | * @return bool|mixed|object 728 | */ 729 | public function deleteWorkspaceUser($workspaceUserId) 730 | { 731 | return $this->DELETE('workspace_users/'.$workspaceUserId); 732 | } 733 | 734 | /** 735 | * Get worksapce user relations. 736 | * 737 | * @param int $wid 738 | * 739 | * @return bool|mixed|object 740 | */ 741 | public function getWorkspaceUserRelations($wid) 742 | { 743 | return $this->GET('workspaces/'.$wid.'/workspace_users'); 744 | } 745 | 746 | /** 747 | * Create tag. 748 | * 749 | * @param array $tag 750 | * Tag has the following properties 751 | * - name: The name of the tag (string, required, unique in workspace) 752 | * - wid: workspace ID, where the tag will be used (integer, required) 753 | * 754 | * @return bool|mixed|object 755 | * 756 | * @see https://github.com/toggl/toggl_api_docs/blob/master/chapters/tags.md 757 | */ 758 | public function createTag($tag) 759 | { 760 | return $this->POST('tags', ['tag' => $tag]); 761 | } 762 | 763 | /** 764 | * Update tag. 765 | * 766 | * @param int $tagId 767 | * @param array $tag 768 | * 769 | * @return bool|mixed|object 770 | */ 771 | public function updateTag($tagId, $tag) 772 | { 773 | return $this->PUT('tags/'.$tagId, ['tag' => $tag]); 774 | } 775 | 776 | /** 777 | * Delete tag. 778 | * 779 | * @param int $tagId 780 | * 781 | * @return bool|mixed|object 782 | */ 783 | public function deleteTag($tagId) 784 | { 785 | return $this->DELETE('tags/'.$tagId); 786 | } 787 | 788 | /* TAGS (https://github.com/toggl/toggl_api_docs/blob/master/chapters/tags.md) 789 | 790 | 791 | 792 | 793 | 794 | */ 795 | 796 | /** 797 | * Get task. 798 | * 799 | * Tasks are available only for pro workspaces. 800 | * 801 | * @param int $taskId 802 | * 803 | * @return bool|mixed|object 804 | * Task has the following properties: 805 | * - name: The name of the task (string, required, unique in project) 806 | * - pid: project ID for the task (integer, required) 807 | * - wid: workspace ID, where the task will be saved (integer, project's workspace id is used when not supplied) 808 | * - uid: user ID, to whom the task is assigned to (integer, not required) 809 | * - estimated_seconds: estimated duration of task in seconds (integer, not required) 810 | * - active: whether the task is done or not (boolean, by default true) 811 | * - at: timestamp that is sent in the response for PUT, indicates the time task was last updated 812 | * - tracked_seconds: total time tracked (in seconds) for the task 813 | * 814 | * Workspace id (wid) and project id (pid) can't be changed on update. 815 | * 816 | * @see https://github.com/toggl/toggl_api_docs/blob/master/chapters/tasks.md 817 | */ 818 | public function getTask($projectId, $taskId) 819 | { 820 | return $this->GET("workspaces/{$this->workspaceId}/projects/{$projectId}/tasks/{$taskId}"); 821 | } 822 | 823 | /** 824 | * Create task. 825 | * 826 | * @param array $task 827 | * 828 | * @return bool|mixed|object 829 | */ 830 | public function createTask($projectId, $task) 831 | { 832 | return $this->POST("workspaces/{$this->workspaceId}/projects/{$projectId}/tasks", ['task' => $task]); 833 | } 834 | 835 | /** 836 | * Update task. 837 | * 838 | * @param int $taskId 839 | * @param array $task 840 | * 841 | * @return bool|mixed|object 842 | */ 843 | public function updateTask($projectId, $taskId, $task) 844 | { 845 | return $this->PUT("workspaces/{$this->workspaceId}/projects/{$projectId}/tasks/{$taskId}", [ 846 | 'task' => $task, 847 | ]); 848 | } 849 | 850 | /** 851 | * Update multiple tasks. 852 | * 853 | * @param array $taskIds 854 | * @param array $task 855 | * 856 | * @return bool|mixed|object 857 | */ 858 | public function updateTasks($taskIds, $task) 859 | { 860 | return $this->PUT('tasks/'.implode(',', $taskIds), ['task' => $task]); 861 | } 862 | 863 | /** 864 | * Delete task. 865 | * 866 | * @param int $taskId 867 | * 868 | * @return bool|mixed|object 869 | */ 870 | public function deleteTask($taskId) 871 | { 872 | return $this->DELETE("workspaces/{$this->workspaceId}/tasks/{$taskId}"); 873 | } 874 | 875 | /** 876 | * Delete multiple tasks. 877 | * 878 | * @param int $taskIds 879 | * 880 | * @return bool|mixed|object 881 | */ 882 | public function deleteTasks($taskIds) 883 | { 884 | return $this->DELETE('tasks/'.implode(',', $taskIds)); 885 | } 886 | 887 | /** TIME ENTRIES () 888 | 889 | 890 | */ 891 | 892 | /** 893 | * Create time entry. 894 | * 895 | * The requests are scoped with the user whose API token is used. Only his/her time entries are updated, retrieved and created. 896 | * 897 | * @param array $entry 898 | * Time entry has the following properties 899 | * - description: (string, strongly suggested to be used) 900 | * - wid: workspace ID (integer, required if pid or tid not supplied) 901 | * - pid: project ID (integer, not required) 902 | * - tid: task ID (integer, not required) 903 | * - billable: (boolean, not required, default false, available for pro workspaces) 904 | * - start: time entry start time (string, required, ISO 8601 date and time) 905 | * - stop: time entry stop time (string, not required, ISO 8601 date and time) 906 | * - duration: time entry duration in seconds. If the time entry is currently running, the duration attribute contains a negative value, denoting the start of the time entry in seconds since epoch (Jan 1 1970). The correct duration can be calculated as current_time + duration, where current_time is the current time in seconds since epoch. (integer, required) 907 | * - created_with: the name of your client app (string, required) 908 | * - tags: a list of tag names (array of strings, not required) 909 | * - duronly: should Toggl show the start and stop time of this time entry? (boolean, not required) 910 | * - at: timestamp that is sent in the response, indicates the time item was last updated 911 | * 912 | * @return bool|mixed|object 913 | * 914 | * @see https://github.com/toggl/toggl_api_docs/blob/master/chapters/time_entries.md 915 | */ 916 | public function createTimeEntry($entry) 917 | { 918 | return $this->POST('time_entries', ['time_entry' => $entry]); 919 | } 920 | 921 | /** 922 | * Start time entry. 923 | * 924 | * @param array $entry 925 | * 926 | * @return bool|mixed|object 927 | */ 928 | public function startTimeEntry($entry) 929 | { 930 | return $this->POST('time_entries/start', ['time_entry' => $entry]); 931 | } 932 | 933 | /** 934 | * Stop time entry. 935 | * 936 | * @param int $timeEntryId 937 | * 938 | * @return bool|mixed|object 939 | */ 940 | public function stopTimeEntry($timeEntryId) 941 | { 942 | return $this->PUT('time_entries/'.$timeEntryId.'/stop'); 943 | } 944 | 945 | /** 946 | * Get time entry. 947 | * 948 | * @param int $timeEntryId 949 | * 950 | * @return bool|mixed|object 951 | */ 952 | public function getTimeEntry($timeEntryId) 953 | { 954 | return $this->GET('time_entries/'.$timeEntryId); 955 | } 956 | 957 | /** 958 | * Get running time entry. 959 | * 960 | * @return bool|mixed|object 961 | */ 962 | public function getRunningTimeEntry() 963 | { 964 | return $this->GET('time_entries/current'); 965 | } 966 | 967 | /** 968 | * Get time entries. 969 | * 970 | * @return bool|mixed|object 971 | */ 972 | public function getTimeEntries() 973 | { 974 | return $this->GET('time_entries'); 975 | } 976 | 977 | /** 978 | * Get time entries in range. 979 | * 980 | * @param string $start ISO 8601 date and time string 981 | * @param string $end ISO 8601 date and time string 982 | * 983 | * @return bool|mixed|object 984 | */ 985 | public function getTimeEntriesInRange($start, $end) 986 | { 987 | return $this->GET('time_entries', ['start_date' => $start, 'end_date' => $end]); 988 | } 989 | 990 | /** 991 | * Update tags for time entries. 992 | * 993 | * @param array $timeEntryIds 994 | * @param array $entry 995 | * 996 | * @return bool|mixed|object 997 | */ 998 | public function updateTagsForTimeEntries($timeEntryIds, $entry) 999 | { 1000 | return $this->PUT('time_entries/'.implode(',', $timeEntryIds), ['time_entry' => $entry]); 1001 | } 1002 | 1003 | /** 1004 | * Update time entry. 1005 | * 1006 | * @param int $timeEntryId 1007 | * @param array $entry 1008 | * 1009 | * @return bool|mixed|object 1010 | */ 1011 | public function updateTimeEntry($timeEntryId, $entry) 1012 | { 1013 | return $this->PUT('time_entries/'.$timeEntryId, ['time_entry' => $entry]); 1014 | } 1015 | 1016 | /** 1017 | * Delete time entry. 1018 | * 1019 | * @param int $timeEntryId 1020 | * 1021 | * @return bool|mixed|object 1022 | */ 1023 | public function deleteTimeEntry($timeEntryId) 1024 | { 1025 | return $this->DELETE('time_entries/'.$timeEntryId); 1026 | } 1027 | 1028 | /** 1029 | * Helper for client get command. 1030 | * 1031 | * @param string $endpoint 1032 | * @param array $body 1033 | * @param array $query 1034 | * 1035 | * @return bool|mixed|object 1036 | */ 1037 | private function GET($endpoint, $query = array()) 1038 | { 1039 | try { 1040 | $response = $this->client->get($endpoint, ['query' => $query]); 1041 | 1042 | return $this->checkResponse($response); 1043 | } catch (ClientException $e) { 1044 | return (object) [ 1045 | 'success' => false, 1046 | 'message' => $e->getResponse()->getBody()->getContents(), 1047 | ]; 1048 | } 1049 | } 1050 | 1051 | /** 1052 | * Wrapper for client post command. 1053 | * 1054 | * @param string $endpoint 1055 | * @param array $body 1056 | * @param array $query 1057 | * 1058 | * @return bool|mixed|object 1059 | */ 1060 | private function POST($endpoint, $body = array(), $query = array()) 1061 | { 1062 | try { 1063 | $response = $this->client->post($endpoint, ['body' => json_encode($body), 'query' => $query]); 1064 | 1065 | return $this->checkResponse($response); 1066 | } catch (ClientException $e) { 1067 | return (object) [ 1068 | 'success' => false, 1069 | 'message' => $e->getResponse()->getBody()->getContents(), 1070 | ]; 1071 | } 1072 | } 1073 | 1074 | /** 1075 | * Helper for client put command. 1076 | * 1077 | * @param string $endpoint 1078 | * @param array $body 1079 | * @param array $query 1080 | * 1081 | * @return bool|mixed|object 1082 | */ 1083 | private function PUT($endpoint, $body = array(), $query = array()) 1084 | { 1085 | try { 1086 | $response = $this->client->put($endpoint, ['body' => json_encode($body), 'query' => $query]); 1087 | 1088 | return $this->checkResponse($response); 1089 | } catch (ClientException $e) { 1090 | return (object) [ 1091 | 'success' => false, 1092 | 'message' => $e->getResponse()->getBody()->getContents(), 1093 | ]; 1094 | } 1095 | } 1096 | 1097 | /** 1098 | * Helper for client delete command. 1099 | * 1100 | * @param $endpoint 1101 | * @param array $body 1102 | * @param array $query 1103 | * 1104 | * @return bool|mixed|object 1105 | */ 1106 | private function DELETE($endpoint, $body = array(), $query = array()) 1107 | { 1108 | try { 1109 | $response = $this->client->delete($endpoint, ['body' => json_encode($body), 'query' => $query]); 1110 | 1111 | return $this->checkResponse($response); 1112 | } catch (ClientException $e) { 1113 | return (object) [ 1114 | 'success' => false, 1115 | 'message' => $e->getResponse()->getBody()->getContents(), 1116 | ]; 1117 | } 1118 | } 1119 | 1120 | /** 1121 | * Helper for checking http response. 1122 | * 1123 | * @param \Psr\Http\Message\ResponseInterface $response 1124 | * 1125 | * @return bool|mixed 1126 | */ 1127 | private function checkResponse($response) 1128 | { 1129 | if ($response->getStatusCode() == 200) { 1130 | $data = json_decode($response->getBody()); 1131 | if (is_object($data) && isset($data->data)) { 1132 | $data = $data->data; 1133 | } 1134 | 1135 | return $data; 1136 | } 1137 | 1138 | return false; 1139 | } 1140 | } 1141 | -------------------------------------------------------------------------------- /src/TogglReportsApi.php: -------------------------------------------------------------------------------- 1 | apiToken = $apiToken; 34 | $this->client = new Client([ 35 | 'base_uri' => 'https://api.track.toggl.com/reports/api/v2/', 36 | 'auth' => [$this->apiToken, 'api_token'], 37 | ]); 38 | } 39 | 40 | /** 41 | * Get available endpoints. 42 | * 43 | * @return bool|mixed|object 44 | */ 45 | public function getAvailableEndpoints() 46 | { 47 | return $this->get(''); 48 | } 49 | 50 | /** 51 | * Get project report. 52 | * 53 | * @param string $query 54 | * 55 | * @return bool|mixed|object 56 | */ 57 | public function getProjectReport($query) 58 | { 59 | return $this->get('project', $query); 60 | } 61 | 62 | /** 63 | * Get summary report. 64 | * 65 | * @param string $query 66 | * 67 | * @return bool|mixed|object 68 | */ 69 | public function getSummaryReport($query) 70 | { 71 | return $this->get('summary', $query); 72 | } 73 | 74 | /** 75 | * Get details report. 76 | * 77 | * @param string $query 78 | * 79 | * @return bool|mixed|object 80 | */ 81 | public function getDetailsReport($query) 82 | { 83 | return $this->get('details', $query); 84 | } 85 | 86 | /** 87 | * Get weekly report. 88 | * 89 | * @param string $query 90 | * 91 | * @return bool|mixed|object 92 | */ 93 | public function getWeeklyReport($query) 94 | { 95 | return $this->get('weekly', $query); 96 | } 97 | 98 | /** 99 | * Helper for client get command. 100 | * 101 | * @param string $endpoint 102 | * @param array $query 103 | * 104 | * @return bool|mixed|object 105 | */ 106 | private function GET($endpoint, $query = array()) 107 | { 108 | try { 109 | $response = $this->client->get($endpoint, ['query' => $query]); 110 | 111 | return $this->checkResponse($response); 112 | } catch (ClientException $e) { 113 | return (object) [ 114 | 'success' => false, 115 | 'message' => $e->getMessage(), 116 | ]; 117 | } 118 | } 119 | 120 | /** 121 | * Helper for client post command. 122 | * 123 | * @param string $endpoint 124 | * @param array $query 125 | * 126 | * @return bool|mixed|object 127 | */ 128 | private function POST($endpoint, $query = array()) 129 | { 130 | try { 131 | $response = $this->client->post($endpoint, ['query' => $query]); 132 | 133 | return $this->checkResponse($response); 134 | } catch (ClientException $e) { 135 | return (object) [ 136 | 'success' => false, 137 | 'message' => $e->getMessage(), 138 | ]; 139 | } 140 | } 141 | 142 | /** 143 | * Helper for client put command. 144 | * 145 | * @param string $endpoint 146 | * @param array $query 147 | * 148 | * @return bool|mixed|object 149 | */ 150 | private function PUT($endpoint, $query = array()) 151 | { 152 | try { 153 | $response = $this->client->put($endpoint, ['query' => $query]); 154 | 155 | return $this->checkResponse($response); 156 | } catch (ClientException $e) { 157 | return (object) [ 158 | 'success' => false, 159 | 'message' => $e->getMessage(), 160 | ]; 161 | } 162 | } 163 | 164 | /** 165 | * Helper for client delete command. 166 | * 167 | * @param string $endpoint 168 | * @param array $query 169 | * 170 | * @return bool|mixed|object 171 | */ 172 | private function DELETE($endpoint, $query = array()) 173 | { 174 | try { 175 | $response = $this->client->delete($endpoint, ['query' => $query]); 176 | 177 | return $this->checkResponse($response); 178 | } catch (ClientException $e) { 179 | return (object) [ 180 | 'success' => false, 181 | 'message' => $e->getMessage(), 182 | ]; 183 | } 184 | } 185 | 186 | /** 187 | * Helper for checking http response. 188 | * 189 | * @param \Psr\Http\Message\ResponseInterface $response 190 | * 191 | * @return bool|mixed 192 | */ 193 | private function checkResponse($response) 194 | { 195 | if ($response->getStatusCode() == 200) { 196 | $data = json_decode($response->getBody()); 197 | if (is_object($data) && isset($data->data)) { 198 | $data = $data->data; 199 | } 200 | 201 | return $data; 202 | } 203 | 204 | return false; 205 | } 206 | } 207 | --------------------------------------------------------------------------------