├── .gitattributes ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── README.md ├── composer.json ├── phpunit.xml ├── src ├── Jelovac │ └── Bitly4laravel │ │ ├── API.php │ │ ├── Bitly4laravel.php │ │ ├── Bitly4laravelServiceProvider.php │ │ ├── BitlyInterface.php │ │ ├── Exceptions │ │ ├── InvalidTypeException.php │ │ ├── NonBooleanTypeException.php │ │ ├── NonIntegerTypeException.php │ │ └── NonStringTypeException.php │ │ ├── Facades │ │ └── Bitly4laravel.php │ │ ├── Laravel4ServiceProvider.php │ │ ├── Laravel5ServiceProvider.php │ │ └── Model.php └── config │ └── config.php └── tests ├── Bitly4laravelTest.php └── ModelTest.php /.gitattributes: -------------------------------------------------------------------------------- 1 | ## GITATTRIBUTES FOR WEB PROJECTS 2 | # 3 | # These settings are for any web project. 4 | # 5 | # Details per file setting: 6 | # text These files should be normalized (i.e. convert CRLF to LF). 7 | # binary These files are binary and should be left untouched. 8 | # 9 | # Note that binary is a macro for -text -diff. 10 | ###################################################################### 11 | 12 | ## AUTO-DETECT 13 | ## Handle line endings automatically for files detected as 14 | ## text and leave all files detected as binary untouched. 15 | ## This will handle all files NOT defined below. 16 | * text=auto 17 | 18 | ## SOURCE CODE 19 | *.bat text eol=crlf 20 | *.coffee text 21 | *.css text 22 | *.htm text 23 | *.html text 24 | *.inc text 25 | *.ini text 26 | *.js text 27 | *.json text 28 | *.jsx text 29 | *.less text 30 | *.od text 31 | *.onlydata text 32 | *.php text 33 | *.pl text 34 | *.py text 35 | *.rb text 36 | *.sass text 37 | *.scm text 38 | *.scss text 39 | *.sh text eol=lf 40 | *.sql text 41 | *.styl text 42 | *.ts text 43 | *.tsx text 44 | *.xml text 45 | *.xhtml text 46 | 47 | ## DOCKER 48 | *.dockerignore text 49 | Dockerfile text 50 | 51 | ## DOCUMENTATION 52 | *.markdown text 53 | *.md text 54 | *.mdwn text 55 | *.mdown text 56 | *.mkd text 57 | *.mkdn text 58 | *.mdtxt text 59 | *.mdtext text 60 | *.txt text 61 | AUTHORS text 62 | CHANGELOG text 63 | CHANGES text 64 | CONTRIBUTING text 65 | COPYING text 66 | copyright text 67 | *COPYRIGHT* text 68 | INSTALL text 69 | license text 70 | LICENSE text 71 | NEWS text 72 | readme text 73 | *README* text 74 | TODO text 75 | 76 | ## TEMPLATES 77 | *.dot text 78 | *.ejs text 79 | *.haml text 80 | *.handlebars text 81 | *.hbs text 82 | *.hbt text 83 | *.jade text 84 | *.latte text 85 | *.mustache text 86 | *.njk text 87 | *.phtml text 88 | *.tmpl text 89 | *.tpl text 90 | *.twig text 91 | 92 | ## LINTERS 93 | .csslintrc text 94 | .eslintrc text 95 | .jscsrc text 96 | .jshintrc text 97 | .jshintignore text 98 | .stylelintrc text 99 | 100 | ## CONFIGS 101 | *.bowerrc text 102 | *.cnf text 103 | *.conf text 104 | *.config text 105 | .browserslistrc text 106 | .editorconfig text 107 | .gitattributes text 108 | .gitconfig text 109 | .gitignore text 110 | .htaccess text 111 | *.npmignore text 112 | *.yaml text 113 | *.yml text 114 | browserslist text 115 | Makefile text 116 | makefile text 117 | 118 | ## HEROKU 119 | Procfile text 120 | .slugignore text 121 | 122 | ## GRAPHICS 123 | *.ai binary 124 | *.bmp binary 125 | *.eps binary 126 | *.gif binary 127 | *.ico binary 128 | *.jng binary 129 | *.jp2 binary 130 | *.jpg binary 131 | *.jpeg binary 132 | *.jpx binary 133 | *.jxr binary 134 | *.pdf binary 135 | *.png binary 136 | *.psb binary 137 | *.psd binary 138 | *.svg text 139 | *.svgz binary 140 | *.tif binary 141 | *.tiff binary 142 | *.wbmp binary 143 | *.webp binary 144 | 145 | ## AUDIO 146 | *.kar binary 147 | *.m4a binary 148 | *.mid binary 149 | *.midi binary 150 | *.mp3 binary 151 | *.ogg binary 152 | *.ra binary 153 | 154 | ## VIDEO 155 | *.3gpp binary 156 | *.3gp binary 157 | *.as binary 158 | *.asf binary 159 | *.asx binary 160 | *.fla binary 161 | *.flv binary 162 | *.m4v binary 163 | *.mng binary 164 | *.mov binary 165 | *.mp4 binary 166 | *.mpeg binary 167 | *.mpg binary 168 | *.swc binary 169 | *.swf binary 170 | *.webm binary 171 | 172 | ## ARCHIVES 173 | *.7z binary 174 | *.gz binary 175 | *.rar binary 176 | *.tar binary 177 | *.zip binary 178 | 179 | ## FONTS 180 | *.ttf binary 181 | *.eot binary 182 | *.otf binary 183 | *.woff binary 184 | *.woff2 binary 185 | 186 | ## EXECUTABLES 187 | *.exe binary 188 | *.pyc binary -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /nbproject 2 | /vendor 3 | composer.phar 4 | composer.lock 5 | .DS_Store -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.6 5 | - 7.0 6 | - 7.1 7 | 8 | before_script: 9 | - curl -s http://getcomposer.org/installer | php 10 | - php composer.phar install --dev 11 | 12 | script: phpunit -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to bitly4laravel repository 2 | 3 | Thank you for willing to contribute to this project. Before doing so, please, read the following guidelines. 4 | 5 | ## Submitting the issues 6 | 7 | When submitting new issues please consider the following: 8 | 9 | * Prior to creating a new issue check if an issue has already been reported (use search) 10 | * When submitting a new issue specify: 11 | * Laravel version (Example: 4.2.0) 12 | * bitly4laravel version (Example: 3.1.0) 13 | * if the issue can be related to caching and caching is enabled please mention it in the description -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | bitly4laravel 2 | ============= 3 | [![Build Status](https://travis-ci.org/jelovac/bitly4laravel.png?branch=master)](https://travis-ci.org/jelovac/bitly4laravel) [![Latest Stable Version](https://poser.pugx.org/jelovac/bitly4laravel/v/stable.png)](https://packagist.org/packages/jelovac/bitly4laravel) [![Total Downloads](https://poser.pugx.org/jelovac/bitly4laravel/downloads.png)](https://packagist.org/packages/jelovac/bitly4laravel) [![Latest Unstable Version](https://poser.pugx.org/jelovac/bitly4laravel/v/unstable.png)](https://packagist.org/packages/jelovac/bitly4laravel) [![License](https://poser.pugx.org/jelovac/bitly4laravel/license.png)](https://packagist.org/packages/jelovac/bitly4laravel) 4 | 5 | Provides a Laravel package to communicate with Bit.ly API. 6 | 7 | In order to use this package you need to get [OAuth Generic Access Token](https://bitly.com/a/oauth_apps) from Bitly website. 8 | 9 | Project status: Archived (Abandoned) 10 | ==================================== 11 | 12 | Due to security concerns decided to archive the project since it hasn't been maintained for years. 13 | 14 | Either fork it or seek other libraries which are more up to date. 15 | 16 | All the best Vladimir J. 17 | 18 | Instalation 19 | =========== 20 | 21 | Warning this is v3 version of bitly4laravel package. If you want to use the old v2 version use the v2 branch. 22 | 23 | Add bitly4laravel to your composer.json file. 24 | 25 | require : { 26 | "jelovac/bitly4laravel": "3.*" 27 | } 28 | 29 | Or with composer command: 30 | 31 | composer require jelovac/bitly4laravel 3.* 32 | 33 | Add provider to your app/config/app.php providers 34 | 35 | Jelovac\Bitly4laravel\Bitly4laravelServiceProvider::class, 36 | 37 | Publish config 38 | 39 | For Laravel 5 use: 40 | 41 | php artisan vendor:publish 42 | 43 | For Laravel 4 use: 44 | 45 | php artisan config:publish jelovac/bitly4laravel 46 | 47 | Optional (recommended) 48 | ====================== 49 | 50 | Add alias to app/config/app.php aliases 51 | 52 | 'Bitly' => Jelovac\Bitly4laravel\Facades\Bitly4laravel::class, 53 | 54 | Usage 55 | ===== 56 | 57 | Shorten links 58 | 59 | Bitly::shorten('http://google.com/'); 60 | 61 | Response format: JSON 62 | 63 | { 64 | "data": { 65 | "global_hash": "900913", 66 | "hash": "ze6poY", 67 | "long_url": "http://google.com/", 68 | "new_hash": 0, 69 | "url": "http://bit.ly/ze6poY" 70 | }, 71 | "status_code": 200, 72 | "status_txt": "OK" 73 | } 74 | 75 | Expand links 76 | 77 | Bitly::expand('http://bit.ly/ze6poY'); 78 | 79 | Response format: JSON 80 | 81 | { 82 | "data": { 83 | "expand": [ 84 | { 85 | "global_hash": "900913", 86 | "long_url": "http://google.com/", 87 | "short_url": "http://bit.ly/ze6poY", 88 | "user_hash": "ze6poY" 89 | } 90 | ] 91 | }, 92 | "status_code": 200, 93 | "status_txt": "OK" 94 | } 95 | 96 | Repository 97 | ========== 98 | https://github.com/jelovac/bitly4laravel 99 | 100 | License 101 | ======= 102 | 103 | The Bitly4laravel package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT) 104 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jelovac/bitly4laravel", 3 | "description": "Provides a Laravel package to communicate with Bit.ly API", 4 | "license": "MIT", 5 | "require": { 6 | "php": ">=5.6", 7 | "illuminate/support": "~4|~5", 8 | "guzzlehttp/guzzle": "~5|~6" 9 | }, 10 | "require-dev": { 11 | "phpunit/phpunit": "4.4.*" 12 | }, 13 | "autoload": { 14 | "psr-0": { 15 | "Jelovac\\Bitly4laravel\\": "src/" 16 | } 17 | }, 18 | "minimum-stability": "dev", 19 | "prefer-stable": true 20 | } 21 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/ 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/Jelovac/Bitly4laravel/API.php: -------------------------------------------------------------------------------- 1 | requestParams['access_token'] = $this->accessToken; 18 | $this->requestParams['format'] = $this->responseFormat; 19 | 20 | if (!empty($params)) { 21 | $this->requestParams = array_merge($this->requestParams , $params); 22 | } 23 | 24 | if ($this->cacheEnabled) { 25 | 26 | $cacheKey = $this->createCacheKey($action); 27 | 28 | // Check if the value is already cached 29 | if (Cache::has($cacheKey)) { 30 | return Cache::get($cacheKey); 31 | } 32 | } 33 | 34 | $response = $this->call($action, $this->requestParams); 35 | 36 | if ($this->cacheEnabled) { 37 | Cache::put($cacheKey, $response, $this->cacheDuration); 38 | } 39 | 40 | return $response; 41 | } 42 | 43 | /** 44 | * Execute the request and return the response 45 | * 46 | * @param string $action 47 | * @param array $params 48 | * @return mixed 49 | */ 50 | protected function call($action, array $params = array()) 51 | { 52 | $url = static::API_URL . '/' . static::API_VERSION . '/' . $action; 53 | 54 | $client = new Client($this->clientConfig); 55 | 56 | try { 57 | 58 | $options = array_merge(array('query' => $params), $this->requestOptions); 59 | 60 | switch (strtolower($this->requestType)) { 61 | 62 | case 'post': 63 | 64 | $response = $client->post($url, $options); 65 | 66 | break; 67 | 68 | case 'get': 69 | 70 | default: 71 | $response = $client->get($url, $options); 72 | } 73 | 74 | switch (strtolower($this->responseFormat)) { 75 | 76 | case 'xml': 77 | 78 | $body = $response->xml(); 79 | 80 | break; 81 | 82 | case 'json': 83 | 84 | default: 85 | $body = method_exists($response, 'json') ? $response->json() : json_decode($response->getBody()); 86 | } 87 | 88 | return $body; 89 | } catch (BadResponseException $ex) { 90 | return $ex->getResponse()->getBody(); 91 | } 92 | } 93 | 94 | /** 95 | * Create cache key 96 | * 97 | * @param string $action 98 | * @return type 99 | */ 100 | protected function createCacheKey($action) 101 | { 102 | $key = $this->cacheKeyPrefix . $action . json_encode($this->requestParams); 103 | return sha1($key); 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /src/Jelovac/Bitly4laravel/Bitly4laravel.php: -------------------------------------------------------------------------------- 1 | make('bundle/archive', array( 15 | 'bundle_link' => $budleLink 16 | )); 17 | } 18 | 19 | /** 20 | * Returns a list of public bundles created by a user. 21 | * 22 | * @param string $user 23 | * @param boolean $expandUser 24 | * @return type 25 | */ 26 | public function bundleBundlesByUser($user, $expandUser = null) 27 | { 28 | $params = array('user' => $user); 29 | 30 | if ($expandUser !== null) { 31 | $params['expand_user'] = $expandUser; 32 | } 33 | 34 | return $this->make('bundle/bundles_by_user', $params); 35 | } 36 | 37 | /** 38 | * Clone a bundle for the authenticated user. 39 | * 40 | * @param string $budleLink 41 | * @return type 42 | */ 43 | public function bundleClone($budleLink) 44 | { 45 | return $this->make('bundle/clone', array('bundle_link', $budleLink)); 46 | } 47 | 48 | /** 49 | * Add a collaborator to a bundle. 50 | * 51 | * @param string $budleLink 52 | * @param string $collaborator 53 | * @return type 54 | */ 55 | public function bundleCollaboratorAdd($budleLink, $collaborator) 56 | { 57 | return $this->make('bundle/collaborator_add', array( 58 | 'bundle_link' => $budleLink, 59 | 'collaborator' => $collaborator, 60 | )); 61 | } 62 | 63 | /** 64 | * Remove a collaborator from a bundle. 65 | * 66 | * @param string $budleLink 67 | * @param string $collaborator 68 | * @return type 69 | */ 70 | public function bundleCollaboratorRemove($budleLink, $collaborator) 71 | { 72 | return $this->make('bundle/collaborator_remove', array( 73 | 'bundle_link' => $budleLink, 74 | 'collaborator' => $collaborator 75 | )); 76 | } 77 | 78 | /** 79 | * Returns information about a bundle. 80 | * 81 | * @param string $bundleLink 82 | * @param boolean $expandUser 83 | * @return type 84 | */ 85 | public function bundleContents($bundleLink, $expandUser = null) 86 | { 87 | $params = array('bundle_link' => $bundleLink); 88 | 89 | if ($expandUser !== null) { 90 | $params['expand_user'] = $expandUser; 91 | } 92 | 93 | return $this->make('bundle/contents', $params); 94 | } 95 | 96 | /** 97 | * Create a new bundle for the authenticated user. 98 | * 99 | * @param boolean $private 100 | * @param string $title 101 | * @param string $description 102 | * @return type 103 | */ 104 | public function bundleCreate($private = null, $title = null, $description = null) 105 | { 106 | $params = array(); 107 | 108 | if ($private !== null) { 109 | $params['private'] = $private; 110 | } 111 | 112 | if ($title !== null) { 113 | $params['title'] = $title; 114 | } 115 | 116 | if ($description !== null) { 117 | $params['description'] = $description; 118 | } 119 | 120 | return $this->make('bundle/create', $params); 121 | } 122 | 123 | /** 124 | * Edit a bundle for the authenticated user 125 | * 126 | * @param string $bundleLink 127 | * @param string $edit 128 | * @param string $title 129 | * @param string $description 130 | * @param boolean $private 131 | * @param boolean $preview 132 | * @param string $ogImage 133 | * @return type 134 | */ 135 | public function bundleEdit($bundleLink, $edit = null, $title = null, $description = null, $private = null, $preview = null, $ogImage = null) 136 | { 137 | $params = array('bundle_link' => $bundleLink); 138 | 139 | if ($edit !== null) { 140 | $params['edit'] = $edit; 141 | } 142 | 143 | if ($title !== null) { 144 | $params['title'] = $title; 145 | } 146 | 147 | if ($description !== null) { 148 | $params['description'] = $description; 149 | } 150 | 151 | if ($private !== null) { 152 | $params['private'] = $private; 153 | } 154 | 155 | if ($preview !== null) { 156 | $params['preview'] = $preview; 157 | } 158 | 159 | if ($ogImage !== null) { 160 | $params['og_image'] = $ogImage; 161 | } 162 | 163 | return $this->make('bundle/edit', $params); 164 | } 165 | 166 | /** 167 | * Returns all bundles this user has access to (public + private + collaborator). 168 | * 169 | * @param boolean $expandUser 170 | * @return type 171 | */ 172 | public function userBundleHistory($expandUser = null) 173 | { 174 | $params = array(); 175 | 176 | if ($expandUser !== null) { 177 | $params['expand_user'] = $expandUser; 178 | } 179 | 180 | return $this->make('user/bundle_history', $params); 181 | } 182 | 183 | /** 184 | * Adds a link to a bitly bundle. Links are automatically added to the top (position 0) of a bundle. 185 | * 186 | * @param string $bundleLink 187 | * @param string $link 188 | * @param string $title 189 | * @return type 190 | */ 191 | public function bundleLinkAdd($bundleLink, $link, $title = null) 192 | { 193 | $params = array( 194 | 'bundle_link' => $bundleLink, 195 | 'link' => $link, 196 | ); 197 | 198 | if ($title !== null) { 199 | $params['title'] = $title; 200 | } 201 | 202 | return $this->make('bundle/link_add', $params); 203 | } 204 | 205 | /** 206 | * Add a comment to bundle item. 207 | * 208 | * @param string $bundleLink 209 | * @param string $link 210 | * @param string $comment 211 | * @return type 212 | */ 213 | public function bundleLinkCommentAdd($bundleLink, $link, $comment) 214 | { 215 | return $this->make('bundle/link_comment_add', array( 216 | 'bundle_link' => $bundleLink, 217 | 'link' => $link, 218 | 'comment' => $comment, 219 | )); 220 | } 221 | 222 | /** 223 | * Add a comment to bundle item. 224 | * 225 | * @param string $bundleLink 226 | * @param string $link 227 | * @param integer $commentId 228 | * @param string $comment 229 | * @return type 230 | */ 231 | public function bundleLinkCommentEdit($bundleLink, $link, $commentId, $comment) 232 | { 233 | return $this->make('bundle/link_comment_edit', array( 234 | 'bundle_link' => $bundleLink, 235 | 'link' => $link, 236 | 'comment_id' => $commentId, 237 | 'comment' => $comment, 238 | )); 239 | } 240 | 241 | /** 242 | * Remove a comment from a bundle item. Only the original commenter and the bundles owner may perform this action. 243 | * 244 | * @param string $bundleLink 245 | * @param string $link 246 | * @param integer $commentId 247 | * @return type 248 | */ 249 | public function bundleLinkCommentRemove($bundleLink, $link, $commentId) 250 | { 251 | return $this->make('bundle/link_comment_remove', array( 252 | 'bundle_link' => $bundleLink, 253 | 'link' => $link, 254 | 'comment_id' => $commentId, 255 | )); 256 | } 257 | 258 | /** 259 | * Edit the title for a link. 260 | * 261 | * @param string $bundleLink 262 | * @param string $link 263 | * @param string $edit 264 | * @param string $title 265 | * @param boolean $preview 266 | * @return type 267 | */ 268 | public function bundleLinkEdit($bundleLink, $link, $edit, $title = null, $preview = null) 269 | { 270 | $params = array( 271 | 'bundle_link' => $bundleLink, 272 | 'link' => $link, 273 | 'edit' => $edit, 274 | ); 275 | 276 | if ($title !== null) { 277 | $params['title'] = $title; 278 | } 279 | 280 | if ($preview !== null) { 281 | $params['preview'] = $preview; 282 | } 283 | 284 | return $this->make('bundle/link_edit', $params); 285 | } 286 | 287 | /** 288 | * Remove a link from a bitly bundle 289 | * 290 | * @param string $bundleLink 291 | * @param string $link 292 | * @return type 293 | */ 294 | public function bundleLinkRemove($bundleLink, $link) 295 | { 296 | return $this->make('bundle/link_remove', array( 297 | 'bundle_link' => $bundleLink, 298 | 'link' => $link, 299 | )); 300 | } 301 | 302 | /** 303 | * Change the position of a link in a bitly bundle. 304 | * 305 | * @param string $bundleLink 306 | * @param string $link 307 | * @param integer $displayOrder 308 | * @return type 309 | */ 310 | public function bundleLinkReorder($bundleLink, $link, $displayOrder) 311 | { 312 | return $this->make('bundle/link_reorder', array( 313 | 'bundle_link' => $bundleLink, 314 | 'link' => $link, 315 | 'display_order' => $displayOrder, 316 | )); 317 | } 318 | 319 | /** 320 | * Removes a pending/invited collaborator from a bundle. 321 | * 322 | * @param string $bundleLink 323 | * @param string $collaborator 324 | * @return type 325 | */ 326 | public function bundlePendingCollaboratorRemove($bundleLink, $collaborator) 327 | { 328 | return $this->make('bundle/pending_collaborator_remove', array( 329 | 'bundle_link' => $bundleLink, 330 | 'collaborator' => $collaborator, 331 | )); 332 | } 333 | 334 | /** 335 | * Re-order the links in a bundle. 336 | * 337 | * @param string $bundleLink 338 | * @param string $link 339 | * @return type 340 | */ 341 | public function bundleReorder($bundleLink, $link) 342 | { 343 | return $this->make('bundle/reorder', array( 344 | 'bundle_link' => $bundleLink, 345 | 'link' => $link, 346 | )); 347 | } 348 | 349 | /** 350 | * Get the number of views for a bundle. 351 | * 352 | * @param string $bundleLink 353 | * @return type 354 | */ 355 | public function bundleViewCount($bundleLink) 356 | { 357 | return $this->make('bundle/view_count', array( 358 | 'bundle_link' => $bundleLink, 359 | )); 360 | } 361 | 362 | /** 363 | * Given a bitly URL or hash (or multiple), returns the target (long) URL. 364 | * 365 | * @param string $shortURLOrHash 366 | * @return type 367 | */ 368 | public function expand($shortURLOrHash) 369 | { 370 | $params = array(); 371 | 372 | if (filter_var($shortURLOrHash, FILTER_VALIDATE_URL) !== false) { 373 | $params['shortUrl'] = $shortURLOrHash; 374 | } else { 375 | $params['hash'] = $shortURLOrHash; 376 | } 377 | 378 | return $this->make('expand', $params); 379 | } 380 | 381 | /** 382 | * Returns a specified number of "high-value" bitly links that are popular across bitly at this particular moment. 383 | * 384 | * @param integer $limit 385 | * @return type 386 | */ 387 | public function highvalue($limit = null) 388 | { 389 | $params = array(); 390 | 391 | if ($limit !== null) { 392 | $params['limit'] = $limit; 393 | } 394 | 395 | return $this->make('highvalue', $params); 396 | } 397 | 398 | /** 399 | * This is used to return the page title for a given bitly link. 400 | * 401 | * @param string $hash 402 | * @param string $shortURL 403 | * @param boolean $expandUser 404 | * @return type 405 | */ 406 | public function info($shortURLOrHash, $expandUser = null) 407 | { 408 | $params = array(); 409 | 410 | if (filter_var($shortURLOrHash, FILTER_VALIDATE_URL) !== false) { 411 | $params['shortUrl'] = $shortURLOrHash; 412 | } else { 413 | $params['hash'] = $shortURLOrHash; 414 | } 415 | 416 | if ($expandUser !== null) { 417 | $params['expand_user'] = $expandUser; 418 | } 419 | 420 | return $this->make('info', $params); 421 | } 422 | 423 | /** 424 | * Returns the detected categories for a document, in descending order of confidence. 425 | * 426 | * @param string $link 427 | * @return type 428 | */ 429 | public function linkCategory($link) 430 | { 431 | return $this->make('link/category', array( 432 | 'link' => $link, 433 | )); 434 | } 435 | 436 | /** 437 | * Returns the number of clicks on a single bitly link. 438 | * 439 | * @param string $link 440 | * @param string $unit 441 | * @param integer $units 442 | * @param string $timezone 443 | * @param boolean $rollup 444 | * @param integer $limit 445 | * @param integer $unitReferenceTimeStamp 446 | * @return type 447 | */ 448 | public function linkClicks($link, $unit = null, $units = null, $timezone = null, $rollup = null, $limit = null, $unitReferenceTimeStamp = null) 449 | { 450 | $params = array('link' => $link); 451 | 452 | if ($unit !== null) { 453 | $params['unit'] = $unit; 454 | } 455 | 456 | if ($units !== null) { 457 | $params['units'] = $units; 458 | } 459 | 460 | if ($timezone !== null) { 461 | $params['timezone'] = $timezone; 462 | } 463 | 464 | if ($rollup !== null) { 465 | $params['rollup'] = $rollup; 466 | } 467 | 468 | if ($limit !== null) { 469 | $params['limit'] = $limit; 470 | } 471 | 472 | if ($unitReferenceTimeStamp !== null) { 473 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 474 | } 475 | 476 | return $this->make('link/clicks', $params); 477 | } 478 | 479 | /** 480 | * Returns the “main article” from the linked page, as determined by the content extractor, in either HTML or plain text format. 481 | * 482 | * @param string $link 483 | * @param string $contentType 484 | * @return type 485 | */ 486 | public function linkContent($link, $contentType = null) 487 | { 488 | $params = array('link' => $link); 489 | 490 | if ($contentType !== null) { 491 | $params['content_type'] = $contentType; 492 | } 493 | 494 | return $this->make('link/content', $params); 495 | } 496 | 497 | /** 498 | * Returns metrics about the countries referring click traffic to a single bitly link. 499 | * 500 | * @param string $link 501 | * @param string $unit 502 | * @param integer $units 503 | * @param string $timezone 504 | * @param integer $limit 505 | * @param integer $unitReferenceTimeStamp 506 | * @return type 507 | */ 508 | public function linkCountries($link, $unit = null, $units = null, $timezone = null, $limit = null, $unitReferenceTimeStamp = null) 509 | { 510 | $params = array('link' => $link); 511 | 512 | if ($unit !== null) { 513 | $params['unit'] = $unit; 514 | } 515 | 516 | if ($units !== null) { 517 | $params['units'] = $units; 518 | } 519 | 520 | if ($timezone !== null) { 521 | $params['timezone'] = $timezone; 522 | } 523 | 524 | if ($limit !== null) { 525 | $params['limit'] = $limit; 526 | } 527 | 528 | if ($unitReferenceTimeStamp !== null) { 529 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 530 | } 531 | 532 | return $this->make('link/countries', $params); 533 | } 534 | 535 | /** 536 | * Returns users who have encoded this link (optionally only those in the requesting user's social graph). 537 | * Note: Some users may not be returned from this call depending on link privacy settings. 538 | * 539 | * @param string $link 540 | * @param boolean $myNetwork 541 | * @param boolean $subaccounts 542 | * @param integer $limit 543 | * @param boolean $expandUser 544 | * @return type 545 | */ 546 | public function linkEncoders($link, $myNetwork = null, $subaccounts = null, $limit = null, $expandUser = null) 547 | { 548 | $params = array('link' => $link); 549 | 550 | if ($myNetwork !== null) { 551 | $params['my_network'] = $myNetwork; 552 | } 553 | 554 | if ($subaccounts !== null) { 555 | $params['subaccounts'] = $subaccounts; 556 | } 557 | 558 | if ($limit !== null) { 559 | $params['limit'] = $limit; 560 | } 561 | 562 | if ($expandUser !== null) { 563 | $params['expand_user'] = $expandUser; 564 | } 565 | 566 | return $this->make('link/encoders', $params); 567 | } 568 | 569 | /** 570 | * Returns users who have encoded this link (optionally only those in the requesting user's social graph), sorted by the number of clicks on each encoding user's link. 571 | * Note: The response will only contain users whose links have gotten at least one click, and will not contain any users whose links are private. 572 | * 573 | * @param string $link 574 | * @param boolean $myNetwork 575 | * @param boolean $subaccounts 576 | * @param integer $limit 577 | * @param boolean $expandUser 578 | * @return type 579 | */ 580 | public function linkEncodersByCount($link, $myNetwork = null, $subaccounts = null, $limit = null, $expandUser = null) 581 | { 582 | $params = array('link' => $link); 583 | 584 | if ($myNetwork !== null) { 585 | $params['my_network'] = $myNetwork; 586 | } 587 | 588 | if ($subaccounts !== null) { 589 | $params['subaccounts'] = $subaccounts; 590 | } 591 | 592 | if ($limit !== null) { 593 | $params['limit'] = $limit; 594 | } 595 | 596 | if ($expandUser !== null) { 597 | $params['expand_user'] = $expandUser; 598 | } 599 | 600 | return $this->make('link/encoders_by_count', $params); 601 | } 602 | 603 | /** 604 | * Returns the number of users who have shortened (encoded) a single bitly link. 605 | * 606 | * @param string $link 607 | * @return type 608 | */ 609 | public function linkEncodersCount($link) 610 | { 611 | return $this->make('link/encoders_count', array( 612 | 'link' => $link, 613 | )); 614 | } 615 | 616 | /** 617 | * Returns metadata about a single bitly link. 618 | * 619 | * @param string $link 620 | * @return type 621 | */ 622 | public function linkInfo($link) 623 | { 624 | return $this->make('link/info', array( 625 | 'link' => $link, 626 | )); 627 | } 628 | 629 | /** 630 | * Returns the significant languages for the bitly link. Note that languages are highly dependent upon activity (clicks) occurring on the bitly link. If there have not been clicks on a bitly link within the last 24 hours, it is possible that language data for that link does not exist. 631 | * 632 | * @param string $link 633 | * @return type 634 | */ 635 | public function linkLanguage($link) 636 | { 637 | return $this->make('link/language', array( 638 | 'link' => $link, 639 | )); 640 | } 641 | 642 | /** 643 | * Returns the significant locations for the bitly link or None if locations do not exist. Note that locations are highly dependent upon activity (clicks) occurring on the bitly link. If there have not been clicks on a bitly link within the last 24 hours, it is possible that location data for that link does not exist. 644 | * 645 | * @param string $link 646 | * @return type 647 | */ 648 | public function linkLocation($link) 649 | { 650 | return $this->make('link/location', array( 651 | 'link' => $link, 652 | )); 653 | } 654 | 655 | /** 656 | * This is used to query for a bitly link based on a long URL. 657 | * 658 | * @param string $url 659 | * @return type 660 | */ 661 | public function linkLookup($url) 662 | { 663 | return $this->make('link/lookup', array( 664 | 'url' => $url, 665 | )); 666 | } 667 | 668 | /** 669 | * 670 | * Returns metrics about the pages referring click traffic to a single bitly link. 671 | * 672 | * @param string $link 673 | * @param string $unit 674 | * @param integer $units 675 | * @param string $timezone 676 | * @param integer $limit 677 | * @param integer $unitReferenceTimeStamp 678 | * @return type 679 | */ 680 | public function linkReferrers($link, $unit = null, $units = null, $timezone = null, $limit = null, $unitReferenceTimeStamp = null) 681 | { 682 | $params = array('link' => $link); 683 | 684 | if ($unit !== null) { 685 | $params['unit'] = $unit; 686 | } 687 | 688 | if ($units !== null) { 689 | $params['units'] = $units; 690 | } 691 | 692 | if ($timezone !== null) { 693 | $params['timezone'] = $timezone; 694 | } 695 | 696 | if ($limit !== null) { 697 | $params['limit'] = $limit; 698 | } 699 | 700 | if ($unitReferenceTimeStamp !== null) { 701 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 702 | } 703 | 704 | return $this->make('link/referrers', $params); 705 | } 706 | 707 | /** 708 | * Returns metrics about the pages referring click traffic to a single bitly link, grouped by referring domain. 709 | * 710 | * @param string $link 711 | * @param string $unit 712 | * @param integer $units 713 | * @param string $timezone 714 | * @param integer $limit 715 | * @param integer $unitReferenceTimeStamp 716 | * @return type 717 | */ 718 | public function linkReferrersByDomain($link, $unit = null, $units = null, $timezone = null, $limit = null, $unitReferenceTimeStamp = null) 719 | { 720 | $params = array('link' => $link); 721 | 722 | if ($unit !== null) { 723 | $params['unit'] = $unit; 724 | } 725 | 726 | if ($units !== null) { 727 | $params['units'] = $units; 728 | } 729 | 730 | if ($timezone !== null) { 731 | $params['timezone'] = $timezone; 732 | } 733 | 734 | if ($limit !== null) { 735 | $params['limit'] = $limit; 736 | } 737 | 738 | if ($unitReferenceTimeStamp !== null) { 739 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 740 | } 741 | 742 | return $this->make('link/referrers_by_domain', $params); 743 | } 744 | 745 | /** 746 | * Returns metrics about the domains referring click traffic to a single bitly link. 747 | * 748 | * @param string $link 749 | * @param string $unit 750 | * @param integer $units 751 | * @param string $timezone 752 | * @param integer $limit 753 | * @param integer $unitReferenceTimeStamp 754 | * @return type 755 | */ 756 | public function linkReferringDomains($link, $unit = null, $units = null, $timezone = null, $limit = null, $unitReferenceTimeStamp = null) 757 | { 758 | $params = array('link' => $link); 759 | 760 | if ($unit !== null) { 761 | $params['unit'] = $unit; 762 | } 763 | 764 | if ($units !== null) { 765 | $params['units'] = $units; 766 | } 767 | 768 | if ($timezone !== null) { 769 | $params['timezone'] = $timezone; 770 | } 771 | 772 | if ($limit !== null) { 773 | $params['limit'] = $limit; 774 | } 775 | 776 | if ($unitReferenceTimeStamp !== null) { 777 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 778 | } 779 | 780 | return $this->make('link/referring_domains', $params); 781 | } 782 | 783 | /** 784 | * Returns metrics about a shares of a single link. 785 | * 786 | * @param string $link 787 | * @param string $unit 788 | * @param integer $units 789 | * @param string $timezone 790 | * @param boolean $rollup 791 | * @param integer $limit 792 | * @param integer $unitReferenceTimeStamp 793 | * @return type 794 | */ 795 | public function linkShares($link, $unit = null, $units = null, $timezone = null, $rollup = null, $limit = null, $unitReferenceTimeStamp = null) 796 | { 797 | $params = array('link' => $link); 798 | 799 | if ($unit !== null) { 800 | $params['unit'] = $unit; 801 | } 802 | 803 | if ($units !== null) { 804 | $params['units'] = $units; 805 | } 806 | 807 | if ($timezone !== null) { 808 | $params['timezone'] = $timezone; 809 | } 810 | 811 | if ($limit !== null) { 812 | $params['limit'] = $limit; 813 | } 814 | 815 | if ($unitReferenceTimeStamp !== null) { 816 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 817 | } 818 | 819 | return $this->make('link/shares', $params); 820 | } 821 | 822 | /** 823 | * Returns the "social score" for a specified bitly link. Note that the social score are highly dependent upon activity (clicks) occurring on the bitly link. If there have not been clicks on a bitly link within the last 24 hours, it is possible a social score for that link does not exist. 824 | * 825 | * @param string $link 826 | * @return type 827 | */ 828 | public function linkSocial($link) 829 | { 830 | return $this->make('link/social', array( 831 | 'link' => $link, 832 | )); 833 | } 834 | 835 | /** 836 | * Return information about an OAuth app. 837 | * 838 | * @param string $clientId 839 | * @return type 840 | */ 841 | public function oAuthApp($clientId) 842 | { 843 | return $this->make('oauth/app', array( 844 | 'client_id' => $clientId, 845 | )); 846 | } 847 | 848 | /** 849 | * Returns the top links shared by you, but not by your audience, ordered by clicks. 850 | * This endpoint is only available to paid customers. 851 | * 852 | * @param string $domain 853 | * @param string $unit 854 | * @param integer $units 855 | * @param string $timezone 856 | * @param integer $limit 857 | * @param integer $unitReferenceTimeStamp 858 | * @return type 859 | */ 860 | public function organizationBrandMessages($domain = null, $unit = null, $units = null, $timezone = null, $limit = null, $unitReferenceTimeStamp = null) 861 | { 862 | $params = array(); 863 | 864 | if ($domain !== null) { 865 | $params['domain'] = $domain; 866 | } 867 | 868 | if ($unit !== null) { 869 | $params['unit'] = $unit; 870 | } 871 | 872 | if ($units !== null) { 873 | $params['units'] = $units; 874 | } 875 | 876 | if ($timezone !== null) { 877 | $params['timezone'] = $timezone; 878 | } 879 | 880 | if ($limit !== null) { 881 | $params['limit'] = $limit; 882 | } 883 | 884 | if ($unitReferenceTimeStamp !== null) { 885 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 886 | } 887 | 888 | return $this->make('organization/brand_messages', $params); 889 | } 890 | 891 | /** 892 | * Returns the top links shared by both your audience and by your account, ordered by clicks. 893 | * This endpoint is only available to paid customers. 894 | * 895 | * @param string $domain 896 | * @param string $unit 897 | * @param integer $units 898 | * @param string $timezone 899 | * @param integer $limit 900 | * @param integer $unitReferenceTimeStamp 901 | * @return type 902 | */ 903 | public function organizationIntersectingLinks($domain = null, $unit = null, $units = null, $timezone = null, $limit = null, $unitReferenceTimeStamp = null) 904 | { 905 | $params = array(); 906 | 907 | if ($domain !== null) { 908 | $params['domain'] = $domain; 909 | } 910 | 911 | if ($unit !== null) { 912 | $params['unit'] = $unit; 913 | } 914 | 915 | if ($units !== null) { 916 | $params['units'] = $units; 917 | } 918 | 919 | if ($timezone !== null) { 920 | $params['timezone'] = $timezone; 921 | } 922 | 923 | if ($limit !== null) { 924 | $params['limit'] = $limit; 925 | } 926 | 927 | if ($unitReferenceTimeStamp !== null) { 928 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 929 | } 930 | 931 | return $this->make('organization/interesecting_links', $params); 932 | } 933 | 934 | /** 935 | * Returns the top-performing organization members ordered by clicks or shortens. 936 | * This endpoint is only available to paid customers. 937 | * 938 | * @param string $domain 939 | * @param string $orderBy 940 | * @param string $unit 941 | * @param integer $units 942 | * @param string $timezone 943 | * @param integer $limit 944 | * @param integer $unitReferenceTimeStamp 945 | * @return type 946 | */ 947 | public function organizationLeaderboard($domain = null, $orderBy = null, $unit = null, $units = null, $timezone = null, $limit = null, $unitReferenceTimeStamp = null) 948 | { 949 | $params = array(); 950 | 951 | if ($domain !== null) { 952 | $params['domain'] = $domain; 953 | } 954 | 955 | if ($orderBy !== null) { 956 | $params['order_by'] = $orderBy; 957 | } 958 | 959 | if ($unit !== null) { 960 | $params['unit'] = $unit; 961 | } 962 | 963 | if ($units !== null) { 964 | $params['units'] = $units; 965 | } 966 | 967 | if ($timezone !== null) { 968 | $params['timezone'] = $timezone; 969 | } 970 | 971 | if ($limit !== null) { 972 | $params['limit'] = $limit; 973 | } 974 | 975 | if ($unitReferenceTimeStamp !== null) { 976 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 977 | } 978 | 979 | return $this->make('organization/leaderboard', $params); 980 | } 981 | 982 | /** 983 | * Returns the top links shared by your audience, but not by you, ordered by clicks. 984 | * This endpoint is only available to paid customers. 985 | * 986 | * @param string $domain 987 | * @param string $unit 988 | * @param integer $units 989 | * @param string $timezone 990 | * @param integer $limit 991 | * @param integer $unitReferenceTimeStamp 992 | * @return type 993 | */ 994 | public function organizationMissedOpportunities($domain = null, $unit = null, $units = null, $timezone = null, $limit = null, $unitReferenceTimeStamp = null) 995 | { 996 | $params = array(); 997 | 998 | if ($domain !== null) { 999 | $params['domain'] = $domain; 1000 | } 1001 | 1002 | if ($unit !== null) { 1003 | $params['unit'] = $unit; 1004 | } 1005 | 1006 | if ($units !== null) { 1007 | $params['units'] = $units; 1008 | } 1009 | 1010 | if ($timezone !== null) { 1011 | $params['timezone'] = $timezone; 1012 | } 1013 | 1014 | if ($limit !== null) { 1015 | $params['limit'] = $limit; 1016 | } 1017 | 1018 | if ($unitReferenceTimeStamp !== null) { 1019 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 1020 | } 1021 | 1022 | return $this->make('organization/missed_opportunities', $params); 1023 | } 1024 | 1025 | /** 1026 | * Returns phrases that are receiving an uncharacteristically high volume of click traffic, and the individual links (hashes) driving traffic to pages containing these phrases. 1027 | * 1028 | * @return type 1029 | */ 1030 | public function realtimeBurstingPhrases() 1031 | { 1032 | return $this->make('realtime/bursting_phrases'); 1033 | } 1034 | 1035 | /** 1036 | * Returns the click rate for content containing a specified phrase. 1037 | * 1038 | * @param string $phrase 1039 | * @return type 1040 | */ 1041 | public function realtimeClickrate($phrase) 1042 | { 1043 | return $this->make('realtime/clickrate', array( 1044 | 'phrase' => $phrase, 1045 | )); 1046 | } 1047 | 1048 | /** 1049 | * Returns phrases that are receiving a consistently high volume of click traffic, and the individual links (hashes) driving traffic to pages containing these phrases. 1050 | * 1051 | * @return type 1052 | */ 1053 | public function realtimeHotPhrases() 1054 | { 1055 | return $this->make('realtime/hot_phrases'); 1056 | } 1057 | 1058 | /** 1059 | * Search links receiving clicks across bitly by content, language, location, and more. 1060 | * 1061 | * @param string $query 1062 | * @param string $fields 1063 | * @param integer $offset 1064 | * @param integer $limit 1065 | * @param string $domain 1066 | * @param string $fullDomain 1067 | * @param string $cities 1068 | * @param string $lang 1069 | * @return type 1070 | */ 1071 | public function search($query, $domain, $fields = null, $offset = null, $limit = null, $fullDomain = null, $cities = null, $lang = null) 1072 | { 1073 | $params = array( 1074 | 'query' => $query, 1075 | 'domain' => $domain, 1076 | ); 1077 | 1078 | if ($fields !== null) { 1079 | $params['fields'] = $fields; 1080 | } 1081 | 1082 | if ($offset !== null) { 1083 | $params['offset'] = $offset; 1084 | } 1085 | 1086 | if ($limit !== null) { 1087 | $params['limit'] = $limit; 1088 | } 1089 | 1090 | if ($fullDomain !== null) { 1091 | $params['full_domain'] = $fullDomain; 1092 | } 1093 | 1094 | if ($cities !== null) { 1095 | $params['cities'] = $cities; 1096 | } 1097 | 1098 | if ($lang !== null) { 1099 | $params['lang'] = $lang; 1100 | } 1101 | 1102 | return $this->make('search', $params); 1103 | } 1104 | 1105 | /** 1106 | * Given a long URL, returns a bitly short URL. 1107 | * 1108 | * @param string $longURL 1109 | * @param type $domain 1110 | * @return type 1111 | */ 1112 | public function shorten($longURL, $domain = null) 1113 | { 1114 | $params = array('longUrl' => $longURL); 1115 | 1116 | if ($domain !== null) { 1117 | $params['domain'] = $domain; 1118 | } 1119 | 1120 | return $this->make('shorten', $params); 1121 | } 1122 | 1123 | /** 1124 | * Returns the aggregate number of clicks on all of the authenticated user's bitly links. 1125 | * 1126 | * @param string $unit 1127 | * @param integer $units 1128 | * @param string $timezone 1129 | * @param boolean $rollup 1130 | * @param integer $limit 1131 | * @param integer $unitReferenceTimeStamp 1132 | * @return type 1133 | */ 1134 | public function userClicks($unit = null, $units = null, $timezone = null, $rollup = null, $limit = null, $unitReferenceTimeStamp = null) 1135 | { 1136 | $params = array(); 1137 | 1138 | if ($unit !== null) { 1139 | $params['unit'] = $unit; 1140 | } 1141 | 1142 | if ($units !== null) { 1143 | $params['units'] = $units; 1144 | } 1145 | 1146 | if ($timezone !== null) { 1147 | $params['timezone'] = $timezone; 1148 | } 1149 | 1150 | if ($rollup !== null) { 1151 | $params['rollup'] = $rollup; 1152 | } 1153 | 1154 | if ($limit !== null) { 1155 | $params['limit'] = $limit; 1156 | } 1157 | 1158 | if ($unitReferenceTimeStamp !== null) { 1159 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 1160 | } 1161 | 1162 | return $this->make('user/clicks', $params); 1163 | } 1164 | 1165 | /** 1166 | * Returns aggregate metrics about the countries referring click traffic to all of the authenticated user's bitly links. 1167 | * 1168 | * @param string $unit 1169 | * @param integer $units 1170 | * @param string $timezone 1171 | * @param boolean $rollup 1172 | * @param integer $limit 1173 | * @param integer $unitReferenceTimeStamp 1174 | * @return type 1175 | */ 1176 | public function userCountries($unit = null, $units = null, $timezone = null, $rollup = null, $limit = null, $unitReferenceTimeStamp = null) 1177 | { 1178 | $params = array(); 1179 | 1180 | if ($unit !== null) { 1181 | $params['unit'] = $unit; 1182 | } 1183 | 1184 | if ($units !== null) { 1185 | $params['units'] = $units; 1186 | } 1187 | 1188 | if ($timezone !== null) { 1189 | $params['timezone'] = $timezone; 1190 | } 1191 | 1192 | if ($rollup !== null) { 1193 | $params['rollup'] = $rollup; 1194 | } 1195 | 1196 | if ($limit !== null) { 1197 | $params['limit'] = $limit; 1198 | } 1199 | 1200 | if ($unitReferenceTimeStamp !== null) { 1201 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 1202 | } 1203 | 1204 | return $this->make('user/countries', $params); 1205 | } 1206 | 1207 | /** 1208 | * Return or update information about a user. 1209 | * 1210 | * @param string $login 1211 | * @param string $fullName 1212 | * @return type 1213 | */ 1214 | public function userInfo($login = null, $fullName = null) 1215 | { 1216 | $params = array(); 1217 | 1218 | if ($login !== null) { 1219 | $params['login'] = $login; 1220 | } 1221 | 1222 | if ($fullName !== null) { 1223 | $params['full_name'] = $fullName; 1224 | } 1225 | 1226 | return $this->make('user/info', $params); 1227 | } 1228 | 1229 | /** 1230 | * Changes link metadata in a user's history. 1231 | * 1232 | * @param string $link 1233 | * @param string $edit 1234 | * @param string $title 1235 | * @param string $note 1236 | * @param boolean $private 1237 | * @param integer $userTimeStamp 1238 | * @param boolean $archived 1239 | * @return type 1240 | */ 1241 | public function userLinkEdit($link, $edit, $title = null, $note = null, $private = null, $userTimeStamp = null, $archived = null) 1242 | { 1243 | $params = array( 1244 | 'link' => $link, 1245 | 'edit' => $edit, 1246 | ); 1247 | 1248 | if ($title !== null) { 1249 | $params['title'] = $title; 1250 | } 1251 | 1252 | if ($note !== null) { 1253 | $params['note'] = $note; 1254 | } 1255 | 1256 | if ($private !== null) { 1257 | $params['private'] = $private; 1258 | } 1259 | 1260 | if ($userTimeStamp !== null) { 1261 | $params['user_ts'] = $userTimeStamp; 1262 | } 1263 | 1264 | if ($archived !== null) { 1265 | $params['archived'] = $archived; 1266 | } 1267 | 1268 | return $this->make('user/link_edit', $params); 1269 | } 1270 | 1271 | /** 1272 | * Returns entries from a user's link history in reverse chronological order. 1273 | * Note: Entries will be sorted by the user_ts field found in the response data. 1274 | * 1275 | * @param string $link 1276 | * @param string $query 1277 | * @param integer $offset 1278 | * @param integer $limit 1279 | * @param integer $createdBefore 1280 | * @param integer $createdAfter 1281 | * @param integer $modifiedAfter 1282 | * @param boolean $expandClientId 1283 | * @param string $archived 1284 | * @param string $private 1285 | * @param string $user 1286 | * @param string $exactDomain 1287 | * @param string $rootDomain 1288 | * @return type 1289 | */ 1290 | public function userLinkHistory($link = null, $query = null, $offset = null, $limit = null, $createdBefore = null, $createdAfter = null, $modifiedAfter = null, $expandClientId = null, $archived = null, $private = null, $user = null, $exactDomain = null, $rootDomain = null) 1291 | { 1292 | $params = array(); 1293 | 1294 | if ($link !== null) { 1295 | $params['link'] = $link; 1296 | } 1297 | 1298 | if ($query !== null) { 1299 | $params['query'] = $query; 1300 | } 1301 | 1302 | if ($offset !== null) { 1303 | $params['offset'] = $offset; 1304 | } 1305 | 1306 | if ($limit !== null) { 1307 | $params['limit'] = $limit; 1308 | } 1309 | 1310 | if ($createdBefore !== null) { 1311 | $params['created_before'] = $createdBefore; 1312 | } 1313 | 1314 | if ($createdAfter !== null) { 1315 | $params['created_after'] = $createdAfter; 1316 | } 1317 | 1318 | if ($modifiedAfter !== null) { 1319 | $params['modified_after'] = $modifiedAfter; 1320 | } 1321 | 1322 | if ($expandClientId !== null) { 1323 | $params['expand_client_id'] = $expandClientId; 1324 | } 1325 | 1326 | if ($archived !== null) { 1327 | $params['archived'] = $archived; 1328 | } 1329 | 1330 | if ($private !== null) { 1331 | $params['private'] = $private; 1332 | } 1333 | 1334 | if ($offset !== null) { 1335 | $params['offset'] = $offset; 1336 | } 1337 | 1338 | if ($user !== null) { 1339 | $params['user'] = $user; 1340 | } 1341 | 1342 | if ($exactDomain !== null) { 1343 | $params['exact_domain'] = $exactDomain; 1344 | } 1345 | 1346 | if ($rootDomain !== null) { 1347 | $params['root_domain'] = $rootDomain; 1348 | } 1349 | 1350 | return $this->make('user/link_history', $params); 1351 | } 1352 | 1353 | /** 1354 | * This is used to query for a bitly link shortened by the authenticated user based on a long URL. 1355 | * 1356 | * @param string $url 1357 | * @return type 1358 | */ 1359 | public function userLinkLookup($url) 1360 | { 1361 | return $this->make('user/link_lookup', array( 1362 | 'url' => $url, 1363 | )); 1364 | } 1365 | 1366 | /** 1367 | * Saves a link as a bitmark in a user's history, with optional pre-set metadata. (Also returns a short URL for that link.) 1368 | * 1369 | * @param string $longURL 1370 | * @param string $title 1371 | * @param string $note 1372 | * @param boolean $private 1373 | * @param integer $userTimeStamp 1374 | * @return type 1375 | */ 1376 | public function userLinkSave($longURL, $title = null, $note = null, $private = null, $userTimeStamp = null) 1377 | { 1378 | $params = array('longUrl' => $longURL); 1379 | 1380 | if ($title !== null) { 1381 | $params['title'] = $title; 1382 | } 1383 | 1384 | if ($note !== null) { 1385 | $params['note'] = $note; 1386 | } 1387 | 1388 | if ($private !== null) { 1389 | $params['private'] = $private; 1390 | } 1391 | 1392 | if ($userTimeStamp !== null) { 1393 | $params['user_ts'] = $userTimeStamp; 1394 | } 1395 | 1396 | return $this->make('user/link_save', $params); 1397 | } 1398 | 1399 | /** 1400 | * Returns entries from a user's network history in reverse chronogical order. (A user's network history includes publicly saved links from Twitter and Facebook connections.) 1401 | * 1402 | * @param integer $offset 1403 | * @param boolean $expandClientId 1404 | * @param integer $limit 1405 | * @param boolean $expandUser 1406 | * @return type 1407 | */ 1408 | public function userNetworkHistory($offset = null, $expandClientId = null, $limit = null, $expandUser = null) 1409 | { 1410 | $params = array(); 1411 | 1412 | if ($offset !== null) { 1413 | $params['offset'] = $offset; 1414 | } 1415 | 1416 | if ($expandClientId !== null) { 1417 | $params['expand_client_id'] = $expandClientId; 1418 | } 1419 | 1420 | if ($limit !== null) { 1421 | $params['limit'] = $limit; 1422 | } 1423 | 1424 | if ($expandUser !== null) { 1425 | $params['expand_user'] = $expandUser; 1426 | } 1427 | 1428 | return $this->make('user/newtork_history', $params); 1429 | } 1430 | 1431 | /** 1432 | * Returns the top links to your tracking domain (or domains) created by users not associated with your account, ordered by clicks. 1433 | * Users can register a tracking domain from their bitly settings page. 1434 | * This endpoint is only available to paid customers. 1435 | * 1436 | * @param string $domain 1437 | * @param string $unit 1438 | * @param integer $units 1439 | * @param string $timezone 1440 | * @param integer $limit 1441 | * @param integer $unitReferenceTimeStamp 1442 | * @return type 1443 | */ 1444 | public function userPopularEarnedByClicks($domain = null, $unit = null, $units = null, $timezone = null, $limit = null, $unitReferenceTimeStamp = null) 1445 | { 1446 | $params = array(); 1447 | 1448 | if ($domain !== null) { 1449 | $params['domain'] = $domain; 1450 | } 1451 | 1452 | if ($unit !== null) { 1453 | $params['unit'] = $unit; 1454 | } 1455 | 1456 | if ($units !== null) { 1457 | $params['units'] = $units; 1458 | } 1459 | 1460 | if ($timezone !== null) { 1461 | $params['timezone'] = $timezone; 1462 | } 1463 | 1464 | if ($limit !== null) { 1465 | $params['limit'] = $limit; 1466 | } 1467 | 1468 | if ($unitReferenceTimeStamp !== null) { 1469 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 1470 | } 1471 | 1472 | return $this->make('user/popular_earned_by_clicks', $params); 1473 | } 1474 | 1475 | /** 1476 | * Returns the top links to your tracking domain (or domains) created by users not associated with your account, ordered by shortens. 1477 | * Users can register a tracking domain from their bitly settings page. 1478 | * This endpoint is only available to paid customers. 1479 | * 1480 | * @param string $domain 1481 | * @param string $unit 1482 | * @param integer $units 1483 | * @param string $timezone 1484 | * @param integer $limit 1485 | * @param integer $unitReferenceTimeStamp 1486 | * @return type 1487 | */ 1488 | public function userPopularEarnedByShortens($domain = null, $unit = null, $units = null, $timezone = null, $limit = null, $unitReferenceTimeStamp = null) 1489 | { 1490 | $params = array(); 1491 | 1492 | if ($domain !== null) { 1493 | $params['domain'] = $domain; 1494 | } 1495 | 1496 | if ($unit !== null) { 1497 | $params['unit'] = $unit; 1498 | } 1499 | 1500 | if ($units !== null) { 1501 | $params['units'] = $units; 1502 | } 1503 | 1504 | if ($timezone !== null) { 1505 | $params['timezone'] = $timezone; 1506 | } 1507 | 1508 | if ($limit !== null) { 1509 | $params['limit'] = $limit; 1510 | } 1511 | 1512 | if ($unitReferenceTimeStamp !== null) { 1513 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 1514 | } 1515 | 1516 | return $this->make('user/popular_earned_by_shortens', $params); 1517 | } 1518 | 1519 | /** 1520 | * Returns the authenticated user's most-clicked bitly links (ordered by number of clicks) in a given time period. 1521 | * Note: This replaces the realtime_links endpoint. 1522 | * 1523 | * @param string $unit 1524 | * @param integer $units 1525 | * @param string $timezone 1526 | * @param integer $limit 1527 | * @param integer $unitReferenceTimeStamp 1528 | * @return type 1529 | */ 1530 | public function userPopularLinks($unit = null, $units = null, $timezone = null, $limit = null, $unitReferenceTimeStamp = null) 1531 | { 1532 | $params = array(); 1533 | 1534 | if ($unit !== null) { 1535 | $params['unit'] = $unit; 1536 | } 1537 | 1538 | if ($units !== null) { 1539 | $params['units'] = $units; 1540 | } 1541 | 1542 | if ($timezone !== null) { 1543 | $params['timezone'] = $timezone; 1544 | } 1545 | 1546 | if ($limit !== null) { 1547 | $params['limit'] = $limit; 1548 | } 1549 | 1550 | if ($unitReferenceTimeStamp !== null) { 1551 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 1552 | } 1553 | 1554 | return $this->make('user/popular_links', $params); 1555 | } 1556 | 1557 | /** 1558 | * Returns the top links to your tracking domain (or domains) created by you or your subaccounts ordered by clicks. 1559 | * Users can register a tracking domain from their bitly settings page. 1560 | * This endpoint is only available to paid customers. 1561 | * 1562 | * @param string $domain 1563 | * @param string $subaccount 1564 | * @param string $unit 1565 | * @param integer $units 1566 | * @param string $timezone 1567 | * @param integer $limit 1568 | * @param integer $unitReferenceTimeStamp 1569 | * @return type 1570 | */ 1571 | public function userPopularOwnedByClicks($domain = null, $subaccount = null, $unit = null, $units = null, $timezone = null, $limit = null, $unitReferenceTimeStamp = null) 1572 | { 1573 | $params = array(); 1574 | 1575 | if ($domain !== null) { 1576 | $params['domain'] = $domain; 1577 | } 1578 | 1579 | if ($subaccount !== null) { 1580 | $params['subaccount'] = $subaccount; 1581 | } 1582 | 1583 | if ($unit !== null) { 1584 | $params['unit'] = $unit; 1585 | } 1586 | 1587 | if ($units !== null) { 1588 | $params['units'] = $units; 1589 | } 1590 | 1591 | if ($timezone !== null) { 1592 | $params['timezone'] = $timezone; 1593 | } 1594 | 1595 | if ($limit !== null) { 1596 | $params['limit'] = $limit; 1597 | } 1598 | 1599 | if ($unitReferenceTimeStamp !== null) { 1600 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 1601 | } 1602 | 1603 | return $this->make('user/popular_owned_by_clicks', $params); 1604 | } 1605 | 1606 | /** 1607 | * Returns the top links to your tracking domain (or domains) created by you or your subaccounts ordered by number of shortens. 1608 | * Users can register a tracking domain from their bitly settings page. 1609 | * This endpoint is only available to paid customers. 1610 | * 1611 | * @param string $domain 1612 | * @param string $subaccount 1613 | * @param string $unit 1614 | * @param integer $units 1615 | * @param string $timezone 1616 | * @param integer $limit 1617 | * @param integer $unitReferenceTimeStamp 1618 | * @return type 1619 | */ 1620 | public function userPopularOwnedByShortens($domain = null, $subaccount = null, $unit = null, $units = null, $timezone = null, $limit = null, $unitReferenceTimeStamp = null) 1621 | { 1622 | $params = array(); 1623 | 1624 | if ($domain !== null) { 1625 | $params['domain'] = $domain; 1626 | } 1627 | 1628 | if ($subaccount !== null) { 1629 | $params['subaccount'] = $subaccount; 1630 | } 1631 | 1632 | if ($unit !== null) { 1633 | $params['unit'] = $unit; 1634 | } 1635 | 1636 | if ($units !== null) { 1637 | $params['units'] = $units; 1638 | } 1639 | 1640 | if ($timezone !== null) { 1641 | $params['timezone'] = $timezone; 1642 | } 1643 | 1644 | if ($limit !== null) { 1645 | $params['limit'] = $limit; 1646 | } 1647 | 1648 | if ($unitReferenceTimeStamp !== null) { 1649 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 1650 | } 1651 | 1652 | return $this->make('user/popular_owned_by_shortens', $params); 1653 | } 1654 | 1655 | /** 1656 | * Returns aggregate metrics about the pages referring click traffic to all of the authenticated user's bitly links. 1657 | * 1658 | * @param string $unit 1659 | * @param integer $units 1660 | * @param string $timezone 1661 | * @param boolean $rollup 1662 | * @param integer $limit 1663 | * @param integer $unitReferenceTimeStamp 1664 | * @return type 1665 | */ 1666 | public function userReferrers($unit = null, $units = null, $timezone = null, $rollup = null, $limit = null, $unitReferenceTimeStamp = null) 1667 | { 1668 | $params = array(); 1669 | 1670 | if ($unit !== null) { 1671 | $params['unit'] = $unit; 1672 | } 1673 | 1674 | if ($units !== null) { 1675 | $params['units'] = $units; 1676 | } 1677 | 1678 | if ($timezone !== null) { 1679 | $params['timezone'] = $timezone; 1680 | } 1681 | 1682 | if ($rollup !== null) { 1683 | $params['rollup'] = $rollup; 1684 | } 1685 | 1686 | if ($limit !== null) { 1687 | $params['limit'] = $limit; 1688 | } 1689 | 1690 | if ($unitReferenceTimeStamp !== null) { 1691 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 1692 | } 1693 | 1694 | return $this->make('user/referrers', $params); 1695 | } 1696 | 1697 | /** 1698 | * Returns aggregate metrics about the domains referring click traffic to all of the authenticated user's bitly links. 1699 | * 1700 | * @param string $unit 1701 | * @param integer $units 1702 | * @param string $timezone 1703 | * @param boolean $rollup 1704 | * @param integer $limit 1705 | * @param integer $unitReferenceTimeStamp 1706 | * @return type 1707 | */ 1708 | public function userReferringDomains($unit = null, $units = null, $timezone = null, $rollup = null, $limit = null, $unitReferenceTimeStamp = null) 1709 | { 1710 | $params = array(); 1711 | 1712 | if ($unit !== null) { 1713 | $params['unit'] = $unit; 1714 | } 1715 | 1716 | if ($units !== null) { 1717 | $params['units'] = $units; 1718 | } 1719 | 1720 | if ($timezone !== null) { 1721 | $params['timezone'] = $timezone; 1722 | } 1723 | 1724 | if ($rollup !== null) { 1725 | $params['rollup'] = $rollup; 1726 | } 1727 | 1728 | if ($limit !== null) { 1729 | $params['limit'] = $limit; 1730 | } 1731 | 1732 | if ($unitReferenceTimeStamp !== null) { 1733 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 1734 | } 1735 | 1736 | return $this->make('user/referring_domains', $params); 1737 | } 1738 | 1739 | /** 1740 | * Save a custom keyword for a custom short domain. 1741 | * 1742 | * @param string $keywordLink 1743 | * @param string $targetLink 1744 | * @return type 1745 | */ 1746 | public function userSaveCustomDomainKeyword($keywordLink, $targetLink) 1747 | { 1748 | return $this->make('user/save_custom_domain_keyword', array( 1749 | 'keyword_link' => $keywordLink, 1750 | 'target_link' => $targetLink, 1751 | )); 1752 | } 1753 | 1754 | /** 1755 | * Returns the number of shares by the authenticated user in a given time period. 1756 | * 1757 | * @param string $unit 1758 | * @param integer $units 1759 | * @param string $timezone 1760 | * @param boolean $rollup 1761 | * @param integer $limit 1762 | * @param integer $unitReferenceTimeStamp 1763 | * @return type 1764 | */ 1765 | public function userShareCounts($unit = null, $units = null, $timezone = null, $rollup = null, $limit = null, $unitReferenceTimeStamp = null) 1766 | { 1767 | $params = array(); 1768 | 1769 | if ($unit !== null) { 1770 | $params['unit'] = $unit; 1771 | } 1772 | 1773 | if ($units !== null) { 1774 | $params['units'] = $units; 1775 | } 1776 | 1777 | if ($timezone !== null) { 1778 | $params['timezone'] = $timezone; 1779 | } 1780 | 1781 | if ($rollup !== null) { 1782 | $params['rollup'] = $rollup; 1783 | } 1784 | 1785 | if ($limit !== null) { 1786 | $params['limit'] = $limit; 1787 | } 1788 | 1789 | if ($unitReferenceTimeStamp !== null) { 1790 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 1791 | } 1792 | 1793 | return $this->make('user/share_counts', $params); 1794 | } 1795 | 1796 | /** 1797 | * Returns the number of shares by the authenticated user, broken down by share type (ie: twitter, facebook, email) in a given time period. 1798 | * 1799 | * @param string $unit 1800 | * @param integer $units 1801 | * @param string $timezone 1802 | * @param boolean $rollup 1803 | * @param integer $limit 1804 | * @param integer $unitReferenceTimeStamp 1805 | * @return type 1806 | */ 1807 | public function userShareCountsByShareType($unit = null, $units = null, $timezone = null, $rollup = null, $limit = null, $unitReferenceTimeStamp = null) 1808 | { 1809 | $params = array(); 1810 | 1811 | if ($unit !== null) { 1812 | $params['unit'] = $unit; 1813 | } 1814 | 1815 | if ($units !== null) { 1816 | $params['units'] = $units; 1817 | } 1818 | 1819 | if ($timezone !== null) { 1820 | $params['timezone'] = $timezone; 1821 | } 1822 | 1823 | if ($rollup !== null) { 1824 | $params['rollup'] = $rollup; 1825 | } 1826 | 1827 | if ($limit !== null) { 1828 | $params['limit'] = $limit; 1829 | } 1830 | 1831 | if ($unitReferenceTimeStamp !== null) { 1832 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 1833 | } 1834 | 1835 | return $this->make('user/share_counts_by_share_type', $params); 1836 | } 1837 | 1838 | /** 1839 | * Returns the number of links shortened (encoded) in a given time period by the authenticated user. 1840 | * 1841 | * @param string $unit 1842 | * @param integer $units 1843 | * @param string $timezone 1844 | * @param boolean $rollup 1845 | * @param integer $limit 1846 | * @param integer $unitReferenceTimeStamp 1847 | * @return type 1848 | */ 1849 | public function userShortenCounts($unit = null, $units = null, $timezone = null, $rollup = null, $limit = null, $unitReferenceTimeStamp = null) 1850 | { 1851 | $params = array(); 1852 | 1853 | if ($unit !== null) { 1854 | $params['unit'] = $unit; 1855 | } 1856 | 1857 | if ($units !== null) { 1858 | $params['units'] = $units; 1859 | } 1860 | 1861 | if ($timezone !== null) { 1862 | $params['timezone'] = $timezone; 1863 | } 1864 | 1865 | if ($rollup !== null) { 1866 | $params['rollup'] = $rollup; 1867 | } 1868 | 1869 | if ($limit !== null) { 1870 | $params['limit'] = $limit; 1871 | } 1872 | 1873 | if ($unitReferenceTimeStamp !== null) { 1874 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 1875 | } 1876 | 1877 | return $this->make('user/shorten_counts', $params); 1878 | } 1879 | 1880 | /** 1881 | * Returns a list of tracking domains a user has configured. 1882 | * 1883 | * @return type 1884 | */ 1885 | public function userTrackingDomainList() 1886 | { 1887 | return $this->make('user/tracking_domain_list'); 1888 | } 1889 | 1890 | /** 1891 | * Query whether a given domain is a valid bitly pro domain. 1892 | * Keep in mind that bitly custom short domains are restricted 1893 | * to less than 15 characters in length. 1894 | * 1895 | * @param string $domain 1896 | * @return type 1897 | */ 1898 | public function domainBitlyProDomain($domain) 1899 | { 1900 | return $this->make('bitly_pro_domain', array( 1901 | 'domain' => $domain, 1902 | )); 1903 | } 1904 | 1905 | /** 1906 | * This lists NSQ Topic and Channel Message Information and Connection State for a Topic. 1907 | * 1908 | * @param type $topic NSQ Data Stream Topic 1909 | * @return type 1910 | */ 1911 | public function nsqStats($topic) 1912 | { 1913 | return $this->make('nsq/stats', array( 1914 | 'topic' => $topic, 1915 | )); 1916 | } 1917 | 1918 | /** 1919 | * Returns the number of clicks on Bitlinks pointing to the specified 1920 | * tracking domain that have occured in a given time period. 1921 | * Users can register a tracking domain from their bitly settings page. 1922 | * 1923 | * @param string $domain 1924 | * @param string $unit 1925 | * @param integer $units 1926 | * @param string $timezone 1927 | * @param boolean $rollup 1928 | * @param integer $limit 1929 | * @param integer $unitReferenceTimeStamp 1930 | * @return type 1931 | */ 1932 | public function userTrackingDomainClicks($domain, $unit = null, $units = null, $timezone = null, $rollup = null, $limit = null, $unitReferenceTimeStamp = null) 1933 | { 1934 | $params = array('domain' => $domain); 1935 | 1936 | if ($unit !== null) { 1937 | $params['unit'] = $unit; 1938 | } 1939 | 1940 | if ($units !== null) { 1941 | $params['units'] = $units; 1942 | } 1943 | 1944 | if ($timezone !== null) { 1945 | $params['timezone'] = $timezone; 1946 | } 1947 | 1948 | if ($rollup !== null) { 1949 | $params['rollup'] = $rollup; 1950 | } 1951 | 1952 | if ($limit !== null) { 1953 | $params['limit'] = $limit; 1954 | } 1955 | 1956 | if ($unitReferenceTimeStamp !== null) { 1957 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 1958 | } 1959 | 1960 | return $this->make('user/tracking_domain_clicks', $params); 1961 | } 1962 | 1963 | /** 1964 | * Returns the number of links, pointing to a specified tracking domain, 1965 | * shortened (encoded) in a given time period by all bitly users. 1966 | * Users can register a tracking domain from their bitly settings page. 1967 | * 1968 | * @param string $domain 1969 | * @param string $unit 1970 | * @param integer $units 1971 | * @param string $timezone 1972 | * @param boolean $rollup 1973 | * @param integer $limit 1974 | * @param integer $unitReferenceTimeStamp 1975 | * @return type 1976 | */ 1977 | public function userTrackingDomainShortenCounts($domain, $unit = null, $units = null, $timezone = null, $rollup = null, $limit = null, $unitReferenceTimeStamp = null) 1978 | { 1979 | $params = array('domain' => $domain); 1980 | 1981 | if ($unit !== null) { 1982 | $params['unit'] = $unit; 1983 | } 1984 | 1985 | if ($units !== null) { 1986 | $params['units'] = $units; 1987 | } 1988 | 1989 | if ($timezone !== null) { 1990 | $params['timezone'] = $timezone; 1991 | } 1992 | 1993 | if ($rollup !== null) { 1994 | $params['rollup'] = $rollup; 1995 | } 1996 | 1997 | if ($limit !== null) { 1998 | $params['limit'] = $limit; 1999 | } 2000 | 2001 | if ($unitReferenceTimeStamp !== null) { 2002 | $params['unit_reference_ts'] = $unitReferenceTimeStamp; 2003 | } 2004 | 2005 | return $this->make('user/tracking_domain_shorten_counts', $params); 2006 | } 2007 | 2008 | } 2009 | -------------------------------------------------------------------------------- /src/Jelovac/Bitly4laravel/Bitly4laravelServiceProvider.php: -------------------------------------------------------------------------------- 1 | provider = $this->getProvider(); 32 | } 33 | 34 | /** 35 | * Bootstrap the application events. 36 | * 37 | * @return void 38 | */ 39 | public function boot() 40 | { 41 | return $this->provider->boot(); 42 | } 43 | 44 | /** 45 | * Register the service provider. 46 | * 47 | * @return void 48 | */ 49 | public function register() 50 | { 51 | return $this->provider->register(); 52 | } 53 | 54 | /** 55 | * Return ServiceProvider according to Laravel version 56 | * 57 | * @return \Jelovac\Bitly4laravel\Laravel4ServiceProvider | \Jelovac\Bitly4laravel\Laravel5ServiceProvider 58 | */ 59 | private function getProvider() 60 | { 61 | $app = $this->app; 62 | $version = intval($app::VERSION); 63 | $provider = sprintf('\Jelovac\Bitly4laravel\Laravel%dServiceProvider', $version); 64 | return new $provider($app); 65 | } 66 | 67 | /** 68 | * Get the services provided by the provider. 69 | * 70 | * @return array 71 | */ 72 | public function provides() 73 | { 74 | return array('bitly4laravel'); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/Jelovac/Bitly4laravel/BitlyInterface.php: -------------------------------------------------------------------------------- 1 | assembleMessage($var, 'Boolean'); 16 | parent::__construct($message); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/Jelovac/Bitly4laravel/Exceptions/NonIntegerTypeException.php: -------------------------------------------------------------------------------- 1 | assembleMessage($var, 'Integer'); 16 | parent::__construct($message); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/Jelovac/Bitly4laravel/Exceptions/NonStringTypeException.php: -------------------------------------------------------------------------------- 1 | assembleMessage($var, 'String'); 16 | parent::__construct($message); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/Jelovac/Bitly4laravel/Facades/Bitly4laravel.php: -------------------------------------------------------------------------------- 1 | package('jelovac/bitly4laravel'); 16 | } 17 | 18 | /** 19 | * Register the service provider. 20 | * 21 | * @return void 22 | */ 23 | public function register() 24 | { 25 | $this->app['bitly4laravel'] = $this->app->share(function($app) { 26 | $config = $app['config']->get('bitly4laravel::config'); 27 | return new Bitly4laravel($config); 28 | }); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/Jelovac/Bitly4laravel/Laravel5ServiceProvider.php: -------------------------------------------------------------------------------- 1 | config_path("bitly4laravel.php"), 19 | ); 20 | 21 | $this->publishes($paths, 'config'); 22 | } 23 | 24 | /** 25 | * Register the service provider. 26 | * 27 | * @return void 28 | */ 29 | public function register() 30 | { 31 | $this->app->bind('bitly4laravel', Bitly4laravel::class); 32 | 33 | $this->app->singleton(Bitly4laravel::class, function($app) { 34 | $config = $app['config']['bitly4laravel']; 35 | return new Bitly4laravel($config); 36 | }); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/Jelovac/Bitly4laravel/Model.php: -------------------------------------------------------------------------------- 1 | setConfig($config); 92 | } 93 | } 94 | 95 | /** 96 | * Set configuration 97 | * 98 | * @param array $config 99 | * @return \Jelovac\Bitly4laravel\Model 100 | * @throws InvalidArgumentException 101 | */ 102 | public function setConfig(array $config) 103 | { 104 | foreach ($config as $key => $value) { 105 | if (is_string($key)) { 106 | $key = "set_" . $key; 107 | $name = $this->snakeCaseToCamelCase($key); 108 | $this->callSetter($name, $value); 109 | } else { 110 | throw new InvalidArgumentException("Invalid config key set!"); 111 | } 112 | } 113 | 114 | return $this; 115 | } 116 | 117 | /** 118 | * Call the setter method 119 | * 120 | * @param type $name 121 | * @param type $value 122 | * @throws InvalidArgumentException 123 | */ 124 | protected function callSetter($name, $value) 125 | { 126 | if (method_exists(__CLASS__, $name)) { 127 | $this->{$name}($value); 128 | } else { 129 | throw new InvalidArgumentException("Invalid config key set!"); 130 | } 131 | } 132 | 133 | /** 134 | * Converts snake_case to camelCase 135 | * 136 | * @param type $value 137 | * @return string 138 | * @throws NonStringTypeException 139 | */ 140 | protected function snakeCaseToCamelCase($value) 141 | { 142 | if (is_string($value)) { 143 | $value = str_replace(' ', '', ucwords(str_replace('_', ' ', $value))); 144 | $value = strtolower(substr($value, 0, 1)) . substr($value, 1); 145 | return $value; 146 | } else { 147 | throw new NonStringTypeException($value); 148 | } 149 | } 150 | 151 | /** 152 | * Get Bitly OAuth Generic Access Token 153 | * 154 | * @return string 155 | */ 156 | public function getAccessToken() 157 | { 158 | return $this->accessToken; 159 | } 160 | 161 | /** 162 | * Set Bitly OAuth Generic Access Token 163 | * 164 | * @param type $accessToken 165 | * @return \Jelovac\Bitly4laravel\Model 166 | * @throws NonStringTypeException 167 | */ 168 | public function setAccessToken($accessToken) 169 | { 170 | if (is_string($accessToken)) { 171 | $this->accessToken = $accessToken; 172 | return $this; 173 | } else { 174 | throw new NonStringTypeException($accessToken); 175 | } 176 | } 177 | 178 | /** 179 | * Get cache enabled 180 | * 181 | * @return bool 182 | */ 183 | public function getCacheEnabled() 184 | { 185 | return $this->cacheEnabled; 186 | } 187 | 188 | /** 189 | * Set cache enabled 190 | * 191 | * @param bool $cacheEnabled 192 | * @return \Jelovac\Bitly4laravel\Model 193 | * @throws NonBooleanTypeException 194 | */ 195 | public function setCacheEnabled($cacheEnabled) 196 | { 197 | if (is_bool($cacheEnabled)) { 198 | $this->cacheEnabled = $cacheEnabled; 199 | return $this; 200 | } else { 201 | throw new NonBooleanTypeException($cacheEnabled); 202 | } 203 | } 204 | 205 | /** 206 | * Get cache duration in minutes 207 | * 208 | * @return int 209 | */ 210 | public function getCacheDuration() 211 | { 212 | return $this->cacheDuration; 213 | } 214 | 215 | /** 216 | * Set cache duration in minutes 217 | * 218 | * @param type $cacheDuration 219 | * @return \Jelovac\Bitly4laravel\Model 220 | * @throws NonIntegerTypeException 221 | */ 222 | public function setCacheDuration($cacheDuration) 223 | { 224 | if (is_int($cacheDuration)) { 225 | $this->cacheDuration = $cacheDuration; 226 | return $this; 227 | } else { 228 | throw new NonIntegerTypeException($cacheDuration); 229 | } 230 | } 231 | 232 | /** 233 | * Get cache key prefix 234 | * 235 | * @return string 236 | */ 237 | public function getCacheKeyPrefix() 238 | { 239 | return $this->cacheKeyPrefix; 240 | } 241 | 242 | /** 243 | * Set cache key prefix 244 | * 245 | * @param type $cacheKeyPrefix 246 | * @return \Jelovac\Bitly4laravel\Model 247 | * @throws NonStringTypeException 248 | */ 249 | public function setCacheKeyPrefix($cacheKeyPrefix) 250 | { 251 | if (is_string($cacheKeyPrefix)) { 252 | $this->cacheKeyPrefix = $cacheKeyPrefix; 253 | return $this; 254 | } else { 255 | throw new NonStringTypeException($cacheKeyPrefix); 256 | } 257 | } 258 | 259 | /** 260 | * Get GuzzleHttp Client configuration 261 | * 262 | * @return array 263 | */ 264 | public function getClientConfig() 265 | { 266 | return $this->clientConfig; 267 | } 268 | 269 | /** 270 | * Set GuzzleHttp Client configuration 271 | * 272 | * @param array $clientConfig 273 | * @return \Jelovac\Bitly4laravel\Model 274 | */ 275 | public function setClientConfig(array $clientConfig) 276 | { 277 | $this->clientConfig = $clientConfig; 278 | return $this; 279 | } 280 | 281 | /** 282 | * Get Bitly API response format 283 | * 284 | * @return string 285 | */ 286 | public function getResponseFormat() 287 | { 288 | return $this->responseFormat; 289 | } 290 | 291 | /** 292 | * Set Bitly API response format 293 | * 294 | * @param string $responseFormat 295 | * @return \Jelovac\Bitly4laravel\Model 296 | * @throws NonStringTypeException 297 | */ 298 | public function setResponseFormat($responseFormat) 299 | { 300 | if (is_string($responseFormat)) { 301 | $this->responseFormat = $responseFormat; 302 | return $this; 303 | } else { 304 | throw new NonStringTypeException($responseFormat); 305 | } 306 | } 307 | 308 | /** 309 | * Get GuzzleHttp Client request options 310 | * 311 | * @return array 312 | */ 313 | public function getRequestOptions() 314 | { 315 | return $this->requestOptions; 316 | } 317 | 318 | /** 319 | * Set GuzzleHttp Client request options 320 | * 321 | * @param array $requestOptions 322 | * @return \Jelovac\Bitly4laravel\Model 323 | */ 324 | public function setRequestOptions(array $requestOptions) 325 | { 326 | $this->requestOptions = $requestOptions; 327 | return $this; 328 | } 329 | 330 | /** 331 | * Get request param 332 | * 333 | * @param mixed $key 334 | * @return mixed 335 | * @throws OutOfRangeException 336 | */ 337 | public function getRequestParam($key) 338 | { 339 | if (array_key_exists($key, $this->requestParams)) { 340 | return $this->requestParams[$key]; 341 | } else { 342 | throw new OutOfRangeException("Provided array key is out of range."); 343 | } 344 | } 345 | 346 | /** 347 | * Set request param 348 | * 349 | * @param type $key 350 | * @param type $value 351 | * @return \Jelovac\Bitly4laravel\Model 352 | */ 353 | public function setRequestParam($key, $value) 354 | { 355 | $this->requestParams[$key] = $value; 356 | return $this; 357 | } 358 | 359 | /** 360 | * Get request params 361 | * 362 | * @return array 363 | */ 364 | public function getRequestParams() 365 | { 366 | return $this->requestParams; 367 | } 368 | 369 | /** 370 | * Set request params 371 | * 372 | * @param array $requestParams 373 | * @return \Jelovac\Bitly4laravel\Model 374 | */ 375 | public function setRequestParams(array $requestParams) 376 | { 377 | $this->requestParams = $requestParams; 378 | return $this; 379 | } 380 | 381 | /** 382 | * Get GuzzleHttp Client request type 383 | * 384 | * @return string 385 | */ 386 | public function getRequestType() 387 | { 388 | return $this->requestType; 389 | } 390 | 391 | /** 392 | * Set GuzzleHttp Client request type 393 | * 394 | * @param string $requestType 395 | * @return \Jelovac\Bitly4laravel\Model 396 | * @throws NonStringTypeException 397 | */ 398 | public function setRequestType($requestType) 399 | { 400 | if (is_string($requestType)) { 401 | $this->requestType = $requestType; 402 | return $this; 403 | } else { 404 | throw new NonStringTypeException($requestType); 405 | } 406 | } 407 | 408 | } 409 | -------------------------------------------------------------------------------- /src/config/config.php: -------------------------------------------------------------------------------- 1 | null, 8 | "cache_enabled" => false, 9 | "cache_duration" => 3600, // Duration in minutes 10 | "cache_key_prefix" => "Bitly4Laravel.", 11 | "response_format" => "json", // json, xml 12 | "request_type" => "get", // get, post 13 | "request_options" => array(), 14 | "client_config" => array(), 15 | ); 16 | -------------------------------------------------------------------------------- /tests/Bitly4laravelTest.php: -------------------------------------------------------------------------------- 1 | assertTrue($condition); 15 | } 16 | 17 | /** 18 | * Tests if provided hash string is not valid URL 19 | */ 20 | public function testProvidedHashStringIsNotValidUrl() 21 | { 22 | $condition = filter_var('1nnxQND', FILTER_VALIDATE_URL) !== false; 23 | $this->assertFalse($condition); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /tests/ModelTest.php: -------------------------------------------------------------------------------- 1 | model = new Model; 16 | } 17 | 18 | /** 19 | * @expectedException \InvalidArgumentException 20 | */ 21 | public function testSetConfigThrowsInvalidArgumentException() 22 | { 23 | $this->model->setConfig(array( 24 | 'invalid_key' => 1, 25 | )); 26 | } 27 | 28 | public function testSetAccessTokenSuccess() 29 | { 30 | $this->model->setAccessToken("1"); 31 | $this->assertEquals("1", $this->model->getAccessToken()); 32 | } 33 | 34 | /** 35 | * @expectedException \Jelovac\Bitly4laravel\Exceptions\NonStringTypeException 36 | */ 37 | public function testSetAccessTokenThrowsNonStringTypeException() 38 | { 39 | $this->model->setAccessToken(1); 40 | } 41 | 42 | public function testGetRequestParamSuccess() 43 | { 44 | $requestParam = "https://github.com/jelovac/bitly4laravel"; 45 | $this->model->setRequestParam('longUrl', $requestParam); 46 | $this->assertEquals($requestParam, $this->model->getRequestParam('longUrl')); 47 | } 48 | 49 | /** 50 | * @expectedException \OutOfRangeException 51 | */ 52 | public function testGetRequestParamThrowsOutOfRangeException() 53 | { 54 | $model = new Model; 55 | $model->getRequestParam('longUrl'); 56 | } 57 | 58 | } 59 | --------------------------------------------------------------------------------