22
33namespace Swader \Diffbot \Abstracts ;
44
5- use GuzzleHttp \Client ;
65use Swader \Diffbot \Diffbot ;
7- use Swader \Diffbot \Exceptions \DiffbotException ;
86
97/**
108 * Class Api
@@ -75,33 +73,10 @@ public function setTimeout($timeout = null)
7573 return $ this ;
7674 }
7775
78- public function __call ($ name , $ arguments )
79- {
80- $ prefix = substr (lcfirst ($ name ), 0 , 3 );
81- $ field = lcfirst (substr ($ name , 3 ));
82-
83- $ fields = static ::getOptionalFields ();
84- if (in_array ($ field , $ fields )) {
85- if ($ prefix == 'get ' ) {
86- return (isset ($ this ->fieldSettings [$ field ])) ? $ this ->fieldSettings [$ field ] : false ;
87- }
88-
89- if ($ prefix == 'set ' ) {
90- if (is_bool ($ arguments [0 ]) || $ arguments [0 ] === null ) {
91- $ this ->fieldSettings [$ field ] = (bool )$ arguments [0 ];
92- return $ this ;
93- }
94- throw new \InvalidArgumentException ('Only booleans and null are allowed as optional field flags! ' );
95- }
96- throw new \BadMethodCallException ('Prefix " ' .$ prefix .'" not allowed. ' );
97- }
98- throw new \BadMethodCallException ($ name . ': such a field does not exist for this API class. ' );
99- }
100-
10176 public function call ()
10277 {
10378 $ response = $ this ->diffbot ->getHttpClient ()->get ($ this ->buildUrl ());
104- return $ this ->diffbot ->getEntityFactory ()->createAppropriate ($ response );
79+ return $ this ->diffbot ->getEntityFactory ()->createAppropriateIterator ($ response );
10580 }
10681
10782 public function buildUrl ()
@@ -112,14 +87,14 @@ public function buildUrl()
11287 $ url .= '?token= ' . $ this ->diffbot ->getToken ();
11388
11489 // Add URL
115- $ url .= '&url= ' .urlencode ($ this ->url );
90+ $ url .= '&url= ' . urlencode ($ this ->url );
91+
11692
11793 // Add Custom Fields
118- $ fields = static :: getOptionalFields () ;
94+ $ fields = $ this -> fieldSettings ;
11995 $ fieldString = '' ;
120- foreach ($ fields as $ field ) {
121- $ methodName = 'get ' . ucfirst ($ field );
122- $ fieldString .= ($ this ->$ methodName ()) ? $ field . ', ' : '' ;
96+ foreach ($ fields as $ field => $ value ) {
97+ $ fieldString .= ($ value ) ? $ field . ', ' : '' ;
12398 }
12499 $ fieldString = trim ($ fieldString , ', ' );
125100 if ($ fieldString != '' ) {
@@ -135,8 +110,10 @@ public function buildUrl()
135110 * @param Diffbot $d
136111 * @return $this
137112 */
138- public function registerDiffbot (Diffbot $ d ) {
113+ public function registerDiffbot (Diffbot $ d )
114+ {
139115 $ this ->diffbot = $ d ;
140116 return $ this ;
141117 }
118+
142119}
0 commit comments