Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add header, request body, response body, accompanying tests #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ To contribute code to this module, please follow this workflow:
npm install --dev
```

3. Make the changes you desire
4. Ensure all changes have a new test in the `test/` folder, and run:
3. Copy test-auth.json.template to test-auth.json and add your credentials
4. Make the changes you desire
5. Ensure all changes have a new test in the `test/` folder, and run:

```bash
npm test
Expand All @@ -248,7 +249,7 @@ To contribute code to this module, please follow this workflow:
* Run all mocha tests listed in `test/`
* Run all code through [istanbul's code coverage runner](https://github.com/gotwarlost/istanbul). You can check the coverage afterwards the coverage report page: `coverage/lcov-report/index.html`

5. After making changes in your fork, open a pull request.
6. After making changes in your fork, open a pull request.

Please note that if your code updates do not pass JS Standard style, mocha tests and code coverage, your PR may be rejected and you'll need to fix any issues listed in it.

Expand Down
8 changes: 4 additions & 4 deletions lib/googleadwords.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var GoogleAdwords = function (spec, my) {
my.awqlOptions = {}
my.auth = {}
my.agent = spec.agent
my.host = spec.host || 'https://adwords.google.com/api/adwords/reportdownload/v201409'
my.host = self.host = spec.host || 'https://adwords.google.com/api/adwords/reportdownload/v201409'
my.port = spec.port || 443

/*******************************/
Expand Down Expand Up @@ -128,12 +128,13 @@ var GoogleAdwords = function (spec, my) {
finalAWQL = finalAWQL.split(', ').join(',').split(' ').join('+')
}
my.awqlOptions = {}
var builtAWQL = '__rdquery=' + finalAWQL + '&__fmt=TSV'
var header = _buildHeader(builtAWQL.length)
var builtAWQL = self.builtAWQL = '__rdquery=' + finalAWQL + '&__fmt=TSV'
var header = self.header = _buildHeader(builtAWQL.length)
request.post(my.host)
.header(header)
.send(builtAWQL)
.end(function (results) {
var body = self.rawBody = results.body
if (results.error) {
var msg
if (results.body.indexOf('ReportDefinitionError.INVALID_FIELD_NAME_FOR_REPORT') > -1) {
Expand All @@ -151,7 +152,6 @@ var GoogleAdwords = function (spec, my) {
msg = msg || results.error
return reject(msg)
}
var body = results.body
resolve(_parseResults(body))
})
})
Expand Down
26 changes: 26 additions & 0 deletions test/google-adwords.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,32 @@ describe('google-adwords', function () {
done(error)
})
})
it('should have accessible data about request', function (done) {
ga.use({
accessToken: auth2.user.accessToken,
tokenExpires: auth2.user.tokenExpires,
refreshToken: auth2.user.refreshToken,
clientCustomerID: auth2.user.clientCustomerId
})
ga.awql()
.select(['Date', 'Clicks'])
.from('ACCOUNT_PERFORMANCE_REPORT')
.where('Clicks>100')
.and('Clicks<150')
.and('Clicks!=110')
.during(['20120101', '20150125'])
.send().then(function (results) {
expect(ga.builtAWQL).to.be.a('string')
expect(ga.header).to.be.a('object')
expect(ga.rawBody).to.be.a('string')
done()
})
.catch(function (error) {
console.log(error)
expect(false).to.equal(true)
done(error)
})
})

it('should error out on bad clientID', function (done) {
ga.use({
Expand Down