Skip to content

Instantly share code, notes, and snippets.

@mapyo
Created November 3, 2014 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mapyo/18775af8546df33f7aba to your computer and use it in GitHub Desktop.
Save mapyo/18775af8546df33f7aba to your computer and use it in GitHub Desktop.
Guzzle3でgetしたりputしたりする ref: http://qiita.com/mapyo/items/c609b9cbaaeb46bc69cf
<?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