Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nico
piphone-front
Commits
c4a724f9
Commit
c4a724f9
authored
Nov 23, 2014
by
Mindiell
Browse files
API modifications in order to contact Django REST API
parent
253c4236
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/Api.php
View file @
c4a724f9
...
...
@@ -7,8 +7,9 @@ class Api {
// Generic get function for REST API
static
function
get
(
$url
)
{
$curl
=
curl_init
();
$url
=
API_BASE
.
$url
;
$url
=
API_BASE
.
$url
.
"/?format=json"
;
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
//curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
true
);
$result
=
curl_exec
(
$curl
);
curl_close
(
$curl
);
...
...
@@ -30,41 +31,31 @@ class Api {
// Asking for campaign informations
static
function
get_campaign
()
{
$json
=
Api
::
get
(
"campaign/"
.
CAMPAIGN_ID
);
return
json_decode
(
$json
,
true
);
}
// Searching a random or specific contact
static
function
get_contact
(
$contact_id
=
''
)
{
if
(
$contact_id
!=
''
)
{
$json
=
Api
::
get
(
"campaign/"
.
CAMPAIGN_ID
.
"/contact/"
.
$contact_id
);
}
else
{
$json
=
Api
::
get
(
"campaign/"
.
CAMPAIGN_ID
.
"/contact"
);
}
$json
=
Api
::
get
(
"campaigns/"
.
CAMPAIGN_ID
);
return
json_decode
(
$json
,
true
);
}
// Asking for complete list of contacts
static
function
get_contacts
()
{
$json
=
Api
::
get
(
"campaign/"
.
CAMPAIGN_ID
.
"/contacts"
);
$json
=
Api
::
get
(
"campaign
s
/"
.
CAMPAIGN_ID
.
"/contacts"
);
return
json_decode
(
$json
,
true
);
}
// Asking for complete list of groups
static
function
get_groups
()
{
$json
=
Api
::
get
(
"campaign/"
.
CAMPAIGN_ID
.
"/groups"
);
$json
=
Api
::
get
(
"campaign
s
/"
.
CAMPAIGN_ID
.
"/groups"
);
return
json_decode
(
$json
,
true
);
}
// Asking for complete list of feedback categories
static
function
get_feedback_categories
()
{
$json
=
Api
::
get
(
"campaign/"
.
CAMPAIGN_ID
.
"/feedback/categories"
);
$json
=
Api
::
get
(
"campaign
s
/"
.
CAMPAIGN_ID
.
"/feedback/categories"
);
return
json_decode
(
$json
,
true
);
}
// Asking for arguments by language
static
function
get_arguments
(
$language
=
'en'
)
{
$json
=
Api
::
get
(
"campaign/"
.
CAMPAIGN_ID
.
"/arguments/"
.
$language
);
$json
=
Api
::
get
(
"campaign
s
/"
.
CAMPAIGN_ID
.
"/arguments/"
.
$language
);
return
json_decode
(
$json
,
true
);
}
...
...
@@ -75,7 +66,7 @@ class Api {
"comment"
=>
$comment
,
"feedback_category"
=>
$feedback_category
);
$json
=
Api
::
post
(
"campaign/"
.
CAMPAIGN_ID
.
"/feedback/add"
,
$data
);
$json
=
Api
::
post
(
"campaign
s
/"
.
CAMPAIGN_ID
.
"/feedback/add"
,
$data
);
return
json_decode
(
$json
,
true
);
}
...
...
app/Controller.php
View file @
c4a724f9
...
...
@@ -22,7 +22,7 @@ class Controller {
// Init contacts list if needed
if
(
!
$f3
->
exists
(
'contacts'
))
{
$f3
->
set
(
'contacts'
,
Api
::
get_contacts
()
[
'contacts'
]
,
API_TIMEOUT
);
$f3
->
set
(
'contacts'
,
Api
::
get_contacts
(),
API_TIMEOUT
);
}
// Workaround for caching variables
$f3
->
set
(
'contacts'
,
$f3
->
get
(
'contacts'
));
...
...
templates/contact.html
View file @
c4a724f9
<!-- contact page -->
<h3>
Random MEP
</h3>
<p
class=
"left"
><img
src=
"http://www.europarl.europa.eu/mepphoto/{{ @contact.
external_
id }}.jpg"
alt=
"mep"
></p>
<h3>
{{ _("
Random MEP
") }}
</h3>
<p
class=
"left"
><img
src=
"http://www.europarl.europa.eu/mepphoto/{{ @contact.id }}.jpg"
alt=
"mep"
></p>
<p
id=
"name"
>
{{ @contact.first_name }} {{ @contact.last_name }}
</p>
<ul
id=
"resume"
>
<li
id=
"phone"
>
Phone number:
<a
href=
"tel:{{ @contact.
tel
}} "
>
{{ @contact.
tel
}}
</a></li>
<li
id=
"phone"
>
{{ _("
Phone number:
") }}
<a
href=
"tel:{{ @contact.
phone
}} "
>
{{ @contact.
phone
}}
</a></li>
<repeat
group=
"{{ @contact.groups }}"
value=
"{{ @group }}"
>
<check
if=
"{{ @group.type!='Committee' }}"
>
<li
id=
"group"
><span>
{{ @group.type }}:
</span><a
href=
"https://memopol.lqdn.fr/europe/parliament/group/{{ @group.name }}"
>
{{ @group.name }}
</a>
</li>
...
...
@@ -17,7 +17,7 @@
</check>
</repeat>
</ul>
<p
id=
"info"
><a
href=
"https://memopol.lqdn.fr/europe/parliament/deputy/AmeliaAndersdotter/"
>
Get more info…
</a></p>
<p
id=
"info"
><a
href=
"https://memopol.lqdn.fr/europe/parliament/deputy/AmeliaAndersdotter/"
>
{{ _("
Get more info…
") }}
</a></p>
<p><a
href=
"/call/{{ @contact.id }}"
>
Use Piphone
</a></p>
<p><a
href=
"/call/{{ @contact.id }}"
>
{{ _("Call") }}
</a></p>
<!-- contact page -->
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment