Tuesday 15 July 2014

php - sending issue to bitbucket using oauth via bitbucket api -



php - sending issue to bitbucket using oauth via bitbucket api -

i have read related question; request oauth token bitbucket

in question above , uses curl . there must way gentlero-api because has php class in oauth.

$bb_user = 'myuser_name'; $bb_pass = 'mypasss'; $account_name = 'account_name'; $repo_slug = 'repo_name'; $issue = new issues(); $issue->setcredentials( new basic($bb_user, $bb_pass) ); // iwanna like. how?? // $issue->setcredentials( new oauth($key, $secret) ); $issue->create($account_name, $repo_slug, array( 'title' => 'konu', 'content' => 'içerik metin 123123', 'kind' => 'proposal', 'priority' => 'blocker' ));

i want oauth simple but. coudnt find resouce.

edit:

//i did basic auth this. https://github.com/gentlero/bitbucket-api/blob/master/docs/repositories/issues.md

//prepare $issue = new bitbucket\api\repositories\issues(); $issue->setcredentials( new bitbucket\api\authentication\basic($bb_user, $bb_pass) ); //create new issue $issue->create($account_name, $repo_slug, array( 'title' => 'dummy title', 'content' => 'dummy content', 'kind' => 'proposal', 'priority' => 'blocker' ));

and there too; code oauth.

// oauth 1-legged illustration // can create new consumer at: account/user/<username or team>/api $oauth_params = array( 'oauth_consumer_key' => 'aaa', 'oauth_consumer_secret' => 'bbb' ); $user = new bitbucket\api\user; $user->getclient()->addlistener( new bitbucket\api\http\listener\oauthlistener($oauth_params) ); // can access protected endpoints consumer owner $response = $user->get();

what want copying user's auth , giving auth issue, this.

$credss = $user->getcredenditals(); $issue->setcredentials( $credss ) ;

edit: yahooooooooooo!! learned form gazaret reply do. here working code of mine

public function createissue() { $account_name = 'companyy'; $repo_slug = 'issuer'; $oauth_params = array( 'oauth_consumer_key' => 'key', 'oauth_consumer_secret' => 'secret' ); $issue = new issues(); //this missing peace of puzzle . 1 single line $issue->getclient()->addlistener( new oauthlistener($oauth_params) ); $issue->create($account_name, $repo_slug, array( 'title' => 'konu o_authlu', 'content' => 'içerik metin 123123', 'kind' => 'proposal', 'priority' => 'blocker' )); return; }

here's how did it. fyi have utilize oauth consumer key & secret personal business relationship , not company account.

protected $bbcompany = 'companyname'; protected $oauth_params = array( 'oauth_consumer_key' => 'key', 'oauth_consumer_secret' => 'secret' ); protected function bitbucketissues() { $issue = new bitbucket\api\repositories\issues(); $issue->getclient()->addlistener( new bitbucket\api\http\listener\oauthlistener($this->oauth_params) ); homecoming $issue; }

you can write new methods start creating new instance of $issue calling bitbucketissues() , making request, e.g.:

public function fetchbitbucketallissues($slug) { $issue = $this->bitbucketissues(); $response = $issue->all($this->bbcompany, $slug); if ($this->checkbitbucketresponse($response)) { homecoming json_decode($response->getcontent()); } else { homecoming null; } }

this method gets issues repo "slug", checks response in separate method. method quite rudimentary job me:

protected function checkbitbucketresponse($response) { $headers = $response->getheaders(); if ($headers[0] == "http/1.1 404 not found") { homecoming false; } elseif ($headers[0] != "http/1.1 200 ok") { throw new internalerrorexception('bad response received bitbucket: ' . $response->getcontent()); } else { homecoming true; } }

php bitbucket bitbucket-api

No comments:

Post a Comment