also looking at this
Remove "data" in array response
#47
5 files
+40
-34
| @@ -46,7 +46,7 @@ class Client | ||
| 46 | 46 | */ |
| 47 | 47 | public function initializeEnv() |
| 48 | 48 | { |
| 49 | if (! file_exists(dirname(__DIR__)).'.env') { | |
| 49 | if (! file_exists(__DIR__.'/../.env')) { | |
| 50 | 50 | return; |
| 51 | 51 | } |
| 52 | 52 | |
| @@ -72,7 +72,13 @@ class Client | ||
| 72 | 72 | ->getBody() |
| 73 | 73 | ->getContents(); |
| 74 | 74 | |
| 75 | return json_decode($content, true); | |
| 75 | $body = json_decode($content, true); | |
| 76 | ||
| 77 | if ($body && $body['data']) { | |
| 78 | return $body['data']; | |
| 79 | } | |
| 80 | ||
| 81 | return $body; | |
| 76 | 82 | } |
| 77 | 83 | |
| 78 | 84 | /** |
| @@ -20,7 +20,7 @@ it('can fetch specific group of favorites', function () { | ||
| 20 | 20 | $favorites = $this->client->favorites()->get($ids); |
| 21 | 21 | |
| 22 | 22 | $this->assertTrue(is_array($favorites)); |
| 23 | $this->assertTrue(count($favorites['data']) === count($ids)); | |
| 23 | $this->assertTrue(count($favorites) === count($ids)); | |
| 24 | 24 | }); |
| 25 | 25 | |
| 26 | 26 | it('can find a single favorite', function () { |
| @@ -29,7 +29,7 @@ it('can find a single favorite', function () { | ||
| 29 | 29 | $favorites = $this->client->favorites()->find($id)->toArray(); |
| 30 | 30 | |
| 31 | 31 | $this->assertTrue(is_array($favorites)); |
| 32 | $this->assertTrue(count($favorites) === 1); | |
| 32 | $this->assertTrue(array_key_exists('id', $favorites)); | |
| 33 | 33 | }); |
| 34 | 34 | |
| 35 | 35 | it('can create a favorite', function () { |
| @@ -38,7 +38,7 @@ it('can create a favorite', function () { | ||
| 38 | 38 | $favorite = $this->client->favorites()->create($data); |
| 39 | 39 | |
| 40 | 40 | $this->assertTrue(is_array($favorite)); |
| 41 | $this->assertTrue($favorite['data']['name'] === $data['name']); | |
| 41 | $this->assertTrue($favorite['name'] === $data['name']); | |
| 42 | 42 | }); |
| 43 | 43 | |
| 44 | 44 | it('can update a favorite', function () { |
| @@ -47,13 +47,13 @@ it('can update a favorite', function () { | ||
| 47 | 47 | $favorites = $this->client->favorites()->update(7, $data); |
| 48 | 48 | |
| 49 | 49 | $this->assertTrue(is_array($favorites)); |
| 50 | $this->assertTrue($favorites['data']['name'] === $data['name']); | |
| 50 | $this->assertTrue($favorites['name'] === $data['name']); | |
| 51 | 51 | }); |
| 52 | 52 | |
| 53 | 53 | it('can delete a favorite', function () { |
| 54 | 54 | $favorites = $this->client->tags()->get(); |
| 55 | 55 | |
| 56 | $favorites = array_reverse($favorites['data']); | |
| 56 | $favorites = array_reverse($favorites); | |
| 57 | 57 | $response = $this->client->tags()->delete($favorites[0]['id']); |
| 58 | 58 | |
| 59 | 59 | $this->assertTrue(is_null($response)); |
| @@ -17,12 +17,12 @@ it('can fetch all folders', function () { | ||
| 17 | 17 | it('can search a folder', function () { |
| 18 | 18 | $folder = $this->client->folders()->find(1)->toArray(); |
| 19 | 19 | |
| 20 | $query = $folder['data']['name']; | |
| 20 | $query = $folder['name']; | |
| 21 | 21 | |
| 22 | 22 | $folders = $this->client->folders()->search($query); |
| 23 | 23 | |
| 24 | 24 | $this->assertTrue(is_array($folders)); |
| 25 | $this->assertTrue(str_contains($folders['data'][0]['name'], $query)); | |
| 25 | $this->assertTrue(str_contains($folders[0]['name'], $query)); | |
| 26 | 26 | }); |
| 27 | 27 | |
| 28 | 28 | it('can fetch specific group of folders', function () { |
| @@ -31,7 +31,7 @@ it('can fetch specific group of folders', function () { | ||
| 31 | 31 | $folders = $this->client->folders()->get($ids); |
| 32 | 32 | |
| 33 | 33 | $this->assertTrue(is_array($folders)); |
| 34 | $this->assertTrue(count($folders['data']) === count($ids)); | |
| 34 | $this->assertTrue(count($folders) === count($ids)); | |
| 35 | 35 | }); |
| 36 | 36 | |
| 37 | 37 | it('can find a single folder', function () { |
| @@ -40,7 +40,7 @@ it('can find a single folder', function () { | ||
| 40 | 40 | $folders = $this->client->folders()->find($id)->toArray(); |
| 41 | 41 | |
| 42 | 42 | $this->assertTrue(is_array($folders)); |
| 43 | $this->assertTrue(count($folders) === 1); | |
| 43 | $this->assertTrue(array_key_exists('id', $folders)); | |
| 44 | 44 | }); |
| 45 | 45 | |
| 46 | 46 | it('can create a folder', function () { |
| @@ -49,7 +49,7 @@ it('can create a folder', function () { | ||
| 49 | 49 | $media = $this->client->folders()->create($name); |
| 50 | 50 | |
| 51 | 51 | $this->assertTrue(is_array($media)); |
| 52 | $this->assertTrue($media['data']['name'] === $name); | |
| 52 | $this->assertTrue($media['name'] === $name); | |
| 53 | 53 | }); |
| 54 | 54 | |
| 55 | 55 | it('can update a folder', function () { |
| @@ -58,21 +58,21 @@ it('can update a folder', function () { | ||
| 58 | 58 | $folders = $this->client->folders()->update(1, $name); |
| 59 | 59 | |
| 60 | 60 | $this->assertTrue(is_array($folders)); |
| 61 | $this->assertTrue($folders['data']['name'] === $name); | |
| 61 | $this->assertTrue($folders['name'] === $name); | |
| 62 | 62 | }); |
| 63 | 63 | |
| 64 | 64 | it('can archive a folder', function () { |
| 65 | 65 | $folders = $this->client->folders()->archive(1); |
| 66 | 66 | |
| 67 | 67 | $this->assertTrue(is_array($folders)); |
| 68 | $this->assertTrue((bool) $folders['data']['is_archived']); | |
| 68 | $this->assertTrue((bool) $folders['is_archived']); | |
| 69 | 69 | }); |
| 70 | 70 | |
| 71 | 71 | it('can unarchive a folder', function () { |
| 72 | 72 | $folders = $this->client->folders()->unarchive(1); |
| 73 | 73 | |
| 74 | 74 | $this->assertTrue(is_array($folders)); |
| 75 | $this->assertFalse((bool) $folders['data']['is_archived']); | |
| 75 | $this->assertFalse((bool) $folders['is_archived']); | |
| 76 | 76 | }); |
| 77 | 77 | |
| 78 | 78 | it('can duplicate a folder', function () { |
| @@ -81,13 +81,13 @@ it('can duplicate a folder', function () { | ||
| 81 | 81 | $duplicated = $folders->duplicate(); |
| 82 | 82 | |
| 83 | 83 | $this->assertTrue(is_array($duplicated)); |
| 84 | $this->assertTrue($duplicated['data']['name'] === $folders->toArray()['data']['name']); | |
| 84 | $this->assertTrue($duplicated['name'] === $folders->toArray()['name']); | |
| 85 | 85 | }); |
| 86 | 86 | |
| 87 | 87 | it('can delete a folder', function () { |
| 88 | 88 | $folders = $this->client->folders()->get(); |
| 89 | 89 | |
| 90 | $folders = array_reverse($folders['data']); | |
| 90 | $folders = array_reverse($folders); | |
| 91 | 91 | $response = $this->client->folders()->delete($folders[0]['id']); |
| 92 | 92 | |
| 93 | 93 | $this->assertTrue(is_null($response)); |
| @@ -16,12 +16,12 @@ it('can be fetch all media', function () { | ||
| 16 | 16 | |
| 17 | 17 | it('can search a media', function () { |
| 18 | 18 | $media = $this->client->media()->find(1)->toArray(); |
| 19 | $query = $media['data']['name']; | |
| 19 | $query = $media['name']; | |
| 20 | 20 | |
| 21 | 21 | $media = $this->client->media()->search($query); |
| 22 | 22 | |
| 23 | 23 | $this->assertTrue(is_array($media)); |
| 24 | $this->assertTrue(str_contains($media['data'][0]['name'], $query)); | |
| 24 | $this->assertTrue(str_contains($media[0]['name'], $query)); | |
| 25 | 25 | }); |
| 26 | 26 | |
| 27 | 27 | it('can be fetch all media for a tag', function () { |
| @@ -50,7 +50,7 @@ it('can be fetch specific group of media', function () { | ||
| 50 | 50 | $media = $this->client->media()->get($ids); |
| 51 | 51 | |
| 52 | 52 | $this->assertTrue(is_array($media)); |
| 53 | $this->assertTrue(count($media['data']) === count($ids)); | |
| 53 | $this->assertTrue(count($media) === count($ids)); | |
| 54 | 54 | }); |
| 55 | 55 | |
| 56 | 56 | it('can find a single media', function () { |
| @@ -59,7 +59,7 @@ it('can find a single media', function () { | ||
| 59 | 59 | $media = $this->client->media()->find($id)->toArray(); |
| 60 | 60 | |
| 61 | 61 | $this->assertTrue(is_array($media)); |
| 62 | $this->assertTrue(count($media) === 1); | |
| 62 | $this->assertTrue(array_key_exists('id', $media)); | |
| 63 | 63 | }); |
| 64 | 64 | |
| 65 | 65 | it('can update a media', function () { |
| @@ -68,35 +68,35 @@ it('can update a media', function () { | ||
| 68 | 68 | $media = $this->client->media()->update(1, $name); |
| 69 | 69 | |
| 70 | 70 | $this->assertTrue(is_array($media)); |
| 71 | $this->assertTrue($media['data']['name'] === $name); | |
| 71 | $this->assertTrue($media['name'] === $name); | |
| 72 | 72 | }); |
| 73 | 73 | |
| 74 | 74 | it('can archive a media', function () { |
| 75 | 75 | $media = $this->client->media()->archive(1); |
| 76 | 76 | |
| 77 | 77 | $this->assertTrue(is_array($media)); |
| 78 | $this->assertTrue((bool) $media['data']['is_archived']); | |
| 78 | $this->assertTrue((bool) $media['is_archived']); | |
| 79 | 79 | }); |
| 80 | 80 | |
| 81 | 81 | it('can unarchive a media', function () { |
| 82 | 82 | $media = $this->client->media()->unarchive(1); |
| 83 | 83 | |
| 84 | 84 | $this->assertTrue(is_array($media)); |
| 85 | $this->assertFalse((bool) $media['data']['is_archived']); | |
| 85 | $this->assertFalse((bool) $media['is_archived']); | |
| 86 | 86 | }); |
| 87 | 87 | |
| 88 | 88 | it('can make a media private', function () { |
| 89 | 89 | $media = $this->client->media()->makePrivate(1); |
| 90 | 90 | |
| 91 | 91 | $this->assertTrue(is_array($media)); |
| 92 | $this->assertFalse((bool) $media['data']['is_public']); | |
| 92 | $this->assertFalse((bool) $media['is_public']); | |
| 93 | 93 | }); |
| 94 | 94 | |
| 95 | 95 | it('can make a media public', function () { |
| 96 | 96 | $media = $this->client->media()->makePublic(1); |
| 97 | 97 | |
| 98 | 98 | $this->assertTrue(is_array($media)); |
| 99 | $this->assertTrue((bool) $media['data']['is_public']); | |
| 99 | $this->assertTrue((bool) $media['is_public']); | |
| 100 | 100 | }); |
| 101 | 101 | |
| 102 | 102 | it('can duplicate a media', function () { |
| @@ -105,13 +105,13 @@ it('can duplicate a media', function () { | ||
| 105 | 105 | $duplicated = $this->client->media()->duplicate(1); |
| 106 | 106 | |
| 107 | 107 | $this->assertTrue(is_array($duplicated)); |
| 108 | $this->assertTrue($duplicated['data']['name'] === $media->toArray()['data']['name']); | |
| 108 | $this->assertTrue($duplicated['name'] === $media->toArray()['name']); | |
| 109 | 109 | }); |
| 110 | 110 | |
| 111 | 111 | it('can delete a media', function () { |
| 112 | 112 | $media = $this->client->media()->get(); |
| 113 | 113 | |
| 114 | $media = array_reverse($media['data']); | |
| 114 | $media = array_reverse($media); | |
| 115 | 115 | $response = $this->client->media()->delete((int) $media[0]['media_id']); |
| 116 | 116 | |
| 117 | 117 | $this->assertTrue(is_null($response)); |
| @@ -20,7 +20,7 @@ it('can fetch specific group of tags', function () { | ||
| 20 | 20 | $tags = $this->client->tags()->get($ids); |
| 21 | 21 | |
| 22 | 22 | $this->assertTrue(is_array($tags)); |
| 23 | $this->assertTrue(count($tags['data']) === count($ids)); | |
| 23 | $this->assertTrue(count($tags) === count($ids)); | |
| 24 | 24 | }); |
| 25 | 25 | |
| 26 | 26 | it('can find a single tag', function () { |
| @@ -29,7 +29,7 @@ it('can find a single tag', function () { | ||
| 29 | 29 | $tags = $this->client->tags()->find($id)->toArray(); |
| 30 | 30 | |
| 31 | 31 | $this->assertTrue(is_array($tags)); |
| 32 | $this->assertTrue(count($tags) === 1); | |
| 32 | $this->assertTrue(array_key_exists('id', $tags)); | |
| 33 | 33 | }); |
| 34 | 34 | |
| 35 | 35 | it('can update a tag', function () { |
| @@ -38,13 +38,13 @@ it('can update a tag', function () { | ||
| 38 | 38 | $tags = $this->client->tags()->update(7, $color); |
| 39 | 39 | |
| 40 | 40 | $this->assertTrue(is_array($tags)); |
| 41 | $this->assertTrue($tags['data']['color'] === $color); | |
| 41 | $this->assertTrue($tags['color'] === $color); | |
| 42 | 42 | }); |
| 43 | 43 | |
| 44 | 44 | it('can delete a tag', function () { |
| 45 | 45 | $tags = $this->client->tags()->get(); |
| 46 | 46 | |
| 47 | $tags = array_reverse($tags['data']); | |
| 47 | $tags = array_reverse($tags); | |
| 48 | 48 | $response = $this->client->tags()->delete($tags[0]['id']); |
| 49 | 49 | |
| 50 | 50 | $this->assertTrue(is_null($response)); |
| @@ -55,7 +55,7 @@ it('can fetch all media tags', function () { | ||
| 55 | 55 | $tags = $media->tags()->get(); |
| 56 | 56 | |
| 57 | 57 | $this->assertTrue(is_array($tags)); |
| 58 | $this->assertTrue(count($tags['data'][0]) > 0); | |
| 58 | $this->assertTrue(count($tags[0]) > 0); | |
| 59 | 59 | }); |
| 60 | 60 | |
| 61 | 61 | it('can fetch all folder tags', function () { |
| @@ -63,5 +63,5 @@ it('can fetch all folder tags', function () { | ||
| 63 | 63 | $tags = $folder->tags()->get(); |
| 64 | 64 | |
| 65 | 65 | $this->assertTrue(is_array($tags)); |
| 66 | $this->assertTrue(count($tags['data'][0]) > 0); | |
| 66 | $this->assertTrue(count($tags[0]) > 0); | |
| 67 | 67 | }); |