Skip to content

Commit

Permalink
refactor: InstagramSocialFeed => InstagramData
Browse files Browse the repository at this point in the history
  • Loading branch information
devuri committed Dec 5, 2020
1 parent f1d4d26 commit d3af859
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/Admin/pages/social-feed-settings/account-setup.admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
}

# update user info
$igsf_profile = SimSocialFeed\InstagramSocialFeed::user_profile();
$igsf_profile = SimSocialFeed\InstagramData::user_profile();
update_option('simsf_user', $igsf_profile);
echo $this->form()->user_feedback('IG User Info Has Been Updated !!!');

# check the user info
if ( ! SimSocialFeed\InstagramSocialFeed::user_check() ) {
if ( ! SimSocialFeed\InstagramData::user_check() ) {
echo $this->form()->user_feedback('User Activation Failed. <br> Configuration data is missing or incorrect <br> Please check your user token !!!', 'error');
}

Expand Down Expand Up @@ -119,7 +119,7 @@


?></form>
<?php if ( SimSocialFeed\InstagramSocialFeed::user_check() ): ?>
<?php if ( SimSocialFeed\InstagramData::user_check() ): ?>
The Following Account is Active:
<br>
<strong><?php echo get_option('simsf_user')['id']; ?></strong>
Expand All @@ -128,7 +128,7 @@
<?php endif;

# check the user info
if ( ! SimSocialFeed\InstagramSocialFeed::user_check() ) {
if ( ! SimSocialFeed\InstagramData::user_check() ) {
echo $this->form()->user_feedback('Please Activate User ID. <br> Configuration data is missing or incorrect !!!', 'error');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
}

# SOMETHING WENT WRONG WITH THE REQUEST
if ( ! SimSocialFeed\InstagramSocialFeed::is_request_ok() ) :
echo $this->form()->user_feedback(SimSocialFeed\InstagramSocialFeed::error_message(), 'error');
if ( ! SimSocialFeed\InstagramData::is_request_ok() ) :
echo $this->form()->user_feedback(SimSocialFeed\InstagramData::error_message(), 'error');
endif;

# REQUEST TOKEN UPDATE
if ( SimSocialFeed\InstagramSocialFeed::is_request_ok() ) :
if ( SimSocialFeed\InstagramData::is_request_ok() ) :
# get new token
$newtoken = SimSocialFeed\InstagramSocialFeed::refresh_token();
$newtoken = SimSocialFeed\InstagramData::refresh_token();

# update the token
update_option('simsf_access_token', $newtoken );
Expand All @@ -39,7 +39,7 @@
<h2><?php _e('Refresh and Update User Access Token'); ?></h2>
<?php _e('Token Expire Date: '); ?>
<span style="color: #cc0000;">
<?php echo SimSocialFeed\InstagramSocialFeed::token_expire_date(); ?>
<?php echo SimSocialFeed\InstagramData::token_expire_date(); ?>
</span>
<hr/>
<div class="description">
Expand All @@ -65,7 +65,7 @@
/**
* only show if we have valid user
*/
if ( SimSocialFeed\InstagramSocialFeed::user_check() ) {
if ( SimSocialFeed\InstagramData::user_check() ) {
// submit button
echo $this->form()->submit_button('Get New Token', 'primary large', 'ig_token_update');
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
}

# SOMETHING WENT WRONG WITH THE REQUEST
if ( ! SimSocialFeed\InstagramSocialFeed::is_request_ok() ) :
echo $this->form()->user_feedback(SimSocialFeed\InstagramSocialFeed::error_message(), 'error');
if ( ! SimSocialFeed\InstagramData::is_request_ok() ) :
echo $this->form()->user_feedback(SimSocialFeed\InstagramData::error_message(), 'error');
endif;

# UPDATE USER MEDIA
if ( SimSocialFeed\InstagramSocialFeed::is_request_ok() ) :
$ig_user_media = SimSocialFeed\InstagramSocialFeed::user_media();
if ( SimSocialFeed\InstagramData::is_request_ok() ) :
$ig_user_media = SimSocialFeed\InstagramData::user_media();
update_option('simsf_user_media', $ig_user_media->data );
echo $this->form()->user_feedback('IG Feed Has Been Updated !!!');
endif;
Expand All @@ -42,7 +42,7 @@
/**
* only show if we have valid user
*/
if ( SimSocialFeed\InstagramSocialFeed::user_check() ) {
if ( SimSocialFeed\InstagramData::user_check() ) {
# submit button
echo $this->form()->submit_button('Refresh Instagram Feed', 'primary large', 'refresh_instagram_feed');
} else {
Expand Down
27 changes: 21 additions & 6 deletions src/InstagramSocialFeed.php → src/InstagramData.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,31 @@

namespace SimSocialFeed;

class InstagramSocialFeed
use EspressoDev\InstagramBasicDisplay\InstagramBasicDisplay;

class InstagramData
{

/**
* Setup the IG class
*
* Initialize the feed API
* how to get the token
*
* @link https://www.youtube.com/watch?v=rWUcb8jXgVA
*/
public static function api() {
return new InstagramBasicDisplay( get_option( 'simsf_token' )['access_token'] );
}

/**
* Lets make sure all is well
*
* @return boolean
*/
public static function is_request_ok() {
try {
simsocial()->getUserProfile();
self::api()->getUserProfile();
} catch ( \Exception $e ) {
return false;
}
Expand Down Expand Up @@ -46,12 +60,13 @@ public static function user_check() {

/**
* User profile
* convert user data object to array
*
* Convert user data object to array
*
* @return array
*/
public static function user_profile() {
$user = simsocial()->getUserProfile();
$user = self::api()->getUserProfile();
$user_data = (array) $user;
return $user_data;
}
Expand All @@ -67,7 +82,7 @@ public static function user_media() {
$id = get_option( 'simsf_user' )['id'];

// get the media.
$user_media = simsocial()->getUserMedia( $id, 49 );
$user_media = self::api()->getUserMedia( $id, 40 );

// media.
return $user_media;
Expand All @@ -93,7 +108,7 @@ public function expires( $expires_in = 5184000 ) {
* @return array
*/
public static function refresh_token() {
$newtoken = simsocial()->refreshToken( get_option( 'simsf_token' )['access_token'] );
$newtoken = self::api()->refreshToken( get_option( 'simsf_token' )['access_token'] );
$user_token = (array) $newtoken;

/**
Expand Down
6 changes: 3 additions & 3 deletions src/schedule.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use SimSocialFeed\InstagramSocialFeed;
use SimSocialFeed\InstagramData;

/**
* Run the sim social feed update
Expand All @@ -9,8 +9,8 @@ function sim_social_igfeed_update() {
/**
* Update user media
*/
if ( InstagramSocialFeed::is_request_ok() ) :
$ig_user_media = InstagramSocialFeed::user_media();
if ( InstagramData::is_request_ok() ) :
$ig_user_media = InstagramData::user_media();
update_option( 'simsf_user_media', $ig_user_media->data );
endif;
}
Expand Down
2 changes: 1 addition & 1 deletion vendor/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'EspressoDev\\InstagramBasicDisplay\\InstagramBasicDisplay' => $vendorDir . '/espresso-dev/instagram-basic-display-php/src/InstagramBasicDisplay.php',
'EspressoDev\\InstagramBasicDisplay\\InstagramBasicDisplayException' => $vendorDir . '/espresso-dev/instagram-basic-display-php/src/InstagramBasicDisplayException.php',
'SimSocialFeed\\Admin\\SocialFeedAdmin' => $baseDir . '/src/Admin/SocialFeedAdmin.php',
'SimSocialFeed\\InstagramSocialFeed' => $baseDir . '/src/InstagramSocialFeed.php',
'SimSocialFeed\\InstagramData' => $baseDir . '/src/InstagramData.php',
'SimSocialFeed\\WPAdminPage\\AdminPage' => $baseDir . '/src/WPAdminPage/AdminPage.php',
'SimSocialFeed\\WPAdminPage\\FormHelper' => $baseDir . '/src/WPAdminPage/FormHelper.php',
);
2 changes: 1 addition & 1 deletion vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ComposerStaticInitd7e54b283c57504fcb44f1d17c61f634
'EspressoDev\\InstagramBasicDisplay\\InstagramBasicDisplay' => __DIR__ . '/..' . '/espresso-dev/instagram-basic-display-php/src/InstagramBasicDisplay.php',
'EspressoDev\\InstagramBasicDisplay\\InstagramBasicDisplayException' => __DIR__ . '/..' . '/espresso-dev/instagram-basic-display-php/src/InstagramBasicDisplayException.php',
'SimSocialFeed\\Admin\\SocialFeedAdmin' => __DIR__ . '/../..' . '/src/Admin/SocialFeedAdmin.php',
'SimSocialFeed\\InstagramSocialFeed' => __DIR__ . '/../..' . '/src/InstagramSocialFeed.php',
'SimSocialFeed\\InstagramData' => __DIR__ . '/../..' . '/src/InstagramData.php',
'SimSocialFeed\\WPAdminPage\\AdminPage' => __DIR__ . '/../..' . '/src/WPAdminPage/AdminPage.php',
'SimSocialFeed\\WPAdminPage\\FormHelper' => __DIR__ . '/../..' . '/src/WPAdminPage/FormHelper.php',
);
Expand Down

0 comments on commit d3af859

Please sign in to comment.