├── .gitattributes
├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── composer.json
├── src
└── getjump
│ └── Vk
│ ├── Auth.php
│ ├── BatchTransaction.php
│ ├── Constants
│ ├── Error.php
│ ├── LongPolling.php
│ ├── Permissions.php
│ └── UserFields.php
│ ├── Core.php
│ ├── Exception
│ └── Error.php
│ ├── Model
│ ├── BaseModel.php
│ ├── Photos
│ │ ├── UploadResponse.php
│ │ └── UploadUrl.php
│ ├── Status.php
│ ├── StatusAudio.php
│ ├── User.php
│ └── Wall.php
│ ├── RequestTransaction.php
│ ├── Response
│ ├── Api.php
│ ├── Auth.php
│ ├── Error.php
│ └── Response.php
│ ├── VkJs.php
│ └── Wrapper
│ ├── Account.php
│ ├── BaseWrapper.php
│ ├── Friends.php
│ ├── LongPoll.php
│ ├── Photos.php
│ └── User.php
└── tests
├── CoreTest.php
├── ExtendedTest.php
├── UserTest.php
└── VersionTest.php
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## Eclipse
3 | #################
4 |
5 | *.pydevproject
6 | .project
7 | .metadata
8 | bin/
9 | tmp/
10 | *.tmp
11 | *.bak
12 | *.swp
13 | *~.nib
14 | local.properties
15 | .classpath
16 | .settings/
17 | .loadpath
18 |
19 | # External tool builders
20 | .externalToolBuilders/
21 |
22 | # Locally stored "Eclipse launch configurations"
23 | *.launch
24 |
25 | # CDT-specific
26 | .cproject
27 |
28 | # PDT-specific
29 | .buildpath
30 |
31 | #################
32 | ## PHPStorm
33 | #################
34 | .idea
35 | .idea/*
36 |
37 | #################
38 | ## Visual Studio
39 | #################
40 |
41 | ## Ignore Visual Studio temporary files, build results, and
42 | ## files generated by popular Visual Studio add-ons.
43 |
44 | # User-specific files
45 | *.suo
46 | *.user
47 | *.sln.docstates
48 |
49 | # Build results
50 |
51 | [Dd]ebug/
52 | [Rr]elease/
53 | x64/
54 | build/
55 | [Bb]in/
56 | [Oo]bj/
57 |
58 | # MSTest test Results
59 | [Tt]est[Rr]esult*/
60 | [Bb]uild[Ll]og.*
61 |
62 | *_i.c
63 | *_p.c
64 | *.ilk
65 | *.meta
66 | *.obj
67 | *.pch
68 | *.pdb
69 | *.pgc
70 | *.pgd
71 | *.rsp
72 | *.sbr
73 | *.tlb
74 | *.tli
75 | *.tlh
76 | *.tmp
77 | *.tmp_proj
78 | *.log
79 | *.vspscc
80 | *.vssscc
81 | .builds
82 | *.pidb
83 | *.log
84 | *.scc
85 |
86 | # Visual C++ cache files
87 | ipch/
88 | *.aps
89 | *.ncb
90 | *.opensdf
91 | *.sdf
92 | *.cachefile
93 |
94 | # Visual Studio profiler
95 | *.psess
96 | *.vsp
97 | *.vspx
98 |
99 | # Guidance Automation Toolkit
100 | *.gpState
101 |
102 | # ReSharper is a .NET coding add-in
103 | _ReSharper*/
104 | *.[Rr]e[Ss]harper
105 |
106 | # TeamCity is a build add-in
107 | _TeamCity*
108 |
109 | # DotCover is a Code Coverage Tool
110 | *.dotCover
111 |
112 | # NCrunch
113 | *.ncrunch*
114 | .*crunch*.local.xml
115 |
116 | # Installshield output folder
117 | [Ee]xpress/
118 |
119 | # DocProject is a documentation generator add-in
120 | DocProject/buildhelp/
121 | DocProject/Help/*.HxT
122 | DocProject/Help/*.HxC
123 | DocProject/Help/*.hhc
124 | DocProject/Help/*.hhk
125 | DocProject/Help/*.hhp
126 | DocProject/Help/Html2
127 | DocProject/Help/html
128 |
129 | # Click-Once directory
130 | publish/
131 |
132 | # Publish Web Output
133 | *.Publish.xml
134 | *.pubxml
135 |
136 | # NuGet Packages Directory
137 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
138 | #packages/
139 |
140 | # Windows Azure Build Output
141 | csx
142 | *.build.csdef
143 |
144 | # Windows Store app package directory
145 | AppPackages/
146 |
147 | # Others
148 | sql/
149 | *.Cache
150 | ClientBin/
151 | [Ss]tyle[Cc]op.*
152 | ~$*
153 | *~
154 | *.dbmdl
155 | *.[Pp]ublish.xml
156 | *.pfx
157 | *.publishsettings
158 |
159 | # RIA/Silverlight projects
160 | Generated_Code/
161 |
162 | # Backup & report files from converting an old project file to a newer
163 | # Visual Studio version. Backup files are not needed, because we have git ;-)
164 | _UpgradeReport_Files/
165 | Backup*/
166 | UpgradeLog*.XML
167 | UpgradeLog*.htm
168 |
169 | # SQL Server files
170 | App_Data/*.mdf
171 | App_Data/*.ldf
172 |
173 | #############
174 | ## Windows detritus
175 | #############
176 |
177 | # Windows image file caches
178 | Thumbs.db
179 | ehthumbs.db
180 |
181 | # Folder config file
182 | Desktop.ini
183 |
184 | # Recycle Bin used on file shares
185 | $RECYCLE.BIN/
186 |
187 | # Mac crap
188 | .DS_Store
189 |
190 |
191 | #############
192 | ## Python
193 | #############
194 |
195 | *.py[co]
196 |
197 | # Packages
198 | *.egg
199 | *.egg-info
200 | dist/
201 | build/
202 | eggs/
203 | parts/
204 | var/
205 | sdist/
206 | develop-eggs/
207 | .installed.cfg
208 |
209 | # Installer logs
210 | pip-log.txt
211 |
212 | # Unit test / coverage reports
213 | .coverage
214 | .tox
215 |
216 | #Translations
217 | *.mo
218 |
219 | #Mr Developer
220 | .mr.developer.cfg
221 |
222 | #############
223 | ## Composer
224 | #############
225 | composer.phar
226 | composer.lock
227 | /vendor/
228 |
229 | test.php
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | notifications:
2 | email: false
3 |
4 | language: php
5 |
6 | php:
7 | - 5.5
8 | - 5.6
9 | - 7.0
10 | - hhvm
11 | - nightly
12 |
13 | script: phpunit --bootstrap vendor/autoload.php tests
14 |
15 | before_script:
16 | - "composer install --dev --prefer-source --no-interaction"
17 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Pavel S.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Vk API PHP
2 |
3 | [](https://travis-ci.org/getjump/VkApiPHP)
4 | [](https://styleci.io/repos/19418792)
5 |
6 | That library will help you organize your work with API Vk.com
7 |
8 | ## Installation
9 |
10 | You can get library and all of it dependencies through [composer](https://getcomposer.org/)
11 |
12 | `composer require "getjump/vk:*"`
13 |
14 | ## Explanation
15 |
16 | Okay, that is how we can instantiate main object for our future requests
17 |
18 | ```php
19 | $vk = getjump\Vk\Core::getInstance()->apiVersion('5.5')->setToken(>>> HERE YOUR TOKENS GOES <<<);
20 | ```
21 |
22 | >YOU CAN GET SOME TOKENS AT :
23 | >You can get some tokens at:
24 | >http://oauth.vk.com/authorize?client_id=3470411&scope=messages,photos,groups,status,wall,offline&redirect_uri=blank.html&display=page&v=5.5&response_type=token
25 | >I can't steal them, since it's VK side stuff guys, scope means what rights you needed for, i recommend as much as you can, if you don't want problems.
26 | If you wanna use site authorization, look at next snippet:
27 |
28 | ```php
29 | $vk = getjump\Vk\Core::getInstance()->apiVersion('5.5');
30 |
31 | $auth = getjump\Vk\Auth::getInstance();
32 | $auth->setAppId('3470411')->setScope('SCOPE')->setSecret('SECRET CODE')->setRedirectUri('http://localhost/test.php'); // SETTING ENV
33 | $token=$auth->startCallback(); // Here we will have token, if everything okay
34 |
35 | printf("LINK", $auth->getUrl());
36 | if($token) {
37 | $vk->setToken($token);
38 | $vk->request('users.get', ['user_ids' => range(1, 100)])->each(function($i, $v) {
39 | if($v->last_name == '') return;
40 | print $v->last_name . '
';
41 | });
42 | }
43 | ```
44 |
45 | I already did some wrappers just for you, if you wanna more, please do and pull request but you still can don't use them, or use something like this.
46 |
47 | ```php
48 | $vk->request('friends.get', ['user_id' => '15157875'])->each(function($i, $v) {});
49 | ```
50 |
51 | That us long polling shiet, it works like a hell, as fast as you can see.
52 | ```php
53 | // Long pooling loop
54 | $lp = new getjump\Vk\Wrapper\LongPoll($vk);
55 | $lp->doLoop();
56 | ```
57 |
58 | We will do badass stuff, like kiss. You can do like the following and it will works
59 | ```php
60 | //KISS
61 | $user=new getjump\Vk\Wrapper\User(getjump\Vk\Core::getInstance()->apiVersion('5.5'));
62 | $user->get(1, 'photo_max_orig, sex'); //It will contain RequestTransaction, and will wait for your action, like getting response ->response or calling ->each(callback)
63 | //Since __get and __call are overrided, we will request for a data, only when it neeeded
64 | ```
65 |
66 | We can use my own sakhalin technilogies and take all the stuff that VK have for that request using generators
67 | ```php
68 | // Friends gets
69 | $friends = new getjump\Vk\Wrapper\Friends($vk);
70 | foreach($friends->get(15157875, 'first_name, last_name')->batch(100) as $f) //BATCH MEAN $f WILL CONTAIN JUST 100 ELEMENTS, AND REQUEST WILL MADE FOR 100 ELEMENTS
71 | {
72 | /**
73 | * @var $f \getjump\Vk\ApiResponse;
74 | */
75 |
76 | $f->response->each(function($i, $j) {
77 | if(!$j->online) return;
78 | print $j->getName() . '
';
79 | });
80 | }
81 | ```
82 |
83 | But you still can do old style stuff
84 | ```php
85 | //SECOND OPTION TO JUST GET EVERYTHING, WITHOUT count BEING SEND
86 | $friends->get(15157875, 'first_name, last_name')->response->each(function($i, $d) {
87 | if($d->online)
88 | {
89 | print $d->getName() . '
';
90 | }
91 | });
92 | ```
93 |
94 | That snippet will show you your last 200 messages
95 | ```php
96 | //MESSAGES
97 | $data = $vk->request('messages.get', ['count' => 200]);
98 |
99 | $userMap = [];
100 | $userCache = [];
101 |
102 | $user = new \getjump\Vk\Wrapper\User($vk);
103 |
104 | $fetchData = function($id) use($user, &$userMap, &$userCache)
105 | {
106 | if(!isset($userMap[$id]))
107 | {
108 | $userMap[$id] = sizeof($userCache);
109 | $userCache[] = $user->get($id)->response->get();
110 | }
111 |
112 | return $userCache[$userMap[$id]];
113 | };
114 |
115 | //REQUEST WILL ISSUE JUST HERE! SINCE __get overrided
116 | $data->each(function($key, $value) use($fetchData) {
117 | $user = $fetchData($value->user_id);
118 | printf("[%s] %s
", $user->getName(), $value->body);
119 | return;
120 | });
121 | ```
122 |
123 | Once more black magic. VK has method called execute, that can take something like JS code. Look what i've done for that.
124 | ```php
125 | $js1 = $vk->request('messages.get', ['count' => 200, 'offset' =>0 * 200])->toJs(); //IT WILL RETURN VkJs object
126 | $js2 = $vk->request('messages.get', ['count' => 200, 'offset' =>1 * 200])->toJs();
127 | $js3 = $vk->request('messages.get', ['count' => 200, 'offset' =>2 * 200])->toJs();
128 | $js4 = $vk->request('messages.get', ['count' => 200, 'offset' =>3 * 200])->toJs();
129 |
130 |
131 | $js1
132 | ->append($js2) // WE ARE APPENDING js2 to js1
133 | ->append($js3)
134 | ->append($js4)
135 | ->execute() // WE WANT EXECUTE THIS (actually it will return RequestTransaction)
136 | ->response //AS FOR NOW WE REALLY DO SOME REQUEST TO API
137 | ->each(
138 | function($i, $v) //FIRST CALLBACK IS NEEDED TO GO FOR EVERY PART OF RESPONSE, ARRAY WITH 4-ELS IN OUR CASE
139 | {
140 | $v->each(function($c, $d) { // SECOND TO CHECK EVERY ELEMENTS IN ARRAY WITH 200 ELEMENTS
141 | if(isset($d->body)) print $d->body; //WE JUST OUTPUTTING MESSAGE IF IT SET
142 | });
143 | });
144 |
145 | ```
146 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "getjump/vk",
3 | "description": "Library for work with API Vk.com",
4 | "keywords": ["php", "vk", "api", "library", "vkontakte"],
5 | "license": "MIT",
6 | "authors": [
7 | {
8 | "name" : "Pavel S.",
9 | "email" : "contact@getjump.me"
10 | }
11 | ],
12 | "require": {
13 | "guzzlehttp/guzzle": "6.*",
14 | "php": ">=5.5.0"
15 | },
16 | "require-dev": {
17 | "phpunit/phpunit": "4.1.*"
18 | },
19 | "autoload": {
20 | "psr-4": {
21 | "getjump\\Vk\\": "src/getjump/Vk/"
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Auth.php:
--------------------------------------------------------------------------------
1 | options = $options;
26 | }
27 | $this->options['response_type'] = 'code';
28 | }
29 |
30 | /**
31 | * @return string
32 | */
33 | public function getAppId()
34 | {
35 | return $this->options['client_id'];
36 | }
37 |
38 | /**
39 | * @param string $id
40 | *
41 | * @return $this
42 | */
43 | public function setAppId($id)
44 | {
45 | $this->options['client_id'] = $id;
46 |
47 | return $this;
48 | }
49 |
50 | /**
51 | * @return string
52 | */
53 | public function getSecret()
54 | {
55 | return $this->options['client_secret'];
56 | }
57 |
58 | /**
59 | * @param string $secret
60 | *
61 | * @return $this
62 | */
63 | public function setSecret($secret)
64 | {
65 | $this->options['client_secret'] = $secret;
66 |
67 | return $this;
68 | }
69 |
70 | /**
71 | * @return string
72 | */
73 | public function getRedirectUri()
74 | {
75 | return $this->options['redirect_uri'];
76 | }
77 |
78 | /**
79 | * @param string $uri
80 | *
81 | * @return $this
82 | */
83 | public function setRedirectUri($uri)
84 | {
85 | $this->options['redirect_uri'] = $uri;
86 |
87 | return $this;
88 | }
89 |
90 | /**
91 | * @param $scope
92 | *
93 | * @return $this
94 | */
95 | public function setScope($scope)
96 | {
97 | $this->options['scope'] = $scope;
98 |
99 | return $this;
100 | }
101 |
102 | /**
103 | * @param $v
104 | *
105 | * @return $this
106 | */
107 | public function setVersion($v)
108 | {
109 | $this->options['v'] = $v;
110 |
111 | return $this;
112 | }
113 |
114 | /**
115 | * @return string
116 | */
117 | public function getUrl()
118 | {
119 | return sprintf('https://oauth.vk.com/authorize?%s', http_build_query($this->options));
120 | }
121 |
122 | /**
123 | * Just an alias, for an array.
124 | *
125 | * @param $d
126 | *
127 | * @return mixed
128 | */
129 | public function g($d)
130 | {
131 | return $this->options[$d];
132 | }
133 |
134 | /**
135 | * Will return token if everything is OK.
136 | *
137 | * @return \getjump\Vk\Response\Auth|bool|string
138 | */
139 | public function startCallback()
140 | {
141 | if (isset($_GET['code'])) {
142 | $token = $this->getToken($_GET['code']);
143 |
144 | return $token;
145 | } elseif (isset($_GET['error'])) {
146 | //blah blah
147 | }
148 |
149 | return false;
150 | }
151 |
152 | /**
153 | * Method converts code to token.
154 | *
155 | * @param $code
156 | *
157 | * @return \getjump\Vk\Response\Auth|bool
158 | */
159 | public function getToken($code)
160 | {
161 | if (!$this->guzzle) {
162 | $this->guzzle = new \GuzzleHttp\Client();
163 | }
164 |
165 | $uri = sprintf(
166 | self::URL_ACCESS_TOKEN,
167 | $this->g('client_id'),
168 | $this->g('client_secret'),
169 | $code,
170 | urlencode($this->g('redirect_uri'))
171 | );
172 |
173 | $data = $this->guzzle->get($uri)->getBody();
174 | $data = json_decode($data);
175 |
176 | if (isset($data->access_token)) {
177 | return new \getjump\Vk\Response\Auth($data->access_token, $data->expires_in, $data->user_id);
178 | } elseif (isset($data->error)) {
179 | // ERROR PROCESSING
180 | }
181 |
182 | return false;
183 | }
184 |
185 | /**
186 | * @return Auth
187 | */
188 | public static function getInstance()
189 | {
190 | return new self();
191 | }
192 | }
193 |
--------------------------------------------------------------------------------
/src/getjump/Vk/BatchTransaction.php:
--------------------------------------------------------------------------------
1 | transaction = $transaction;
21 | $this->position = 0;
22 | $this->count = $count;
23 | }
24 |
25 | /**
26 | * (PHP 5 >= 5.0.0)
27 | * Return the current element.
28 | *
29 | * @link http://php.net/manual/en/iterator.current.php
30 | *
31 | * @return Api
32 | */
33 | public function current()
34 | {
35 | $this->transaction->incrementOffset($this->position * $this->count);
36 | $d = $this->transaction->fetchData();
37 | $count = count($d->response->items);
38 | $this->eof = $count > 0 && $count >= $this->count ? false : true;
39 |
40 | return $d;
41 | }
42 |
43 | /**
44 | * (PHP 5 >= 5.0.0)
45 | * Move forward to next element.
46 | *
47 | * @link http://php.net/manual/en/iterator.next.php
48 | *
49 | * @return void Any returned value is ignored.
50 | */
51 | public function next()
52 | {
53 | $this->position++;
54 | }
55 |
56 | /**
57 | * (PHP 5 >= 5.0.0)
58 | * Return the key of the current element.
59 | *
60 | * @link http://php.net/manual/en/iterator.key.php
61 | *
62 | * @return mixed scalar on success, or null on failure.
63 | */
64 | public function key()
65 | {
66 | return $this->position;
67 | }
68 |
69 | /**
70 | * (PHP 5 >= 5.0.0)
71 | * Checks if current position is valid.
72 | *
73 | * @link http://php.net/manual/en/iterator.valid.php
74 | *
75 | * @return bool The return value will be casted to boolean and then evaluated.
76 | * Returns true on success or false on failure.
77 | */
78 | public function valid()
79 | {
80 | return !$this->eof;
81 | }
82 |
83 | /**
84 | * (PHP 5 >= 5.0.0)
85 | * Rewind the Iterator to the first element.
86 | *
87 | * @link http://php.net/manual/en/iterator.rewind.php
88 | *
89 | * @return void Any returned value is ignored.
90 | */
91 | public function rewind()
92 | {
93 | $this->position = 0;
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Constants/Error.php:
--------------------------------------------------------------------------------
1 | params[$key] = $value;
76 |
77 | return $this;
78 | }
79 |
80 | /**
81 | * Set many params.
82 | *
83 | * @param array $data
84 | *
85 | * @return $this
86 | */
87 | public function params(array $data)
88 | {
89 | foreach ($data as $k => $v) {
90 | $this->param($k, $v);
91 | }
92 |
93 | return $this;
94 | }
95 |
96 | /**
97 | * Will set callback for element creation.
98 | *
99 | * @param Closure $callback
100 | *
101 | * @return $this
102 | */
103 | public function createAs(Closure $callback)
104 | {
105 | $this->callback = $callback;
106 |
107 | return $this;
108 | }
109 |
110 | /**
111 | * API Request, will return RequestTransaction.
112 | *
113 | * @param string $methodName
114 | * @param bool|array $args
115 | *
116 | * @return Api|RequestTransaction
117 | */
118 | public function request($methodName, $args = false)
119 | {
120 | if (is_array($args)) {
121 | $this->params($args);
122 | }
123 |
124 | $this->params = array_merge($this->params, $this->systemArgs());
125 |
126 | $d = new RequestTransaction($methodName, $this->params, $this->accessToken, $this->callback, $this->noHttpsSecret);
127 | $this->reset();
128 |
129 | return $d;
130 | }
131 |
132 | /**
133 | * Clear current params.
134 | */
135 | public function reset()
136 | {
137 | $this->params = [];
138 | }
139 |
140 | /**
141 | * Set necessary arguments.
142 | *
143 | * @return array
144 | */
145 | private function systemArgs()
146 | {
147 | $array = [];
148 |
149 | if ($this->lang) {
150 | $array['lang'] = $array;
151 | }
152 | if ($this->version) {
153 | $array['v'] = $this->version;
154 | }
155 |
156 | return $array;
157 | }
158 |
159 | /**
160 | * Set's token.
161 | *
162 | * @param string $accessToken
163 | *
164 | * @return $this
165 | */
166 | public function setToken($accessToken)
167 | {
168 | $this->accessToken = $accessToken;
169 |
170 | return $this;
171 | }
172 |
173 | /**
174 | * Sets nohttps secret.
175 | *
176 | * @param string $noHttpsSecret
177 | *
178 | * @return $this
179 | */
180 | public function setNoHttpsSecret($noHttpsSecret)
181 | {
182 | $this->noHttpsSecret = $noHttpsSecret;
183 |
184 | return $this;
185 | }
186 |
187 | public function setLang($lang)
188 | {
189 | $this->lang = $lang;
190 |
191 | return $this;
192 | }
193 |
194 | /**
195 | * Set's api version.
196 | *
197 | * @param string $version
198 | *
199 | * @return $this
200 | */
201 | public function apiVersion($version)
202 | {
203 | $this->version = $version;
204 |
205 | return $this;
206 | }
207 |
208 | /**
209 | * @var Core
210 | */
211 | public static $instance;
212 |
213 | /**
214 | * We want same instance.
215 | *
216 | * @return Core
217 | */
218 | public static function getInstance()
219 | {
220 | if (self::$instance === null) {
221 | self::$instance = new self();
222 | }
223 |
224 | return self::$instance;
225 | }
226 | }
227 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Exception/Error.php:
--------------------------------------------------------------------------------
1 | error = $e;
22 | $this->message = $message;
23 | $this->code = $code;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Model/BaseModel.php:
--------------------------------------------------------------------------------
1 | data = $data;
31 | }
32 |
33 | /**
34 | * We are overriding get, so data will pulling from data array.
35 | *
36 | * @param string $name
37 | *
38 | * @return bool
39 | */
40 | public function __get($name)
41 | {
42 | return isset($this->data->$name) ? $this->data->$name : false;
43 | }
44 |
45 | /**
46 | * We are overriding set, so data will writing to data array.
47 | *
48 | * @param string $name
49 | * @param mixed $value
50 | */
51 | public function __set($name, $value)
52 | {
53 | $this->data->$name = $value;
54 | }
55 |
56 | /**
57 | * We are overriding isset, so data will querying in data array.
58 | *
59 | * @param string $name
60 | *
61 | * @return bool
62 | */
63 | public function __isset($name)
64 | {
65 | return isset($this->data->$name);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Model/Photos/UploadResponse.php:
--------------------------------------------------------------------------------
1 | text;
19 | }
20 |
21 | /**
22 | * Get current audio that user is listening for.
23 | *
24 | * @return bool|StatusAudio
25 | */
26 | public function getAudio()
27 | {
28 | if ($this->audio !== false) {
29 | return new StatusAudio($this->audio);
30 | }
31 |
32 | return false;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Model/StatusAudio.php:
--------------------------------------------------------------------------------
1 | url;
19 | }
20 |
21 | /**
22 | * Return song artist concatenated with name using '-'.
23 | *
24 | * @return string
25 | */
26 | public function getName()
27 | {
28 | return $this->artist.' - '.$this->title;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Model/User.php:
--------------------------------------------------------------------------------
1 | first_name.' '.$this->last_name;
19 | }
20 |
21 | /**
22 | * Return users status.
23 | *
24 | * @return Status
25 | */
26 | public function getStatus()
27 | {
28 | return new Status($this->status);
29 | }
30 |
31 | /**
32 | * Return user mobile phone.
33 | *
34 | * @return string|bool
35 | */
36 | public function getMobile()
37 | {
38 | return $this->mobile_phone;
39 | }
40 |
41 | /**
42 | * Return user home phone.
43 | *
44 | * @return string|bool
45 | */
46 | public function getPhone()
47 | {
48 | return $this->home_phone;
49 | }
50 |
51 | /**
52 | * Return true if user has mobile.
53 | *
54 | * @return bool
55 | */
56 | public function hasMobile()
57 | {
58 | return $this->has_mobile;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Model/Wall.php:
--------------------------------------------------------------------------------
1 | id;
19 | }
20 |
21 | /**
22 | * Return true if this is repost.
23 | *
24 | * @return bool
25 | */
26 | public function isRepost()
27 | {
28 | return $this->copy_history !== false;
29 | }
30 |
31 | /**
32 | * Return recursive wall instance.
33 | *
34 | * @param int $id
35 | *
36 | * @return bool|Wall
37 | */
38 | public function getSource($id = 0)
39 | {
40 | if ($this->copy_history === false) {
41 | return false;
42 | }
43 | if (!isset($this->copy_history[$id])) {
44 | return false;
45 | }
46 |
47 | return new self($this->copy_history[0 + $id]);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/getjump/Vk/RequestTransaction.php:
--------------------------------------------------------------------------------
1 | methodName = $methodName;
80 | $this->args = $args;
81 | $this->accessToken = $accessToken;
82 | $this->callback = $callback;
83 | $this->noHttpsSecret = $noHttpsSecret;
84 | }
85 |
86 | /**
87 | * Batch method, for pulling just $count data at a time with foreach loop.
88 | *
89 | * @param int $count
90 | *
91 | * @return BatchTransaction
92 | */
93 | public function batch($count = 10)
94 | {
95 | $this->args['count'] = $count;
96 | $this->args['offset'] = 0;
97 |
98 | return new BatchTransaction($this, $count);
99 | }
100 |
101 | public function incrementOffset($offset = 0)
102 | {
103 | isset($this->args['offset']) ? $this->args['offset'] += $offset : $this->args['offset'] = 0;
104 | }
105 |
106 | /**
107 | * We are overriding get, so when we will try to access response, our data will get from a server.
108 | *
109 | * @param string $name
110 | *
111 | * @return bool
112 | */
113 | public function __get($name)
114 | {
115 | if (!$this->init) {
116 | return $this->fetchData()->$name;
117 | }
118 |
119 | return false;
120 | }
121 |
122 | /**
123 | * We are overriding call, so when we will call to each, our data will get from a server.
124 | *
125 | * @param string $name
126 | * @param array $arguments
127 | *
128 | * @return bool|mixed
129 | */
130 | public function __call($name, array $arguments)
131 | {
132 | if (!$this->init) {
133 | return call_user_func_array([$this->fetchData(), $name], $arguments);
134 | }
135 |
136 | return false;
137 | }
138 |
139 | /**
140 | * Querying API for a data.
141 | *
142 | * @return Api
143 | */
144 | public function fetchData()
145 | {
146 | if (!$this->guzzle) {
147 | $this->guzzle = new \GuzzleHttp\Client();
148 | }
149 |
150 | $args = $this->args;
151 | if ($this->accessToken) {
152 | $args['access_token'] = $this->accessToken;
153 | }
154 |
155 | if ((empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off') && false !== $this->noHttpsSecret) {
156 | $args['sig'] = md5('/method/'.$this->methodName.'?'.http_build_query($args).$this->noHttpsSecret);
157 | }
158 |
159 | $data = $this->guzzle->post(self::URL_VK_API . $this->methodName, ['form_params' => $args])->getBody();
160 | $data = json_decode($data);
161 | $c = new Api($data, $this->callback);
162 |
163 | return $c;
164 | }
165 |
166 | /**
167 | * We want just execute, without getting any data.
168 | */
169 | public function execute()
170 | {
171 | $this->fetchData();
172 | }
173 |
174 | /**
175 | * Will return VkJs object.
176 | *
177 | * @return VkJs
178 | */
179 | public function toJs()
180 | {
181 | return new VkJs(Core::getInstance(), $this->methodName, $this->args);
182 | }
183 | }
184 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Response/Api.php:
--------------------------------------------------------------------------------
1 | response = !isset($data->response) ? false : new Response($data->response, $callback);
26 | $this->error = !isset($data->error) ? false : new Error($data->error);
27 | }
28 |
29 | /**
30 | * Execute callable on every element of array.
31 | *
32 | * @param bool|callable $callback
33 | */
34 | public function each($callback = false)
35 | {
36 | $this->response->each($callback);
37 | }
38 |
39 | /**
40 | * Try to get one element.
41 | *
42 | * @return mixed
43 | */
44 | public function one()
45 | {
46 | return $this->response->one();
47 | }
48 |
49 | /**
50 | * Magic method for calling functions on api response.
51 | *
52 | * @param $name
53 | * @param $arguments
54 | *
55 | * @return mixed
56 | */
57 | public function __call($name, $arguments)
58 | {
59 | return call_user_func_array([$this->response, $name], $arguments);
60 | }
61 |
62 | /**
63 | * Magic method for accessing api response.
64 | *
65 | * @param $name
66 | *
67 | * @return bool
68 | */
69 | public function __get($name)
70 | {
71 | return $this->response->{$name};
72 | }
73 |
74 | /**
75 | * Return ApiResponse.
76 | *
77 | * @return array|bool
78 | */
79 | public function getResponse()
80 | {
81 | return $this->response->getResponse();
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Response/Auth.php:
--------------------------------------------------------------------------------
1 | token = $token;
14 | $this->expiresIn = $expiresIn;
15 | $this->userId = $userId;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Response/Error.php:
--------------------------------------------------------------------------------
1 | $v) {
44 | $this->{$k} = $v;
45 | }
46 | throw new Exception\Error($error->error_msg, $error->error_code, $this);
47 | }
48 |
49 | /**
50 | * @return mixed
51 | */
52 | public function getCode()
53 | {
54 | return $this->error_code;
55 | }
56 |
57 | /**
58 | * @return mixed
59 | */
60 | public function getMessage()
61 | {
62 | return $this->error_msg;
63 | }
64 |
65 | /**
66 | * @return array
67 | */
68 | public function getRequestParams()
69 | {
70 | return $this->request_params;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Response/Response.php:
--------------------------------------------------------------------------------
1 | $value) {
42 | if (property_exists($this, $key)) {
43 | continue;
44 | }
45 |
46 | $this->{$key} = $value;
47 | $this->extendedFields[] = $key;
48 | }
49 |
50 | if (is_callable($callback) && isset($data->items)) {
51 | foreach ($data->items as $d) {
52 | $this->items[] = call_user_func_array($callback, [$d]);
53 | }
54 | } else {
55 | $this->items = !isset($data->items) ? false : $data->items;
56 | }
57 | $this->count = !isset($data->count) ? false : $data->count;
58 | if (is_array($data) || !isset($data->items)) {
59 | $this->count = count($data);
60 | if (is_array($data) && is_callable($callback)) {
61 | foreach ($data as $d) {
62 | $this->data[] = call_user_func_array($callback, [$d]);
63 | }
64 | } else {
65 | $this->data = $data;
66 | }
67 | }
68 |
69 | // TODO: Avoid hack
70 | if ($this->data) {
71 | $this->items = &$this->data;
72 | }
73 | if ($this->items) {
74 | $this->data = &$this->items;
75 | }
76 |
77 | if (is_object($data) && is_callable($callback)) {
78 | $this->data = call_user_func_array($callback, [$data]);
79 | }
80 | }
81 |
82 | /**
83 | * This method takes Closure as argument, so every element from response will go into this Closure.
84 | *
85 | * @param Closure $callback
86 | */
87 | public function each(Closure $callback)
88 | {
89 | if (!is_callable($callback)) {
90 | return;
91 | }
92 | $data = [];
93 | $this->items ? $data = &$this->items : (!$this->data ?: $data = &$this->data);
94 | foreach ($data as $k => $v) {
95 | call_user_func_array($callback, [$k, $v]);
96 | }
97 | }
98 |
99 | /**
100 | * This method will return one element if id is not specified or element of array otherwise.
101 | *
102 | * @param bool|int $id
103 | *
104 | * @return mixed
105 | */
106 | public function get($id = false)
107 | {
108 | if (!$id) {
109 | if (is_array($this->data)) {
110 | return $this->data[0];
111 | } elseif (isset($this->items) && $this->items !== false) {
112 | return $this->items[0];
113 | } else {
114 | return $this->data;
115 | }
116 | } else {
117 | return $this->data[$id];
118 | }
119 | }
120 |
121 | public function extended()
122 | {
123 | $temp = [];
124 |
125 | foreach ($this->extendedFields as $key) {
126 | $temp[$key] = $this->{$key};
127 | }
128 |
129 | return (object) $temp;
130 | }
131 |
132 | /**
133 | * This magic method try to return field from response.
134 | *
135 | * @param $name
136 | *
137 | * @return bool
138 | */
139 | public function __get($name)
140 | {
141 | if (!is_array($this->data)) {
142 | return $this->data->{$name};
143 | } elseif (count($this->data) == 0 && is_object($this->data[0])) {
144 | return $this->data[0]->{$name};
145 | }
146 |
147 | return false;
148 | }
149 |
150 | /**
151 | * Just wrap over Response->get().
152 | *
153 | * @return mixed
154 | */
155 | public function one()
156 | {
157 | return $this->get();
158 | }
159 |
160 | /**
161 | * This method return raw Response->data.
162 | *
163 | * @return array|bool
164 | */
165 | public function getResponse()
166 | {
167 | return $this->data;
168 | }
169 |
170 | public function offsetExists($offset)
171 | {
172 | return isset($this->items[$offset]);
173 | }
174 |
175 | public function offsetGet($offset)
176 | {
177 | return $this->items[$offset];
178 | }
179 |
180 | public function offsetSet($offset, $value)
181 | {
182 | $this->itmes[$offset] = $value;
183 | }
184 |
185 | public function offsetUnset($offset)
186 | {
187 | unset($this->items[$offset]);
188 | }
189 |
190 | public function count()
191 | {
192 | return count($this->items);
193 | }
194 |
195 | public function rewind()
196 | {
197 | $this->pointer = 0;
198 | }
199 |
200 | public function current()
201 | {
202 | return $this->items[$this->pointer];
203 | }
204 |
205 | public function key()
206 | {
207 | return $this->pointer;
208 | }
209 |
210 | public function next()
211 | {
212 | $this->pointer++;
213 | }
214 |
215 | public function valid()
216 | {
217 | return isset($this[$this->pointer]);
218 | }
219 | }
220 |
--------------------------------------------------------------------------------
/src/getjump/Vk/VkJs.php:
--------------------------------------------------------------------------------
1 | $v) {
59 | $arg[] = sprintf('"%s" : "%s"', $k, $v);
60 | }
61 | }
62 | if ($vk instanceof Core) {
63 | $this->vk = $vk;
64 | }
65 | $this->dataString = sprintf('API.%s({%s})', $methodName, implode(', ', $arg));
66 | }
67 |
68 | /**
69 | * We wanna send our current VkJs to Vk execute.
70 | *
71 | * @return RequestTransaction|Api
72 | */
73 | public function execute()
74 | {
75 | $execute = $this->dataString;
76 | if ($this->requests) {
77 | foreach ($this->requests as $request) {
78 | $execute .= ','.$request->dataString;
79 | }
80 | $execute = '['.$execute.']';
81 |
82 | if (!$this->callback && !$this->vk->jsCallback) {
83 | $this->vk->jsCallback = true;
84 | $oldCallback = $this->vk->callback;
85 |
86 | $this->callback = function ($data) use (&$oldCallback) {
87 | $std = new stdClass();
88 | $std->response = $data;
89 |
90 | return new Api($std, $oldCallback);
91 | };
92 |
93 | $this->vk->createAs($this->callback);
94 | }
95 | }
96 |
97 | return $this->vk->request('execute', ['code' => sprintf('return %s;', $execute)]);
98 | }
99 |
100 | /**
101 | * Method will append one VkJs object, to another one.
102 | *
103 | * @param VkJs $js
104 | *
105 | * @return $this
106 | */
107 | public function append(VkJs $js)
108 | {
109 | $this->requests[] = $js;
110 |
111 | return $this;
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Wrapper/Account.php:
--------------------------------------------------------------------------------
1 | vk->request('account.getAppPermissions')->response->data;
24 | }
25 |
26 | /**
27 | * Used to validate rights.
28 | *
29 | * @param $permissions
30 | * @param int|array $bitmask
31 | *
32 | * @return int
33 | */
34 | public function validateRights($permissions, $bitmask = 0)
35 | {
36 | $valid = 0;
37 | if (is_array($bitmask)) {
38 | foreach ($bitmask as $bit) {
39 | $valid = $this->validateRights($permissions, $bit);
40 | }
41 | } else {
42 | $valid = $permissions & $bitmask;
43 | }
44 |
45 | return $valid;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Wrapper/BaseWrapper.php:
--------------------------------------------------------------------------------
1 | vk = $vk;
30 | }
31 |
32 | if (!$this->guzzle) {
33 | $this->guzzle = new \GuzzleHttp\Client();
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Wrapper/Friends.php:
--------------------------------------------------------------------------------
1 | vk->param('user_id', $userId)
31 | ->param('fields', $this->fieldsToString($fields), null)
32 | ->param('order', 'hints')
33 | ->createAs(function ($d) {
34 | return new User($d);
35 | })
36 | ->request('friends.get');
37 | }
38 |
39 | /**
40 | * @param $data
41 | *
42 | * @return null|string
43 | *
44 | * @todo Put this to another place (duplicate with User)
45 | */
46 | public function fieldsToString($data)
47 | {
48 | if (!$data) {
49 | return;
50 | }
51 |
52 | return implode(',', $data);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Wrapper/LongPoll.php:
--------------------------------------------------------------------------------
1 | server, $d->key, $d->ts);
30 | }
31 |
32 | /**
33 | * Get connection info for long polling from api.
34 | *
35 | * @return array|bool
36 | */
37 | public function getServerData()
38 | {
39 | return $this->vk->request(self::LONG_POOL_REQUEST_METHOD)->response->getResponse();
40 | }
41 |
42 | /**
43 | * LongPoll loop.
44 | *
45 | * @todo make something other than putting data to STDOUT
46 | */
47 | public function doLoop()
48 | {
49 | $server = $this->getServerData();
50 | $initial = $this->getConnectionInfo($server);
51 |
52 | $user = new User($this->vk);
53 |
54 | $userMap = [];
55 | $userCache = [];
56 |
57 | /*
58 | * @param $id
59 | * @return Model\User
60 | */
61 | $fetchData = function ($id) use ($user, &$userMap, &$userCache) {
62 | if (!isset($userMap[$id])) {
63 | $userMap[$id] = count($userCache);
64 | $userCache[] = $user->get($id)->response->get();
65 | }
66 |
67 | return $userCache[$userMap[$id]];
68 | };
69 |
70 | while ($data = $this->guzzle->get($initial)->json(['object' => true])) {
71 | $server->ts = $data->ts;
72 | $initial = $this->getConnectionInfo($server);
73 |
74 | foreach ($data->updates as $update) {
75 | /*
76 | * @var $user Model\User
77 | */
78 | switch ($update[0]) {
79 | case LP::MESSAGE_ADD:
80 | $user = $fetchData($update[3]);
81 | if ($update[2] & 2) {
82 | continue;
83 | }
84 | printf("New message from %s '%s'\n", $user->getName(), $update[6]);
85 | var_dump($update);
86 | break;
87 | case LP::MESSAGE_WRITE:
88 | $user = $fetchData($update[1]);
89 | printf("User %s writing\n", $user->getName());
90 | break;
91 | case LP::DATA_ADD:
92 | break;
93 | case LP::FRIEND_OFFLINE:
94 | $user = $fetchData($update[1] * -1);
95 | $status = $update[2] == 1 ? 'AFK' : 'Exit';
96 | printf("User %s offline(%s)\n", $user->getName(), $status);
97 | break;
98 | case LP::FRIEND_ONLINE:
99 | $user = $fetchData($update[1] * -1);
100 | printf("User %s online\n", $user->getName());
101 | break;
102 | default:
103 | printf("Unknown event %s {%s}\n", $update[0], implode(',', $update));
104 | break;
105 | }
106 | }
107 | }
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Wrapper/Photos.php:
--------------------------------------------------------------------------------
1 | vk
20 | ->param('album_id', $album)
21 | ->param('group_id', $group)
22 | ->request('photos.getUploadServer')
23 | ->one();
24 | }
25 |
26 | /**
27 | * @return UploadUrl
28 | */
29 | public function getMessagesUploadServer()
30 | {
31 | return $this->vk
32 | ->request('photos.getMessagesUploadServer')
33 | ->one();
34 | }
35 |
36 | /**
37 | * todo Process response.
38 | *
39 | * @param UploadResponse $data
40 | */
41 | public function save($data)
42 | {
43 | $this->vk
44 | ->param('album_id', $data->aid)
45 | ->param('server', $data->server)
46 | ->param('photos_list', $data->photos_list)
47 | ->param('hash', $data->hash)
48 | ->request('photos.save')->execute();
49 | }
50 |
51 | public function saveMessagesPhoto($data)
52 | {
53 | return $this->vk
54 | ->param('photo', $data->photo)
55 | ->param('hash', $data->hash)
56 | ->param('server', $data->server)
57 | ->request('photos.saveMessagesPhoto')->one();
58 | }
59 |
60 | public function uploadAlbum(array $files = [], $album = false, $group = false)
61 | {
62 | if (count($files) > 5 || count($files) == 0) {
63 | // todo Exception
64 | }
65 |
66 | $server = $this->getUploadServer($album, $group);
67 |
68 | $request = $this->guzzle->createRequest('POST', $server->upload_url);
69 | $postBody = $request->getBody();
70 | foreach ($files as $k => $file) {
71 | $postBody->addFile(new PostFile('file'.($k + 1), fopen($file, 'r')));
72 | }
73 | $response = $this->guzzle->send($request);
74 | $this->save($response->json(['object' => 1]));
75 | }
76 |
77 | public function uploadMessages($file)
78 | {
79 | $server = $this->getMessagesUploadServer();
80 | var_dump($server);
81 | $request = $this->guzzle->createRequest('POST', $server->upload_url);
82 | $postBody = $request->getBody();
83 | $postBody->addFile(new PostFile('photo', fopen($file, 'r')));
84 | $response = $this->guzzle->send($request);
85 |
86 | return $this->saveMessagesPhoto($response->json(['object' => 1]));
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/src/getjump/Vk/Wrapper/User.php:
--------------------------------------------------------------------------------
1 | vk->param('user_ids', $userId)
29 | ->param('fields', $this->fieldsToString($fields), null)
30 | ->createAs(function ($d) {
31 | return new \getjump\Vk\Model\User($d);
32 | })
33 | ->request('users.get');
34 | }
35 |
36 | /**
37 | * @param bool|array $data
38 | *
39 | * @return bool|string
40 | */
41 | public function fieldsToString($data = false)
42 | {
43 | if (!is_array($data)) {
44 | return false;
45 | }
46 |
47 | return implode(',', $data);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/tests/CoreTest.php:
--------------------------------------------------------------------------------
1 | apiVersion('5.5')->createAs($x);
11 | $this->assertInstanceOf('\getjump\Vk\Core', $vk);
12 | $rT = $vk->request('users.get', ['user_id' => 1]);
13 | $this->assertInstanceOf('\getjump\Vk\RequestTransaction', $rT);
14 | $js = $rT->toJs();
15 | $this->assertInstanceOf('\getjump\Vk\VkJs', $js);
16 | $this->assertInstanceOf('\getjump\Vk\RequestTransaction', $js->execute());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/tests/ExtendedTest.php:
--------------------------------------------------------------------------------
1 | apiVersion('5.22');
9 |
10 | $object = $vk->request('wall.get', ['owner_id' => 1, 'count' => 1, 'extended' => 1]);
11 |
12 | $extended = $object->response->extended();
13 |
14 | $this->assertEquals($extended->profiles[0]->id, 1);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/tests/UserTest.php:
--------------------------------------------------------------------------------
1 | apiVersion('5.21'));
11 | $obj = $user->get(1, [U::STATUS, 'id'])->response->one();
12 | $this->assertInstanceOf('\getjump\Vk\Model\Status', $obj->getStatus());
13 | $this->assertInstanceOf('\getjump\Vk\Model\User', $obj);
14 | $this->assertEquals(1, $obj->id);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/tests/VersionTest.php:
--------------------------------------------------------------------------------
1 | apiVersion('5.27');
9 | $v1 = $v2 = false;
10 | try {
11 | $vk->request('users.get', ['user_id' => 'test'])->one();
12 | } catch (\getjump\Vk\Exception\Error $e) {
13 | foreach ($e->error->request_params as &$p) {
14 | if ($p->key == 'v') {
15 | $v1 = $p->value;
16 | break;
17 | }
18 | }
19 | $this->assertEquals(100, $e->getCode());
20 | }
21 | try {
22 | $obj2 = $vk->request('users.get', ['user_id' => 'test'])->one();
23 | } catch (\getjump\Vk\Exception\Error $e) {
24 | foreach ($e->error->request_params as &$p) {
25 | if ($p->key == 'v') {
26 | $v2 = $p->value;
27 | break;
28 | }
29 | }
30 | $this->assertEquals(100, $e->getCode(), 'Error code doesn\'t equal');
31 | $this->assertEquals('5.27', $v1);
32 | $this->assertEquals('5.27', $v2);
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------