Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Challonge
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Challonge
Commits
5b7f73ea
Commit
5b7f73ea
authored
Nov 24, 2013
by
Aaron Tidwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comments
parent
95cfe9b2
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
25 additions
and
19 deletions
+25
-19
lib/api/client.js
lib/api/client.js
+14
-10
lib/api/error-handler.js
lib/api/error-handler.js
+1
-0
lib/api/matches.js
lib/api/matches.js
+1
-1
lib/api/participants.js
lib/api/participants.js
+2
-1
lib/api/tournaments.js
lib/api/tournaments.js
+1
-1
lib/challonge.js
lib/challonge.js
+6
-5
test/test.js
test/test.js
+0
-1
No files found.
lib/api/client.js
View file @
5b7f73ea
...
@@ -13,6 +13,7 @@ var errorHandler = require('./error-handler');
...
@@ -13,6 +13,7 @@ var errorHandler = require('./error-handler');
var
Client
=
exports
.
Client
=
function
(
options
)
{
var
Client
=
exports
.
Client
=
function
(
options
)
{
this
.
options
=
options
;
this
.
options
=
options
;
// add a getter to the options passed in - DO NOT mess with instance configs in resources
if
(
typeof
this
.
options
.
get
!==
'
function
'
)
{
if
(
typeof
this
.
options
.
get
!==
'
function
'
)
{
this
.
options
.
get
=
function
(
key
)
{
this
.
options
.
get
=
function
(
key
)
{
return
this
[
key
];
return
this
[
key
];
...
@@ -20,19 +21,18 @@ var Client = exports.Client = function(options) {
...
@@ -20,19 +21,18 @@ var Client = exports.Client = function(options) {
}
}
};
};
var
propertiesToDelete
=
[
'
callback
'
,
'
path
'
,
'
method
'
];
var
propertiesToDelete
=
[
'
callback
'
,
'
path
'
,
'
method
'
];
// resources generate props internal to https requests
// cleans the passed in object, generates the API url/query-string, makes the request, delegates errors and calls callbacks
// cleans the passed in object, generates the API url/query-string, makes the request, delegates errors and calls callbacks
Client
.
prototype
.
makeRequest
=
function
(
obj
)
{
Client
.
prototype
.
makeRequest
=
function
(
obj
)
{
var
err
;
var
self
=
this
;
// cache vars that are about to be removed
// clean up the object to get ready to send it to the API
var
callback
=
obj
.
callback
;
var
callback
=
obj
.
callback
;
var
path
=
obj
.
path
;
var
path
=
obj
.
path
;
var
method
=
obj
.
method
;
var
method
=
obj
.
method
;
obj
.
api_key
=
this
.
options
.
get
(
'
apiKey
'
);
//convert for url
var
self
=
this
;
// massage camel to underscore
obj
.
api_key
=
this
.
options
.
get
(
'
apiKey
'
);
//convert for url
// serialize nested params to tournament[name] style
// serialize nested params to tournament[name] style
var
compiledParams
=
''
;
var
compiledParams
=
''
;
...
@@ -48,31 +48,35 @@ Client.prototype.makeRequest = function(obj) {
...
@@ -48,31 +48,35 @@ Client.prototype.makeRequest = function(obj) {
}
}
}
}
// remove params
propertiesToDelete
.
forEach
(
function
(
prop
)
{
propertiesToDelete
.
forEach
(
function
(
prop
)
{
delete
obj
[
prop
];
delete
obj
[
prop
];
});
});
//generate path
//
generate path
path
=
path
+
'
.
'
+
this
.
options
.
get
(
'
format
'
)
+
'
?
'
+
qs
.
stringify
(
obj
)
+
compiledParams
;
path
=
path
+
'
.
'
+
this
.
options
.
get
(
'
format
'
)
+
'
?
'
+
qs
.
stringify
(
obj
)
+
compiledParams
;
// opts for the https call
var
options
=
{
var
options
=
{
hostname
:
'
api.challonge.com
'
,
hostname
:
'
api.challonge.com
'
,
path
:
path
,
path
:
path
,
method
:
method
,
method
:
method
,
headers
:
{
headers
:
{
'
Content-Length
'
:
0
//
server throww
nginx error without a content-length
'
Content-Length
'
:
0
//
server throws
nginx error without a content-length
}
}
};
};
console
.
log
(
'
making request to
'
,
path
,
options
);
console
.
log
(
'
making request to
'
,
path
,
options
);
var
req
=
https
.
request
(
options
,
function
(
res
)
{
var
req
=
https
.
request
(
options
,
function
(
res
)
{
// store the chunked data as it comes back
var
resData
=
''
;
var
resData
=
''
;
res
.
on
(
'
data
'
,
function
(
chunk
)
{
res
.
on
(
'
data
'
,
function
(
chunk
)
{
resData
+=
chunk
;
resData
+=
chunk
;
});
});
res
.
on
(
'
end
'
,
function
()
{
res
.
on
(
'
end
'
,
function
()
{
//error
//
error
if
(
res
.
statusCode
!==
200
)
{
if
(
res
.
statusCode
!==
200
)
{
errorHandler
.
handle
(
res
,
resData
,
callback
);
errorHandler
.
handle
(
res
,
resData
,
callback
);
return
;
return
;
...
@@ -81,7 +85,7 @@ Client.prototype.makeRequest = function(obj) {
...
@@ -81,7 +85,7 @@ Client.prototype.makeRequest = function(obj) {
if
(
self
.
options
.
get
(
'
format
'
)
==
'
json
'
)
{
if
(
self
.
options
.
get
(
'
format
'
)
==
'
json
'
)
{
resData
=
JSON
.
parse
(
resData
);
resData
=
JSON
.
parse
(
resData
);
}
}
callback
(
err
,
resData
);
callback
(
null
,
resData
);
//no error, so no err object
});
});
});
});
...
...
lib/api/error-handler.js
View file @
5b7f73ea
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
// 422 - Validation error(s) for create or update method
// 422 - Validation error(s) for create or update method
exports
.
handle
=
function
(
res
,
resData
,
callback
)
{
exports
.
handle
=
function
(
res
,
resData
,
callback
)
{
var
err
;
// 401 - Invalid API key
// 401 - Invalid API key
if
(
res
.
statusCode
===
401
)
{
if
(
res
.
statusCode
===
401
)
{
err
=
{
err
=
{
...
...
lib/api/matches.js
View file @
5b7f73ea
...
@@ -6,7 +6,7 @@ var util = require('util');
...
@@ -6,7 +6,7 @@ var util = require('util');
var
Client
=
require
(
'
./client
'
).
Client
;
var
Client
=
require
(
'
./client
'
).
Client
;
var
Matches
=
exports
.
Matches
=
function
(
options
)
{
var
Matches
=
exports
.
Matches
=
function
(
options
)
{
Client
.
call
(
this
,
options
);
Client
.
call
(
this
,
options
);
// call parent constructor
};
};
// Inherit from Client base object
// Inherit from Client base object
...
...
lib/api/participants.js
View file @
5b7f73ea
...
@@ -4,11 +4,12 @@
...
@@ -4,11 +4,12 @@
// update PUT tournaments/:tournament/participants/:participant_id
// update PUT tournaments/:tournament/participants/:participant_id
// destroy DELETE tournaments/:tournament/participants/:participant_id
// destroy DELETE tournaments/:tournament/participants/:participant_id
// randomize GET tournaments/:tournament/participants/randomize
// randomize GET tournaments/:tournament/participants/randomize
var
util
=
require
(
'
util
'
);
var
util
=
require
(
'
util
'
);
var
Client
=
require
(
'
./client
'
).
Client
;
var
Client
=
require
(
'
./client
'
).
Client
;
var
Participants
=
exports
.
Participants
=
function
(
options
)
{
var
Participants
=
exports
.
Participants
=
function
(
options
)
{
Client
.
call
(
this
,
options
);
Client
.
call
(
this
,
options
);
// call parent constructor
};
};
// Inherit from Client base object
// Inherit from Client base object
...
...
lib/api/tournaments.js
View file @
5b7f73ea
...
@@ -11,7 +11,7 @@ var util = require('util');
...
@@ -11,7 +11,7 @@ var util = require('util');
var
Client
=
require
(
'
./client
'
).
Client
;
var
Client
=
require
(
'
./client
'
).
Client
;
var
Tournaments
=
exports
.
Tournaments
=
function
(
options
)
{
var
Tournaments
=
exports
.
Tournaments
=
function
(
options
)
{
Client
.
call
(
this
,
options
);
Client
.
call
(
this
,
options
);
// call parent constructor
};
};
// Inherit from Client base object
// Inherit from Client base object
...
...
lib/challonge.js
View file @
5b7f73ea
...
@@ -6,14 +6,15 @@ parts.forEach(function forEach(k) {
...
@@ -6,14 +6,15 @@ parts.forEach(function forEach(k) {
exports
[
k
]
=
require
(
'
./api/
'
+
k
.
toLowerCase
())[
k
];
exports
[
k
]
=
require
(
'
./api/
'
+
k
.
toLowerCase
())[
k
];
});
});
/
/
/
*
//
### function createClient(options)
### function createClient(options)
//
#### @options {Object} options for the clients
#### @options {Object} options for the clients
//
Generates a new API client.
Generates a new API client.
/
/
*
/
exports
.
createClient
=
function
createClient
(
options
)
{
exports
.
createClient
=
function
createClient
(
options
)
{
var
client
=
{};
var
client
=
{};
// require each lib in ./api and instantiate a new instance of each object, passing the options we were passed
parts
.
forEach
(
function
generate
(
k
)
{
parts
.
forEach
(
function
generate
(
k
)
{
var
endpoint
=
k
.
toLowerCase
();
var
endpoint
=
k
.
toLowerCase
();
client
[
endpoint
]
=
new
exports
[
k
](
options
);
client
[
endpoint
]
=
new
exports
[
k
](
options
);
...
...
test/test.js
View file @
5b7f73ea
...
@@ -203,7 +203,6 @@ function mupdate() {
...
@@ -203,7 +203,6 @@ function mupdate() {
index
();
index
();
//show();
//create();
//create();
//show();
//show();
//update();
//update();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment