webservice MDL-23077 fix execute ws function when the return value is null
[moodle.git] / repository / dropbox / lib.php
CommitLineData
3e123368
DC
1<?php
2
3// This file is part of Moodle - http://moodle.org/
4//
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * dropbox class
20 * A helper class to access dropbox resources
21 *
22 * @since 2.0
23 * @package moodlecore
24 * @subpackage repository
25 * @copyright 2010 Dongsheng Cai
26 * @author Dongsheng Cai <dongsheng@moodle.com>
27 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 */
29
30
31require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
32require_once($CFG->libdir.'/oauthlib.php');
33
34class dropbox extends oauth_helper {
35 private $mode = 'sandbox';
36 private $dropbox_api = 'http://api.dropbox.com/0';
37 private $dropbox_content_api = 'http://api-content.dropbox.com/0';
38 function __construct($args) {
39 parent::__construct($args);
40 }
41 public function get_listing($path='/', $token='', $secret='') {
42 $url = $this->dropbox_api.'/metadata/'.$this->mode.$path;
43 $content = $this->get($url, array(), $token, $secret);
44 $data = json_decode($content);
45 return $data;
46 }
47 public function get_account_info($token, $secret) {
48 $url = $this->dropbox_api.'/account/info';
49 $content = $this->get($url, array(), $token, $secret);
50 return $content;
51 }
52 public function get_file($filepath, $saveas) {
53 $url = 'http://api-content.dropbox.com/0/files/sandbox'.$filepath;
54 $content = $this->get($url, array());
55 file_put_contents($saveas, $content);
56 return array('path'=>$saveas, 'url'=>$url);
57 }
58}