├── .github
└── FUNDING.yml
├── .gitignore
├── LICENSE
├── README.md
├── composer.json
├── config
└── upcitemdb.php
└── src
├── UPCItemDB.php
├── UPCItemDBManager.php
└── UPCItemDBServiceProvider.php
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | open_collective: infyomlabs
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | vendor/
2 | .env.*.php
3 | .env.php
4 | .env
5 | .idea
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 InfyOm Labs (InfyOm Technologies)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |

2 |
3 | Laravel UPCItemDB
4 | ==========================
5 |
6 | [](https://packagist.org/packages/infyomlabs/laravel-upcitemdb)
7 | [](https://packagist.org/packages/infyomlabs/laravel-upcitemdb)
8 | [](https://packagist.org/packages/infyomlabs/laravel-upcitemdb)
9 | [](https://packagist.org/packages/infyomlabs/laravel-upcitemdb)
10 |
11 | ## Documentation
12 |
13 | Read [Documentation](https://infyom.com/open-source/laravel-upcitemdb/docs) for detailed installation steps and usage.
14 |
15 | ## Support Us
16 |
17 | We have created [14+ Laravel packages](https://github.com/InfyOmLabs) and invested a lot of resources into creating these all packages and maintaining them.
18 |
19 | You can support us by either sponsoring us or buying one of our paid products. Or help us by spreading the word about us on social platforms via tweets and posts.
20 |
21 | ### Buy our Paid Products
22 |
23 | [](https://bit.ly/infy-gpt)
24 |
25 | You can also check out our other paid products on [CodeCanyon](https://1.envato.market/BXAnR1).
26 |
27 | ### Sponsors
28 |
29 | [Become a sponsor](https://opencollective.com/infyomlabs#sponsor) and get your logo on our README on Github with a link to your site.
30 |
31 |
32 |
33 | ### Backers
34 |
35 | [Become a backer](https://opencollective.com/infyomlabs#backer) and get your image on our README on Github with a link to your site.
36 |
37 |
38 |
39 | ### Follow Us
40 |
41 | - [Twitter](https://twitter.com/infyom)
42 | - [Facebook](https://www.facebook.com/infyom)
43 | - [LinkedIn](https://in.linkedin.com/company/infyom-technologies)
44 | - [Youtube](https://www.youtube.com/channel/UC8IvwfChD6i7Wp4yZp3tNsQ)
45 | - [Contact Us](https://infyom.com/contact-us)
46 |
47 | ## Made with InfyOm Generator
48 |
49 | Also, Do not forget to add your website to [Made with InfyOm Generator List](https://github.com/InfyOmLabs/laravel-generator/blob/develop/made-with-generator.md) list.
50 |
51 | ## Security
52 |
53 | If you discover any security-related issues, create an issue using the issue tracker.
54 |
55 | ## Credits
56 |
57 | - [InfyOm Technologies](https://github.com/infyomlabs)
58 | - [All Contributors](../../contributors)
59 |
60 | ## License
61 |
62 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
63 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "infyomlabs/laravel-upcitemdb",
3 | "description": "Laravel Wrapper for UPCItemDB.",
4 | "type": "library",
5 | "keywords": [
6 | "laravel",
7 | "upcitemdb",
8 | "infyom",
9 | "upc lookup",
10 | "upc",
11 | "ean",
12 | "isbn"
13 | ],
14 | "authors": [
15 | {
16 | "name": "Mitul Golakiya",
17 | "email": "me@mitul.me"
18 | }
19 | ],
20 | "license": "MIT",
21 | "require": {
22 | "php": "^7.2.5|^8.0",
23 | "illuminate/support": "^6.0|^7.0|^8.0|^9.0",
24 | "guzzlehttp/guzzle": "~6.0|^7.4"
25 | },
26 | "require-dev": {
27 | "phpunit/phpunit": "^8.5.8|^9.5"
28 | },
29 | "autoload": {
30 | "psr-4": {
31 | "InfyOm\\UPCItemDB\\": "src/"
32 | }
33 | },
34 | "extra": {
35 | "laravel": {
36 | "providers": [
37 | "\\InfyOm\\UPCItemDB\\UPCItemDBServiceProvider"
38 | ],
39 | "aliases": {
40 | "UPCItemDB": "InfyOm\\UPCItemDB\\UPCItemDB"
41 | }
42 | }
43 | },
44 | "funding": [
45 | {
46 | "type": "opencollective",
47 | "url": "https://opencollective.com/infyomlabs"
48 | }
49 | ]
50 | }
51 |
--------------------------------------------------------------------------------
/config/upcitemdb.php:
--------------------------------------------------------------------------------
1 | 'https://api.upcitemdb.com/prod/trial/',
16 |
17 | /*
18 | |-------------------------------------------------------------------------------------------
19 | | Key Type - Needed for paid plans
20 | |-------------------------------------------------------------------------------------------
21 | |
22 | */
23 | 'key_type' => '',
24 |
25 | /*
26 | |-------------------------------------------------------------------------------------------
27 | | User Key - Needed for paid plans
28 | |-------------------------------------------------------------------------------------------
29 | |
30 | */
31 | 'user_key' => '',
32 | ];
33 |
--------------------------------------------------------------------------------
/src/UPCItemDB.php:
--------------------------------------------------------------------------------
1 | client;
21 | }
22 |
23 | /**
24 | * @param ClientInterface $client
25 | */
26 | public function setClient(ClientInterface $client)
27 | {
28 | $this->client = $client;
29 | }
30 |
31 | /**
32 | * UPCItemDBManager constructor.
33 | */
34 | public function __construct()
35 | {
36 | $this->initClient();
37 | }
38 |
39 | protected function initClient()
40 | {
41 | $url = config('upcitemdb.url');
42 |
43 | $this->client = new Client([
44 | 'base_uri' => $url,
45 | ]);
46 | }
47 |
48 | /**
49 | * @return array
50 | */
51 | protected function getHeaders()
52 | {
53 | $headers = [
54 | 'Content-Type' => 'application/json',
55 | 'Accept' => 'application/json',
56 | ];
57 |
58 | $keyType = config('upcitemdb.key_type');
59 |
60 | if (!empty($keyType)) {
61 | $headers['key_type'] = $keyType;
62 | }
63 |
64 | $userKey = config('upcitemdb.user_key');
65 |
66 | if (!empty($userKey)) {
67 | $headers['user_key'] = $userKey;
68 | }
69 |
70 | return $headers;
71 | }
72 |
73 | /**
74 | * @param string $upc
75 | *
76 | * @throws \Exception
77 | * @throws \GuzzleHttp\Exception\GuzzleException
78 | *
79 | * @return array|mixed
80 | */
81 | public function lookup($upc)
82 | {
83 | $headers = $this->getHeaders();
84 |
85 | try {
86 | $response = $this->client->request('GET', 'lookup', [
87 | 'headers' => $headers,
88 | 'query' => ['upc' => $upc],
89 | ]);
90 | $body = $response->getBody();
91 |
92 | return json_decode($body->getContents(), true);
93 | } catch (\Exception $exception) {
94 | return [
95 | 'code' => $exception->getCode(),
96 | 'message' => $exception->getMessage(),
97 | ];
98 | }
99 | }
100 |
101 | /**
102 | * @param string|array $search
103 | * @param array $options
104 | *
105 | * @throws \GuzzleHttp\Exception\GuzzleException
106 | *
107 | * @return array|mixed
108 | */
109 | public function search($search, $options = [])
110 | {
111 | $query = array_merge(['s' => $search], $options);
112 |
113 | $headers = $this->getHeaders();
114 |
115 | $response = null;
116 |
117 | try {
118 | $response = $this->client->request('GET', 'search', [
119 | 'headers' => $headers,
120 | 'query' => $query,
121 | ]);
122 | $body = $response->getBody();
123 |
124 | return json_decode($body->getContents(), true);
125 | } catch (\Exception $exception) {
126 | return [
127 | 'code' => $exception->getCode(),
128 | 'message' => $exception->getMessage(),
129 | ];
130 | }
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/src/UPCItemDBServiceProvider.php:
--------------------------------------------------------------------------------
1 | publishes([
19 | $configPath => config_path('upcitemdb.php'),
20 | ]);
21 | }
22 |
23 | /**
24 | * Register the application services.
25 | *
26 | * @return void
27 | */
28 | public function register()
29 | {
30 | $this->app->singleton('upcitemdb', function ($app) {
31 | return new UPCItemDBManager();
32 | });
33 | }
34 | }
35 |
--------------------------------------------------------------------------------