new-rajaongkir 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.travis.yml +14 -0
- package/LICENSE +21 -0
- package/README.md +237 -0
- package/appveyor.yml +18 -0
- package/index.js +1 -0
- package/lib/rajaongkir/basic/index.js +376 -0
- package/lib/rajaongkir/index.js +20 -0
- package/lib/rajaongkir/pro/index.js +1038 -0
- package/lib/rajaongkir/starter/index.js +155 -0
- package/package.json +50 -0
- package/test/basic.js +255 -0
- package/test/pro.js +776 -0
- package/test/starter.js +118 -0
package/.travis.yml
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
language: node_js
|
|
2
|
+
node_js:
|
|
3
|
+
- 4
|
|
4
|
+
- 6
|
|
5
|
+
- 7
|
|
6
|
+
before_install:
|
|
7
|
+
- npm install
|
|
8
|
+
script:
|
|
9
|
+
- npm test
|
|
10
|
+
- npm run test-ci
|
|
11
|
+
after_script: npm install coveralls@2.10.0 && cat ./coverage/lcov.info | coveralls
|
|
12
|
+
env:
|
|
13
|
+
global:
|
|
14
|
+
- secure: "nRTDzmE+x1ux0+Dg+rhgcSGECE60VgkIKIfrFoP+L4qzU0aXTqtY+w5IJcNrDGreRFx/AO7wG0zpNp4OZ+o7EfR1qyCcF+LKQS43IMa0+vO2u48Fw6+VDwglJ+ZYFU+/lT1RcPZgoDYi/OPk3VcIl9aVncvKEGvq/JOCH2vvThPD84nXiHjWKizOr41vqIlcUaykmmWwHwGdXmg/hIeCO76GHfc5O7JwmFNAT4HoVmYJpGyjyKX4olQ1IOfloiDKRk05OTyI3G+Q0k26IzYeNNHDIxmfX5epkMu75wJ5t0D/gfW4T8WY8HM3n/mbJFO5tuimlbtPZor7sIUWsh+VO5E3fz0eka8HpqK35Tck5a776HEz6hDOD3d/D5tWkLQ+H4u2yh8tdYS0cxLF3gkjh6g9oLR4GQ1VMzmNdR49CMGLYaBQkhLBi4+K2Jo8J/0G15P+FFZVBIdCriV6NnOEGTwYwnnq/Bv1OFzapPwZajb9esBkhit5+tw8AO8oq8/T8SI+6AUFxX+H7coGtDRB6r3muRLwyepwwiJIRP15cKQNWHL4yHzYEgBQIkCXN1IkInz4mN33+r8FMeqHMaHA4e4d4YRatiz+CESbvVS61vg1kmgu5VGwnKikxhEpnUIzDvkDCM1fqYUfdZ5pBj9UmtRutBbwuJ0XTORAunobebw="
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Andhika Maheva Wicaksono
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# RajaOngkir Node.js
|
|
2
|
+
|
|
3
|
+
[![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url] [![Linux Build][build-image]][build-url] [![Windows Build][appveyor-image]][appveyor-url] [![Coverage Status][coveralls-image]][coveralls-url] [](https://standardjs.com)
|
|
4
|
+
|
|
5
|
+
RajaOngkir Node.js merupakan Node.js Package yang memudahkan pengembang perangkat lunak dalam mengkonsumsi API dari http://rajaongkir.com .
|
|
6
|
+
|
|
7
|
+
Silahkan baca dokumentasi di bawah ini untuk penggunaan lengkap dari RajaOngkir Node.js.
|
|
8
|
+
|
|
9
|
+
# Daftar Isi
|
|
10
|
+
|
|
11
|
+
* [Dokumentasi](#documentation)
|
|
12
|
+
* [Instalasi](#installation)
|
|
13
|
+
* [Quick Start](#quick_start)
|
|
14
|
+
* [Penggunaan](#usage)
|
|
15
|
+
* [Pengumuman](#announcements)
|
|
16
|
+
* [Cara Kontribusi](#contribute)
|
|
17
|
+
* [Tentang](#about)
|
|
18
|
+
* [Lisensi](#license)
|
|
19
|
+
|
|
20
|
+
<a name="documentation"></a>
|
|
21
|
+
# Dokumentasi
|
|
22
|
+
Silahkan buka halaman [Wiki](https://github.com/andhikamaheva/rajaongkir-nodejs/wiki) untuk dokumentasi penggunaan lengkap dari RajaOngkir Node.js
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
<a name="installation"></a>
|
|
26
|
+
# Instalasi
|
|
27
|
+
|
|
28
|
+
## Prasyarat
|
|
29
|
+
- Node.js versi 4, 6 atau 7
|
|
30
|
+
- RajaOngkir Service (telah mendaftar di RajaOngkir.com dengan akun tipe Starter, Basic maupun Pro dan telah memiliki **API Key**)
|
|
31
|
+
|
|
32
|
+
## Cara Install
|
|
33
|
+
Penggunaan Package RajaOngkir Node.js membutuhkan [NPM](https://npmjs.org/). Jika Anda tidak familiar dengan NPM, Anda dapat membaca [NPM Docs](https://npmjs.org/doc/) terlebih dahulu.
|
|
34
|
+
Pada dasarnya NPM telah terinstal dengan Node.js sejak node versi 0.8.x karena itu Anda mungkin sudah memilikinya.
|
|
35
|
+
|
|
36
|
+
Jalankan perintah di bawah ini pada terminal Anda untuk menginstall <code>rajaongkir-nodejs</code> dan menyimpannya di file <code>package.json</code> .
|
|
37
|
+
```bash
|
|
38
|
+
npm install --save rajaongkir-nodejs
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Dependencies
|
|
42
|
+
Terdapat beberapa Dependency yang mendukung RajaOngkir Node.js dapat berjalan, antara lain :
|
|
43
|
+
|
|
44
|
+
### Main Dependencies
|
|
45
|
+
* [fs](https://nodejs.org/api/fs.html)
|
|
46
|
+
* [http](https://www.npmjs.com/package/http)
|
|
47
|
+
* [request](https://github.com/request/request)
|
|
48
|
+
* [promise](https://github.com/then/promise)
|
|
49
|
+
* [querystring](https://github.com/Gozala/querystring)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
### Development Dependencies
|
|
53
|
+
* [assert](https://github.com/defunctzombie/commonjs-assert)
|
|
54
|
+
* [chai](https://github.com/chaijs/chai)
|
|
55
|
+
* [coveralls](https://github.com/nickmerwin/node-coveralls)
|
|
56
|
+
* [istanbul](https://github.com/gotwarlost/istanbul)
|
|
57
|
+
* [mocha](https://github.com/mochajs/mocha)
|
|
58
|
+
* [mocha-lcov-reporter](https://github.com/StevenLooman/mocha-lcov-reporter)
|
|
59
|
+
* [nock](https://github.com/node-nock/nock)
|
|
60
|
+
* [vows](https://github.com/vowsjs/vows)
|
|
61
|
+
* [standard](https://github.com/standard/standard)
|
|
62
|
+
|
|
63
|
+
<a name="quick_start"></a>
|
|
64
|
+
# Quick Start
|
|
65
|
+
|
|
66
|
+
### Menampilkan Seluruh Provinsi (Starter)
|
|
67
|
+
```javascript
|
|
68
|
+
var RajaOngkir = require('rajaongkir-nodejs').Starter('apiKey');
|
|
69
|
+
|
|
70
|
+
RajaOngkir.getProvinces().then(function (result){
|
|
71
|
+
// Aksi ketika data Provinsi berhasil ditampilkan
|
|
72
|
+
}).catch(function (error){
|
|
73
|
+
// Aksi ketika error terjadi
|
|
74
|
+
});
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Menampilkan Spesifik Provinsi (Starter)
|
|
78
|
+
```javascript
|
|
79
|
+
var RajaOngkir = require('rajaongkir-nodejs').Starter('apiKey');
|
|
80
|
+
|
|
81
|
+
var id = 1; // ID Provinsi
|
|
82
|
+
RajaOngkir.getProvince(id).then(function (result){
|
|
83
|
+
// Aksi ketika data Provinsi berhasil ditampilkan
|
|
84
|
+
}).catch(function (error){
|
|
85
|
+
// Aksi ketika error terjadi
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
### Menampilkan Seluruh Kota (Starter)
|
|
89
|
+
```javascript
|
|
90
|
+
var RajaOngkir = require('rajaongkir-nodejs').Starter('apiKey');
|
|
91
|
+
|
|
92
|
+
RajaOngkir.getCities().then(function (result){
|
|
93
|
+
// Aksi ketika data Kota berhasil ditampilkan
|
|
94
|
+
}).catch(function (error){
|
|
95
|
+
// Aksi ketika error terjadi
|
|
96
|
+
});
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Menghitung Biaya Kirim JNE (Starter)
|
|
100
|
+
```javascript
|
|
101
|
+
var RajaOngkir = require('rajaongkir-nodejs').Starter('apiKey');
|
|
102
|
+
|
|
103
|
+
var params = {
|
|
104
|
+
origin: 501, // ID Kota atau Kabupaten Asal
|
|
105
|
+
destination: 114, // ID Kota atau Kabupaten Tujuan
|
|
106
|
+
weight: 1700 // Berat Barang dalam gram (gr)
|
|
107
|
+
};
|
|
108
|
+
RajaOngkir.getJNECost(params).then(function (result){
|
|
109
|
+
// Aksi ketika data Biaya berhasil ditampilkan
|
|
110
|
+
}).catch(function (error){
|
|
111
|
+
// Aksi ketika error terjadi
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
<a name="usage"></a>
|
|
116
|
+
# Penggunaan
|
|
117
|
+
Dalam RajaOngkir Node.js terdapat 3 jenis API yang dapat digunakan yaitu **Starter, Basic, dan Pro** sesuai dengan [dokumentasi](http://rajaongkir.com/dokumentasi) RajaOngkir.com.
|
|
118
|
+
Untuk menjalankan masing - masing API tersebut Anda dapat menggunakan perintah sebagai berikut :
|
|
119
|
+
|
|
120
|
+
### Starter
|
|
121
|
+
```javascript
|
|
122
|
+
var RajaOngkir = require('rajaongkir-nodejs').Starter('apiKey');
|
|
123
|
+
```
|
|
124
|
+
Tipe akun **Starter** memiliki beberapa fitur antara lain :
|
|
125
|
+
* <code>getProvinces()</code> untuk menampilkan seluruh data Provinsi
|
|
126
|
+
* <code>getProvince(idProvinsi)</code> untuk menampilkan data Provinsi berdasarkan ID / parameter ID
|
|
127
|
+
* <code>getCities()</code> untuk menampilkan seluruh data Kota
|
|
128
|
+
* <code>getCity(idKota)</code> untuk menampilkan data Kota berdasarkan ID / Parameter ID
|
|
129
|
+
* <code>getJNECost(params)</code> untuk menampilkan biaya pengiriman Kurir JNE
|
|
130
|
+
* <code>getPOSCost(params)</code> untuk menampilkan biaya pengiriman Kurir POS
|
|
131
|
+
* <code>getTIKICost(params)</code> untuk menampilkan biaya pengiriman Kurir TIKI
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
### Basic
|
|
135
|
+
```javascript
|
|
136
|
+
var RajaOngkir = require('rajaongkir-nodejs').Basic('apiKey');
|
|
137
|
+
```
|
|
138
|
+
Tipe akun **Basic** memiliki beberapa fitur antara lain :
|
|
139
|
+
* <code>getProvinces()</code> untuk menampilkan seluruh data Provinsi
|
|
140
|
+
* <code>getProvince(idProvinsi)</code> untuk menampilkan data Provinsi berdasarkan ID / parameter ID
|
|
141
|
+
* <code>getCities()</code> untuk menampilkan seluruh data Kota
|
|
142
|
+
* <code>getCity(idKota)</code> untuk menampilkan data Kota berdasarkan ID / Parameter ID
|
|
143
|
+
* <code>getJNECost(params)</code> untuk menampilkan biaya pengiriman Kurir JNE
|
|
144
|
+
* <code>getPOSCost(params)</code> untuk menampilkan biaya pengiriman Kurir POS
|
|
145
|
+
* <code>getTIKICost(params)</code> untuk menampilkan biaya pengiriman Kurir TIKI
|
|
146
|
+
* <code>getRPXCost(params)</code> untuk menampilkan biaya pengiriman Kurir RPX
|
|
147
|
+
* <code>getESLCost(params)</code> untuk menampilkan biaya pengiriman Kurir ESL
|
|
148
|
+
* <code>getPCPCost(params)</code> untuk menampilkan biaya pengiriman Kurir PCP
|
|
149
|
+
* <code>getInterOrigins()</code> untuk menampilkan data Kota (asal pengiriman) yang tersedia untuk pengiriman internasional
|
|
150
|
+
* <code>getInterOrigin(idKota)</code> untuk menampilkan data Kota (asal pengiriman) yang tersedia untuk pengiriman internasional berdasarkan ID Kota/Kabupaten
|
|
151
|
+
* <code>getInterDests()</code> untuk menampilkan data Negara yang mendukung pengiriman internasional
|
|
152
|
+
* <code>getInterDest(idNegara)</code> untuk menampilkan data Negara yang mendukung pengiriman internasional berdasarkan ID Negara
|
|
153
|
+
* <code>getTIKIInterConst(params)</code> untuk menampilkan biaya pengiriman internasional melalui kurir TIKI
|
|
154
|
+
* <code>getPOSInterCost(params)</code> untuk menampilkan biaya pengiriman internasional melalui kurir POS
|
|
155
|
+
* <code>getCurrency()</code> untuk menampilkan informasi nilai tukar rupiah terhadap US dollar
|
|
156
|
+
* <code>getJNEWaybill(params)</code> untuk melacak / mengetahui status pengiriman berdasarkan nomor resi JNE
|
|
157
|
+
|
|
158
|
+
### Pro
|
|
159
|
+
```javascript
|
|
160
|
+
var RajaOngkir = require('rajaongkir-nodejs').Pro('apiKey');
|
|
161
|
+
```
|
|
162
|
+
Tipe akun **Basic** memiliki beberapa fitur antara lain :
|
|
163
|
+
* <code>getProvinces()</code> untuk menampilkan seluruh data Provinsi
|
|
164
|
+
* <code>getProvince(idProvinsi)</code> untuk menampilkan data Provinsi berdasarkan ID / parameter ID
|
|
165
|
+
* <code>getCities()</code> untuk menampilkan seluruh data Kota
|
|
166
|
+
* <code>getCity(idKota)</code> untuk menampilkan data Kota berdasarkan ID / Parameter ID
|
|
167
|
+
* <code>getJNECost(params)</code> untuk menampilkan biaya pengiriman Kurir JNE
|
|
168
|
+
* <code>getPOSCost(params)</code> untuk menampilkan biaya pengiriman Kurir POS
|
|
169
|
+
* <code>getTIKICost(params)</code> untuk menampilkan biaya pengiriman Kurir TIKI
|
|
170
|
+
* <code>getRPXCost(params)</code> untuk menampilkan biaya pengiriman Kurir RPX
|
|
171
|
+
* <code>getESLCost(params)</code> untuk menampilkan biaya pengiriman Kurir ESL
|
|
172
|
+
* <code>getPCPCost(params)</code> untuk menampilkan biaya pengiriman Kurir PCP
|
|
173
|
+
* <code>getInterOrigins()</code> untuk menampilkan data Kota (asal pengiriman) yang tersedia untuk pengiriman internasional
|
|
174
|
+
* <code>getInterOrigin(idKota)</code> untuk menampilkan data Kota (asal pengiriman) yang tersedia untuk pengiriman internasional berdasarkan ID Kota/Kabupaten
|
|
175
|
+
* <code>getInterDests()</code> untuk menampilkan data Negara yang mendukung pengiriman internasional
|
|
176
|
+
* <code>getInterDest(idNegara)</code> untuk menampilkan data Negara yang mendukung pengiriman internasional berdasarkan ID Negara
|
|
177
|
+
* <code>getTIKIInterConst(params)</code> untuk menampilkan biaya pengiriman internasional melalui kurir TIKI
|
|
178
|
+
* <code>getPOSInterCost(params)</code> untuk menampilkan biaya pengiriman internasional melalui kurir POS
|
|
179
|
+
* <code>getCurrency()</code> untuk menampilkan informasi nilai tukar rupiah terhadap US dollar
|
|
180
|
+
* <code>getJNEWaybill(params)</code> untuk melacak / mengetahui status pengiriman berdasarkan nomor resi JNE
|
|
181
|
+
|
|
182
|
+
<a name="announcements"></a>
|
|
183
|
+
# Pengumuman
|
|
184
|
+
RajaOngkimumr Node.js masih dalam tahap pengembangan, mungkin semua fitur tidak tercover atau masih terdapat Bug dalam penggunaan API RajaOngkir.com
|
|
185
|
+
|
|
186
|
+
<a name="contribute"></a>
|
|
187
|
+
# Cara Kontribusi
|
|
188
|
+
Saya sangat menghargai setiap kontribusi Anda dalam pengembangan Package RajaOngkir Node.js.
|
|
189
|
+
* Anda dapat Melaporkan issue (Kesalahan Program, Saran, dll) dengan membuat **New Issue** melalui halaman [Issue](https://github.com/andhikamaheva/rajaongkir-nodejs/issues)
|
|
190
|
+
* Anda juga dapat berkontribusi untuk Package ini dengan cara [Pull Request](https://github.com/andhikamaheva/rajaongkir-nodejs/pulls)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
<a name="about"></a>
|
|
194
|
+
# Tentang
|
|
195
|
+
RajaOngkir NodeJS merupakan Package Node.js yang dapat digunakan oleh pengembang perangkat lunak dalam mengkonsumsi API http://rajaongkir.com . RajaOngkir Node.js merupakan Unofficial Package yang dikembangkan oleh pihak eksternal RajaOngkir.com.
|
|
196
|
+
Package ini masih dalam tahap pengembangan dan mungkin terjadi beberapa error dalam penggunaanya.
|
|
197
|
+
|
|
198
|
+
Info lebih lanjut Anda dapat menghubungi Andhika Maheva Wicaksono melalui email [andhikamaheva@gmail.com](mailto:andhikamaheva@gmail.com).
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
<a name="license"></a>
|
|
203
|
+
# Lisensi
|
|
204
|
+
|
|
205
|
+
**MIT License**
|
|
206
|
+
|
|
207
|
+
Copyright (c) 2017 Andhika Maheva Wicaksono
|
|
208
|
+
|
|
209
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
210
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
211
|
+
in the Software without restriction, including without limitation the rights
|
|
212
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
213
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
214
|
+
furnished to do so, subject to the following conditions:
|
|
215
|
+
|
|
216
|
+
The above copyright notice and this permission notice shall be included in all
|
|
217
|
+
copies or substantial portions of the Software.
|
|
218
|
+
|
|
219
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
220
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
221
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
222
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
223
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
224
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
225
|
+
SOFTWARE.
|
|
226
|
+
|
|
227
|
+
[build-image]: https://img.shields.io/travis/andhikamaheva/rajaongkir-nodejs/master.svg?label=linux
|
|
228
|
+
[build-url]: https://travis-ci.org/andhikamaheva/rajaongkir-nodejs
|
|
229
|
+
[npm-image]: https://badge.fury.io/js/rajaongkir-nodejs.svg
|
|
230
|
+
[npm-url]: https://badge.fury.io/js/rajaongkir-nodejs
|
|
231
|
+
[downloads-image]: https://img.shields.io/npm/dm/rajaongkir-nodejs.svg
|
|
232
|
+
[downloads-url]: https://npmjs.org/package/rajaongkir-nodejs
|
|
233
|
+
[appveyor-image]: https://img.shields.io/appveyor/ci/andhikamaheva/rajaongkir-nodejs/master.svg?label=windows
|
|
234
|
+
[appveyor-url]: https://ci.appveyor.com/project/andhikamaheva/rajaongkir-nodejs
|
|
235
|
+
[coveralls-image]: https://coveralls.io/repos/github/andhikamaheva/rajaongkir-nodejs/badge.svg?branch=master
|
|
236
|
+
[coveralls-url]: https://coveralls.io/github/andhikamaheva/rajaongkir-nodejs?branch=master
|
|
237
|
+
|
package/appveyor.yml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
environment:
|
|
2
|
+
matrix:
|
|
3
|
+
- nodejs_version: "4.8"
|
|
4
|
+
- nodejs_version: "5.12"
|
|
5
|
+
- nodejs_version: "6.11"
|
|
6
|
+
- nodejs_version: "7.10"
|
|
7
|
+
cache:
|
|
8
|
+
- node_modules
|
|
9
|
+
install:
|
|
10
|
+
- ps: Install-Product node $env:nodejs_version
|
|
11
|
+
- if exist node_modules npm prune
|
|
12
|
+
- if exist node_modules npm rebuild
|
|
13
|
+
- npm install
|
|
14
|
+
build: off
|
|
15
|
+
test_script:
|
|
16
|
+
- node --version
|
|
17
|
+
- npm --version
|
|
18
|
+
version: "{build}"
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./lib/rajaongkir')
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
var http = require('http')
|
|
2
|
+
var request = require('request')
|
|
3
|
+
var Promise = require('promise')
|
|
4
|
+
|
|
5
|
+
function Basic (apiKey) {
|
|
6
|
+
this.version = 'basic'
|
|
7
|
+
this.apiKey = apiKey
|
|
8
|
+
this.httpUri = 'http://api.rajaongkir.com/' + this.version
|
|
9
|
+
this.couriers = {
|
|
10
|
+
JNE: 'jne',
|
|
11
|
+
TIKI: 'tiki',
|
|
12
|
+
POS: 'pos',
|
|
13
|
+
RPX: 'rpx',
|
|
14
|
+
ESL: 'esl',
|
|
15
|
+
PCP: 'pcp'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = Basic
|
|
20
|
+
|
|
21
|
+
Basic.prototype.getProvinces = function () {
|
|
22
|
+
var uri = this.httpUri + '/province'
|
|
23
|
+
var apiKey = this.apiKey
|
|
24
|
+
return new Promise(function (resolve, reject) {
|
|
25
|
+
request({
|
|
26
|
+
uri: uri,
|
|
27
|
+
method: 'GET',
|
|
28
|
+
headers: {
|
|
29
|
+
'key': apiKey
|
|
30
|
+
}
|
|
31
|
+
}, function (error, response, body) {
|
|
32
|
+
var result = JSON.parse(body)
|
|
33
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
34
|
+
resolve(result)
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
Basic.prototype.getProvince = function (id) {
|
|
40
|
+
var uri = this.httpUri + '/province?id=' + id
|
|
41
|
+
var apiKey = this.apiKey
|
|
42
|
+
return new Promise(function (resolve, reject) {
|
|
43
|
+
request({
|
|
44
|
+
uri: uri,
|
|
45
|
+
method: 'GET',
|
|
46
|
+
headers: {
|
|
47
|
+
'key': apiKey
|
|
48
|
+
}
|
|
49
|
+
}, function (error, response, body) {
|
|
50
|
+
var result = JSON.parse(body)
|
|
51
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
52
|
+
|
|
53
|
+
resolve(result)
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
Basic.prototype.getCities = function () {
|
|
59
|
+
var uri = this.httpUri + '/city'
|
|
60
|
+
var apiKey = this.apiKey
|
|
61
|
+
return new Promise(function (resolve, reject) {
|
|
62
|
+
request({
|
|
63
|
+
uri: uri,
|
|
64
|
+
method: 'GET',
|
|
65
|
+
headers: {
|
|
66
|
+
'key': apiKey
|
|
67
|
+
}
|
|
68
|
+
}, function (error, response, body) {
|
|
69
|
+
var result = JSON.parse(body)
|
|
70
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
71
|
+
|
|
72
|
+
resolve(result)
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
Basic.prototype.getCity = function (id) {
|
|
78
|
+
var uri = this.httpUri + '/city?id=' + id
|
|
79
|
+
var apiKey = this.apiKey
|
|
80
|
+
return new Promise(function (resolve, reject) {
|
|
81
|
+
request({
|
|
82
|
+
uri: uri,
|
|
83
|
+
method: 'GET',
|
|
84
|
+
headers: {
|
|
85
|
+
'key': apiKey
|
|
86
|
+
}
|
|
87
|
+
}, function (error, response, body) {
|
|
88
|
+
var result = JSON.parse(body)
|
|
89
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
90
|
+
|
|
91
|
+
resolve(result)
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
Basic.prototype.getJNECost = function (params) {
|
|
97
|
+
var uri = this.httpUri + '/cost'
|
|
98
|
+
var apiKey = this.apiKey
|
|
99
|
+
params.courier = this.couriers.JNE
|
|
100
|
+
return new Promise(function (resolve, reject) {
|
|
101
|
+
request({
|
|
102
|
+
uri: uri,
|
|
103
|
+
method: 'POST',
|
|
104
|
+
headers: {
|
|
105
|
+
'key': apiKey,
|
|
106
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
107
|
+
},
|
|
108
|
+
form: params
|
|
109
|
+
}, function (error, response, body) {
|
|
110
|
+
var result = JSON.parse(body)
|
|
111
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
112
|
+
|
|
113
|
+
resolve(result)
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
Basic.prototype.getTIKICost = function (params) {
|
|
119
|
+
var uri = this.httpUri + '/cost'
|
|
120
|
+
var apiKey = this.apiKey
|
|
121
|
+
params.courier = this.couriers.TIKI
|
|
122
|
+
return new Promise(function (resolve, reject) {
|
|
123
|
+
request({
|
|
124
|
+
uri: uri,
|
|
125
|
+
method: 'POST',
|
|
126
|
+
headers: {
|
|
127
|
+
'key': apiKey,
|
|
128
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
129
|
+
},
|
|
130
|
+
form: params
|
|
131
|
+
}, function (error, response, body) {
|
|
132
|
+
var result = JSON.parse(body)
|
|
133
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
134
|
+
|
|
135
|
+
resolve(result)
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
Basic.prototype.getPOSCost = function (params) {
|
|
141
|
+
var uri = this.httpUri + '/cost'
|
|
142
|
+
var apiKey = this.apiKey
|
|
143
|
+
params.courier = this.couriers.POS
|
|
144
|
+
return new Promise(function (resolve, reject) {
|
|
145
|
+
request({
|
|
146
|
+
uri: uri,
|
|
147
|
+
method: 'POST',
|
|
148
|
+
headers: {
|
|
149
|
+
'key': apiKey,
|
|
150
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
151
|
+
},
|
|
152
|
+
form: params
|
|
153
|
+
}, function (error, response, body) {
|
|
154
|
+
var result = JSON.parse(body)
|
|
155
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
156
|
+
resolve(result)
|
|
157
|
+
})
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
Basic.prototype.getRPXCost = function (params) {
|
|
162
|
+
var uri = this.httpUri + '/cost'
|
|
163
|
+
var apiKey = this.apiKey
|
|
164
|
+
params.courier = this.couriers.RPX
|
|
165
|
+
return new Promise(function (resolve, reject) {
|
|
166
|
+
request({
|
|
167
|
+
uri: uri,
|
|
168
|
+
method: 'POST',
|
|
169
|
+
headers: {
|
|
170
|
+
'key': apiKey,
|
|
171
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
172
|
+
},
|
|
173
|
+
form: params
|
|
174
|
+
}, function (error, response, body) {
|
|
175
|
+
var result = JSON.parse(body)
|
|
176
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
177
|
+
resolve(result)
|
|
178
|
+
})
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
Basic.prototype.getESLCost = function (params) {
|
|
183
|
+
var uri = this.httpUri + '/cost'
|
|
184
|
+
var apiKey = this.apiKey
|
|
185
|
+
params.courier = this.couriers.ESL
|
|
186
|
+
return new Promise(function (resolve, reject) {
|
|
187
|
+
request({
|
|
188
|
+
uri: uri,
|
|
189
|
+
method: 'POST',
|
|
190
|
+
headers: {
|
|
191
|
+
'key': apiKey,
|
|
192
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
193
|
+
},
|
|
194
|
+
form: params
|
|
195
|
+
}, function (error, response, body) {
|
|
196
|
+
var result = JSON.parse(body)
|
|
197
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
198
|
+
resolve(result)
|
|
199
|
+
})
|
|
200
|
+
})
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
Basic.prototype.getPCPCost = function (params) {
|
|
204
|
+
var uri = this.httpUri + '/cost'
|
|
205
|
+
var apiKey = this.apiKey
|
|
206
|
+
params.courier = this.couriers.PCP
|
|
207
|
+
return new Promise(function (resolve, reject) {
|
|
208
|
+
request({
|
|
209
|
+
uri: uri,
|
|
210
|
+
method: 'POST',
|
|
211
|
+
headers: {
|
|
212
|
+
'key': apiKey,
|
|
213
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
214
|
+
},
|
|
215
|
+
form: params
|
|
216
|
+
}, function (error, response, body) {
|
|
217
|
+
var result = JSON.parse(body)
|
|
218
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
219
|
+
resolve(result)
|
|
220
|
+
})
|
|
221
|
+
})
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
Basic.prototype.getInterOrigins = function () {
|
|
225
|
+
var uri = this.httpUri + '/v2/internationalOrigin'
|
|
226
|
+
var apiKey = this.apiKey
|
|
227
|
+
return new Promise(function (resolve, reject) {
|
|
228
|
+
request({
|
|
229
|
+
uri: uri,
|
|
230
|
+
method: 'GET',
|
|
231
|
+
headers: {
|
|
232
|
+
'key': apiKey
|
|
233
|
+
}
|
|
234
|
+
}, function (error, response, body) {
|
|
235
|
+
var result = JSON.parse(body)
|
|
236
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
237
|
+
resolve(result)
|
|
238
|
+
})
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
Basic.prototype.getInterOrigin = function (id) {
|
|
243
|
+
var uri = this.httpUri + '/v2/internationalOrigin?id=' + id
|
|
244
|
+
var apiKey = this.apiKey
|
|
245
|
+
return new Promise(function (resolve, reject) {
|
|
246
|
+
request({
|
|
247
|
+
uri: uri,
|
|
248
|
+
method: 'GET',
|
|
249
|
+
headers: {
|
|
250
|
+
'key': apiKey
|
|
251
|
+
}
|
|
252
|
+
}, function (error, response, body) {
|
|
253
|
+
var result = JSON.parse(body)
|
|
254
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
255
|
+
resolve(result)
|
|
256
|
+
})
|
|
257
|
+
})
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
Basic.prototype.getInterDests = function () {
|
|
261
|
+
var uri = this.httpUri + '/v2/internationalDestination'
|
|
262
|
+
var apiKey = this.apiKey
|
|
263
|
+
return new Promise(function (resolve, reject) {
|
|
264
|
+
request({
|
|
265
|
+
uri: uri,
|
|
266
|
+
method: 'GET',
|
|
267
|
+
headers: {
|
|
268
|
+
'key': apiKey
|
|
269
|
+
}
|
|
270
|
+
}, function (error, response, body) {
|
|
271
|
+
var result = JSON.parse(body)
|
|
272
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
273
|
+
resolve(result)
|
|
274
|
+
})
|
|
275
|
+
})
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
Basic.prototype.getInterDest = function (id) {
|
|
279
|
+
var uri = this.httpUri + '/v2/internationalDestination?id=' + id
|
|
280
|
+
var apiKey = this.apiKey
|
|
281
|
+
return new Promise(function (resolve, reject) {
|
|
282
|
+
request({
|
|
283
|
+
uri: uri,
|
|
284
|
+
method: 'GET',
|
|
285
|
+
headers: {
|
|
286
|
+
'key': apiKey
|
|
287
|
+
}
|
|
288
|
+
}, function (error, response, body) {
|
|
289
|
+
var result = JSON.parse(body)
|
|
290
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
291
|
+
resolve(result)
|
|
292
|
+
})
|
|
293
|
+
})
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
Basic.prototype.getTIKIInterConst = function (params) {
|
|
297
|
+
var uri = this.httpUri + '/v2/internationalCost'
|
|
298
|
+
var apiKey = this.apiKey
|
|
299
|
+
params.courier = this.couriers.TIKI
|
|
300
|
+
return new Promise(function (resolve, reject) {
|
|
301
|
+
request({
|
|
302
|
+
uri: uri,
|
|
303
|
+
method: 'POST',
|
|
304
|
+
headers: {
|
|
305
|
+
'key': apiKey,
|
|
306
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
307
|
+
},
|
|
308
|
+
form: params
|
|
309
|
+
}, function (error, response, body) {
|
|
310
|
+
var result = JSON.parse(body)
|
|
311
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
312
|
+
resolve(result)
|
|
313
|
+
})
|
|
314
|
+
})
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
Basic.prototype.getPOSInterCost = function (params) {
|
|
318
|
+
var uri = this.httpUri + '/v2/internationalCost'
|
|
319
|
+
var apiKey = this.apiKey
|
|
320
|
+
params.courier = this.couriers.POS
|
|
321
|
+
return new Promise(function (resolve, reject) {
|
|
322
|
+
request({
|
|
323
|
+
uri: uri,
|
|
324
|
+
method: 'POST',
|
|
325
|
+
headers: {
|
|
326
|
+
'key': apiKey,
|
|
327
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
328
|
+
},
|
|
329
|
+
form: params
|
|
330
|
+
}, function (error, response, body) {
|
|
331
|
+
var result = JSON.parse(body)
|
|
332
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
333
|
+
resolve(result)
|
|
334
|
+
})
|
|
335
|
+
})
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
Basic.prototype.getCurrency = function () {
|
|
339
|
+
var uri = this.httpUri + '/currency'
|
|
340
|
+
var apiKey = this.apiKey
|
|
341
|
+
return new Promise(function (resolve, reject) {
|
|
342
|
+
request({
|
|
343
|
+
uri: uri,
|
|
344
|
+
method: 'GET',
|
|
345
|
+
headers: {
|
|
346
|
+
'key': apiKey
|
|
347
|
+
}
|
|
348
|
+
}, function (error, response, body) {
|
|
349
|
+
var result = JSON.parse(body)
|
|
350
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
351
|
+
resolve(result)
|
|
352
|
+
})
|
|
353
|
+
})
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
Basic.prototype.getJNEWaybill = function (params) {
|
|
357
|
+
var uri = this.httpUri + '/waybill'
|
|
358
|
+
var apiKey = this.apiKey
|
|
359
|
+
params.courier = this.couriers.JNE
|
|
360
|
+
return new Promise(function (resolve, reject) {
|
|
361
|
+
request({
|
|
362
|
+
uri: uri,
|
|
363
|
+
method: 'POST',
|
|
364
|
+
headers: {
|
|
365
|
+
'key': apiKey,
|
|
366
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
367
|
+
},
|
|
368
|
+
form: params
|
|
369
|
+
}, function (error, response, body) {
|
|
370
|
+
var result = JSON.parse(body)
|
|
371
|
+
if (result.rajaongkir.status.code !== 200) reject(result)
|
|
372
|
+
|
|
373
|
+
resolve(result)
|
|
374
|
+
})
|
|
375
|
+
})
|
|
376
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
var Starter = require('./starter'),
|
|
2
|
+
Basic = require('./basic'),
|
|
3
|
+
Pro = require('./pro'),
|
|
4
|
+
fs = require('fs')
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
Starter: function (apiKey) {
|
|
8
|
+
if (!apiKey) throw new Error('You must provide RajaOngkir API key')
|
|
9
|
+
return new Starter(apiKey)
|
|
10
|
+
},
|
|
11
|
+
Basic: function (apiKey) {
|
|
12
|
+
if (!apiKey) throw new Error('You must provide RajaOngkir API key')
|
|
13
|
+
return new Basic(apiKey)
|
|
14
|
+
},
|
|
15
|
+
Pro: function (apiKey) {
|
|
16
|
+
if (!apiKey) throw new Error('You must provide RajaOngkir API key')
|
|
17
|
+
return new Pro(apiKey)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
}
|