Exemplo n.º 1
0
 /**
  * memo/create API.
  *
  * @Any("create", as="api.memo.create")
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function anyCreate()
 {
     try {
         $id = $this->request('id');
         if (empty($id) || !is_string($id)) {
             throw new RuntimeException('id is empty.');
         }
         $info = $this->TwistOAuth->get('statuses/show', compact('id'));
         $data = ['user_sn' => $info->user->screen_name, 'user_id' => $info->user->id_str, 'content' => $info->text];
         foreach ($info->entities->urls as $url) {
             $data['content'] = str_replace($url->url, $url->expanded_url, $data['content']);
         }
         if (isset($info->extended_entities)) {
             foreach ($info->extended_entities->media as $m) {
                 $data['content'] = str_replace($m->url, $m->media_url_https, $data['content']);
             }
         }
         $validate = $this->memo->insert($data, ['save' => true]);
         if ($validate === true) {
             $id = $this->memo->select('id')->where('user_sn', '=', $data['user_sn'])->where('user_id', '=', $data['user_id'])->where('content', '=', $data['content'])->get()->last()->id;
             $json = ['id' => $id, 'user_sn' => $data['user_sn'], 'user_id' => $data['user_id'], 'content' => $data['content']];
             return $this->onSuccess($json);
         }
         throw new RuntimeException($validate->errors()->first(), 400);
     } catch (Exception $e) {
         return $this->onError($e);
     }
 }
Exemplo n.º 2
0
 /**
  * Test insert method.
  *
  * @dataProvider insertDataProvider
  *
  * @param mixed $user_sn
  * @param mixed $user_id
  * @param mixed $content
  * @param bool  $hasError
  */
 public function testInsert($user_sn, $user_id, $content, $hasError)
 {
     $data = compact('user_sn', 'user_id', 'content');
     $response = $this->memo->insert($data);
     $this->checkError($response, $hasError);
 }