Skip to content

Commit

Permalink
triv
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-drzewiecki committed Nov 21, 2013
2 parents 2d31846 + 4e217a9 commit 9deb61a
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Then set `api.Config.ClientId` to your MangoPay Client ID and
`api.Config.ClientPassword` to your passphrase.

`api.Config.BaseUrl` is set to sandbox environment by default. To enable production
environment, set it to `https://mangopay-api.leetchi.com`.
environment, set it to `https://api.mangopay.com`.

import com.mangopay.MangoPayApi;

Expand Down
61 changes: 61 additions & 0 deletions src/com/mangopay/core/FileStorageStrategy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.mangopay.core;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* File token storage strategy implementation.
*/
public class FileStorageStrategy implements IStorageStrategy {

private String _tempDir = null;

public FileStorageStrategy(String tempDir) {
_tempDir = tempDir;
}

/**
* Gets the currently stored token.
* @return Currently stored token instance or null.
*/
@Override
public OAuthToken get() {
try
{
FileInputStream fileIn = new FileInputStream(getFilePath());
ObjectInputStream in = new ObjectInputStream(fileIn);
OAuthToken token = (OAuthToken) in.readObject();
in.close();
fileIn.close();
return token;
} catch (Exception ex)
{
return null; // it's not an error: e.g. file not found cause not stored yet
}
}

/**
* Stores authorization token passed as an argument.
* @param token Token instance to be stored.
*/
@Override
public void store(OAuthToken token) {
FileOutputStream fileOut;
try {
fileOut = new FileOutputStream(getFilePath());
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(token);
out.close();
fileOut.close();
} catch (Exception ex) {
Logger.getLogger(FileStorageStrategy.class.getName()).log(Level.SEVERE, null, ex);
}
}

private String getFilePath() { return _tempDir + getClass().getName() + ".tmp"; }
}
3 changes: 2 additions & 1 deletion src/com/mangopay/core/OAuthToken.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.mangopay.core;

import com.mangopay.core.Dto;
import java.io.Serializable;

/**
* OAuth entity.
*/
public class OAuthToken extends Dto {
public class OAuthToken extends Dto implements Serializable {

/**
* Created time.
Expand Down
6 changes: 0 additions & 6 deletions src/com/mangopay/entities/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,4 @@ public class Card extends EntityBase {
* Validity.
*/
public String Validity;

/**
* Reusable.
*/
public Boolean Reusable;

}
5 changes: 0 additions & 5 deletions src/com/mangopay/entities/CardRegistration.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,6 @@ public class CardRegistration extends EntityBase {
* Status.
*/
public String Status;

/**
* Reusable.
*/
public Boolean Reusable;

@Override
public ArrayList<String> getReadOnlyProperties() {
Expand Down
3 changes: 0 additions & 3 deletions test/com/mangopay/core/TokensTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.mangopay.core;
import com.mangopay.entities.*;
import org.junit.Test;
import static org.junit.Assert.*;
import java.lang.Exception;
import com.mangopay.core.OAuthToken;
import com.mangopay.MangoPayApi;

/**
Expand Down

0 comments on commit 9deb61a

Please sign in to comment.