Skip to content

Commit

Permalink
Merge f3baf52 into c16f007
Browse files Browse the repository at this point in the history
  • Loading branch information
Chyroc-MD committed Jan 11, 2017
2 parents c16f007 + f3baf52 commit 0d02487
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 14 deletions.
16 changes: 15 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
{
"presets": ["latest"]
"presets": [
"latest",
"stage-0"
],
"plugins": [
[
"transform-runtime",
{
"helpers": false,
"polyfill": false,
"regenerator": true,
"moduleName": "babel-runtime"
}
]
]
}
10 changes: 9 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
sudo: required

services:
- docker

language: node_js

node_js:
Expand All @@ -6,5 +11,8 @@ node_js:
- "5"
- "4"

before_install:
- docker run -d -p 12000:12000 jimexist/sqoop

script:
npm run coverage
npm run coverage
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
"coverage": "nyc npm test && nyc report --reporter=text-lcov | coveralls"
},
"dependencies": {
"isomorphic-fetch": "^2.2.1"
"isomorphic-fetch": "^2.2.1",
"url": "^0.11.0"
},
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-core": "^6.21.0",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-latest": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"chai": "^3.5.0",
"coveralls": "^2.11.15",
"mocha": "^3.2.0",
Expand Down
34 changes: 33 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,40 @@
* Created by Chyroc on 17/1/10.
*/

import { sendGetRequest } from './utils/sendRequest'

const url = require('url');

export class Hasoop {
constructor (config) {
this.config = config
this.userName = config.userName
this.host = config.host
this.port = config.port
this.weapp = config.webapp

this.versionUri = 'version'
}

formatUrl ([basicPath, queryString = {}], ...otherPath) {
queryString['user.name'] = this.userName
const query = Object.keys(queryString)
.map(k => encodeURIComponent(k) + '=' + encodeURIComponent(queryString[k]))
.join('&')
let path = [this.weapp, basicPath, otherPath].join('/')
path = path.substring(0, path.length - 1)
const urlObj = {
protocol: 'http:',
slashes: true,
hostname: this.host,
port: this.port,
search: '?' + query,
pathname: path
}
return url.format(urlObj);
}

getVersion () {
const url = this.formatUrl([this.versionUri])
return sendGetRequest(url)
}
}
31 changes: 31 additions & 0 deletions src/utils/sendRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Created by Chyroc on 17/1/10.
*/

const fetch = require('isomorphic-fetch')

function sendRequest (method, url, body = null) {
return fetch(url, {method: method, body: body})
.then(function (res) {
return res.json()
})
.catch(function (err) {
console.log(err)
})
}

export function sendGetRequest (url, body = null) {
return sendRequest('GET', url, body)
}

export function senPostRequest (url, body) {
return sendRequest('POST', url, body)
}

export function senPutRequest (url, body) {
return sendRequest('PUT', url, body)
}

export function senDeleteRequest (url, body = null) {
return sendRequest('DELETE', url, body)
}
13 changes: 13 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Created by Chyroc on 17/1/10.
*/

import { Hasoop } from '../src/index'

const config = {
'userName': 'Developer',
'host': 'localhost',
'port': 12000,
'webapp': 'sqoop'
}
export const sqoopClient = new Hasoop(config)
11 changes: 5 additions & 6 deletions test/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
*/

import { expect } from 'chai'
import { Hasoop } from '../src/index'

const sqoopClient = new Hasoop('')
import { sqoopClient } from './index'

suite('utils', () => {
test.skip('getVersion', () => {
sqoopClient.getVersion()
test('getVersion', async () => {
const data = await sqoopClient.getVersion()
expect(data).to.be.an('object')
expect(data['api-versions'][0]).to.equal('v1')
})

})
Loading

0 comments on commit 0d02487

Please sign in to comment.