-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFriendFeed.class.php
More file actions
151 lines (131 loc) · 3.83 KB
/
FriendFeed.class.php
File metadata and controls
151 lines (131 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/**
* FriendFeed API Class for PHP5
*
* This aims to be a simplistic interface to the FriendFeed API
* using PHP 5.
*
* @package FriendFeed API
* @author Evan Fribourg <evan@dotevan.com>
* @copyright 2010. All Rights Reserved.
* @license see LICENSE provided with this package.
*/
require_once (dirname(__FILE__) . '/FriendFeedMessage.class.php');
class FriendFeed {
/**
* Base url for the API
*/
const API_BASE_URL = 'http://friendfeed-api.com/v2/';
/**
* Constants corresponding to the FF API v2 Options
*/
const VALIDATE = 'validate';
const ENTRY = 'entry';
const ENTRY_DELETE = 'entry/delete';
const COMMENT = 'comment';
const LIKE = 'like';
/**
* FriendFeed username
*
* @var String
*/
private $user;
/**
* FriendFeed API key
*
* @var String
*/
private $api_key;
/**
* holds the curl information from the last curl request
*/
private $response;
private $info;
public function __construct($user, $api_key) {
$this->user = $user;
$this->api_key = $api_key;
}
public function getInfo() {
return @$this->info;
}
public function getResponse() {
return @$this->response;
}
/**
* Sends a VALIDATE request to the FriendFeed API
* @return stdClass
* @link http://friendfeed.com/api/documentation#validate
*/
public function validate() {
return $this->request(self::VALIDATE, new FriendFeedMessage());
}
/**
* Posts an entry corresponding to the FriendFeedMessage
*
* @param FriendFeedMessage $message
* @return stdClass
* @link http://friendfeed.com/api/documentation#write_entry
*/
public function postEntry(FriendFeedMessage $message) {
return $this->request(self::ENTRY, $message);
}
/**
* Deletes an entry
*
* @param FriendFeedMessage $message
* @return stdClass
*/
public function deleteEntry(FriendFeedMessage $message) {
$message->moveEntryToId();
return $this->request(self::ENTRY_DELETE, $message);
}
/**
* Creates a comment against an entry
*
* @param FriendFeedMessage $comment
* @return stdClass
* @link http://friendfeed.com/api/documentation#write_comment
*/
public function postComment(FriendFeedMessage $comment) {
return $this->request(self::COMMENT, $comment);
}
/**
* Likes a specific entry
*
* @param FriendFeedMessage $like
* @return stdClass
* @link http://friendfeed.com/api/documentation#write_like
*/
public function like(FriendFeedMessage $like) {
return $this->request(self::LIKE, $like);
}
/**
* Submits the FriendFeedMessage to FriendFeed
*
* @param string $request_type
* @param FriendFeedMessage $message
* @return stdClass
*
*/
private function request($request_type, FriendFeedMessage $message) {
$url = self::API_BASE_URL . $request_type;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
if($this->user && $this->api_key) {
curl_setopt($curl, CURLOPT_USERPWD, $this->user . ":" . $this->api_key);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
}
if($request_type != self::VALIDATE) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, "json={$message}");
}
$this->response = curl_exec($curl);
$this->info = curl_getinfo($curl);
curl_close($curl);
if($this->info['http_code'] != 200) {
return null;
}
return json_decode($this->response);
}
}