/** * Check if twitter settings are valid * @return boolean */ public function validTwitterSettings() { if ($this->config->exists() && $this->config->first()->linked_twitter) { return true; } try { $client = initTwitter(); $verification = $client->get('account/verify_credentials.json'); $verification = json_decode($verification->getBody(), true); if ($this->config->exists() && $this->config->first()->exists()) { $this->config->insertTwitterId($verification); } return true; } catch (\GuzzleHttp\Exception\ClientException $e) { if ($e->getCode() == self::TOO_MANY_REQUEST_CODE) { getErrorMessage($e->getResponse()->getStatusCode()); } return false; } }
/** * Follow/unfollow user * * @param object $contact * @param integer $twitterId * * @return void|\Illuminate\View\View */ public function toggleFollowUser($contact, $twitterId) { $client = initTwitter(); try { if ($contact->following) { $contact->following = 0; $client->post('friendships/destroy.json?follow=true&user_id=' . $twitterId); Session::flash('flash_success', trans('crm-launcher::success.unfollow')); } else { $contact->following = 1; $client->post('friendships/create.json?follow=true&user_id=' . $twitterId); Session::flash('flash_success', trans('crm-launcher::success.follow')); } $contact->save(); } catch (\GuzzleHttp\Exception\ClientException $e) { getErrorMessage($e->getResponse()->getStatusCode()); return back(); } }