Skip to content

Commit

Permalink
Prepare for release 1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
skpassegna committed Sep 28, 2024
1 parent 14b537d commit b8fed41
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 43 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ If you need to access multiple products, use the `developer` scope. To get your
<?php
require_once './vendor/autoload.php';

use Freemius\Freemius_Api;
use Freemius\Freemius;

define( 'FS__API_SCOPE', 'developer' );
define( 'FS__API_DEV_ID', 1234 );
define( 'FS__API_PUBLIC_KEY', 'pk_YOUR_PUBLIC_KEY' );
define( 'FS__API_SECRET_KEY', 'sk_YOUR_SECRET_KEY' );

// Init SDK.
$api = new Freemius_Api(FS__API_SCOPE, FS__API_DEV_ID, FS__API_PUBLIC_KEY, FS__API_SECRET_KEY);
$api = new Freemius(FS__API_SCOPE, FS__API_DEV_ID, FS__API_PUBLIC_KEY, FS__API_SECRET_KEY);

// Get all products.
$result = $api->Api('/plugins.json');
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"type": "library",
"autoload": {
"psr-4": {
"Freemius\\": "src/"
"Freemius\\": "src/",
"Freemius\\Exceptions\\": "src/Exceptions/"
}
},
"require": {
Expand Down
4 changes: 2 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 8 additions & 18 deletions src/Freemius.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php

namespace Freemius;

Expand All @@ -9,30 +9,20 @@
}


define('FS_SDK__USER_AGENT', 'fs-php-' . Freemius_Api_Base::VERSION);

$curl_version = curl_version();

define('FS_API__PROTOCOL', version_compare($curl_version['version'], '7.37', '>=') ? 'https' : 'http');

if (! defined('FS_API__ADDRESS')) {
define('FS_API__ADDRESS', FS_API__PROTOCOL . '://api.freemius.com');
}
if (! defined('FS_API__SANDBOX_ADDRESS')) {
define('FS_API__SANDBOX_ADDRESS', FS_API__PROTOCOL . '://sandbox-api.freemius.com');
}

if (! class_exists('Freemius_Api')) {
class Freemius_Api extends Freemius_Api_Base
if (! class_exists('Freemius')) {
class Freemius extends FreemiusBase
{
private const FS_SDK_USER_AGENT = 'fs-php-' . FreemiusBase::VERSION;
private const FS_API_ADDRESS = 'https://api.freemius.com';
private const FS_API_SANDBOX_ADDRESS = 'https://sandbox-api.freemius.com';
/**
* Default options for curl.
*/
public static $CURL_OPTS = array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => FS_SDK__USER_AGENT,
CURLOPT_USERAGENT => self::FS_SDK_USER_AGENT,
CURLOPT_HTTPHEADER => array()
);

Expand All @@ -55,7 +45,7 @@ public function __construct($pScope, $pID, $pPublic, $pSecret = false, $pSandbox

public function GetUrl($pCanonizedPath = '')
{
return ($this->_sandbox ? FS_API__SANDBOX_ADDRESS : FS_API__ADDRESS) . $pCanonizedPath;
return ($this->_sandbox ? self::FS_API_SANDBOX_ADDRESS : self::FS_API_ADDRESS) . $pCanonizedPath;
}

/**
Expand Down
27 changes: 7 additions & 20 deletions src/FreemiusBase.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
<?php
<?php

namespace Freemius;

use Freemius\Exceptions\Freemius_Exception;

if (! defined('FS_API__VERSION')) {
define('FS_API__VERSION', '1');
}
if (! defined('FS_SDK__PATH')) {
define('FS_SDK__PATH', dirname(__FILE__));
}
if (! defined('FS_SDK__EXCEPTIONS_PATH')) {
define('FS_SDK__EXCEPTIONS_PATH', FS_SDK__PATH . '/Exceptions/');
}

if (! function_exists('json_decode')) {
throw new \Exception('Freemius needs the JSON PHP extension.');
}


if (! class_exists('Freemius_Api_Base')) {
abstract class Freemius_Api_Base
if (! class_exists('FreemiusBase')) {
abstract class FreemiusBase
{
protected const FS_API_VERSION = 1;
public const VERSION = '1.0.4';
public const FORMAT = 'json';

Expand Down Expand Up @@ -93,7 +80,7 @@ public function CanonizePath($pPath)
throw new Freemius_Exception('Scope not implemented.');
}

return '/v' . FS_API__VERSION . $base .
return '/v' . self::FS_API_VERSION . $base .
(!empty($pPath) ? '/' : '') . $pPath .
((false === strpos($pPath, '.')) ? '.' . self::FORMAT : '') . $query;
}
Expand Down Expand Up @@ -131,7 +118,7 @@ private function _Api($pPath, $pMethod = 'GET', $pParams = array(), $pFileParams
*/
public function Test()
{
$pong = $this->_Api('/v' . FS_API__VERSION . '/ping.json');
$pong = $this->_Api('/v' . self::FS_API_VERSION . '/ping.json');

return (is_object($pong) && isset($pong->api) && 'pong' === $pong->api);
}
Expand All @@ -145,7 +132,7 @@ public function Test()
public function FindClockDiff()
{
$time = time();
$pong = $this->_Api('/v' . FS_API__VERSION . '/ping.json');
$pong = $this->_Api('/v' . self::FS_API_VERSION . '/ping.json');
return ($time - strtotime($pong->timestamp));
}

Expand Down

0 comments on commit b8fed41

Please sign in to comment.