Skip to content
This repository was archived by the owner on Oct 30, 2023. It is now read-only.

Commit 59b6b9b

Browse files
author
Jon Eyrick
authored
Merge pull request #46 from jaggedsoft/master
Simplify constructor
2 parents 9f55594 + ecc35bd commit 59b6b9b

File tree

2 files changed

+13
-94
lines changed

2 files changed

+13
-94
lines changed

examples/balances.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// @see home_directory_config.php
66
// use config from ~/.confg/jaggedsoft/php-binance-api.json
7-
$api = new Binance\API( "/home/dave/.config/jaggedsoft/php-binance-api-1.json" );
7+
$api = new Binance\API();
88

99
// Get all of your positions, including estimated BTC value
1010
$balances = $api->balances();

php-binance-api.php

Lines changed: 12 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ class API
5353

5454
/**
5555
* Constructor for the class,
56-
* send as many agument as you want.
56+
* send as many argument as you want.
57+
*
58+
* No arguments - use file setup
59+
* 1 argument - file to load config from
60+
* 2 arguments - api key and api secret
5761
*
5862
* @return null
5963
*/
@@ -62,106 +66,21 @@ public function __construct()
6266
$param = func_get_args();
6367
switch (func_num_args()) {
6468
case 0:
65-
$this->__construct0();
69+
$this->setupApiConfigFromFile();
70+
$this->setupProxyConfigFromFile();
6671
break;
6772
case 1:
68-
$this->__construct1($param[0]);
73+
$this->setupApiConfigFromFile($param[0]);
74+
$this->setupProxyConfigFromFile($param[0]);
75+
$this->setupCurlOptsFromFile($param[0]);
6976
break;
7077
case 2:
71-
$this->__construct2($param[0], $param[1]);
72-
break;
73-
case 3:
74-
$this->__construct3($param[0], $param[1], $param[2]);
75-
break;
76-
case 4:
77-
$this->__construct4($param[0], $param[1], $param[2], $param[3]);
78+
$this->api_key = $param[0];
79+
$this->api_secret = $param[1];
7880
break;
7981
}
8082
}
8183

82-
/**
83-
* Constructor for the class
84-
*
85-
* @return null
86-
*/
87-
private function __construct0()
88-
{
89-
$this->setupApiConfigFromFile();
90-
$this->setupProxyConfigFromFile();
91-
}
92-
93-
/**
94-
* Constructor for the class
95-
* Specifiy the filename where the config is stored
96-
*
97-
* @param $filename string the config file location
98-
* @return null
99-
*/
100-
private function __construct1(string $filename = null)
101-
{
102-
$this->setupApiConfigFromFile($filename);
103-
$this->setupProxyConfigFromFile($filename);
104-
$this->setupCurlOptsFromFile($filename);
105-
}
106-
107-
/**
108-
* Constructor for the class
109-
*
110-
* @param $api_key string api key
111-
* @param $api_secret string api secret
112-
* @return null
113-
*/
114-
private function __construct2(string $api_key = null, string $api_secret = null)
115-
{
116-
$this->api_key = $api_key;
117-
$this->api_secret = $api_secret;
118-
}
119-
120-
/**
121-
* Constructor for the class
122-
*
123-
* @param $api_key string api key
124-
* @param $api_secret string api secret
125-
* @param $options array addtional coniguration options
126-
* @return null
127-
*/
128-
private function __construct3(string $api_key = null, string $api_secret = null, array $options = ["useServerTime" => false])
129-
{
130-
$this->api_key = $api_key;
131-
$this->api_secret = $api_secret;
132-
if (isset($options['useServerTime']) && $options['useServerTime']) {
133-
$this->useServerTime();
134-
}
135-
if (isset($options['curlOpts']) && is_array($options['curlOpts'])) {
136-
$this->curlOpts = $options['curlOpts'];
137-
}
138-
}
139-
140-
/**
141-
* Constructor for the class
142-
*
143-
* @param $api_key string api key
144-
* @param $api_secret string api secret
145-
* @param $options array addtional coniguration options
146-
* @param $proxyConf array config
147-
* @return null
148-
*/
149-
private function __construct4(string $api_key = null, string $api_secret = null, array $options = ["useServerTime" => false], array $proxyConf = null)
150-
{
151-
$this->api_key = $api_key;
152-
$this->api_secret = $api_secret;
153-
$this->proxyConf = $proxyConf;
154-
if (isset($options['useServerTime']) && $options['useServerTime']) {
155-
$this->useServerTime();
156-
}
157-
if (isset($options['curlOpts']) && is_array($options['curlOpts'])) {
158-
$this->curlOpts = $options['curlOpts'];
159-
}
160-
$this->setupApiConfigFromFile();
161-
$this->setupProxyConfigFromFile();
162-
$this->setupCurlOptsFromFile();
163-
}
164-
16584
/**
16685
* magic get for private and protected members
16786
*

0 commit comments

Comments
 (0)