Exemplo n.º 1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $uri = $input->getArgument("uri");
     $username = $input->getArgument("username");
     $password = $input->getArgument("password");
     $request = $this->client->post("http://" . $uri . "/rest/user/login", array(), ["login" => $username, "password" => $password]);
     $response = $request->send();
     if ($response->getStatusCode() == 200) {
         echo "Successfully logged in.\n";
         $jar = new FileCookieJar("cookies.json");
         $jar->addCookiesFromResponse($response, $request);
     } else {
         echo "You entered the wrong information.\n";
     }
 }
 public function testPersistsToFileFile()
 {
     $jar = new FileCookieJar($this->file);
     $jar->add(new Cookie(array('name' => 'foo', 'value' => 'bar', 'domain' => 'foo.com', 'expires' => time() + 1000)));
     $jar->add(new Cookie(array('name' => 'baz', 'value' => 'bar', 'domain' => 'foo.com', 'expires' => time() + 1000)));
     $jar->add(new Cookie(array('name' => 'boo', 'value' => 'bar', 'domain' => 'foo.com')));
     $this->assertEquals(3, count($jar));
     unset($jar);
     // Make sure it wrote to the file
     $contents = file_get_contents($this->file);
     $this->assertNotEmpty($contents);
     // Load the cookieJar from the file
     $jar = new FileCookieJar($this->file);
     // Weeds out temporary and session cookies
     $this->assertEquals(2, count($jar));
     unset($jar);
     unlink($this->file);
 }
Exemplo n.º 3
0
 /**
  * Write one data item
  *
  * @param array $item The data item with converted values
  *
  * @return $this
  */
 public function writeItem(array $item)
 {
     // TODO: Implement writeItem() method.
     $project = $item["project"];
     $summary = $item["summary"];
     $description = $item["description"];
     $jar = new FileCookieJar("cookies.json");
     $client = new Client();
     $cookie = $jar->all()[0];
     $domain = $cookie->getDomain();
     $path = $cookie->getPath();
     $request = $client->put("http://" . $domain . $path . "/rest/issue", array(), ["project" => $project, "summary" => $summary, "description" => $description]);
     foreach ($jar->all() as $cookie) {
         $request->addCookie($cookie->getName(), $cookie->getValue());
     }
     $response = $request->send();
     if ($response->getStatusCode() == 201) {
         echo "Successfully created the issue [" . $summary . "].\n";
     } else {
         echo "Something went wrong with [" . $summary . "]\n";
     }
 }