-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlm-api.php
218 lines (173 loc) · 5.46 KB
/
lm-api.php
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
/**
* Registers zeen101's LiveMarket API Functions
*
* @package zeen101's LiveMarket
* @since 1.0.0
*/
/**
* zeen101's LiveMarket API for retrieving all the user's publications
*
* @since 1.0.0
*
* @return mixed Value set for the issuem options.
*/
function get_livemarket_publications() {
$settings = get_livemarket_settings();
$args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $settings['api_key'],
)
);
$results = wp_remote_get( LIVEMARKET_API_URL . 'publications/', $args );
$body = wp_remote_retrieve_body( $results );
return json_decode( $body );
}
/**
* zeen101's LiveMarket API for retrieving all the publication's advertisement categories
*
* @since 1.0.0
*
* @return mixed Value set for the issuem options.
*/
function get_livemarket_advertisement_categories() {
$settings = get_livemarket_settings();
$args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $settings['api_key'],
)
);
$results = wp_remote_get( LIVEMARKET_API_URL . 'publication/' . $settings['publication_id'] . '/categories', $args );
$body = wp_remote_retrieve_body( $results );
return json_decode( $body );
}
/**
* zeen101's LiveMarket API for retrieving all a publications advertisements
*
* @since 1.0.0
*
* @return mixed Value set for the issuem options.
*/
function get_livemarket_advertisements( $page = 0, $limit = 10, $category = '', $advertiser = '' ) {
$settings = get_livemarket_settings();
$cache_key = 'livemarket_advertisements_' . $limit . $category . $advertiser;
if ( false === ( $advertisements = get_transient( $cache_key ) ) ) {
$args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $settings['api_key'],
)
);
$query = array(
'page' => $page,
'limit' => $limit,
'category' => $category,
'advertiser' => $advertiser,
);
$query = http_build_query( $query );
$results = wp_remote_get( LIVEMARKET_API_URL . 'publication/' . $settings['publication_id'] . '/advertisements?' . $query, $args );
$body = wp_remote_retrieve_body( $results );
$advertisements = json_decode( $body );
$expires = apply_filters( 'livemarket_advertisements_expires', 300 );
set_transient( $cache_key, $advertisements, $expires );
}
return $advertisements;
}
/**
* zeen101's LiveMarket API for retrieving advertiser details
*
* @since 1.7.0
*
* @return mixed Value set for the issuem options.
*/
function get_livemarket_advertiser( $advertiser ) {
$settings = get_livemarket_settings();
$cache_key = 'livemarket_advertiser_' . $advertiser;
if ( false === ( $business_data = get_transient( $cache_key ) ) ) {
$args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $settings['api_key'],
)
);
$results = wp_remote_get( LIVEMARKET_API_URL . 'publication/' . $settings['publication_id'] . '/advertiser/' . $advertiser, $args );
$body = wp_remote_retrieve_body( $results );
$business_data = json_decode( $body );
$expires = apply_filters( 'livemarket_advertiser_expires', 300 );
set_transient( $cache_key, $business_data, $expires );
}
return $business_data;
}
/**
* zeen101's LiveMarket API for retrieving a specific advertisement
*
* @since 1.0.0
*
* @return mixed Value set for the issuem options.
*/
function get_livemarket_advertisement( $advertisement_slug ) {
$settings = get_livemarket_settings();
$args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $settings['api_key'],
)
);
$results = wp_remote_get( LIVEMARKET_API_URL . 'publication/' . $settings['publication_id'] . '/advertisement/' . $advertisement_slug, $args );
$body = wp_remote_retrieve_body( $results );
return json_decode( $body );
}
/**
* zeen101's LiveMarket API for tracking impressions
*
* @since 1.0.0
*
* @return mixed Value set for the issuem options.
*/
function livemarket_track_impressions( $advertisement_ids = array(), $data = array() ) {
$settings = get_livemarket_settings();
$args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $settings['api_key'],
),
'body' => array( 'advertisements' => $advertisement_ids )
);
$results = wp_remote_post( LIVEMARKET_API_URL . 'publication/' . $settings['publication_id'] . '/advertisement/impressions', $args );
$body = wp_remote_retrieve_body( $results );
return json_decode( $body );
}
/**
* zeen101's LiveMarket API for tracking views
*
* @since 1.0.0
*
* @return mixed Value set for the issuem options.
*/
function livemarket_track_view( $advertisement_slug, $data = array() ) {
$settings = get_livemarket_settings();
$args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $settings['api_key'],
),
'body' => $data
);
$results = wp_remote_post( LIVEMARKET_API_URL . 'publication/' . $settings['publication_id'] . '/advertisement/' . $advertisement_slug . '/view', $args );
$body = wp_remote_retrieve_body( $results );
return json_decode( $body );
}
/**
* zeen101's LiveMarket API for tracking clicks
*
* @since 1.0.0
*
* @return mixed Value set for the issuem options.
*/
function livemarket_track_click( $advertisement_slug, $data = array() ) {
$settings = get_livemarket_settings();
$args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $settings['api_key'],
),
'body' => $data
);
$results = wp_remote_post( LIVEMARKET_API_URL . 'publication/' . $settings['publication_id'] . '/advertisement/' . $advertisement_slug . '/click', $args );
$body = wp_remote_retrieve_body( $results );
return json_decode( $body );
}