Package com.tagtraum.ubermusic.amazon
Class Amazon
- java.lang.Object
-
- com.tagtraum.core.WebService
-
- com.tagtraum.ubermusic.amazon.Amazon
-
- All Implemented Interfaces:
Charts
public class Amazon extends WebService implements Charts
Encapsulates access to Amazon. Handles caching and REST request creation.- Author:
- Hendrik Schreiber
-
-
Field Summary
-
Fields inherited from class com.tagtraum.core.WebService
HTTP_METHOD_GET, HTTP_METHOD_POST, HTTP_METHOD_PUT, LOG
-
-
Constructor Summary
Constructors Constructor Description Amazon()
No arg constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)
Add property change listener.org.json.simple.JSONObject
browseNodeLookup(long browseNodeId, long maximumAge, TimeUnit timeUnit)
Looks up browsenode.org.json.simple.JSONObject
browseNodeLookup(BrowseNode browseNode)
Looks up browsenode with default max age.org.json.simple.JSONObject
browseNodeLookup(BrowseNode browseNode, long maximumAge, TimeUnit timeUnit)
Looks up browsenode.protected boolean
cacheResource(URL url, byte[] content)
Allows turning caching for a specific resource and its content on and off.List<PlayList>
getCharts(Locale market)
List<org.json.simple.JSONObject>
getGenreBrowseNodes()
Get the genre browse nodes for the currently configured locale.protected org.json.simple.JSONObject
getJSONObject(String request, org.json.simple.JSONObject requestPayload)
protected org.json.simple.JSONObject
getJSONObject(String request, org.json.simple.JSONObject requestPayload, long maximumAge, TimeUnit timeUnit)
Locale
getLocale()
LocaleConfiguration
getLocaleConfiguration()
org.json.simple.JSONObject
getMP3DownloadsAlbum(String artist, String title)
ItemSearch for MP3Downloads matching an encodedArtist/encodedTitle.org.json.simple.JSONObject
getMusicAlbum(String artist, String title)
ItemSearch for Music matching an encodedArtist/encodedTitle.String
getName()
Name of this chart provider.org.json.simple.JSONObject
getTitle(String searchIndex, String title)
ItemSearch for an item with the specified title.protected void
handleStatusCode(HttpURLConnection httpURLConnection, int statusCode)
Handles standard responses to status codes.org.json.simple.JSONObject
itemLookup(String... asin)
Look up an item using it's ASIN.org.json.simple.JSONObject
itemSearch(String keywords)
Searches in SearchIndex Music for items which match the given keywords.org.json.simple.JSONObject
itemSearch(String searchIndex, BrowseNode browseNode, String keywords, String sortBy, int page, long maximumAge, TimeUnit timeUnit)
Searches in a given SearchIndex for items which match the given keywords.org.json.simple.JSONObject
itemSearch(String searchIndex, String keywords)
Searches in a given SearchIndex for items which match the given keywords.org.json.simple.JSONObject
itemSearchNewReleases(BrowseNode browseNode, int page)
ItemSearch in a Music search index, result ordered by age.org.json.simple.JSONObject
itemSearchNewReleases(String searchIndex, BrowseNode browseNode, int page)
ItemSearch result, ordered by age.org.json.simple.JSONObject
itemSearchTopSellers(BrowseNode browseNode, int page)
ItemSearch in a Music search index, result ordered by relevance.org.json.simple.JSONObject
itemSearchTopSellers(String searchIndex, BrowseNode browseNode, int page)
ItemSearch result, ordered by relevance (whatever that is).void
removePropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)
Remove property change listener.void
setLocale(Locale locale)
Sets the locale.static Stream<org.json.simple.JSONObject>
toItems(org.json.simple.JSONObject itemSearchResponse)
protected boolean
useCacheOnly(URL url)
Allows to suppress the actual request.void
writeGenreBrowseNodes()
Dump genre browse nodes to a file called"browsenode_[locale].txt"
.void
writeGenreBrowseNodes(Path path)
Dump genre browse nodes to a file.-
Methods inherited from class com.tagtraum.core.WebService
clearCache, getCache, getConnectTimeOut, getDomFactory, getJSONArray, getJSONArray, getJSONObject, getJSONObject, getJSONObjectWithPayload, getMaxAge, getReadTimeOut, getRequestDelay, getSSLSocketFactory, getUserAgent, getXmlDocument, getXmlObject, isAcceptGzipContentEncoding, openConnection, openConnection, openInputStream, readURL, setAcceptGzipContentEncoding, setCache, setConnectTimeOut, setDomFactory, setMaxAge, setNextAllowedConnection, setReadTimeOut, setRequestDelay, setSSLSocketFactory, setUserAgent, toParameterString, waitForTurn
-
-
-
-
Method Detail
-
getName
public String getName()
Description copied from interface:Charts
Name of this chart provider.
-
toItems
public static Stream<org.json.simple.JSONObject> toItems(org.json.simple.JSONObject itemSearchResponse)
-
addPropertyChangeListener
public void addPropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)
Add property change listener.- Parameters:
propertyName
- property namepropertyChangeListener
- listener
-
removePropertyChangeListener
public void removePropertyChangeListener(String propertyName, PropertyChangeListener propertyChangeListener)
Remove property change listener.- Parameters:
propertyName
- property namepropertyChangeListener
- listener
-
getLocaleConfiguration
public LocaleConfiguration getLocaleConfiguration()
-
setLocale
public void setLocale(Locale locale)
Sets the locale. Note that at the same timesetLocaleConfiguration(LocaleConfiguration)
is called.- Parameters:
locale
- locale
-
getLocale
public Locale getLocale()
-
browseNodeLookup
public org.json.simple.JSONObject browseNodeLookup(BrowseNode browseNode) throws IOException, org.json.simple.parser.ParseException
Looks up browsenode with default max age.- Parameters:
browseNode
- browsenode- Returns:
- response
- Throws:
IOException
org.json.simple.parser.ParseException
- See Also:
browseNodeLookup(BrowseNode, long, TimeUnit)
,WebService.setMaxAge(long)
-
browseNodeLookup
public org.json.simple.JSONObject browseNodeLookup(BrowseNode browseNode, long maximumAge, TimeUnit timeUnit) throws IOException, org.json.simple.parser.ParseException
Looks up browsenode.- Parameters:
browseNode
- browsenodemaximumAge
- max agetimeUnit
- max age time unit- Returns:
- response
- Throws:
IOException
org.json.simple.parser.ParseException
-
browseNodeLookup
public org.json.simple.JSONObject browseNodeLookup(long browseNodeId, long maximumAge, TimeUnit timeUnit) throws IOException, org.json.simple.parser.ParseException
Looks up browsenode.- Parameters:
browseNodeId
- browsenode idmaximumAge
- max agetimeUnit
- max age time unit- Returns:
- response
- Throws:
IOException
org.json.simple.parser.ParseException
-
getGenreBrowseNodes
public List<org.json.simple.JSONObject> getGenreBrowseNodes() throws IOException, org.json.simple.parser.ParseException
Get the genre browse nodes for the currently configured locale.- Returns:
- list of genres
- Throws:
IOException
org.json.simple.parser.ParseException
-
writeGenreBrowseNodes
public void writeGenreBrowseNodes(Path path) throws IOException, org.json.simple.parser.ParseException
Dump genre browse nodes to a file.- Parameters:
path
- file- Throws:
IOException
org.json.simple.parser.ParseException
-
writeGenreBrowseNodes
public void writeGenreBrowseNodes() throws IOException, org.json.simple.parser.ParseException
Dump genre browse nodes to a file called"browsenode_[locale].txt"
.- Throws:
IOException
javax.xml.bind.DataBindingException
org.json.simple.parser.ParseException
-
itemSearch
public org.json.simple.JSONObject itemSearch(String keywords) throws IOException, org.json.simple.parser.ParseException
Searches in SearchIndex Music for items which match the given keywords.- Parameters:
keywords
- String that contains keywords- Returns:
- search result
- Throws:
IOException
javax.xml.bind.DataBindingException
org.json.simple.parser.ParseException
-
itemSearch
public org.json.simple.JSONObject itemSearch(String searchIndex, String keywords) throws IOException, org.json.simple.parser.ParseException
Searches in a given SearchIndex for items which match the given keywords. Sorted by "Relevance".- Parameters:
searchIndex
- search index like "Music" or "MP3Downloads"keywords
- String that contains keywords- Returns:
- search result
- Throws:
IOException
org.json.simple.parser.ParseException
-
itemSearch
public org.json.simple.JSONObject itemSearch(String searchIndex, BrowseNode browseNode, String keywords, String sortBy, int page, long maximumAge, TimeUnit timeUnit) throws IOException, org.json.simple.parser.ParseException
Searches in a given SearchIndex for items which match the given keywords.- Parameters:
searchIndex
- search index like "Music" or "MP3Downloads"browseNode
- browse node (may be null)keywords
- String that contains keywordssortBy
- e.g. "Relevance" or "NewestArrivals" (docs)page
- page, use -1, if you don't want to specify- Returns:
- search result
- Throws:
IOException
org.json.simple.parser.ParseException
-
itemSearchTopSellers
public org.json.simple.JSONObject itemSearchTopSellers(BrowseNode browseNode, int page) throws IOException, org.json.simple.parser.ParseException
ItemSearch in a Music search index, result ordered by relevance.- Parameters:
browseNode
- browsenode in which to searchpage
- result page to return- Returns:
- result
- Throws:
IOException
org.json.simple.parser.ParseException
-
itemSearchTopSellers
public org.json.simple.JSONObject itemSearchTopSellers(String searchIndex, BrowseNode browseNode, int page) throws IOException, org.json.simple.parser.ParseException
ItemSearch result, ordered by relevance (whatever that is).- Parameters:
searchIndex
- usually "Music", but values like "MP3Downloads" should also be possible (for the US at least).browseNode
- browsenode in which to searchpage
- result page to return- Returns:
- result
- Throws:
IOException
org.json.simple.parser.ParseException
-
itemSearchNewReleases
public org.json.simple.JSONObject itemSearchNewReleases(BrowseNode browseNode, int page) throws IOException, org.json.simple.parser.ParseException
ItemSearch in a Music search index, result ordered by age.- Parameters:
browseNode
- browsenode in which to searchpage
- result page to return- Returns:
- result
- Throws:
IOException
org.json.simple.parser.ParseException
-
itemSearchNewReleases
public org.json.simple.JSONObject itemSearchNewReleases(String searchIndex, BrowseNode browseNode, int page) throws IOException, org.json.simple.parser.ParseException
ItemSearch result, ordered by age.- Parameters:
searchIndex
- usually "Music", but values like "MP3Downloads" should also be possible (for the US at least).browseNode
- browsenode in which to searchpage
- result page to return- Returns:
- result
- Throws:
IOException
org.json.simple.parser.ParseException
-
getMusicAlbum
public org.json.simple.JSONObject getMusicAlbum(String artist, String title) throws IOException, org.json.simple.parser.ParseException
ItemSearch for Music matching an encodedArtist/encodedTitle.- Parameters:
artist
- encodedArtist or null, if not significanttitle
- encodedTitle or null, if not significant- Returns:
- matching articles
- Throws:
IOException
org.json.simple.parser.ParseException
-
getMP3DownloadsAlbum
public org.json.simple.JSONObject getMP3DownloadsAlbum(String artist, String title) throws IOException, org.json.simple.parser.ParseException
ItemSearch for MP3Downloads matching an encodedArtist/encodedTitle.- Parameters:
artist
- encodedArtist or null, if not significanttitle
- encodedTitle or null, if not significant- Returns:
- matching articles
- Throws:
IOException
org.json.simple.parser.ParseException
-
getTitle
public org.json.simple.JSONObject getTitle(String searchIndex, String title) throws IOException, org.json.simple.parser.ParseException
ItemSearch for an item with the specified title.- Parameters:
searchIndex
- index to searchtitle
- encodedTitle- Returns:
- matching articles
- Throws:
IOException
org.json.simple.parser.ParseException
-
itemLookup
public org.json.simple.JSONObject itemLookup(String... asin) throws IOException, org.json.simple.parser.ParseException
Look up an item using it's ASIN.- Parameters:
asin
- an ASIN- Returns:
- response
- Throws:
IOException
javax.xml.bind.DataBindingException
org.json.simple.parser.ParseException
-
getJSONObject
protected org.json.simple.JSONObject getJSONObject(String request, org.json.simple.JSONObject requestPayload) throws IOException, org.json.simple.parser.ParseException
- Throws:
IOException
org.json.simple.parser.ParseException
-
getJSONObject
protected org.json.simple.JSONObject getJSONObject(String request, org.json.simple.JSONObject requestPayload, long maximumAge, TimeUnit timeUnit) throws IOException, org.json.simple.parser.ParseException
- Throws:
IOException
org.json.simple.parser.ParseException
-
cacheResource
protected boolean cacheResource(URL url, byte[] content)
Description copied from class:WebService
Allows turning caching for a specific resource and its content on and off.- Overrides:
cacheResource
in classWebService
- Parameters:
url
- urlcontent
- resource content- Returns:
- by default this method returns
true
-
useCacheOnly
protected boolean useCacheOnly(URL url)
Description copied from class:WebService
Allows to suppress the actual request.- Overrides:
useCacheOnly
in classWebService
- Parameters:
url
- url- Returns:
- true, if we only want to look stuff up in the cache, but never want to retrieve the actual URL
-
handleStatusCode
protected void handleStatusCode(HttpURLConnection httpURLConnection, int statusCode) throws IOException
Description copied from class:WebService
Handles standard responses to status codes.- Overrides:
handleStatusCode
in classWebService
- Parameters:
httpURLConnection
- http url connectionstatusCode
- status code- Throws:
IOException
-
-