1 | <?php |
||
15 | final class Service |
||
16 | { |
||
17 | /** |
||
18 | * The solvemedia server URL's |
||
19 | */ |
||
20 | const ADCOPY_API_SERVER = 'http://api.solvemedia.com'; |
||
21 | const ADCOPY_API_SECURE_SERVER = 'https://api-secure.solvemedia.com'; |
||
22 | const ADCOPY_VERIFY_SERVER = 'http://verify.solvemedia.com/papi/verify'; |
||
23 | const ADCOPY_SIGNUP = 'http://api.solvemedia.com/public/signup'; |
||
24 | |||
25 | /** |
||
26 | * @var ClientInterface |
||
27 | */ |
||
28 | private $_client; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | */ |
||
33 | private $_pubkey; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | private $_privkey; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | private $_hashkey; |
||
44 | |||
45 | /** |
||
46 | * Construct a Service object with the required api key values. |
||
47 | * |
||
48 | * @param ClientInterface $client The guzzle client to send the requests over. |
||
49 | * @param string $pubkey A public key for solvemedia |
||
50 | * @param string $privkey A private key for solvemedia |
||
51 | * @param string $hashkey An optional hash key for verification |
||
52 | * @throws Exception |
||
53 | */ |
||
54 | public function __construct(ClientInterface $client, string $pubkey, string $privkey, string $hashkey = '') |
||
65 | |||
66 | /** |
||
67 | * Gets the challenge HTML (javascript and non-javascript version). |
||
68 | * This is called from the browser, and the resulting solvemedia HTML widget |
||
69 | * is embedded within the HTML form it was called from. |
||
70 | * |
||
71 | * @param string $error The error given by solvemedia (optional, default is null) |
||
72 | * @param boolean $useSsl Should the request be made over ssl? (optional, default is false) |
||
73 | * @return string The HTML to be embedded in the user's form. |
||
74 | */ |
||
75 | public function getHtml(string $error = null, bool $useSsl = false) : string |
||
89 | |||
90 | /** |
||
91 | * Calls an HTTP POST function to verify if the user's guess was correct |
||
92 | * |
||
93 | * @param string $remoteip |
||
94 | * @param string $challenge |
||
95 | * @param string $response |
||
96 | * @throws Exception |
||
97 | * @return Response |
||
98 | */ |
||
99 | public function checkAnswer(string $remoteip, string $challenge = null, string $response = null) : Response |
||
145 | |||
146 | /** |
||
147 | * Gets a URL where the user can sign up for solvemedia. If your application |
||
148 | * has a configuration page where you enter a key, you should provide a link |
||
149 | * using this function. |
||
150 | * |
||
151 | * @param string $domain The domain where the page is hosted |
||
152 | * @param string $appname The name of your application |
||
153 | * @return string url for signup page |
||
154 | */ |
||
155 | public function getSignupUrl(string $domain = null, string $appname = null) : string |
||
159 | } |
||
160 |