Chapter 1 Price Spectre Custom Algorithms

Price Spectre
Contents
1
2
Price Spectre Custom Algorithms
1
1.1
1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Algorithm Editor
3
2.1
Script . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
2.2
Algorithm Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
2.2.1
Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
2.2.2
Require Search Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
2.2.3
Perform Search Automatically
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
2.2.4
X
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
2.2.5
Y
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
2.2.6
Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
2.2.7
Number of Searches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
Algorithm Simulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
2.3
3
Pricing Logic
7
4
Script Debugging
9
4.1
throw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9
4.2
debugMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9
5
6
7
Sample Scripts
11
5.1
X Lowest By $Y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11
5.2
X Lowest By Y% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11
5.3
Average X Y% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12
5.4
Discount X Days $Y . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12
5.5
Discount X Days Y%
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12
5.6
Quota Elastic X Days Y% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13
5.7
Ebay Products Lowest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13
Hierarchical Index
15
6.1
15
Class Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Data Structure Index
17
ii
CONTENTS
7.1
8
Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17
Data Structure Documentation
19
8.1
Listing Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
19
8.1.1
Detailed Description
19
8.1.2
Member Function Documentation
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
19
8.1.2.1
getConditionID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
19
8.1.2.2
getConditionName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
20
8.1.2.3
getEndDate
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
20
8.1.2.4
getEndTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
20
8.1.2.5
getFeedbackPercent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
21
8.1.2.6
getFeedbackRating . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
21
8.1.2.7
getFeedbackScore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
21
8.1.2.8
getFeedbackStar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
22
8.1.2.9
getFreeShipping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
22
8.1.2.10 getListingID
8.2
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
22
8.1.2.11 getLocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
22
8.1.2.12 getMerchantID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23
8.1.2.13 getOneDayShipping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23
8.1.2.14 getPrice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23
8.1.2.15 getReturnsAccepted . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
24
8.1.2.16 getSecondsRemaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
24
8.1.2.17 getSecondsSinceStart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
24
8.1.2.18 getSeller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
24
8.1.2.19 getSite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
25
8.1.2.20 getStartDate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
25
8.1.2.21 getStartTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
25
8.1.2.22 getTitle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
25
8.1.2.23 isDeleted . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
26
8.1.2.24 isTRS
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
26
PS Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
26
8.2.1
Detailed Description
27
8.2.2
Member Function Documentation
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
27
8.2.2.1
averageX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
27
8.2.2.2
delete
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
28
8.2.2.3
getCeilingPrice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
28
8.2.2.4
getCurrentPrice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
29
8.2.2.5
getData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
29
8.2.2.6
getErrorMessage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
29
8.2.2.7
getFloorPrice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
29
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
CONTENTS
8.3
iii
8.2.2.8
getGoldAsk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
30
8.2.2.9
getGoldBid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
30
8.2.2.10 getLastPriceChangePrice . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
30
8.2.2.11 getLastPriceChangeTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
31
8.2.2.12 getLastSaleTime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
31
8.2.2.13 getMyAmazonPrice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
31
8.2.2.14 getNoCompetitionFound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
32
8.2.2.15 getNumResults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
32
8.2.2.16 getNumSales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
32
8.2.2.17 getNumSalesSince . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
33
8.2.2.18 getQuantity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
33
8.2.2.19 getRank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
33
8.2.2.20 getRealNumResults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
34
8.2.2.21 getRealRank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
34
8.2.2.22 getRealResults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
35
8.2.2.23 getResults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
35
8.2.2.24 getSearchParameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
35
8.2.2.25 getSecondsRemaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
36
8.2.2.26 getSecondsSinceLastPriceChange . . . . . . . . . . . . . . . . . . . . . . . .
36
8.2.2.27 getSecondsSinceStart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
36
8.2.2.28 getShippingHandling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
37
8.2.2.29 getSilverAsk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
37
8.2.2.30 getSilverBid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
38
8.2.2.31 getSiteCountry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
38
8.2.2.32 overrideNoCompetitionFound . . . . . . . . . . . . . . . . . . . . . . . . . . .
38
8.2.2.33 performSafeSearch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
39
8.2.2.34 performSearch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
39
8.2.2.35 performSelfSafeSearch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
39
8.2.2.36 performSelfSearch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
40
8.2.2.37 setPrice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
40
8.2.2.38 setSearchParameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
41
8.2.2.39 writeData . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
41
8.2.2.40 xLowestY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
42
8.2.2.41 xLowestYPercent
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
42
WS Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
43
8.3.1
Detailed Description
43
8.3.2
Member Function Documentation
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
43
8.3.2.1
get . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
43
8.3.2.2
post
43
8.3.2.3
setEndpoint
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
44
iv
CONTENTS
8.4
8.3.2.4
setHeaders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
44
8.3.2.5
setRequestBody . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
44
XMLDocument Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
45
8.4.1
Detailed Description
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
45
8.4.2
Constructor & Destructor Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . .
45
8.4.2.1
45
8.4.3
8.6
Index
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Member Function Documentation
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
46
toString . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
46
XMLNode Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
46
8.5.1
Detailed Description
46
8.5.2
Member Function Documentation
8.4.3.1
8.5
__construct
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
46
8.5.2.1
getChildNodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
46
8.5.2.2
getElement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
47
8.5.2.3
getElements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
47
8.5.2.4
getName . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
48
8.5.2.5
getValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
48
XMLNodeList Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
48
8.6.1
Detailed Description
48
8.6.2
Member Function Documentation
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
48
8.6.2.1
count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
48
8.6.2.2
item
49
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
49
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
Chapter 1
Price Spectre Custom Algorithms
This document describes a javascript language interface that allows users to create their own custom algorithms.
1.1
Introduction
Price Spectre is a dynamic pricing agent for eBay and Half.com listings. Every user has access to several predefined algorithms (pricing scripts) but some users may need more flexibility or control with their pricing.
Price Spectre provides a javascript interface which allows users to write their own scripts to control their pricing.
Each user-defined script is run once per pricing cycle per managed listing.
It is assumed the reader already has a beginner level understanding of javascript and programming concepts.
An introduction to the javascript language can be found at https://developer.mozilla.org/en/A_re-introduction_to_JavaScript . Since pricing scripts are run server side and not in a browser all
browser related javascript functions are disabled.
2
Price Spectre Custom Algorithms
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
Chapter 2
Algorithm Editor
The algorithm editor consists of three components.
2.1
Script
This is where the pricing script is input. The script must be valid javascript code.
2.2
Algorithm Options
2.2.1
Name
Allows the user to specify a name of this algorithm.
2.2.2
Require Search Parameters
Allows the user to indicate whether search parameters (keywords or product code) are required.
2.2.3
Perform Search Automatically
Allows the user to specify whether a search is performed automatically at the start of the script without requiring a
call to PS::performSearch() or PS::performSafeSearch().
If this is set, it counts towards the total search count for premium billing purposes.
If this is set, Require Search Parameters Require Search Parameters must be also checked.
2.2.4
X
Allows the user to define whether the variable x is defined in the algorithm along with its datatype.
2.2.5
Y
Allows the user to define whether the variable y is defined in the algorithm along with its datatype.
4
2.2.6
Algorithm Editor
Description
Allows the user to specify a description for the algorithm.
2.2.7
Number of Searches
The calculated number of searches performed by the algorithm. This is calculated every time the algorithm is
saved. If the number of searches exceeds 1 then premium points may be charged for using the algorithm. See your
"Premium Points" page for details on billing.
2.3
Algorithm Simulator
The embedded search console allows the user to test their new algorithm against a live listing. The simulator uses
the script as it is currently defined in the script section. It is not necessary to save the script between changes for
them to take effect in the simulator.
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
2.3 Algorithm Simulator
5
Figure 2.1: Algorithm Simulator
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
6
Algorithm Editor
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
Chapter 3
Pricing Logic
The following steps occur once per pricing cycle per managed listing:
1) Initial search is performed if the option "Perform Search Automatically" was selected.
2) The PS object "ps" is created. This is the object the user-defined script interfaces with. Variables x and y are also
set if specified.
3) User-defined script is executed. In order to set a new total price PS::setPrice() must be executed.
4) If an exception was thrown, then execution stops and an error message is sent to the user.
5) "No competition found" check is performed.
5a) If no competitors were found and PS::overrideNoCompetitionFound() was not called, then the new total price is
changed according to the behavior "No competition found".
5b) Otherwise, the new total price is passed through the Bat’a pricing filter if Bat’a pricing is enabled.
6) The new total price is then passed through the floor and ceiling price filter to ensure it meets these constraints.
7) Finally the total price of the listing is set to the new total price.
Figure 3.1: Pricing Logic
8
Pricing Logic
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
Chapter 4
Script Debugging
Price Spectre provides two ways of receiving output from custom algorithms.
4.1
throw
The javascript throw syntax is supported. This immediately terminates the script with the specified error message.
Use this on conditions that are unrecoverable.
throw ’An error has occurred’;
4.2
debugMessage
The PS class has a public function PS::debugMessage() that is similar to throw but does not immediately terminate
the script. Each call to PS::debugMessage() appends the new message to the previous ones. This is useful in
cases where control flow is being observed or where multiple different bugs or errors must be tracked.
Attention
Even though execution continues after a call to PS::debugMessage() the script will still terminate with an error
once execution finishes.
if(x < 0)
ps.debugMessage(’x is less than 0 x = ’ + x + ’.’);
if(y < 0)
ps.debugMessage(’y is less than 0 y = ’ + y + ’.’);
10
Script Debugging
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
Chapter 5
Sample Scripts
Price Spectre provides several sample scripts to get started. Several of these are also pre-defined algorithms that
are available to all users.
All sample scripts are free to use in part or whole within Price Spectre. Users are welcome to create their own
derivative works based on these samples for use within Price Spectre.
5.1
X Lowest By $Y
The X Lowest By $Y script sets a final price that is Y less than the Xth lowest price found.
// X Lowest By $Y
// Assumes "Perform Search Automatically" is selected.
// Copyright 2011 NullApps
if(x < 1)
throw ’X must be positive.’;
count = 0;
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
count++;
// if this is the listing to match against
if(count >= x)
{
ps.setPrice(results[i].getPrice() - y);
break;
}
}
5.2
X Lowest By Y%
The X Lowest Y% script sets a final price that is Y less than the Xth lowest price found.
// X Lowest Y%
// Assumes "Perform Search Automatically" is selected.
// Copyright 2011 NullApps
if(x < 1)
throw ’X must be positive.’;
if(y > 50)
throw ’Y must be 50% or less.’;
count = 0;
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
count++;
12
Sample Scripts
// if this is the listing to match against
if(count >= x)
{
ps.setPrice(results[i].getPrice() * (1 - y/100));
break;
}
}
5.3
Average X Y%
The Average X Y% script sets a final price that is Y% less than the average X lowest prices found.
// Average X Y%
// Assumes "Perform Search Automatically" is NOT selected.
// Copyright 2011 NullApps
if(x < 1)
throw ’X must be positive.’;
if(y > 50)
throw ’Y must be 50% or less.’;
// Grab the average of the X lowest priced listings.
averagePrice = ps.averageX(x);
// Sets price to y% lower than the average of the lowest X prices found.
ps.setPrice(averagePrice * (1 - y/100));
5.4
Discount X Days $Y
The Discount X Days $Y script sets a final price that is Y less than the current price if X days have passed since the
last price change.
// Discount X Days $Y
// Copyright 2011 NullApps
if(x < 1)
throw ’X must be positive.’;
if(y == 0)
throw ’Y cannot be 0.’;
secondsPerDay = 86400;
secondsSincePriceChange = ps.getSecondsSinceLastPriceChange();
daysSinceChange = secondsSincePriceChange / secondsPerDay;
currentPrice = ps.getCurrentPrice();
if(daysSinceChange >= x)
ps.setPrice(currentPrice - y);
5.5
Discount X Days Y%
The Discount X Days Y% script sets a final price that is Y% less than the current price if X days have passed since
the last price change.
// Discount X Days Y%
// Copyright 2011 NullApps
if(x < 1)
throw ’X must be positive.’;
secondsPerDay = 86400;
secondsSincePriceChange = ps.getSecondsSinceLastPriceChange();
daysSinceChange = secondsSincePriceChange / secondsPerDay;
currentPrice = ps.getCurrentPrice();
if(daysSinceChange >= x)
ps.setPrice(currentPrice * (1 - y/100));
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
5.6 Quota Elastic X Days Y%
5.6
13
Quota Elastic X Days Y%
The Quota Elastic script increases or decreases price Y% depending on whether the required quota of sales was
achieved over the period of X days.
Attention
This is not the same as the pre-defined Elastic algorithm which uses the revenue generated in determining the
final price.
// Quota Elastic X Days Y%
// Copyright 2011 NullApps
if(x < 1)
throw ’X must be positive.’;
if(y <= 0)
throw ’Y must be positive.’;
if(y > 50)
throw ’Y must be 50% or less.’;
quota = 3;
secondsPerDay = 86400;
secondsPerX = secondsPerDay * x;
secondsSincePriceChange = ps.getSecondsSinceLastPriceChange();
// Make sure enough time has elapsed.
if(secondsSincePriceChange >= secondsPerX)
{
numSales = ps.getNumSalesSince(secondsPerX);
currentPrice = ps.getCurrentPrice();
// Change price by y% depending on if sales quota has been reached.
if(numSales >= quota)
ps.setPrice(currentPrice * (1 + y/100));
else
ps.setPrice(currentPrice * (1 - y/100));
}
5.7
Ebay Products Lowest
The Find Ebay Products Lowest script uses the WS class to call eBay’s Finding API and set the price $0.01 lower
than the lowest price found
Attention
This script is provided for informational purposes only and should not be used. Leave calling eBay’s API to
Price Spectre as we have years of experience doing this. However this script can be used as a starting point
for calling similar external APIs.
// Find Ebay Products Lowest
// Copyright 2011 NullApps
// fetch UPC from keywords
var upc = ps.getSearchParameter(’keywords’);
// create request XML
var xmlStr = "<?xml version=’1.0’?>"
+ ’<findItemsByProductRequest xmlns="http://www.ebay.com/marketplace/search/v1/services">’
+ "<productId type=\"UPC\">" + upc + "</productId>"
+ "<sortOrder>PricePlusShippingLowest</sortOrder>"
+ "</findItemsByProductRequest>";
var request = new XMLDocument(xmlStr);
var headers = new Array(
"X-EBAY-SOA-OPERATION-NAME: findItemsByProduct",
"X-EBAY-SOA-SECURITY-APPNAME: <YOUR APP ID>",
"X-EBAY-SOA-GLOBAL-ID: EBAY-US",
"X-EBAY-SOA-SERVICE-VERSION: 1.11.0"
);
ws.setRequestBody(request);
ws.setHeaders(headers);
ws.setEndpoint("http://svcs.ebay.com/services/search/FindingService/v1");
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
14
var
var
var
var
Sample Scripts
response = ws.post();
responseXML = new XMLDocument(response);
priceNode = responseXML.getElement(’currentPrice’);
price = ps.getCurrentPrice();
if(priceNode)
{
price = priceNode.getValue() - 0.01;
}
ps.setPrice(price);
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
Chapter 6
Hierarchical Index
6.1
Class Hierarchy
This inheritance list is sorted roughly, but not completely, alphabetically:
Listing . .
PS . . . .
WS . . . .
XMLNode
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
19
26
43
46
XMLDocument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
45
XMLNodeList . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
48
16
Hierarchical Index
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
Chapter 7
Data Structure Index
7.1
Data Structures
Here are the data structures with brief descriptions:
Listing . . . .
PS . . . . . .
WS . . . . .
XMLDocument
XMLNode . .
XMLNodeList
. . . .
. . . .
. . . .
. . .
. . . .
. . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
19
26
43
45
46
48
18
Data Structure Index
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
Chapter 8
Data Structure Documentation
8.1
Listing Class Reference
Public Member Functions
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
8.1.1
getListingID ()
getTitle ()
getPrice ()
getStartTime ()
getStartDate ()
getEndTime ()
getEndDate ()
getSeller ()
getMerchantID ()
getFeedbackScore ()
getFeedbackPercent ()
getFeedbackRating ()
getFeedbackStar ()
isTRS ()
getReturnsAccepted ()
getFreeShipping ()
getOneDayShipping ()
getConditionID ()
getConditionName ()
getSite ()
getLocation ()
getSecondsSinceStart ()
getSecondsRemaining ()
isDeleted ()
Detailed Description
A class that represents a competitor’s listing.
8.1.2
Member Function Documentation
8.1.2.1
getConditionID ( )
Retrieves the numerical representation of the condition of the item.
20
Data Structure Documentation
Returns
If a condition is specified returns an integer as specified at http://developer.ebay.com/devzone/finding/callr
Enums/conditionIdList.html . Returns 0, otherwise.
// Delete all non-new listings
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
// Delete if not new
if(results[i].getConditionID() != 1000)
{
ps.delete(i);
}
}
8.1.2.2
getConditionName ( )
Retrieves the string representation of the condition of a listing, if available.
Returns
A string such as ’Brand New’, ’Like New’, ’New in Box’, etc. This value is dependent on the category and site the
item is listed to. See http://pages.ebay.com/sellerinformation/sellingresources/itemconditionlo
html and http://developer.ebay.com/devzone/finding/callref/Enums/conditionIdList.html for example return values.
8.1.2.3
getEndDate ( )
Retrieves the end date of a competitor’s listing.
Returns
The end date of the listing in format ’MMM DD’ if listed on eBay. Returns an empty string, otherwise.
8.1.2.4
getEndTime ( )
Retrieves the number of seconds after 1970-01-01T00:00:00Z that the listing will end.
Returns
The epoch time representing when the listing will end if the listing was posted to eBay. Returns 2147483647,
otherwise.
results = ps.getResults();
numResults = ps.getNumResults();
now = Math.round(Date.now() / 1000);
secondsPerDay = 86400;
// Delete all results that will end in less than one day.
for(i = 0; i < numResults; ++i)
{
end = results[i].getEndTime();
timeleft = end - now;
if(timeleft < secondsPerDay)
{
ps.delete(i);
}
}
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
8.1 Listing Class Reference
8.1.2.5
21
getFeedbackPercent ( )
Retrieves the feedback percentage of the listing’s seller.
Returns
For eBay and Half.com listings, a real number between 0 and 100 representing the feedback percentage of the
listing’s seller. Returns 0 for Amazon listings.
// Delete all listings that have an eBay feedback percent below 98% or Amazon rating below 4.8.
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
site = results[i].getSite();
percent = results[i].getFeedbackPercent();
rating = results[i].getFeedbackRating();
if(site == ’eBay’ && percent < 98)
{
ps.delete(i);
}
else if(site == ’Amazon’ && rating < 4.8)
{
ps.delete(i);
}
}
8.1.2.6
getFeedbackRating ( )
Retrieves the feedback rating of the listing’s seller.
Returns
For eBay and Half.com listings, returns 0. For Amazon sellers returns a real number between 0 and 5 representing the seller’s feedback rating.
// Delete all listings that have an eBay feedback percentage below 98% or Amazon rating below 4.8.
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
site = results[i].getSite();
percent = results[i].getFeedbackPercent();
rating = results[i].getFeedbackRating();
if(site == ’eBay’ && percent < 98)
{
ps.delete(i);
}
else if(site == ’Amazon’ && rating < 4.8)
{
ps.delete(i);
}
}
8.1.2.7
getFeedbackScore ( )
Retrieves the feedback score of the listing’s seller.
Returns
An integer representing the net feedback score of the listing’s seller.
// Delete all listings that have an Amazon feedback score below minFeedback or rating less than 4.8.
// By default the minFeedback filter only works on eBay/Half.com listings.
results = ps.getResults();
numResults = ps.getNumResults();
minFeedback = ps.getSearchParameter(’minFeedback’);
for(i = 0; i < numResults; ++i)
{
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
22
Data Structure Documentation
site = results[i].getSite();
rating = results[i].getFeedbackRating();
score = results[i].getFeedbackScore();
if(site == ’Amazon’ && (rating < 4.8 || score < minFeedback))
{
ps.delete(i);
}
}
8.1.2.8
getFeedbackStar ( )
Retrieves a string representation of the feedback star of the seller.
Returns
If the listing is on eBay or Half.com returns a string representation such as ’none’, ’yellow’, or ’silverShooting’.
Returns ’none’ for all Amazon listings.
8.1.2.9
getFreeShipping ( )
Retrieves whether the listing offers free shipping.
Returns
If free shipping is offered return TRUE. Returns FALSE, otherwise.
// Delete all listings that don’t offer free shipping
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
if(!results[i].getFreeShipping())
{
ps.delete(i);
}
}
8.1.2.10
getListingID ( )
Retrieves the item number or ASIN of a competitor’s listing.
Returns
If the listing is found on eBay or Half.com, returns the 12 digit item number. If the listing was located on Amazon
then return the ten character ASIN.
// Sets price first listing found that isn’t specified by X.
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
if(results[i].getListingID() != x)
{
ps.setPrice(results[i].getPrice());
break;
}
}
8.1.2.11
getLocation ( )
Retrieves the country the item is located.
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
8.1 Listing Class Reference
23
Returns
Two-letter ISO 3166 country code to indicate the country where the item is located (e.g., "US" for the United
States or "GB" for the United Kingdom).
results = ps.getResults();
numResults = ps.getNumResults();
// Delete all results that are not located in the US or Canada.
for(i = 0; i < numResults; ++i)
{
country = results[i].getLocation();
if(country != ’US’ && country != ’CA’)
{
ps.delete(i);
}
}
8.1.2.12
getMerchantID ( )
Retrieves the merchant ID of the listing’s seller.
Returns
For Amazon listings returns the Amazon merchant ID of the listing’s seller. Otherwise returns an empty string.
8.1.2.13
getOneDayShipping ( )
Retrieves whether the listing offers one day shipping.
Returns
If one day shipping is available return TRUE. Returns FALSE, otherwise.
// Delete all listings that don’t offer one day shipping
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
if(!results[i].getOneDayShipping())
{
ps.delete(i);
}
}
8.1.2.14
getPrice ( )
Retrieves the total price of a competitor’s listing.
Returns
The total price of the competitor’s listing.
// Matches the price of the lowest found listing.
results = ps.getResults();
numResults = ps.getNumResults();
if(numResults > 0)
ps.setPrice(results[0].getPrice());
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
24
Data Structure Documentation
8.1.2.15
getReturnsAccepted ( )
Retrieves whether the listing allows for returns.
Returns
If returns are accepted return TRUE. Returns FALSE, otherwise.
// Delete all listings that allow returns.
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
if(results[i].getReturnsAccepted())
{
ps.delete(i);
}
}
8.1.2.16
getSecondsRemaining ( )
Retrieves the number of seconds before the listing will end.
Returns
The number of seconds that before the listing will end if it was listed on eBay. Returns 2147483647, otherwise.
results = ps.getResults();
numResults = ps.getNumResults();
secondsPerDay = 86400;
// Delete all results that will end in less than one day.
for(i = 0; i < numResults; ++i)
{
timeleft = results[i].getSecondsRemaining();
if(timeleft < secondsPerDay)
{
ps.delete(i);
}
}
8.1.2.17
getSecondsSinceStart ( )
Retrieves the number of seconds since the listing has started.
Returns
The number of seconds that have elapsed since the listing started if it was listed on eBay. Otherwise, returns 0.
results = ps.getResults();
numResults = ps.getNumResults();
secondsPerDay = 86400;
// Delete all results that have been listed less than one day.
for(i = 0; i < numResults; ++i)
{
age = results[i].getSecondsSinceStart();
if(age < secondsPerDay)
{
ps.delete(i);
}
}
8.1.2.18
getSeller ( )
Retrieves the seller ID of the listing’s seller.
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
8.1 Listing Class Reference
25
Returns
A string containing the userid of the listing’s seller.
8.1.2.19
getSite ( )
Retrieves the site the listing is from.
Returns
The string ’eBay’ if the item is listed on eBay. The string ’Half’ if the item is listed on Half.com. The string
’Amazon’ if the item is listed on Amazon.
8.1.2.20
getStartDate ( )
Retrieves the start date of a competitor’s listing.
Returns
The start date of the listing in format ’MMM DD’ if listed on eBay. Returns an empty string, otherwise.
8.1.2.21
getStartTime ( )
Retrieves the number of seconds after 1970-01-01T00:00:00Z that the listing was listed.
Returns
The epoch time representing when the listing was first listed if the listing was posted to eBay. Returns 0,
otherwise.
results = ps.getResults();
numResults = ps.getNumResults();
now = Math.round(Date.now() / 1000);
secondsPerDay = 86400;
// Delete all results that have been listed less than one day.
for(i = 0; i < numResults; ++i)
{
start = results[i].getStartTime();
age = now - start;
if(age < secondsPerDay)
{
ps.delete(i);
}
}
8.1.2.22
getTitle ( )
Retrieves the title of a competitor’s listing.
Returns
The title of listing.
results = ps.getResults();
numResults = ps.getNumResults();
// Delete all results containing the word ’parts’
// Note: this should be done using the keyword "-parts" instead.
for(i = 0; i < numResults; ++i)
{
title = results[i].getTitle();
if(title.indexOf(’parts’) != -1)
{
ps.delete(i);
}
}
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
26
Data Structure Documentation
8.1.2.23
isDeleted ( )
Retrieves whether the listing has been deleted or not.
Returns
TRUE if the listing has been deleted. Otherwise, returns FALSE.
// Delete all non-new listings
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
// Delete if not new
if(results[i].getConditionID() != 1000)
{
ps.delete(i);
}
}
// Perform X lowest by $Y on remaining listings.
count = 0;
for(i = 0; i < numResults; ++i)
{
// skip if this is a deleted listing.
if(results[i].isDeleted())
continue;
// if this is the listing to match against
count++;
if(count >= x)
{
ps.setPrice(results[i].getPrice() - y);
break;
}
}
8.1.2.24
isTRS ( )
Retrieves whether or not the listing is from a Top Rated Seller.
Returns
If the listing is on eBay or Half.com and the seller is a Top Rated Seller then return TRUE. Returns FALSE,
otherwise.
8.2
PS Class Reference
Public Member Functions
•
•
•
•
•
•
•
•
•
•
•
•
•
•
performSearch ()
getErrorMessage ()
performSafeSearch ()
performSelfSearch ()
performSelfSafeSearch ()
xLowestY ($x, $y)
xLowestYPercent ($x, $y)
averageX ($x)
getMyAmazonPrice ()
getCeilingPrice ()
getFloorPrice ()
getShippingHandling ()
getSearchParameter ($key)
setSearchParameter ($key, $value)
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
8.2 PS Class Reference
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
27
getSiteCountry ()
getResults ()
getRealResults ()
getNumResults ()
getRealNumResults ()
getRank ($price)
getRealRank ($price)
getNoCompetitionFound ()
overrideNoCompetitionFound ()
delete ($index)
setPrice ($price)
getCurrentPrice ()
getLastPriceChangePrice ()
getLastPriceChangeTime ()
getSecondsSinceLastPriceChange ()
getLastSaleTime ()
getNumSales ($start=0, $end=2147483647)
getNumSalesSince ($seconds)
getData ()
writeData ($str)
getSecondsSinceStart ()
getSecondsRemaining ()
getQuantity ()
getGoldBid ($currency, $unit)
getGoldAsk ($currency, $unit)
getSilverBid ($currency, $unit)
getSilverAsk ($currency, $unit)
8.2.1
Detailed Description
A publicly available class that exposes Price Spectre functionality.
8.2.2
Member Function Documentation
8.2.2.1
averageX ( $x )
Performs pre-defined x Average algorithm.
Performs a search based on the current search parameters and then performs the "x Average" algorithm. Returns
the total price based on "x Average".
Warning
This generates a new search and discards the results of any prior searches generated from PS::performSearch(), PS::xLowestY(), etc. or the one provided automatically by Price Spectre. This may result in usage of
premium points.
Parameters
x
Specifies the number of search results to average.
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
28
Data Structure Documentation
Returns
The total price as computed by "x Average". Execution terminates on failure.
// Sets our price to y% lower than the average of the lowest X prices found.
price = ps.averageX(x) * (1 - y/100);
ps.setPrice(price);
8.2.2.2
delete ( $index )
Deletes a listing from the results set.
This function does not actually delete the listing but prevents Price Spectre from considering it in the final results
(e.g. reporting, reprice history, etc.). Calling this function will affect the values returned by PS::getRealResults() and
PS::getRealNumResults(). Calling this function also makes Listing::isDeleted() return TRUE.
This may be useful in situations where a search parameter is not sufficient to filter out a particular type of listing.
Warning
Since Price Spectre is limited to retrieving the first 100 matching results from eBay, search parameters should
always be used as a filter instead whenever possible.
If all results are deleted Price Spectre will observe that no competitor listings were found. Deletion of a listing
is not required to ignore it but may make the results easier to understand. Deletions are not carried over to
subsequent searches.
Parameters
index
Specifies which result to remove from the results set.
// Delete all non-new listings
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
// Delete if not new
if(results[i].getConditionID() != 1000)
{
ps.delete(i);
}
}
// Perform X lowest by $Y on remaining listings.
count = 0;
results = ps.getRealResults();
numResults = ps.getRealNumResults();
for(i = 0; i < numResults; ++i)
{
// if this is the listing to match against
count++;
if(count >= x)
{
ps.setPrice(results[i].getPrice() - y);
break;
}
}
8.2.2.3
getCeilingPrice ( )
Retrieves the total ceiling price of the seller’s listing. This amount is inclusive of shipping charges unless shipping
and handling charges are being ignored.
Returns
The total ceiling price.
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
8.2 PS Class Reference
8.2.2.4
29
getCurrentPrice ( )
Returns the current price of the listing.
Returns
The current price of the listing.
// Increases current price by 1%.
currentPrice = ps.getCurrentPrice();
ps.setPrice(currentPrice * 1.01);
8.2.2.5
getData ( )
Retrieves user data for the listing.
A string of up to 255 characters can be stored containing any user-defined data or state information.
Examples of possible data could be information regarding the current or past state of the listing or additional variables.
Returns
A string containing user data that has been saved for the listing. If no data has been stored then returns an
empty string.
//
//
//
//
Example of pulling 3 variables from data.
Previously a string of three comma-separated
values was stored in data.
Example: 1,2,3
var data = ps.getData();
var arr = data.split(",");
// fetches data
// create array
// assign each variable x, y, and z.
x = arr[0];
y = arr[1];
z = arr[2];
if(x < 1)
throw ’x must be positive’;
if(y < 1)
throw ’y must be positive’;
if(z < 1)
throw ’z must be positive’;
8.2.2.6
getErrorMessage ( )
Returns error message for last call to PS::performSearch().
Returns
Error message string if error exists. If no error message exists returns empty string.
// Performs search and terminates with error message on failure.
if(!ps.performSearch())
throw ps.getErrorMessage();
8.2.2.7
getFloorPrice ( )
Retrieves the total floor price of the seller’s listing. This amount is inclusive of shipping charges unless shipping and
handling charges are being ignored.
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
30
Data Structure Documentation
Returns
The total floor price.
// Perform X lowest by $Y on listings.
floorPrice = ps.getFloorPrice();
count = 0;
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
// ignore this listing if it is below our floor price.
if(results[i].getPrice() < floorPrice)
{
continue;
}
// if this is the listing to match against
count++;
if(count >= x)
{
ps.setPrice(results[i].getPrice() - y);
break;
}
}
8.2.2.8
getGoldAsk ( $currency, $unit )
Retrieves the current ask price for gold bullion.
Parameters
currency
unit
Specifies the currency to retrieve price in. Possible values: ’USD’, ’GBP’, ’EUR’, ’AUD’, ’CAD’
Specifies the mass unit. Possible values: ’kg’, ’g’, ’gr’, ’ozt’, ’troy’
Returns
The current ask price for gold bullion per the unit mass specified.
// Sets our price to 5% higher than gold.
// X specifies the weight in grains we are selling.
price = ps.getGoldAsk(’USD’, ’gr’) * x * 1.05;
ps.setPrice(price);
8.2.2.9
getGoldBid ( $currency, $unit )
Retrieves the current bid price for gold bullion.
Parameters
currency
unit
Specifies the currency to retrieve price in. Possible values: ’USD’, ’GBP’, ’EUR’, ’AUD’, ’CAD’
Specifies the mass unit. Possible values: ’kg’, ’g’, ’gr’, ’ozt’, ’troy’
Returns
The current bid price for gold bullion per the unit mass specified.
// Sets our price to 5% higher than gold.
// X specifies the weight in troy ounces we are selling.
price = ps.getGoldBid(’USD’, ’ozt’) * x * 1.05;
ps.setPrice(price);
8.2.2.10
getLastPriceChangePrice ( )
Retrieves the last price that the listing was set to. This should be equal to PS::getCurrentPrice();
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
8.2 PS Class Reference
31
Returns
The last price that the listing was set to.
8.2.2.11
getLastPriceChangeTime ( )
Retrieves the epoch time of the last price change for the listing.
Returns
The epoch time of the last price change. If no price changes then returns the timestamp when Price Spectre
first became aware of the listing.
// Reduce price by y% every x days.
now = Math.round(Date.now() / 1000);
secondsPerDay = 86400;
lastPriceChange = ps.getLastPriceChangeTime();
daysSinceChange = (now - lastPriceChange) / secondsPerDay;
currentPrice = ps.getCurrentPrice();
if(daysSinceChange >= x)
ps.setPrice(currentPrice * (1 - y/100));
8.2.2.12
getLastSaleTime ( )
Retrieves the epoch time of the last time a sale was made for the listing.
Returns
The epoch time of the last time a sale was made for the listing. If no sales are recorded then returns 0.
// Reduce price by y% if sale hasn’t been made in x days and price
// hasn’t changed in 7 days.
now = Math.round(Date.now() / 1000);
secondsPerDay = 86400;
secondsPerXDay = secondsPerDay * x;
secondsSincePriceChange = ps.getSecondsSinceLastPriceChange();
daysSinceChange = secondsSincePriceChange / secondsPerDay;
lastSaleTime = ps.getLastSaleTime();
daysSinceLastSale = (now - lastSaleTime) / secondsPerDay;
currentPrice = ps.getCurrentPrice();
if(daysSinceLastSale >= x && daysSinceChange >= secondsPerXDay)
ps.setPrice(currentPrice * (1 - y/100));
8.2.2.13
getMyAmazonPrice ( )
Checks Amazon for the seller’s own Amazon price based on ASIN.
Performs an ASIN search against the seller’s own Amazon account. If a product is found return its price. Otherwise,
throw an exception. The ASIN is retrieved from the Product Code or Keywords search parameter. Useful for
maintaining price parity.
Returns
The total price of product from the Amazon seller account. Exception thrown on failure.
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
32
Data Structure Documentation
Warning
Amazon does not permit searching against a specific Amazon competitor. In order for this function to work the
seller must have provided Amazon MWS access to Price Spectre.
// Sync our eBay price to our Amazon price.
// If no Amazon listing found perform xLowestY instead
try {
price = ps.getMyAmazonPrice();
} catch (err) {
price = ps.xLowestY(x,y);
}
ps.setPrice(price);
8.2.2.14
getNoCompetitionFound ( )
Checks whether no competitors were found during last search performed.
Returns
Returns TRUE if no competitor listings were found. Returns FALSE if competitor listings were found.
// Set price to X lowest Y with x = 1, y = 0.01.
// But terminates with an error if no competitors were found.
price = ps.xLowestY(1, 0.01);
if(ps.getNoCompetitionFound())
{
throw ’No competitors found’;
}
8.2.2.15
getNumResults ( )
Retrieves the number of competitor listings found. Deleted listings are included in the count.
Returns
The count of competitor listings found.
// Perform X lowest by $Y on listings.
count = 0;
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
// if this is the listing to match against
count++;
if(count >= x)
{
ps.setPrice(results[i].getPrice() - y);
break;
}
}
8.2.2.16
getNumSales ( $start = 0, $end = 2147483647 )
Retrieves the quantity sold between two epoch times.
Parameters
start
end
Specifies the epoch time to begin counting sales. If not specified a default of 0 is used.
Specifies the epoch time to stop counting sales. If not specified a default of 2147483647 is
used.
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
8.2 PS Class Reference
Returns
The quantity sold during the specified period of time.
// Reduce price by y% if x sales haven’t been made in 7 days and price hasn’t
// changed in 7 days.
now = Math.round(Date.now() / 1000);
secondsPerDay = 86400;
secondsPerWeek = secondsPerDay * 7;
secondsSincePriceChange = ps.getSecondsSinceLastPriceChange();
daysSinceChange = secondsSincePriceChange / secondsPerDay;
numSales = ps.getNumSales(now - secondsPerWeek);
currentPrice = ps.getCurrentPrice();
if(numSales < x && daysSinceChange >= 7)
ps.setPrice(currentPrice * (1 - y/100));
8.2.2.17
getNumSalesSince ( $seconds )
Retrieves the quantity sold during the past number of seconds.
Parameters
seconds
Specifies the number of seconds in the past to begin counting sales.
Returns
The quantity sold during the past number of seconds.
// Reduce price by y% if x sales haven’t been made in 7 days and price
// hasn’t changed in 7 days.
now = Math.round(Date.now() / 1000);
secondsPerDay = 86400;
secondsPerWeek = secondsPerDay * 7;
secondsSincePriceChange = ps.getSecondsSinceLastPriceChange();
daysSinceChange = secondsSincePriceChange / secondsPerDay;
numSales = ps.getNumSalesSince(secondsPerWeek);
currentPrice = ps.getCurrentPrice();
if(numSales < x && daysSinceChange >= 7)
ps.setPrice(currentPrice * (1 - y/100));
8.2.2.18
getQuantity ( )
Retrieves the quantity available of the listing.
Returns
The quantity available of the listing.
// Perform X Lowest By $Y algorithm
// But increases price 10x when only one remains.
quantity = ps.getQuantity();
if(quantity <= 1)
{
price = ps.getSearchParameter(’binPrice’) * 10;
}
else
{
price = ps.xLowestY(x, y);
}
ps.setPrice(price);
8.2.2.19
getRank ( $price )
Retrieves the rank achieved at a given price based on the competitors found.
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
33
34
Data Structure Documentation
Parameters
price
Specifies the price to check rank against.
Returns
The rank at a given price. Returns 0 if no competitors were found.
// Sets our price 0.05 lower than the lowest price.
price = ps.xLowestY(1, 0.05);
rank = ps.getRank(price);
if(rank > 1)
throw ’FAILED: Could only achieve a ranking of ’ + rank;
ps.setPrice(price);
8.2.2.20
getRealNumResults ( )
Retrieves the actual number of competitor listings found. Deleted listings are ignored in the count.
Returns
The count of competitor listings found excluding previously deleted listings.
// Delete all non-new listings
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
// delete if not new
if(results[i].getConditionID() != 1000)
{
ps.delete(i);
}
}
// Perform X lowest by $Y on remaining listings.
count = 0;
results = ps.getRealResults();
numResults = ps.getRealNumResults();
for(i = 0; i < numResults; ++i)
{
// if this is the listing to match against
count++;
if(count >= x)
{
ps.setPrice(results[i].getPrice() - y);
break;
}
}
8.2.2.21
getRealRank ( $price )
Retrieves the rank achieved at a given price based on the competitors found. Deleted listings are ignored in the
count.
Parameters
price
Specifies the price to check rank against.
Returns
The rank at a given price. Returns 0 if no competitors were found.
// Sets our price 0.05 lower than the lowest price.
price = ps.xLowestY(1, 0.05);
rank = ps.getRealRank(price);
if(rank > 1)
throw ’FAILED: Could only achieve a ranking of ’ + rank;
ps.setPrice(price);
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
8.2 PS Class Reference
8.2.2.22
35
getRealResults ( )
Retrieves an array of class Listing representing the actual competitor listings found. Deleted listings are ignored.
Returns
Array of Listing objects.
// Delete all non-new listings
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
// Delete if not new
if(results[i].getConditionID() != 1000)
{
ps.delete(i);
}
}
// Perform X lowest by $Y on remaining listings.
count = 0;
results = ps.getRealResults();
numResults = ps.getRealNumResults();
for(i = 0; i < numResults; ++i)
{
// if this is the listing to match against
count++;
if(count >= x)
{
ps.setPrice(results[i].getPrice() - y);
break;
}
}
8.2.2.23
getResults ( )
Retrieves an array of class Listing representing the actual competitor listings found.
Returns
Array of Listing objects.
// Perform X lowest by $Y on listings.
count = 0;
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
// if this is the listing to match against
count++;
if(count >= x)
{
ps.setPrice(results[i].getPrice() - y);
break;
}
}
8.2.2.24
getSearchParameter ( $key )
Retrieves a specified search parameter.
Parameters
key
Specifies the search parameter to retrieve. Possible values: ’keywords’, ’productCode’, ’minFeedback’, ’maxFeedback’, ’minPrice’, ’maxPrice’, ’minQty’, ’maxQty’, ’maxHandlingTime’,
’includeSellers’, ’excludeSellers’, ’exemptSellers’, ’ebayFixedprice’, ’ebayAuctions’, ’findHalf’,
’findAmazon’, ’domestic’, ’hideDuplicates’, ’trs’, ’returnsAccepted’, ’restrictCategory’, ’searchCategory’, ’searchCondition’, ’binPrice’, ’floorPrice’, ’ceilPrice’, ’postalCodeUS’, ’destination’
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
36
Data Structure Documentation
Returns
The current value of the search parameter.
// Retrieves the keywords specified for the listing.
keywords = ps.getSearchParameter(’keywords’);
8.2.2.25
getSecondsRemaining ( )
Retrieves the number of seconds before the listing will end.
Returns
The number of seconds that before the listing will end if it was listed on eBay. Returns 2147483647, otherwise.
results = ps.getResults();
numResults = ps.getNumResults();
secondsPerDay = 86400;
// Delete all results that will end in less than one day.
for(i = 0; i < numResults; ++i)
{
timeleft = results[i].getSecondsRemaining();
if(timeleft < secondsPerDay)
{
ps.delete(i);
}
}
8.2.2.26
getSecondsSinceLastPriceChange ( )
Retrieves the number of seconds since the last price change.
Returns
The number of seconds since the last price change.
// Reduce price by y% every x days.
secondsPerDay = 86400;
secondsSincePriceChange = ps.getSecondsSinceLastPriceChange();
daysSinceChange = secondsSincePriceChange / secondsPerDay;
currentPrice = ps.getCurrentPrice();
if(daysSinceChange >= x)
ps.setPrice(currentPrice * (1 - y/100));
8.2.2.27
getSecondsSinceStart ( )
Adds debug message. Append message to any previously debug messages.
If this is called at anytime during execution this will become an error message and may be reported the user.
Attention
This does not interrupt execution of the script but any price changes will be ignored. To immediately terminate
execution of script with an error message use throw instead.
Parameters
message
Debug message that will be returned as an error once script ends.
// Perform X lowest by $Y on listings.
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
8.2 PS Class Reference
37
// if x is less than or equal to 0 generate an error but continue running.
if(x <= 0)
{
ps.debugMessage(’Warning: Invalid value for x ’ + x + ’.’);
}
count = 0;
results = ps.getResults();
numResults = ps.getNumResults();
for(i = 0; i < numResults; ++i)
{
// if this is the listing to match against
count++;
if(count >= x)
{
price = results[i].getPrice() - y;
// if we are trying to set a price of $0 or less generate warning but continue.
if(price <= 0)
{
item = results[i].getListingID();
ps.debugMessage(’Warning: Price attempted set to ’ + price + ’ item = ’ + item + ’.’);
continue;
}
ps.setPrice(price);
break;
}
}
Retrieves the number of seconds since the listing has started.
Returns
The number of seconds that have elapsed since the listing started if it was listed on eBay. Otherwise, returns 0.
results = ps.getResults();
numResults = ps.getNumResults();
secondsPerDay = 86400;
// Delete all results that have been listed less than one day.
for(i = 0; i < numResults; ++i)
{
age = results[i].getSecondsSinceStart();
if(age < secondsPerDay)
{
ps.delete(i);
}
}
8.2.2.28
getShippingHandling ( )
Retrieves the shipping and handling charges for the seller’s listing.
Returns
The shipping and handling charges. If shipping and handling charges are being ignored then returns 0.
8.2.2.29
getSilverAsk ( $currency, $unit )
Retrieves the current ask price for silver bullion.
Parameters
currency
unit
Specifies the currency to retrieve price in. Possible values: ’USD’, ’GBP’, ’EUR’, ’AUD’, ’CAD’
Specifies the mass unit. Possible values: ’kg’, ’g’, ’gr’, ’ozt’, ’troy’
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
38
Data Structure Documentation
Returns
The current ask price for silver bullion per the unit mass specified.
// Sets our price to 5% higher than silver.
// X specifies the weight in kilograms we are selling.
price = ps.getSilverAsk(’USD’, ’kg’) * x * 1.05;
ps.setPrice(price);
8.2.2.30
getSilverBid ( $currency, $unit )
Retrieves the current bid price for silver bullion.
Parameters
currency
unit
Specifies the currency to retrieve price in. Possible values: ’USD’, ’GBP’, ’EUR’, ’AUD’, ’CAD’
Specifies the mass unit. Possible values: ’kg’, ’g’, ’gr’, ’ozt’, ’troy’
Returns
The current bid price for silver bullion per the unit mass specified.
// Sets our price to 5% higher than silver.
// X specifies the weight in grams we are selling.
price = ps.getSilverBid(’USD’, ’g’) * x * 1.05;
ps.setPrice(price);
8.2.2.31
getSiteCountry ( )
Retrieves the country associated with the eBay site the item was listed to.
Returns
Two-letter ISO 3166 country code to indicate the country of the eBay site where the item is listed (e.g., "US" for
the eBay.com or "GB" for the eBay.co.uk).
results = ps.getResults();
numResults = ps.getNumResults();
myCountry = ps.getSiteCountry();
// Delete all international results.
for(i = 0; i < numResults; ++i)
{
theirCountry = results[i].getLocation();
if(myCountry != theirCountry)
{
ps.delete(i);
}
}
8.2.2.32
overrideNoCompetitionFound ( )
Tells Price Spectre to not apply its own logic during the "No competition found" situation.
By default Price Spectre will override any prices set if the last search performed results in no competitor listings
being found. The price set can be configured via the "No competition found" behavior.
Make a call to this function if you wish to provide your own logic for handling this situation and prevent Price Spectre
from applying its own. This can be called at any time.
// Set price to X lowest Y with x = 1, y = 0.01.
// But decrease price 5% if no results.
price = ps.xLowestY(1, 0.01);
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
8.2 PS Class Reference
39
if(ps.getNoCompetitionFound())
{
price = ps.getCurrentPrice() * 0.95;
}
ps.setPrice(price);
ps.overrideNoCompetitionFound();
8.2.2.33
performSafeSearch ( )
Performs a search based on the given search parameters.
This function differs from PS::performSearch() in that if a failure occurs execution of algorithm will immediately
terminate with the appropriate error message.
After the search is performed make a call to PS::getResults() and PS::getNumResults() to retrieve the search results
and number of results found.
Warning
This generates a new search and discards the results of any prior searches generated from PS::performSearch(), PS::xLowestY(), etc. or the one provided automatically by Price Spectre. This may result in usage of
premium points.
Returns
TRUE on success. Execution terminates on failure.
8.2.2.34
performSearch ( )
Performs a search based on the given search parameters.
After the search is performed make a call to PS::getResults() and PS::getNumResults() to retrieve the search results
and number of results found.
The user must make their own accommodations in the case that the search fails. See PS::performSafeSearch() for
an identical function that doesn’t have this requirement.
Warning
This generates a new search and discards the results of any prior searches generated from PS::performSearch(), PS::xLowestY(), etc. or the one provided automatically by Price Spectre. This may result in usage of
premium points.
Returns
TRUE on success or FALSE on search failure. Make call to PS::getErrorMessage() to retrieve error messages.
// Performs search and terminates on failure.
if(!ps.performSearch())
throw ps.getErrorMessage();
8.2.2.35
performSelfSafeSearch ( )
Performs a self search on Amazon.
This function differs from PS::performSelfSearch() in that if a failure occurs execution of algorithm will immediately
terminate with the appropriate error message.
After the search is performed make a call to PS::getResults() and PS::getNumResults() to retrieve the search results
and number of results found.
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
40
Data Structure Documentation
Warning
This generates a new search and discards the results of any prior searches generated from PS::performSearch(), PS::xLowestY(), etc. or the one provided automatically by Price Spectre. This may result in usage of
premium points.
Returns
TRUE on success. Execution terminates on failure.
// Sync our eBay price to our Amazon price.
ps.performSelfSafeSearch();
results = ps.getResults();
numResults = ps.getNumResults();
if(numResults >= 1)
{
price = results[0].getPrice();
ps.setPrice(price);
}
8.2.2.36
performSelfSearch ( )
Performs a self search on Amazon.
After the search is performed make a call to PS::getResults() and PS::getNumResults() to retrieve the search results
and number of results found.
The user must make their own accommodations in the case that the search fails. See PS::performSelfSafeSearch()
for an identical function that doesn’t have this requirement.
Warning
This generates a new search and discards the results of any prior searches generated from PS::performSearch(), PS::xLowestY(), etc. or the one provided automatically by Price Spectre. This may result in usage of
premium points.
Returns
TRUE on success or FALSE on search failure. Make call to PS::getErrorMessage() to retrieve error messages.
// Sync our eBay price to our Amazon price.
// Performs search and terminates on failure.
if(!ps.performSelfSearch())
throw ps.getErrorMessage();
results = ps.getResults();
numResults = ps.getNumResults();
if(numResults >= 1)
{
price = results[0].getPrice();
ps.setPrice(price);
}
8.2.2.37
setPrice ( $price )
Sets the total price of the listing.
If this function is not called within the algorithm the final price will remain at its current level.
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
8.2 PS Class Reference
41
Warning
The listing’s final price may or may not be equal to the price specified. Once your algorithm finishes Price
Spectre may perform additional changes to ensure the final price fits within the constraints of your floor and
ceiling prices along with performing Bat’a pricing.
By default if no competitor listings are found with the last search performed then the final price would also be
overridden based on "No competition found" behavior that was set. This can be avoided by making a call to PS::overrideNoCompetitionFound().
Parameters
price
Specifies the total price to set the listing to.
Returns
The current price of the listing.
// Increases current price by 1%.
currentPrice = ps.getCurrentPrice();
ps.setPrice(currentPrice * 1.01);
8.2.2.38
setSearchParameter ( $key, $value )
Sets a specified search parameter.
Parameters
key
value
Specifies the search parameter to set. Possible values: ’keywords’, ’productCode’, ’minFeedback’, ’maxFeedback’, ’minPrice’, ’maxPrice’, ’minQty’, ’maxQty’, ’maxHandlingTime’,
’includeSellers’, ’excludeSellers’, ’exemptSellers’, ’ebayFixedprice’, ’ebayAuctions’, ’findHalf’,
’findAmazon’, ’domestic’, ’hideDuplicates’, ’trs’, ’returnsAccepted’, ’restrictCategory’, ’searchCategory’, ’searchCondition’, ’binPrice’, ’floorPrice’, ’ceilPrice’, ’postalCodeUS’, ’destination’
Specifies the new value for the search parameter.
Returns
FALSE on failure. TRUE on success.
// Disables TRS filter and retries search if no competition found.
price = ps.xLowestY(x,y);
// if no competitor listings found
if(ps.getNoCompetitionFound())
{
trs = ps.getSearchParameter(’trs’);
// if we had TRS set unset and make us 5th lowest price.
if(trs)
{
ps.setSearchParameter(’trs’, false);
price = ps.xLowestY(5, 0.01);
}
}
ps.setPrice(price);
8.2.2.39
writeData ( $str )
Writes user data to the database for the listing.
A string of up to 255 characters can be stored containing any user-defined data or state information.
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
42
Data Structure Documentation
Examples of possible data could be information regarding the current or past state of the listing or additional variables.
Parameters
str
Specifies a string to store as data for the listing.
Returns
TRUE on success or FALSE on failure.
// Example of writing an array to the database.
var arr = [1, 0.01, 3];
var str = arr.toString();
ps.writeData(str);
8.2.2.40
// our array which represents three variables.
// a string representation of that array.
// write the data to the DB
xLowestY ( $x, $y )
Performs pre-defined "x lowest by $y" algorithm
Performs a search based on the current search parameters and then performs the "x lowest by $y" algorithm.
Returns the total price based on "x lowest by $y".
Warning
This generates a new search and discards the results of any prior searches generated from PS::performSearch(), PS::xLowestY(), etc. or the one provided automatically by Price Spectre. This may result in usage of
premium points.
Parameters
x
y
Specifies which search result to match against. ex: 1 matches against the lowest price, 2
matches against the second lowest price, etc.
Specifies the amount to discount the Xth lowest price. Positive values of Y result in pricing
below the Xth lowest price. A zero value of Y results in matching the Xth lowest price. Negative
values of Y result in pricing above the Xth lowest price.
Returns
The total price as computed by "x lowest by $y". Execution terminates on failure.
// Sets our price 0.05 lower than the lowest price.
price = ps.xLowestY(1, 0.05);
ps.setPrice(price);
8.2.2.41
xLowestYPercent ( $x, $y )
Performs pre-defined "x lowest y%" algorithm.
Performs a search based on the current search parameters and then performs the "x lowest y%" algorithm. Returns
the total price based on "x lowest y%".
Warning
This generates a new search and discards the results of any prior searches generated from PS::performSearch(), PS::xLowestY(), etc. or the one provided automatically by Price Spectre. This may result in usage of
premium points.
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
8.3 WS Class Reference
43
Parameters
x
y
Specifies which search result to match against. ex: 1 matches against the lowest price, 2
matches against the second lowest price, etc.
Specifies the percentage to discount the Xth lowest price. Positive values of Y result in pricing
below the Xth lowest price. A zero value of Y results in matching the Xth lowest price. Negative
values of Y result in pricing above the Xth lowest price.
Returns
The total price as computed by "x lowest y%". Execution terminates on failure.
// Sets our price 5% lower than the lowest price.
price = ps.xLowestYPercent(1, 5);
ps.setPrice(price);
8.3
WS Class Reference
Public Member Functions
•
•
•
•
•
setEndpoint ($endpoint)
setHeaders ($headers)
setRequestBody ($requestBody)
get ()
post ()
8.3.1
Detailed Description
A class that allows calling external webservices and APIs.
8.3.2
Member Function Documentation
8.3.2.1
get ( )
Performs a GET call to the external webservice.
Returns
A String with the output of the webservice call.
// Perform a GET request and store in XMLDocument
var response = ws.get();
var xmlResponse = new XMLDocument(response);
8.3.2.2
post ( )
Performs a POST call to the external webservice.
Returns
A String with the output of the webservice call.
// Perform a POST request and store in XMLDocument
var response = ws.post();
var xmlResponse = new XMLDocument(response);
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
44
Data Structure Documentation
8.3.2.3
setEndpoint ( $endpoint )
Sets the endpoint of the external webservice to contact.
Returns
The calling WS object.
Parameters
endpoint
Specifies the endpoint of the external webservice. This should include any necessary GET
parameters.
// sets up WS object to communicate with eBay’s finding API.
var findingAPI = ’http://svcs.ebay.com/services/search/FindingService/v1’;
ws.setEndpoint(findingAPI);
8.3.2.4
setHeaders ( $headers )
Sets the headers to include when calling the external webservice.
Returns
The calling WS object.
Parameters
headers
An array specifying the headers to include when calling the external webservice.
// sets up WS object to communicate with eBay’s finding API.
var headers = new Array(
"X-EBAY-SOA-OPERATION-NAME: findItemsByProduct",
"X-EBAY-SOA-SECURITY-APPNAME: <YOUR APP ID>",
"X-EBAY-SOA-GLOBAL-ID: EBAY-US",
"X-EBAY-SOA-SERVICE-VERSION: 1.11.0"
);
ws.setHeaders(headers);
8.3.2.5
setRequestBody ( $requestBody )
Sets the request body to include when POSTing to the external webservice.
Returns
The calling WS object.
Parameters
requestBody
The body to POST when making the exterenal webservice call. requestBody can be of type
String or XMLDocument
// fetch UPC from keywords
var upc = ps.getSearchParameter(’keywords’);
// sets up WS object to communicate with eBay’s finding API.
var xmlStr = "<?xml version=’1.0’?>"
+ ’<findItemsByProductRequest
+ "<productId type=\"UPC\">" + upc + "</productId>"
+ "<sortOrder>PricePlusShippingLowest</sortOrder>"
+ "</findItemsByProductRequest>";
);
ws.setRequestBody(xmlStr);
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
8.4 XMLDocument Class Reference
8.4
45
XMLDocument Class Reference
Inheritance diagram for XMLDocument:
XMLNode
XMLDocument
Collaboration diagram for XMLDocument:
XMLNode
XMLDocument
Public Member Functions
• __construct ($str)
• toString ()
8.4.1
Detailed Description
A class that represents an XML document.
8.4.2
8.4.2.1
Constructor & Destructor Documentation
construct ( $str )
Creates the XMLDocument.
// fetch UPC from keywords
var upc = ps.getSearchParameter(’keywords’);
// create request XML
var xmlStr = "<?xml version=’1.0’?>"
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
46
+
+
+
+
Data Structure Documentation
’<findItemsByProductRequest xmlns="http://www.ebay.com/marketplace/search/v1/services">’
"<productId type=\"UPC\">" + upc + "</productId>"
"<sortOrder>PricePlusShippingLowest</sortOrder>"
"</findItemsByProductRequest>";
// Create an XMLDocument object from the above string.
var xmlRequest = new XMLDocument(xmlStr);
8.4.3
Member Function Documentation
8.4.3.1
toString ( )
Returns a string representing the XMLDocument.
Returns
A string representing the XMLDocument.
// copy XML request as requestCopy
var requestCopy = new XMLDocument(request.toString());
8.5
XMLNode Class Reference
Inheritance diagram for XMLNode:
XMLNode
XMLDocument
Public Member Functions
•
•
•
•
•
8.5.1
getChildNodes ()
getElements ($name)
getElement ($name)
getName ()
getValue ()
Detailed Description
A class that a node in an XML document.
8.5.2
Member Function Documentation
8.5.2.1
getChildNodes ( )
Retrieves all child nodes of an XML node.
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
8.5 XMLNode Class Reference
Returns
An XMLNodeList containing all child nodes of an XML Node.
var response = new XMLDocument(ws.post());
// Throw exception on error.
var errorMessage = response.getElement(’errorMessage’);
if(errorMessage)
{
var nodeList = errorMessage.getChildNodes();
for(i = 0; i < count(nodeList); ++i)
{
if(nodeList.item(i).getName() == ’error’)
{
throw nodeList.item(i).getElement(’message’).getValue();
}
}
}
8.5.2.2
getElement ( $name )
Retrieves an XMLNode of the first lower-level node which has the specified name.
Returns
An XMLNode of the first lower-level node which have the specified name.
Parameters
name
Specifies the name of a node to retrieve.
var response = new XMLDocument(ws.post());
var price = response.getElement(’currentPrice’);
if(price !== null)
{
ps.setPrice(price.getValue() - 0.01);
}
else
{
throw "No prices found.";
}
8.5.2.3
getElements ( $name )
Retrieves an XMLNodeList of all lower-level nodes which have the specified name.
Returns
An XMLNodeList of all lower-level nodes which have the specified name.
Parameters
name
Specifies the name of the lower-level nodes to retrieve.
var response = new XMLDocument(ws.post());
var prices = response.getElements(’currentPrice’);
var price = prices.item(0);
if(price !== null)
{
ps.setPrice(price.getValue() - 0.01);
}
else
{
throw "No prices found.";
}
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
47
48
Data Structure Documentation
8.5.2.4
getName ( )
Retrieves the name of the XMLNode.
Returns
The name of the XMLNode.
var response = new XMLDocument(ws.post());
// Throw exception on error.
var errorMessage = response.getElement(’errorMessage’);
if(errorMessage)
{
var nodeList = errorMessage.getChildNodes();
for(i = 0; i < count(nodeList); ++i)
{
if(nodeList.item(i).getName() == ’error’)
{
throw nodeList.item(i).getElement(’message’).getValue();
}
}
}
8.5.2.5
getValue ( )
Retrieves the value of the XMLNode.
Returns
The value of the XMLNode.
var response = new XMLDocument(ws.post());
var prices = response.getElements(’currentPrice’);
var price = prices.item(0);
if(price !== null)
{
ps.setPrice(price.getValue() - 0.01);
}
else
{
throw "No prices found.";
}
8.6
XMLNodeList Class Reference
Public Member Functions
• item ($index)
• count ()
8.6.1
Detailed Description
A class that represents a list of XMLNodes .
8.6.2
Member Function Documentation
8.6.2.1
count ( )
Retrieves number of top-level nodes in the XMLNodeList.
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
8.6 XMLNodeList Class Reference
Returns
A count of the number of top-level nodes.
var response = new XMLDocument(ws.post());
var errors = response.getElements(’errors’);
var countErrors = errors.count();
if(countErrors > 0)
{
throw countErrors + " errors.";
}
8.6.2.2
item ( $index )
Retrieves number of top-level nodes in the XMLNodeList.
Returns
The node in the list at the specified index. NULL if index is out of bounds.
Parameters
index
Specifies the index of a node in the XMLNodeList to retrieve.
var response = new XMLDocument(ws.post());
var prices = response.getElements(’currentPrice’);
var price = prices.item(0);
if(price !== null)
{
ps.setPrice(price.getValue() - 0.01);
}
else
{
throw "No prices found.";
}
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
49
Index
__construct
XMLDocument, 45
averageX
PS, 27
count
XMLNodeList, 48
delete
PS, 28
get
WS, 43
getCeilingPrice
PS, 28
getChildNodes
XMLNode, 46
getConditionID
Listing, 19
getConditionName
Listing, 20
getCurrentPrice
PS, 28
getData
PS, 29
getElement
XMLNode, 47
getElements
XMLNode, 47
getEndDate
Listing, 20
getEndTime
Listing, 20
getErrorMessage
PS, 29
getFeedbackPercent
Listing, 20
getFeedbackRating
Listing, 21
getFeedbackScore
Listing, 21
getFeedbackStar
Listing, 22
getFloorPrice
PS, 29
getFreeShipping
Listing, 22
getGoldAsk
PS, 30
getGoldBid
PS, 30
getLastPriceChangePrice
PS, 30
getLastPriceChangeTime
PS, 31
getLastSaleTime
PS, 31
getListingID
Listing, 22
getLocation
Listing, 22
getMerchantID
Listing, 23
getMyAmazonPrice
PS, 31
getName
XMLNode, 48
getNoCompetitionFound
PS, 32
getNumResults
PS, 32
getNumSales
PS, 32
getNumSalesSince
PS, 33
getOneDayShipping
Listing, 23
getPrice
Listing, 23
getQuantity
PS, 33
getRank
PS, 33
getRealNumResults
PS, 34
getRealRank
PS, 34
getRealResults
PS, 34
getResults
PS, 35
getReturnsAccepted
Listing, 23
getSearchParameter
PS, 35
getSecondsRemaining
Listing, 24
PS, 36
INDEX
getSecondsSinceLastPriceChange
PS, 36
getSecondsSinceStart
Listing, 24
PS, 36
getSeller
Listing, 24
getShippingHandling
PS, 37
getSilverAsk
PS, 37
getSilverBid
PS, 38
getSite
Listing, 25
getSiteCountry
PS, 38
getStartDate
Listing, 25
getStartTime
Listing, 25
getTitle
Listing, 25
getValue
XMLNode, 48
isDeleted
Listing, 25
isTRS
Listing, 26
item
XMLNodeList, 49
Listing, 19
getConditionID, 19
getConditionName, 20
getEndDate, 20
getEndTime, 20
getFeedbackPercent, 20
getFeedbackRating, 21
getFeedbackScore, 21
getFeedbackStar, 22
getFreeShipping, 22
getListingID, 22
getLocation, 22
getMerchantID, 23
getOneDayShipping, 23
getPrice, 23
getReturnsAccepted, 23
getSecondsRemaining, 24
getSecondsSinceStart, 24
getSeller, 24
getSite, 25
getStartDate, 25
getStartTime, 25
getTitle, 25
isDeleted, 25
isTRS, 26
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen
51
overrideNoCompetitionFound
PS, 38
PS, 26
averageX, 27
delete, 28
getCeilingPrice, 28
getCurrentPrice, 28
getData, 29
getErrorMessage, 29
getFloorPrice, 29
getGoldAsk, 30
getGoldBid, 30
getLastPriceChangePrice, 30
getLastPriceChangeTime, 31
getLastSaleTime, 31
getMyAmazonPrice, 31
getNoCompetitionFound, 32
getNumResults, 32
getNumSales, 32
getNumSalesSince, 33
getQuantity, 33
getRank, 33
getRealNumResults, 34
getRealRank, 34
getRealResults, 34
getResults, 35
getSearchParameter, 35
getSecondsRemaining, 36
getSecondsSinceLastPriceChange, 36
getSecondsSinceStart, 36
getShippingHandling, 37
getSilverAsk, 37
getSilverBid, 38
getSiteCountry, 38
overrideNoCompetitionFound, 38
performSafeSearch, 39
performSearch, 39
performSelfSafeSearch, 39
performSelfSearch, 40
setPrice, 40
setSearchParameter, 41
writeData, 41
xLowestY, 42
xLowestYPercent, 42
performSafeSearch
PS, 39
performSearch
PS, 39
performSelfSafeSearch
PS, 39
performSelfSearch
PS, 40
post
WS, 43
setEndpoint
WS, 43
setHeaders
52
INDEX
WS, 44
setPrice
PS, 40
setRequestBody
WS, 44
setSearchParameter
PS, 41
toString
XMLDocument, 46
WS, 43
get, 43
post, 43
setEndpoint, 43
setHeaders, 44
setRequestBody, 44
writeData
PS, 41
xLowestY
PS, 42
xLowestYPercent
PS, 42
XMLDocument, 45
__construct, 45
toString, 46
XMLNode, 46
getChildNodes, 46
getElement, 47
getElements, 47
getName, 48
getValue, 48
XMLNodeList, 48
count, 48
item, 49
Generated on Mon Feb 25 2013 23:55:55 for "Price Spectre" by Doxygen