somin-team / somin-api-sdk
SoMin API SDK is a PHP library for making calls to SoMin API.
Installs: 1 309
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=5.6.0
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpmd/phpmd: ~2.6
- phpunit/phpunit: ~5.7
- squizlabs/php_codesniffer: ~3.0
README
SoMin API SDK for Somin API is a PHP library for making calls to Somin API. The library enables users for making API calls from PHP 5.6 or high.
Example
$requester = new SimpleHttpRequester(); $authorizer = new CredentialsAuthorizer($requester); $tokenRequest = (new UserCredential()) ->setUsername(USERNAME) ->setPassword(PASSWORD); // Call authorization method $tokenResponse = $authorizer->auth($tokenRequest); // Set bearer token to current HttpRequester $requester->setBearer($tokenResponse->getToken()); $request = (new UserProfileData()) ->setTexts([ "Hello friend!", "The weather is good :)" ]) ->setImageURLs([ "https://pbs.twimg.com/media/C6ij4CLUwAAxu9r.jpg", "https://pbs.twimg.com/media/C6jO3UiVoAQYc_8.jpg" ]) ->setLang('en') ->withAgeGroup() ->withEducationLevel() ->withGender() ->withIncome() ->withOccupation() ->withRelationship(); $userProfiler = new IndividualUserProfiler($requester); // Call individual user profile method and get request id $requestResponse = $userProfiler->predictIndividualUserProfile($request); $request = (new ResponseRequest()) ->setRequestID($requestResponse->getRequestId()) ->setResponseClass(IndividualUserProfile::class); // Call method for check current request status $commonProcessor = new CommonProcessor($this->requester); $numAttempts = 10; $response = null; /** @var $response IndividualUserProfile */ while($numAttempts-- > 0 && ($response == null || $response->getHttpCode() !== 200)) { sleep(self::RESPONSE_WAIT_TIME_SECONDS); $response = $commonProcessor->response($request); } var_dump($response);
Testing
- Install PHP Unit
- Set environment variables TEST_USERNAME and TEST_PASSWORD to SoMin API user name and password, respectively.
- run phpunit in main directory
API Documentation
More information can be found on the SoMin developer web site.