本文整理汇总了Java中de.umass.lastfm.Session类的典型用法代码示例。如果您正苦于以下问题:Java Session类的具体用法?Java Session怎么用?Java Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Session类属于de.umass.lastfm包,在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scrobble
import de.umass.lastfm.Session; //导入依赖的package包/类
public List<ScrobbleResult> scrobble(Session session) throws IOException {
File file = new File(cacheDir, SUBMISSIONS_FILE);
List<ScrobbleResult> result = new ArrayList<ScrobbleResult>();
if (file.exists()) {
BufferedReader r = new BufferedReader(new FileReader(file));
List<ScrobbleData> list = new ArrayList<ScrobbleData>(50);
String line;
while ((line = r.readLine()) != null) {
ScrobbleData d = decodeScrobbleData(line);
list.add(d);
if (list.size() == 50) {
result.addAll(Track.scrobble(list, session));
list.clear();
}
}
if (list.size() > 0)
result.addAll(Track.scrobble(list, session));
r.close();
FileWriter w = new FileWriter(file);
w.close();
}
return result;
}
示例2: getSession_setsSessionOnSuccess
import de.umass.lastfm.Session; //导入依赖的package包/类
@Test
public void getSession_setsSessionOnSuccess() {
String token = "token";
String sessionKey = "sessionKey";
when(lastfmApi.getSession(any(), any(), any()))
.thenReturn(Session.createSession(API_KEY, API_SECRET, sessionKey));
AuthResult expectedAuthResult = AuthResult.builder().sessionKey(sessionKey).build();
client = new LastfmClient(lastfmApi, caller, "test");
client.getSession(token, callback);
assertThat(client.isAuthenticated()).isTrue();
verify(lastfmApi).getSession(eq(token), eq(API_KEY), eq(API_SECRET));
verify(callback).handleMessage(argThat(message -> expectedAuthResult.equals(message.obj)));
}
示例3: scrobble
import de.umass.lastfm.Session; //导入依赖的package包/类
public List<ScrobbleResult> scrobble(Session session) throws IOException {
File file = new File(cacheDir, SUBMISSIONS_FILE);
List<ScrobbleResult> result = new ArrayList<ScrobbleResult>();
if (file.exists()) {
BufferedReader r = new BufferedReader(new FileReader(file));
List<ScrobbleData> list = new ArrayList<ScrobbleData>(50);
String line;
while ((line = r.readLine()) != null) {
ScrobbleData d = decodeScrobbleData(line);
list.add(d);
if (list.size() == 50) {
result.addAll(Track.scrobble(list, session));
list.clear();
}
}
if (list.size() > 0)
result.addAll(Track.scrobble(list, session));
r.close();
FileWriter w = new FileWriter(file);
w.close();
}
return result;
}
示例4: Lastfm
import de.umass.lastfm.Session; //导入依赖的package包/类
public Lastfm(Context context) {
super(context);
mContext = context;
Resources res = context.getResources();
API_KEY = res.getString(R.string.lastfm_api_key);
API_SECRET = res.getString(R.string.lastfm_api_secret);
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
mAccessKey = mPrefs.getString("lastfm_access_key", null);
mUserName = mPrefs.getString("lastfm_user_name", null);
//if username and key not null -> recreate the lastfm session
if(mAccessKey != null) {
mSession = Session.createSession(API_KEY, API_SECRET, mAccessKey);
}
String ua = res.getString(R.string.user_agent);
mLastfm = Caller.getInstance();
mLastfm.setUserAgent(ua);
mLastfm.setCache(null);
mLastfm.setDebugMode(true);
}
示例5: login
import de.umass.lastfm.Session; //导入依赖的package包/类
@ActionMethod(Actions.LOGIN_ID)
public void login(User user) {
String username = user.getUsername();
String password = user.getPassword();
try {
Session session = lastfmAuthenticator.login(username, password);
if (session != null) {
user.setSession(session);
configurator.getControlEngine().set(Model.CURRENT_USER, user, null);
configurator.getControlEngine().fireEvent(Events.LOGGED, new ValueEvent<User>(user));
} else {
configurator.getControlEngine().fireEvent(Events.LOGIN_FAILED);
}
} catch (IOException ioe) {
log.error(ioe, ioe);
configurator.getControlEngine().fireEvent(Events.LOGIN_FAILED);
}
}
示例6: handshake
import de.umass.lastfm.Session; //导入依赖的package包/类
/**
* Performs a web-service handshake.
*
* @param session An authenticated Session.
* @return the status of the operation
* @throws IOException on I/O errors
* @see de.umass.lastfm.Authenticator
*/
public ResponseStatus handshake(Session session) throws IOException {
long time = System.currentTimeMillis() / 1000;
String auth = md5(session.getSecret() + time);
String url = String
.format("%s?hs=true&p=1.2.1&c=%s&v=%s&u=%s&t=%s&a=%s&api_key=%s&sk=%s", handshakeUrl, clientId,
clientVersion, user, time, auth, session.getApiKey(), session.getKey());
return performHandshake(url);
}
示例7: doInBackground
import de.umass.lastfm.Session; //导入依赖的package包/类
@Override
protected AuthResult doInBackground(String... params) {
String token = params[0];
Session session = api.getSession(token, API_KEY, API_SECRET);
if (session != null) {
return AuthResult.builder().sessionKey(session.getKey()).build();
}
de.umass.lastfm.Result result = caller.getLastResult();
AuthResult.Builder authResultBuilder = AuthResult.builder();
int httpErrorCode = result.getHttpErrorCode();
int errorCode = result.getErrorCode();
String errorMessage = result.getErrorMessage();
if (httpErrorCode > -1) {
authResultBuilder.httpErrorCode(httpErrorCode);
}
if (errorCode > -1) {
authResultBuilder.errorCode(errorCode);
}
if (errorMessage != null) {
authResultBuilder.error(errorMessage);
}
return authResultBuilder.build();
}
示例8: isAuthorized
import de.umass.lastfm.Session; //导入依赖的package包/类
public boolean isAuthorized(){
if(session == null){
if(sessionKey == null || username == null)
return false;
session = Session.createSession(key, secret, sessionKey, username, false);
}
return true;
}
示例9: handshake
import de.umass.lastfm.Session; //导入依赖的package包/类
/**
* Performs a web-service handshake.
*
* @param session An authenticated Session.
* @return the status of the operation
* @throws IOException on I/O errors
* @see de.umass.lastfm.Authenticator
*/
public ResponseStatus handshake(Session session) throws IOException {
long time = System.currentTimeMillis() / 1000;
String auth = md5(session.getSecret() + time);
String url = String
.format("%s?hs=true&p=1.2.1&c=%s&v=%s&u=%s&t=%s&a=%s&api_key=%s&sk=%s", handshakeUrl, clientId,
clientVersion, user, time, auth, session.getApiKey(), session.getKey());
return performHandshake(url);
}
示例10: setSession
import de.umass.lastfm.Session; //导入依赖的package包/类
private void setSession(String sessionKey) {
session = Session.createSession(API_KEY, API_SECRET, sessionKey);
}
示例11: UpdateNowPlayingTask
import de.umass.lastfm.Session; //导入依赖的package包/类
public UpdateNowPlayingTask(LastfmApi api, Session session, Handler.Callback callback) {
this.api = api;
this.session = session;
this.callback = callback;
}
示例12: ScrobbleTracksTask
import de.umass.lastfm.Session; //导入依赖的package包/类
ScrobbleTracksTask(LastfmApi api, Session session, Handler.Callback callback) {
this.api = api;
this.callback = callback;
this.session = session;
}
示例13: GetTrackInfoTask
import de.umass.lastfm.Session; //导入依赖的package包/类
public GetTrackInfoTask(Session session, Handler.Callback callback) {
this.session = session;
this.callback = callback;
}
示例14: scrobble
import de.umass.lastfm.Session; //导入依赖的package包/类
/**
* @see Track#scrobble(List, Session)
*/
public List<ScrobbleResult> scrobble(List<ScrobbleData> scrobbleData, Session session) {
return Track.scrobble(scrobbleData, session);
}
示例15: updateNowPlaying
import de.umass.lastfm.Session; //导入依赖的package包/类
/**
* @see Track#updateNowPlaying(String, String, Session)
*/
public ScrobbleResult updateNowPlaying(String artistName, String trackName, Session session) {
return Track.updateNowPlaying(artistName, trackName, session);
}