diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..4c6abf4 --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +{"version":1,"defects":{"tolgatasci\\soundcloud\\RequestExample::test_example":4,"tolgatasci\\soundcloud\\tests\\RequestExample::test_example":5,"tolgatasci\\soundcloud\\tests\\RequestExample::test_get_tracks_with_id":5,"tolgatasci\\soundcloud\\tests\\RequestExample::test_search_tracks":5,"tolgatasci\\soundcloud\\tests\\RequestExample::test_next_url":5,"tolgatasci\\soundcloud\\tests\\RequestExample::test_related_music":5,"tolgatasci\\soundcloud\\tests\\RequestExample::test_featured_music":5,"tolgatasci\\soundcloud\\tests\\RequestExample::test_search_playlist":4,"tolgatasci\\soundcloud\\tests\\RequestExample::test_get_comments":4,"tolgatasci\\soundcloud\\tests\\ToolsExample::test_convert_time_to_text":5},"times":{"tolgatasci\\soundcloud\\RequestExample::test_example":0.006,"tolgatasci\\soundcloud\\tests\\RequestExample::test_example":0.606,"tolgatasci\\soundcloud\\tests\\RequestExample::test_get_tracks_with_id":0.499,"tolgatasci\\soundcloud\\tests\\RequestExample::test_search_tracks":1.377,"tolgatasci\\soundcloud\\tests\\RequestExample::test_next_url":1.962,"tolgatasci\\soundcloud\\tests\\RequestExample::test_related_music":1.122,"tolgatasci\\soundcloud\\tests\\RequestExample::test_featured_music":1.519,"tolgatasci\\soundcloud\\tests\\RequestExample::test_search_playlist":1.371,"tolgatasci\\soundcloud\\tests\\RequestExample::test_get_comments":0.568,"tolgatasci\\soundcloud\\tests\\ToolsExample::test_convert_time_to_text":0.405,"tolgatasci\\soundcloud\\tests\\RequestExample::test_suggest_keyword":0.407}} \ No newline at end of file diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 0000000..c3bb259 --- /dev/null +++ b/.styleci.yml @@ -0,0 +1 @@ +preset: laravel \ No newline at end of file diff --git a/changelog.md b/changelog.md new file mode 100644 index 0000000..87766aa --- /dev/null +++ b/changelog.md @@ -0,0 +1,8 @@ +# Changelog + +All notable changes to `Soundcloud` will be documented in this file. + +## Version 1.0 + +### Added +- Everything diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..e74c715 --- /dev/null +++ b/composer.json @@ -0,0 +1,42 @@ +{ + "name": "tolgatasci/soundcloud", + "description": "SoundCloud v2 api for laravel", + "license": "MIT", + "authors": [ + { + "name": "tolga", + "email": "tolgatasci1@gmail.com", + "homepage": "https://www.henyr.com" + } + ], + "homepage": "https://github.com/tolgatasci/soundcloud", + "keywords": ["Laravel", "Soundcloud"], + "require": { + "illuminate/support": "~7|~8", + "ixudra/curl": "6.*" + }, + "require-dev": { + "phpunit/phpunit": "~9.0", + "orchestra/testbench": "~5|~6" + }, + "autoload": { + "psr-4": { + "Tolgatasci\\Soundcloud\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Tolgatasci\\Soundcloud\\Tests\\": "tests" + } + }, + "extra": { + "laravel": { + "providers": [ + "Tolgatasci\\Soundcloud\\SoundcloudServiceProvider" + ], + "aliases": { + "Soundcloud": "Tolgatasci\\Soundcloud\\Facades\\Soundcloud" + } + } + } +} diff --git a/config/soundcloud.php b/config/soundcloud.php new file mode 100644 index 0000000..481f330 --- /dev/null +++ b/config/soundcloud.php @@ -0,0 +1,7 @@ + env('CLIENT_ID', ''), + 'app_version'=> env('APP_VERSION', '1620206878'), + 'app_locale'=> env('APP_LOCALE', 'en'), +]; diff --git a/contributing.md b/contributing.md new file mode 100644 index 0000000..441062a --- /dev/null +++ b/contributing.md @@ -0,0 +1,27 @@ +# Contributing + +Contributions are welcome and will be fully credited. + +Contributions are accepted via Pull Requests on [Github](https://github.com/tolgatasci/soundcloud). + +# Things you could do +If you want to contribute but do not know where to start, this list provides some starting points. +- Add license text +- Remove rewriteRules.php +- Set up TravisCI, StyleCI, ScrutinizerCI +- Write a comprehensive ReadMe + +## Pull Requests + +- **Add tests!** - Your patch won't be accepted if it doesn't have tests. + +- **Document any change in behaviour** - Make sure the `readme.md` and any other relevant documentation are kept up-to-date. + +- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option. + +- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. + +- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting. + + +**Happy coding**! diff --git a/license.md b/license.md new file mode 100644 index 0000000..45a392b --- /dev/null +++ b/license.md @@ -0,0 +1,21 @@ +# The license + +Copyright (c) tolga + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..59ad359 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,28 @@ + + + + + ./tests/ + + + ./tests/Unit + + + ./tests/Feature + + + + + src/ + + + diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..08f84df --- /dev/null +++ b/readme.md @@ -0,0 +1,57 @@ +# Soundcloud + +[![Latest Version on Packagist][ico-version]][link-packagist] +[![Total Downloads][ico-downloads]][link-downloads] +[![Build Status][ico-travis]][link-travis] +[![StyleCI][ico-styleci]][link-styleci] + +This is where your description should go. Take a look at [contributing.md](contributing.md) to see a to do list. + +## Installation + +Via Composer + +``` bash +$ composer require tolgatasci/soundcloud +``` + +## Usage + +## Change log + +Please see the [changelog](changelog.md) for more information on what has changed recently. + +## Testing + +``` bash +$ composer test +``` + +## Contributing + +Please see [contributing.md](contributing.md) for details and a todolist. + +## Security + +If you discover any security related issues, please email tolgatasci1@gmail.com instead of using the issue tracker. + +## Credits + +- [tolga][link-author] +- [All Contributors][link-contributors] + +## License + +license. Please see the [license file](license.md) for more information. + +[ico-version]: https://img.shields.io/packagist/v/tolgatasci/soundcloud.svg?style=flat-square +[ico-downloads]: https://img.shields.io/packagist/dt/tolgatasci/soundcloud.svg?style=flat-square +[ico-travis]: https://img.shields.io/travis/tolgatasci/soundcloud/master.svg?style=flat-square +[ico-styleci]: https://styleci.io/repos/12345678/shield + +[link-packagist]: https://packagist.org/packages/tolgatasci/soundcloud +[link-downloads]: https://packagist.org/packages/tolgatasci/soundcloud +[link-travis]: https://travis-ci.org/tolgatasci/soundcloud +[link-styleci]: https://styleci.io/repos/12345678 +[link-author]: https://github.com/tolgatasci +[link-contributors]: ../../contributors diff --git a/src/Api.php b/src/Api.php new file mode 100644 index 0000000..9dfe8aa --- /dev/null +++ b/src/Api.php @@ -0,0 +1,260 @@ +fixed_url($url)) + ->asJson() + ->get(); + return $response; + } + /* + * Suggest + * @param $text String + * @param $limit Int + * @param $offset Int + * return Json + */ + public function suggest($text,$limit = 5, $offset = 0){ + $data = [ + "q" => $text, + "limit" => $limit, + "offset" => $offset, + "client_id" => config('soundcloud.client_id'), + "linked_partitioning" => 1, + "app_version" => config('soundcloud.app_version'), + "app_locale" => config('soundcloud.app_locale'), + ]; + $response = Curl::to($this->BASE_API."search/queries") + ->withData($data) + ->asJson() + ->get(); + return $response; + } + /* + * Search Result + * @param $text String + * @param $limit Int + * @param $offset Int + * return Json + */ + public function search_tracks($text,$limit = 20, $offset = 0){ + $data = [ + "q" => $text, + "variant_ids" => "", + "facet" => "genre", + "limit" => $limit, + "offset" => $offset, + "client_id" => config('soundcloud.client_id'), + "linked_partitioning" => "1", + "app_version" => config('soundcloud.app_version'), + "app_locale" => config('soundcloud.app_locale'), + ]; + $response = Curl::to($this->BASE_API."search/tracks") + ->withData($data) + ->asJson() + ->get(); + return $response; + } + /* + * Get Music or Musics + * @param $ids String 1063731295,1063731295,1063731295,1063731295 max 50 + * return Json array + */ + public function musics($ids){ + $data = [ + "ids" => $ids, + "variant_ids" => "", + "client_id" => config('soundcloud.client_id'), + "linked_partitioning" => "1", + "app_version" => config('soundcloud.app_version'), + "app_locale" => config('soundcloud.app_locale'), + ]; + + $response = Curl::to($this->BASE_API."tracks") + ->withData($data) + ->asJson() + ->get(); + return $response; + } + /* + * Get Music Related + * @param $id int Music id + * return Json + */ + public function related($id,$limit = 20, $offset = 0){ + + $data = [ + "client_id" => config('soundcloud.client_id'), + "limit" => $limit, + "offset" => $offset, + "linked_partitioning" => "1", + "app_version" => config('soundcloud.app_version'), + "app_locale" => config('soundcloud.app_locale'), + ]; + + $response = Curl::to($this->BASE_API."tracks/".$id."/related") + ->withData($data) + ->asJson() + ->get(); + return $response; + } + /* + * Get Music Featured + * @param $limit int + * return Json + * + */ + public function featured($limit = 100){ + + $data = [ + "client_id" => config('soundcloud.client_id'), + "limit" => $limit, + "app_version" => config('soundcloud.app_version'), + "app_locale" => config('soundcloud.app_locale'), + ]; + + $response = Curl::to($this->BASE_API."featured_tracks/top/all-music") + ->withData($data) + ->asJson() + ->get(); + return $response; + } + /* + * Get Search Playlists + * @param $text String + * return Json + * + */ + public function search_playlist($text,$limit = 20, $offset = 0){ + + $data = [ + "q" => $text, + "facet" => "genre", + "client_id" => config('soundcloud.client_id'), + "limit" => $limit, + "offset" => $offset, + "linked_partitioning" => "1", + "app_version" => config('soundcloud.app_version'), + "app_locale" => config('soundcloud.app_locale'), + ]; + + $response = Curl::to($this->BASE_API."search/playlists_without_albums") + ->withData($data) + ->asJson() + ->get(); + return $response; + } + /* + * Get User + * @param $id int + * return Json + * + */ + public function user($id){ + + $data = [ + "client_id" => config('soundcloud.client_id'), + "linked_partitioning" => "1", + "app_version" => config('soundcloud.app_version'), + "app_locale" => config('soundcloud.app_locale'), + ]; + + $response = Curl::to($this->BASE_API."users/".$id) + ->withData($data) + ->asJson() + ->get(); + return $response; + } + /* + * Get Track Comments + * @param $track_id int + * return Json + * + */ + public function comments($track_id,$limit = 20,$offset = 0){ + + $data = [ + "client_id" => config('soundcloud.client_id'), + "filter_replies" => 0, + "threaded"=>1, + "limit" => $limit, + "offset" => $offset, + "app_version" => config('soundcloud.app_version'), + "app_locale" => config('soundcloud.app_locale'), + ]; + + $response = Curl::to($this->BASE_API."tracks/".(int)$track_id."/comments") + ->withData($data) + ->asJson() + ->get(); + return $response; + } + /* + * Get Track Comments + * @param $user_id int + * return Json + * + */ + public function WebProfiles($user_id,$limit = 20,$offset = 0){ + + $data = [ + "client_id" => config('soundcloud.client_id'), + "filter_replies" => 0, + "threaded"=>1, + "limit" => $limit, + "offset" => $offset, + "app_version" => config('soundcloud.app_version'), + "app_locale" => config('soundcloud.app_locale'), + ]; + + $response = Curl::to($this->BASE_API."users/soundcloud:users:".$user_id."/web-profiles") + ->withData($data) + ->asJson() + ->get(); + return $response; + } + /* + * Get playlist + * @param $playlist_id int + * return Json + * + */ + public function playlist($playlist_id){ + + $data = [ + "client_id" => config('soundcloud.client_id'), + "representation"=>"full", + "app_version" => config('soundcloud.app_version'), + "app_locale" => config('soundcloud.app_locale'), + ]; + + $response = Curl::to($this->BASE_API."playlists/".(int)$playlist_id) + ->withData($data) + ->asJson() + ->get(); + return $response; + } +} diff --git a/src/Facades/Soundcloud.php b/src/Facades/Soundcloud.php new file mode 100644 index 0000000..5f9caf5 --- /dev/null +++ b/src/Facades/Soundcloud.php @@ -0,0 +1,18 @@ +loadTranslationsFrom(__DIR__.'/../resources/lang', 'tolgatasci'); + // $this->loadViewsFrom(__DIR__.'/../resources/views', 'tolgatasci'); + // $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); + // $this->loadRoutesFrom(__DIR__.'/routes.php'); + + // Publishing is only necessary when using the CLI. + if ($this->app->runningInConsole()) { + $this->bootForConsole(); + } + } + + /** + * Register any package services. + * + * @return void + */ + public function register(): void + { + $this->mergeConfigFrom(__DIR__.'/../config/soundcloud.php', 'soundcloud'); + + // Register the service the package provides. + $this->app->singleton('soundcloud', function ($app) { + return new Soundcloud; + }); + } + + /** + * Get the services provided by the provider. + * + * @return array + */ + public function provides() + { + return ['soundcloud']; + } + + /** + * Console-specific booting. + * + * @return void + */ + protected function bootForConsole(): void + { + // Publishing the configuration file. + $this->publishes([ + __DIR__.'/../config/soundcloud.php' => config_path('soundcloud.php'), + ], 'soundcloud.config'); + + // Publishing the views. + /*$this->publishes([ + __DIR__.'/../resources/views' => base_path('resources/views/vendor/tolgatasci'), + ], 'soundcloud.views');*/ + + // Publishing assets. + /*$this->publishes([ + __DIR__.'/../resources/assets' => public_path('vendor/tolgatasci'), + ], 'soundcloud.views');*/ + + // Publishing the translation files. + /*$this->publishes([ + __DIR__.'/../resources/lang' => resource_path('lang/vendor/tolgatasci'), + ], 'soundcloud.views');*/ + + // Registering package commands. + // $this->commands([]); + } +} diff --git a/src/Tools.php b/src/Tools.php new file mode 100644 index 0000000..95fc3a7 --- /dev/null +++ b/src/Tools.php @@ -0,0 +1,22 @@ +expectNotToPerformAssertions(); + $data = Soundcloud::api()->suggest("t"); + dump($data); + } + + public function test_get_tracks_with_id() + { + $this->expectNotToPerformAssertions(); + $musics = Soundcloud::api()->musics("1063731295"); + dump($musics); + } + public function test_search_tracks() + { + $this->expectNotToPerformAssertions(); + $musics = Soundcloud::api()->search_tracks("tarkan"); + dump($musics); + } + public function test_next_url() + { + $this->expectNotToPerformAssertions(); + $search = Soundcloud::api()->search_tracks("tarkan"); + $musics = Soundcloud::api()->call($search->next_href); + dump($musics); + } + public function test_related_music() + { + $this->expectNotToPerformAssertions(); + $musics = Soundcloud::api()->related(1063731295); + dump($musics); + } + public function test_featured_music() + { + $this->expectNotToPerformAssertions(); + $musics = Soundcloud::api()->featured(); + dump($musics); + } + public function test_search_playlist() + { + $this->expectNotToPerformAssertions(); + $musics = Soundcloud::api()->search_playlist("tarkan"); + dd($musics); + } + public function test_get_user() + { + $this->expectNotToPerformAssertions(); + $musics = Soundcloud::api()->user(988374727); + dd($musics); + } + public function test_get_comments() + { + $this->expectNotToPerformAssertions(); + $musics = Soundcloud::api()->comments(143744209); + dd($musics); + } + + public function test_get_web_profiles() + { + $this->expectNotToPerformAssertions(); + $musics = Soundcloud::api()->WebProfiles(988374727); + dd($musics); + } + public function test_get_playlist() + { + $this->expectNotToPerformAssertions(); + $musics = Soundcloud::api()->playlist(165400570); + dd($musics); + } +} diff --git a/tests/ToolsExample.php b/tests/ToolsExample.php new file mode 100644 index 0000000..5f453e7 --- /dev/null +++ b/tests/ToolsExample.php @@ -0,0 +1,26 @@ +expectNotToPerformAssertions(); + $musics = Soundcloud::api()->musics("1063731295"); + $duration = $musics[0]->duration; + dump(Soundcloud::tools()->time_to_text($duration)); + } +}