Created
November 3, 2014 13:27
-
-
Save mapyo/18775af8546df33f7aba to your computer and use it in GitHub Desktop.
Guzzle3でgetしたりputしたりする ref: http://qiita.com/mapyo/items/c609b9cbaaeb46bc69cf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require 'vendor/autoload.php'; | |
use Guzzle\Http\Client; | |
$settings = parse_ini_file('config/settings.ini'); | |
$client = new Client($settings['base_url']); | |
$client->setDefaultOption('headers', | |
array( | |
'Content-Type' => 'application/json', | |
'Authorization' => "Bearer ${settings['token']}", | |
) | |
); | |
# get | |
$response = $client->get( | |
$settings['api_path'], | |
null # header だが、setDefaultOptionで既に設定している。 | |
)->send()->json(); | |
var_dump($response); | |
# 金額を+100円する | |
$response['product']['price'] += 100; | |
$response = $client->put( | |
$settings['api_path'], | |
null, # header だが、setDefaultOptionで既に設定している。 | |
json_encode($response) | |
)->send()->json(); | |
var_dump($response); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment