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
e545b700
Commit
e545b700
authored
Dec 09, 2013
by
Aaron Tidwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cameCase to under_score property conversion
parent
c6a1ff6a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
44 deletions
+80
-44
lib/api/client.js
lib/api/client.js
+32
-36
lib/api/properties-to-convert.js
lib/api/properties-to-convert.js
+41
-0
readme.md
readme.md
+3
-4
test/test.js
test/test.js
+4
-4
No files found.
lib/api/client.js
View file @
e545b700
...
@@ -45,42 +45,34 @@ function serializeProperties(obj) {
...
@@ -45,42 +45,34 @@ function serializeProperties(obj) {
};
};
}
}
var
propertiesToDelete
=
[
'
callback
'
,
'
path
'
,
'
method
'
];
// resources generate props internal to https requests
// resources generate props internal to https requests
var
propertiesToDelete
=
[
'
callback
'
,
'
path
'
,
'
method
'
];
//all the stuff we have to convert camelCase to underScores
var
propertiesToConvert
=
[
// all the stuff we have to convert camelCase to under_scores
'
create_after
'
,
var
propertiesToConvert
=
require
(
'
./properties-to-convert
'
);
'
created_before
'
,
'
include_participants
'
,
function
camelToUnderscore
(
str
)
{
'
include_matches
'
,
return
str
.
replace
(
/
\W
+/g
,
'
-
'
)
'
tournament_type
'
,
.
replace
(
/
([
a-z
\d])([
A-Z
])
/g
,
'
$1_$2
'
).
toLowerCase
();
'
open_signup
'
,
}
'
hold_third_place_match
'
,
function
convertPropertyCamelCaseToUnderscore
(
obj
)
{
'
pts_for_match_win
'
,
for
(
var
prop
in
obj
)
{
'
pts_for_match_tie
'
,
if
(
obj
.
hasOwnProperty
(
prop
))
{
'
pts_for_game_win
'
,
//objects recurse
'
pts_for_game_tie
'
,
if
(
typeof
obj
[
prop
]
===
'
object
'
)
{
'
pts_for_bye
'
,
obj
[
camelToUnderscore
(
prop
)]
=
convertPropertyCamelCaseToUnderscore
(
obj
[
prop
]);
'
swiss_rounds
'
,
}
'
ranked_by
'
,
//otherwise, if the underscore version is in the list we convert it
'
rr_pts_for_match_win
'
,
else
if
(
propertiesToConvert
.
indexOf
(
camelToUnderscore
(
prop
))
!==
-
1
)
{
'
rr_pts_for_match_tie
'
,
obj
[
camelToUnderscore
(
prop
)]
=
obj
[
prop
];
'
rr_pts_for_game_win
'
,
//remove it
'
rr_pts_for_game_tie
'
,
delete
obj
[
prop
];
'
accept_attachments
'
,
}
'
hide_forum
'
,
//otherwise leave it alone
'
show_rounds
'
,
}
'
notify_users_when_matches_open
'
,
}
'
notify_users_when_the_tournament_ends
'
,
return
obj
;
'
sequential_pairings
'
,
}
'
signup_cap
'
,
'
challonge_username
'
,
'
participant_id
'
,
'
scores_csv
'
,
'
winner_id
'
,
'
player1_votes
'
,
'
player2_votes
'
,
];
Client
.
prototype
.
setSubdomain
=
function
(
subdomain
)
{
Client
.
prototype
.
setSubdomain
=
function
(
subdomain
)
{
//generate the subdomain URL string if there is one
//generate the subdomain URL string if there is one
...
@@ -102,6 +94,10 @@ Client.prototype.makeRequest = function(obj) {
...
@@ -102,6 +94,10 @@ Client.prototype.makeRequest = function(obj) {
// massage camel to underscore
// massage camel to underscore
obj
.
api_key
=
this
.
options
.
get
(
'
apiKey
'
);
//convert for url
obj
.
api_key
=
this
.
options
.
get
(
'
apiKey
'
);
//convert for url
// normalize the rest of the properties
obj
=
convertPropertyCamelCaseToUnderscore
(
obj
);
console
.
log
(
obj
)
//serialize the properties
//serialize the properties
var
serialized
=
serializeProperties
(
obj
);
var
serialized
=
serializeProperties
(
obj
);
var
compiledParams
=
serialized
.
serialized
;
var
compiledParams
=
serialized
.
serialized
;
...
...
lib/api/properties-to-convert.js
0 → 100644
View file @
e545b700
//all the stuff we have to convert camelCase to under_scores
var
propertiesToConvert
=
[
'
create_after
'
,
'
created_before
'
,
'
include_participants
'
,
'
include_matches
'
,
'
tournament_type
'
,
'
open_signup
'
,
'
hold_third_place_match
'
,
'
pts_for_match_win
'
,
'
pts_for_match_tie
'
,
'
pts_for_game_win
'
,
'
pts_for_game_tie
'
,
'
pts_for_bye
'
,
'
swiss_rounds
'
,
'
ranked_by
'
,
'
rr_pts_for_match_win
'
,
'
rr_pts_for_match_tie
'
,
'
rr_pts_for_game_win
'
,
'
rr_pts_for_game_tie
'
,
'
accept_attachments
'
,
'
hide_forum
'
,
'
show_rounds
'
,
'
notify_users_when_matches_open
'
,
'
notify_users_when_the_tournament_ends
'
,
'
sequential_pairings
'
,
'
signup_cap
'
,
'
challonge_username
'
,
'
participant_id
'
,
'
scores_csv
'
,
'
winner_id
'
,
'
player1_votes
'
,
'
player2_votes
'
,
];
module
.
exports
=
propertiesToConvert
;
\ No newline at end of file
readme.md
View file @
e545b700
...
@@ -52,10 +52,9 @@ client.tournaments.create({
...
@@ -52,10 +52,9 @@ client.tournaments.create({
###Challonge docs: http://api.challonge.com/v1
###Challonge docs: http://api.challonge.com/v1
##TODO
##TODO
2.
support camelCase -> under_score params
1.
validate required params
3.
validate required params
2.
docs
4.
docs
3.
tests
5.
tests
---
---
...
...
test/test.js
View file @
e545b700
...
@@ -6,7 +6,7 @@ var client = challonge.createClient({
...
@@ -6,7 +6,7 @@ var client = challonge.createClient({
version
:
1
,
version
:
1
,
});
});
var
tourneyName
=
'
nodeapitest
3
'
;
var
tourneyName
=
'
nodeapitest
Camel
'
;
function
index
()
{
function
index
()
{
client
.
tournaments
.
index
({
client
.
tournaments
.
index
({
...
@@ -22,8 +22,8 @@ function create() {
...
@@ -22,8 +22,8 @@ function create() {
tournament
:
{
tournament
:
{
name
:
'
name-
'
+
tourneyName
,
name
:
'
name-
'
+
tourneyName
,
url
:
tourneyName
,
url
:
tourneyName
,
signup
_c
ap
:
8
,
signup
C
ap
:
8
,
tournament
_t
ype
:
'
single elimination
'
,
tournament
T
ype
:
'
single elimination
'
,
},
},
callback
:
function
(
err
,
data
){
callback
:
function
(
err
,
data
){
if
(
err
)
{
console
.
log
(
err
);
return
;
}
if
(
err
)
{
console
.
log
(
err
);
return
;
}
...
@@ -204,7 +204,7 @@ function mupdate() {
...
@@ -204,7 +204,7 @@ function mupdate() {
//index();
//index();
client
.
setSubdomain
(
'
nodeapitest
'
);
//
client.setSubdomain('nodeapitest');
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