Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fullcontact
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
prospector
fullcontact
Commits
f7b55e5d
Commit
f7b55e5d
authored
May 14, 2013
by
3rd-Eden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[fix] Throw if we don't get an API key
[fix] Response headers are lowercased [fix] Proper setting of pre-loaded values
parent
7249c43d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
16 deletions
+56
-16
index.js
index.js
+10
-6
fullcontact.test.js
test/fullcontact.test.js
+44
-10
person.test.js
test/person.test.js
+2
-0
No files found.
index.js
View file @
f7b55e5d
...
...
@@ -24,6 +24,8 @@ function FullContact(api) {
this
.
queueing
=
false
;
// Should we be queueing requests
this
.
requests
=
[];
// Stores all queued commands
if
(
!
this
.
key
)
throw
new
Error
(
'Missing API key'
);
}
/**
...
...
@@ -70,9 +72,9 @@ FullContact.prototype.request = function req(packet, args) {
,
self
=
this
;
request
(
packet
,
function
requested
(
err
,
res
,
body
)
{
self
.
ratereset
=
+
res
.
headers
[
'
X-Rate-Limit-R
eset'
]
||
self
.
ratereste
;
self
.
ratelimit
=
+
res
.
headers
[
'
X-Rate-Limit-L
imit'
]
||
self
.
ratelimit
;
self
.
remaining
=
+
res
.
headers
[
'
X-Rate-Limit-R
emaining'
]
||
self
.
remaining
;
self
.
ratereset
=
+
res
.
headers
[
'
x-rate-limit-r
eset'
]
||
self
.
ratereste
;
self
.
ratelimit
=
+
res
.
headers
[
'
x-rate-limit-l
imit'
]
||
self
.
ratelimit
;
self
.
remaining
=
+
res
.
headers
[
'
x-rate-limit-r
emaining'
]
||
self
.
remaining
;
if
(
err
)
return
fn
(
err
);
...
...
@@ -212,12 +214,14 @@ FullContact.define = function define(where, name, fn) {
Object
.
defineProperty
(
where
,
name
,
{
configurable
:
true
,
get
:
function
get
()
{
return
where
[
name
]
=
fn
.
call
(
this
);
return
Object
.
defineProperty
(
this
,
name
,
{
value
:
fn
.
call
(
this
)
})[
name
];
},
set
:
function
set
(
value
)
{
Object
.
defineProperty
(
where
,
name
,
{
return
Object
.
defineProperty
(
this
,
name
,
{
value
:
value
});
})
[
name
]
;
}
});
};
...
...
test/fullcontact.test.js
View file @
f7b55e5d
...
...
@@ -5,6 +5,8 @@ describe('FullContact', function () {
,
chai
=
require
(
'chai'
)
,
expect
=
chai
.
expect
;
chai
.
Assertion
.
includeStack
=
true
;
//
// The API key we use for testing.
//
...
...
@@ -15,10 +17,15 @@ describe('FullContact', function () {
//
this
.
timeout
(
20000
);
//
// Pre-create an API instance
//
var
api
=
new
FullContact
(
key
);
it
(
'exposes the createClient api which initializes the constructor'
,
function
()
{
var
api
=
FullContact
.
createClient
(
key
);
var
client
=
FullContact
.
createClient
(
key
);
expect
(
api
).
to
.
be
.
instanceOf
(
FullContact
);
expect
(
client
).
to
.
be
.
instanceOf
(
FullContact
);
});
it
(
'exposes the Person constructor'
,
function
()
{
...
...
@@ -37,27 +44,54 @@ describe('FullContact', function () {
expect
(
FullContact
.
Name
).
to
.
be
.
a
(
'function'
);
});
it
(
'sets the x-rate properties on request'
,
function
(
done
)
{
var
fc
=
new
FullContact
(
key
);
it
(
'throws an error when the API is constructed without a key'
,
function
()
{
try
{
new
FullContact
();
}
catch
(
e
)
{
return
expect
(
e
.
message
).
to
.
equal
(
'Missing API key'
);
}
throw
new
Error
(
'I should have failed'
);
});
it
(
'errors when an invalid API key is given'
,
function
(
done
)
{
var
client
=
new
FullContact
(
key
+
'adfasfdsfadsfas'
);
client
.
person
.
email
(
'arnout@observe.it'
,
function
(
err
)
{
expect
(
err
).
to
.
be
.
instanceOf
(
Error
);
expect
(
err
.
message
.
toLowerCase
()).
to
.
include
(
'api'
);
expect
(
err
.
message
.
toLowerCase
()).
to
.
include
(
'key'
);
done
();
});
});
it
(
'sets the x-rate properties on request'
,
function
(
done
)
{
[
'remaining'
,
'ratelimit'
,
'ratereset'
].
forEach
(
function
(
prop
)
{
expect
(
fc
[
prop
]).
to
.
equal
(
0
);
expect
(
api
[
prop
]).
to
.
equal
(
0
);
});
fc
.
person
.
email
(
'arnout@observe.it'
,
function
normalize
(
err
,
data
)
{
api
.
person
.
email
(
'arnout@observe.it'
,
function
email
(
err
,
data
)
{
if
(
err
)
return
done
(
err
);
[
'remaining'
,
'ratelimit'
,
'ratereset'
].
forEach
(
function
(
prop
)
{
expect
(
fc
[
prop
]).
to
.
not
.
equal
(
0
);
expect
(
fc
[
prop
]).
to
.
be
.
a
(
'number'
);
expect
(
api
[
prop
]).
to
.
not
.
equal
(
0
);
expect
(
api
[
prop
]).
to
.
be
.
a
(
'number'
);
});
done
();
});
});
it
(
'decreases the rate remaining on request'
);
it
(
'errors when an invalid API key is given'
);
it
(
'decreases the rate remaining on request'
,
function
(
done
)
{
var
remaining
=
api
.
remaining
;
api
.
person
.
email
(
'arnout@observe.it'
,
function
email
(
err
)
{
if
(
err
)
return
done
(
err
);
expect
(
api
.
remaining
).
to
.
be
.
below
(
remaining
);
done
();
});
});
it
(
'does batch requests'
);
});
test/person.test.js
View file @
f7b55e5d
...
...
@@ -5,6 +5,8 @@ describe('FullContact.Person', function () {
,
chai
=
require
(
'chai'
)
,
expect
=
chai
.
expect
;
chai
.
Assertion
.
includeStack
=
true
;
//
// The API key we use for testing.
//
...
...
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