Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Feeds
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MickGe
Feeds
Commits
79f9bef7
Commit
79f9bef7
authored
11 years ago
by
Andrew Dolgov
Browse files
Options
Downloads
Patches
Plain Diff
add support for plugins adding API methods
parent
5e725f9c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
classes/api.php
+13
-2
13 additions, 2 deletions
classes/api.php
classes/pluginhost.php
+10
-0
10 additions, 0 deletions
classes/pluginhost.php
plugins/example_api/init.php
+31
-0
31 additions, 0 deletions
plugins/example_api/init.php
with
54 additions
and
2 deletions
classes/api.php
+
13
−
2
View file @
79f9bef7
...
...
@@ -464,8 +464,19 @@ class API extends Handler {
}
function
index
()
{
print
$this
->
wrap
(
self
::
STATUS_ERR
,
array
(
"error"
=>
'UNKNOWN_METHOD'
));
function
index
(
$method
)
{
global
$pluginhost
;
$plugin
=
$pluginhost
->
get_api_method
(
strtolower
(
$method
));
if
(
$plugin
&&
method_exists
(
$plugin
,
$method
))
{
$reply
=
$plugin
->
$method
();
print
$this
->
wrap
(
$reply
[
0
],
$reply
[
1
]);
}
else
{
print
$this
->
wrap
(
self
::
STATUS_ERR
,
array
(
"error"
=>
'UNKNOWN_METHOD'
,
"method"
=>
$method
));
}
}
function
shareToPublished
()
{
...
...
This diff is collapsed.
Click to expand it.
classes/pluginhost.php
+
10
−
0
View file @
79f9bef7
...
...
@@ -7,6 +7,7 @@ class PluginHost {
private
$commands
=
array
();
private
$storage
=
array
();
private
$feeds
=
array
();
private
$api_methods
=
array
();
private
$owner_uid
;
private
$debug
;
...
...
@@ -347,5 +348,14 @@ class PluginHost {
return
PLUGIN_FEED_BASE_INDEX
-
1
+
abs
(
$feed
);
}
function
add_api_method
(
$name
,
$sender
)
{
if
(
$this
->
is_system
(
$sender
))
{
$this
->
api_methods
[
strtolower
(
$name
)]
=
$sender
;
}
}
function
get_api_method
(
$name
)
{
return
$this
->
api_methods
[
$name
];
}
}
?>
This diff is collapsed.
Click to expand it.
plugins/example_api/init.php
0 → 100644
+
31
−
0
View file @
79f9bef7
<?php
class
Example_Api
extends
Plugin
{
// Demonstrates adding a method to the API
// Plugin methods return an array containint
// 1. status (STATUS_OK or STATUS_ERR)
// 2. arbitrary payload
private
$link
;
private
$host
;
function
about
()
{
return
array
(
1.0
,
"Example plugin adding an API method"
,
"fox"
,
true
,
"http://tt-rss.org/"
);
}
function
init
(
$host
)
{
$this
->
link
=
$host
->
get_link
();
$this
->
host
=
$host
;
$host
->
add_api_method
(
"example_testmethod"
,
$this
);
}
function
example_testmethod
()
{
return
array
(
API
::
STATUS_OK
,
array
(
"current_time"
=>
time
()));
}
}
?>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment