• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pixelpeter / laravel5-genderize-api-client / 15695833074

17 Jun 2025 01:29AM UTC coverage: 98.925%. Remained the same
15695833074

Pull #25

github

web-flow
Merge 6c20c15f7 into cc744372a
Pull Request #25: Bump stefanzweifel/git-auto-commit-action from 5 to 6

92 of 93 relevant lines covered (98.92%)

21.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/GenderizeClient.php
1
<?php
2

3
namespace Pixelpeter\Genderize;
4

5
use Pixelpeter\Genderize\Models\GenderizeResponse;
6
use Unirest\Request;
7

8
class GenderizeClient
9
{
10
    /**
11
     * @var array Holds one or more names to check
12
     */
13
    protected $names;
14

15
    /**
16
     * @var string | null The language used for the check
17
     */
18
    protected $lang;
19

20
    /**
21
     * @var string | null The country used for the check
22
     */
23
    protected $country;
24

25
    /**
26
     * @var string The api key used for the request
27
     */
28
    protected $apikey;
29

30
    /**
31
     * @var \Unirest\Request
32
     */
33
    protected $request;
34

35
    /**
36
     * @const API_URL The URL of the api endpoint
37
     */
38
    const API_URL = 'https://api.genderize.io';
39

40
    /**
41
     * Create new instance of Pixelpeter\Genderize\GenderizeClient
42
     */
43
    public function __construct(Request $request)
48✔
44
    {
45
        $this->apikey = config('genderize.apikey');
48✔
46
        $this->request = $request;
48✔
47
    }
48✔
48

49
    /**
50
     * Fluent setter for names given as string
51
     *
52
     * @param  string | array  $name
53
     * @return $this|GenderizeClient
54
     */
55
    public function name($name = '')
42✔
56
    {
57
        if (is_array($name)) {
42✔
58
            return $this->names($name);
6✔
59
        }
60

61
        $this->names = [$name];
36✔
62

63
        return $this;
36✔
64
    }
65

66
    /**
67
     * Fluent setter for names given as array
68
     *
69
     * @return $this
70
     */
71
    public function names(array $names)
12✔
72
    {
73
        $this->names = $names;
12✔
74

75
        return $this;
12✔
76
    }
77

78
    /**
79
     * Fluent setter for language
80
     *
81
     * @param  null  $lang
82
     * @return $this
83
     */
84
    public function lang($lang = null)
12✔
85
    {
86
        $this->lang = $lang;
12✔
87

88
        return $this;
12✔
89
    }
90

91
    /**
92
     * Fluent setter for country
93
     *
94
     * @param  null  $country
95
     * @return $this
96
     */
97
    public function country($country = null)
12✔
98
    {
99
        $this->country = $country;
12✔
100

101
        return $this;
12✔
102
    }
103

104
    /**
105
     * Send the request
106
     *
107
     * @return GenderizeResponse
108
     */
109
    public function get()
6✔
110
    {
111
        $headers = ['Accept' => 'application/json'];
6✔
112

113
        $response = $this->request->get(self::API_URL, $headers, $this->buildQuery());
6✔
114

115
        return new GenderizeResponse($response);
6✔
116
    }
117

118
    /**
119
     * Build the query
120
     *
121
     * @return array
122
     */
123
    protected function buildQuery()
6✔
124
    {
125
        $query = [
126
            'name' => $this->names,
6✔
127
            'country_id' => $this->country,
6✔
128
            'language_id' => $this->lang,
6✔
129
            'apikey' => $this->apikey,
6✔
130
        ];
131

132
        return array_filter($query);
6✔
133
    }
134
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc