Commits

Arjan Scherpenisse committed 9b7d7fb

Added documentation about the instance variables; fixed notices about
missing instance variables; added a default user-agent string.

Comments (0)

Files changed (1)

src/AnymetaAPI.php

 
 class AnyMetaAPI
 {
+    const version = "1.0";
+
+    // Entrypoint, e.g. http://www.mediamatic.net/services/rest/, given in constructor
+    public $entrypoint;
+
+    // Signature method; instance of OAuthSignatureMethod; defaults to HMAC_SHA1
+    public $signature_method;
+
+    // Information about the most recent HTTP request.
+    public $http_info;
+
+    // User agent string
+    public $agent = NULL;
+
+    // CURL timeout
+    public $timeout = 30;
+
+    // Verify peer yes/no
+    public $ssl_verifypeer = true;
+
+
+    private $consumer;
+    private $token;
+
+    /**
+     * Setup a new Anymeta connection.
+     */
     public function __construct($entrypoint, $ckey, $csec, $tkey, $tsec)
     {
         $this->entrypoint = $entrypoint;
-        $this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1();
+        $this->signature_method = new OAuthSignatureMethod_HMAC_SHA1();
         $this->consumer = new OAuthConsumer($ckey, $csec);
         if (!empty($tkey) && !empty($tsec))
         {
         {
             $this->token = NULL;
         }
+
+        $this->agent = sprintf('AnyMetaAPI/%s (%s; PHP)', AnyMetaAPI::version, php_uname('n'));
     }
 
 
         }
 
         $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, 'POST', $this->entrypoint, $param);
-        $request->sign_request($this->sha1_method, $this->consumer, $this->token);
+        $request->sign_request($this->signature_method, $this->consumer, $this->token);
 
         $result = $this->http($request->get_normalized_http_url(), 'POST', $request->to_postdata());
         return json_decode($result, true);
         $this->http_info = array();
         $ci = curl_init();
         /* Curl settings */
-        curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);
-        //curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);
+        curl_setopt($ci, CURLOPT_USERAGENT, $this->agent);
         curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);
         curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
         curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
         curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);
-        //curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));
         curl_setopt($ci, CURLOPT_HEADER, FALSE);
 
         switch ($method) {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.