I am using the SmartyStreets API to verify valid street addresses in New York City.
I downloaded their example code file and I tried running it with a variety of different values. I tried my address, the address of Apples HQ, and even the stock address they had preloaded and nothing is working. This is the Example class and it is the shortest template of them all.
public class Example {
public static void main(String[] args) throws IOException, SmartyException {
// This keypair will have been deleted by the time you are watching this video...
String authId = "d418a4cc-69da-e48f-bc9d-ee7357b30d61";
String authToken = "clDiwTlcW5YTFjEl5mp1";
System.out.println("Step 0. Wire up the client with your keypair.");
Client client = new ClientBuilder(authId, authToken).buildUsStreetApiClient();
System.out.println("Step 1. Make a lookup. (BTW, you can also send entire batches of lookups...)");
Lookup lookup = new Lookup();
lookup.setStreet("1 Rosedale");
lookup.setLastline("Baltimore MD");
lookup.setMaxCandidates(10);
System.out.println("Step 2. Send the lookup.");
client.send(lookup);
System.out.println("Step 3. Show the resulting candidate addresses:");
int index = 0;
for (Candidate candidate : lookup.getResult()) {
System.out.printf("- %d: %s, %s\n", index, candidate.getDeliveryLine1(), candidate.getLastLine());
index++;
}
}
The message I am supposed to get after running this main method is:
Step 0. Wire up the client with your keypair.
Step 1. Make a lookup. (BTW, you can also send entire batches of lookups...)
Step 2. Send the lookup.
Step 3. Show the resulting candidate addresses:
- 0: 1 N Rosedale St, Baltimore MD 21229-3737
- 1: 1 S Rosedale St, Baltimore MD 21229-3739
But instead I am getting this and an error code:
Step 0. Wire up the client with your keypair.
Step 1. Make a lookup. (BTW, you can also send entire batches of lookups...)
Step 2. Send the lookup.
Exception in thread "main" com.smartystreets.api.exceptions.BadCredentialsException: Unauthorized: The credentials were provided incorrectly or did not match any existing, active credentials.
at com.smartystreets.api.StatusCodeSender.send(StatusCodeSender.java:21)
at com.smartystreets.api.SigningSender.send(SigningSender.java:18)
at com.smartystreets.api.URLPrefixSender.send(URLPrefixSender.java:19)
at com.smartystreets.api.RetrySender.trySend(RetrySender.java:34)
at com.smartystreets.api.RetrySender.send(RetrySender.java:23)
at com.smartystreets.api.us_street.Client.send(Client.java:48)
at com.smartystreets.api.us_street.Client.send(Client.java:27)
at examples.Example.main(Example.java:25)
Process finished with exit code 1
SOLUTION:
I received the following solution for my problem privately with whom I assume is a developer for the program.
Go to the following link
https://account.smartystreets.com/#keys
Login and scroll to the bottom of the page where it says auto-generated.
You must take the auth-id and auth-token values from here and use them to replace the dummy values in the Example class.
At this point you are able to test out whatever addresses you want in USA.
For rulings on what combinations and parts of addresses are required check this link:
https://smartystreets.com/docs/cloud/us-street-api#root
Related
I am trying to send test USDT to a particular account in Java using the following code:
final Web3j web3 = createWeb3If(ethNetworkUrl);
final Credentials credentials = Credentials.create(privateKey);
final ERC20 usdtContract = ERC20.load(usdtContractAddress, web3, credentials, new TestGasProvider());
usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send();
The last statement results in the following exception:
java.lang.RuntimeException: Error processing transaction request: intrinsic gas too low
at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:176)
at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:128)
at org.web3j.tx.Contract.executeTransaction(Contract.java:367)
at org.web3j.tx.Contract.executeTransaction(Contract.java:350)
at org.web3j.tx.Contract.executeTransaction(Contract.java:344)
at org.web3j.tx.Contract.executeTransaction(Contract.java:339)
at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:410)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
at com.dpisarenko.minimalcryptoexchange.delegates.TransferUsdtToExchangeAccount.execute(TransferUsdtToExchangeAccount.java:57)
TestGasProvider is defined as:
public class TestGasProvider extends StaticGasProvider {
public static final BigInteger GAS_PRICE = BigInteger.valueOf(10L);
public static final BigInteger GAS_LIMIT = BigInteger.valueOf(1L);
public TestGasProvider() {
super(GAS_PRICE, GAS_LIMIT);
}
}
usdtContract was deployed using this script, which calls deploy.js:
async function main() {
const USDT = await ethers.getContractFactory("USDT");
const usdt = await USDT.deploy(1000000000000000);
console.log("USDT contract deployed to:", usdt.address);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
This contract is running on a local testnet set up as described here.
What do I need to change in any of these components (testnet, contract, deploy scripts, Java code) in order to send any amount of USDT to a particular address (without any errors)?
Update 1: If I change TestGasProvider to
public class TestGasProvider extends StaticGasProvider {
public static final BigInteger GAS_PRICE = BigInteger.valueOf(1L);
public static final BigInteger GAS_LIMIT = BigInteger.valueOf(1000000000L);
public TestGasProvider() {
super(GAS_PRICE, GAS_LIMIT);
}
}
I get another error:
java.lang.RuntimeException: Error processing transaction request: exceeds block gas limit
at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:176)
at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:128)
at org.web3j.tx.Contract.executeTransaction(Contract.java:367)
at org.web3j.tx.Contract.executeTransaction(Contract.java:350)
at org.web3j.tx.Contract.executeTransaction(Contract.java:344)
at org.web3j.tx.Contract.executeTransaction(Contract.java:339)
at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:410)
at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
at com.dpisarenko.minimalcryptoexchange.delegates.TransferUsdtToExchangeAccount.execute(TransferUsdtToExchangeAccount.java:57)
Update 1
I am looking to submit a set of code changes to the branch i16 of the minimal-crypto-exchange project which passes the following test:
Step 1
Set up the environment as described here.
Step 2
Set a breakpoint on line usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send(); in TransferUsdtToExchangeAccount class:
Step 3
Start the process engine application in debug mode. Its Java main method is located here.
Wait until you see the message starting to acquire jobs in the console output:
11:59:16.031 [JobExecutor[org.camunda.bpm.engine.spring.components.jobexecutor.SpringJobExecutor]] INFO org.camunda.bpm.engine.jobexecutor - ENGINE-14018 JobExecutor[org.camunda.bpm.engine.spring.components.jobexecutor.SpringJobExecutor] starting to acquire jobs
Step 4
Login with the credentials demo/demo at http://localhost:8080.
After login you should see a page like this:
Step 5
Click on the tasklist link. You should see a page that looks like this:
Press the "Start process" link. Following screen will appear:
Click on Send USDT to the exchange account process link. Following dialog box will appear:
Enter an arbitrary value into the "business key" field and press the "Start" button.
Step 6
After a couple of seconds, the breakpoint from step 2 will activate.
The problem will be solved if usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send() is executed without errors.
Notes
You are allowed to modify the amount in usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send(); from 10 to something else.
You can also modify the parameters of the Ethereum testnet specified in docker-compose.yml and genesis.json, as well as those of the USDT smart contract which is deployed using this script.
Your solution must work in this controlled environment (i. e. no faucets must be used).
Update 2
I made following changes:
The set-up tutorial now contains step 7 in which ETH is added to the exchange account.
Now a new version of the ETH testnet is being used, major changes being that log output is more verbose and the gas price is set to 1 (see --miner.gasprice 1 in entrypoint.sh).
Modified the code in TransferUsdtToExchangeAccount so that now USDT is transferred not from the exchange account (which has zero balance), but from the buffer account.
Now I am receiving the error
org.web3j.protocol.exceptions.TransactionException: Transaction 0x4bce379a2673c4564b2eb6080607b00d1a8ac232fbddf903f353f4eeda566cae
has failed with status: 0x0. Gas used: 32767.
Revert reason: 'ERC20: transfer amount exceeds allowance'.
My skills with Ethereum are still not sharp enough to give you a proper answer, but I hope you get some guidance.
The error states that you are trying to transfer by a party A certain quantity in the name of another party B, to a third one C, but the amount you are trying to transfer, using transferFrom, is greater than the one party B approved party A to send.
You can check the actual allowance between to parties using the method with the same name of your contract.
Please, consider review this integration test from the web3j library in Github. It is different than yours but I think it could be helpful.
Especially, it states that the actual transferFrom operation should be performed by the beneficiary of the allowance. Please, see the relevant code:
final String aliceAddress = ALICE.getAddress();
final String bobAddress = BOB.getAddress();
ContractGasProvider contractGasProvider = new DefaultGasProvider();
HumanStandardToken contract =
HumanStandardToken.deploy(
web3j,
ALICE,
contractGasProvider,
aliceQty,
"web3j tokens",
BigInteger.valueOf(18),
"w3j$")
.send();
//...
// set an allowance
assertEquals(contract.allowance(aliceAddress, bobAddress).send(), (BigInteger.ZERO));
transferQuantity = BigInteger.valueOf(50);
TransactionReceipt approveReceipt =
contract.approve(BOB.getAddress(), transferQuantity).send();
HumanStandardToken.ApprovalEventResponse approvalEventValues =
contract.getApprovalEvents(approveReceipt).get(0);
assertEquals(approvalEventValues._owner, (aliceAddress));
assertEquals(approvalEventValues._spender, (bobAddress));
assertEquals(approvalEventValues._value, (transferQuantity));
assertEquals(contract.allowance(aliceAddress, bobAddress).send(), (transferQuantity));
// perform a transfer as Bob
transferQuantity = BigInteger.valueOf(25);
// Bob requires his own contract instance
HumanStandardToken bobsContract =
HumanStandardToken.load(
contract.getContractAddress(), web3j, BOB, STATIC_GAS_PROVIDER);
TransactionReceipt bobTransferReceipt =
bobsContract.transferFrom(aliceAddress, bobAddress, transferQuantity).send();
HumanStandardToken.TransferEventResponse bobTransferEventValues =
contract.getTransferEvents(bobTransferReceipt).get(0);
assertEquals(bobTransferEventValues._from, (aliceAddress));
assertEquals(bobTransferEventValues._to, (bobAddress));
assertEquals(bobTransferEventValues._value, (transferQuantity));
//...
This fact is also indicated in this OpenZeppelin forum post.
I'm developing a project. The subject of this project, companies send message to users. Each company has a message limit and the system throws an exception based on the language chosen by the company when the message limit is exceeded.
I wrote unit test for the exception.
// given
Company company = new Company("Comp1", 2); // constructor (company name, language) ** 2 -> EN
User user = new User("User1");
Email email = new Email("Email Test", "Test");
int emailLimit = company.getEmailLimit();
// when
for (int i = 0; i < emailLimit; i++) {
company.SendEmail(email, user);
}
Throwable throwable = catchThrowable(() -> company.SendEmail(email, user));
// then
assertThat(throwable).isInstanceOf(MessageLimitException.class);
I also want to check the message content.
There is a class named "ErrorMessages" that manages the content of the error message.
public class ErrorMessages {
private static String[] messageLimitErrorMessage = {
"Message Limit Error", // 0 -> default
"Mesaj limiti aşıldı", // 1 -> TR
"Message limit exceeded" // 2 -> EN
};
public static String messageLimitException(int languageIndex) {
return messageLimitErrorMessage[languageIndex];
};
}
Which one should I prefer as the expected value?
// Option 1
assertThat(throwable).hasMessage(ErrorMessages.messageLimitException(company.getLanguage()));
// or
// Option 2
assertThat(throwable).hasMessage("Message limit exceeded");
Both are correct but which one should I prefer for the accuracy of the test, Option 1 or 2 ?
Thanks for your answer in advance.
There is no definitive answer to this question. It depends what you're trying to achieve. If the exact error message that is returned is important (e.g. part of the spec) then you should choose Option 2. If you don't want to hard code the message into the test (e.g. because it may change) then you can choose Option 1.
In general a test should focus on one specific thing that it's trying to test. Testing the exact error message might be better off done in a separate unit test (e.g. where you could test all of the different messages). Personally, I don't usually bother to write tests for error messages, unless there is something special about them (e.g. they have some kind of variability within the message itself). You only have so much time and it's probably better spent elsewhere.
You should also consider using Java's built-in support for internationalized message bundles. It lets you hold Locale-specific messages in properties files and loads them in for you.
"As the tests become more specific, the code becomes more generic."
Writing the test with a very specific expectation, decouples it from the implementation, and allows the code to become more generic over time.
This should tell you that you should probably use option 2.
Here's Robert Martin's take on it.
I have an application that interacts with Twilio. My Twilio account has 2000+ numbers and my app tries to retrieve them all. This is required and there is no way around this.
I use the following snippet of code to iterate across all numbers,
try {
// Initiate Twilio RESTful session
TwilioRestClient client = new TwilioRestClient(/* sid */, /* token */);
IncomingPhoneNumberList numbers = client.getAccount().getIncomingPhoneNumbers();
LogMsg.info("Attempting to retrieve phone numbers", "Phone Numbers");
// Loop over numbers and print out a property for each one.
for (IncomingPhoneNumber number : numbers) {
// Twilio Phone number
String twilioNumber = number.getPhoneNumber();
/*
* ...
*/
}
}
I keep getting,
java.lang.RuntimeException: com.twilio.sdk.TwilioRestException: Page number out of range
From what I see, I'm usually at the 1400th number when this happens. Since I'm not doing anything specific with pages, I don't understand why I'm getting this error. Is there anything I can do to be able to iterate across all my numbers?
Thanks
This turned out to be something wrong on Twilio's end. I have not since received that error.
I am making an app in java that uses Netsuite's SuiteTalk web services to create a report. I defined a transaction saved search in which I use as a criteria the date and I print in the results the default Transaction columns plus the Department external ID and the sum of the amount. I run the saved search via UI and I get what I am expecting, however, when I try to get the information in my java code I keep getting null results. I have tried the java versions of the following solutions:
C# NetSuite WebServices: Get value from custom field in saved search (ItemSearchAdvanced)
http://www.anyforum.in/question/web-service/netsuite/How-to-get-data-from-saved-search-through-webservice-request/345
However, none of this has worked for me. When I go to the Lists->Search->Saved Searches menu on my Netsuite UI, I am able to see my saved search when I set in the filters "General" and "Transaction". However, I haven't been able to retrieve it's information via API.
This is the code that I use to try to get the saved search data:
public void printReport() throws ExceededUsageLimitFault, UnexpectedErrorFault, InvalidSessionFault, ExceededRecordCountFault, RemoteException, UnsupportedEncodingException, SOAPException{
//METHOD 1: Transaction Search
TransactionSearchAdvanced sr = new TransactionSearchAdvanced();
//"customsearchreport" is the IF of my saved search
sr.setSavedSearchId("customsearchreport");
SearchResult res = _port.search(sr);
System.out.println(res.getTotalRecords());
//METHOD 2: Item search
ItemSearchAdvanced isa = new ItemSearchAdvanced();
isa.setSavedSearchId("customsearchreport");
SearchResult resp = _port.search(isa);
System.out.println(resp.getTotalRecords());
//METHOD 3: General saved search
GetSavedSearchRecord gssr= new GetSavedSearchRecord();
//I set the record type as "transaction" as I created a transaction saved search.
gssr.setSearchType(SearchRecordType.transaction);
GetSavedSearchResult gssre = _port.getSavedSearch(gssr);
System.out.println("Saved Search status: "+ gssre.getStatus().isIsSuccess());
RecordRefList srl = gssre.getRecordRefList();
RecordRef[] rr = srl.getRecordRef();
System.out.println("RecordRef[] size: " + rr.length);
for (int i = 0; i < rr.length; i++) {
RecordRef rref = rr[i];
System.out.println("External ID: " + rref.getExternalId());
System.out.println("Internal ID: "+ rref.getInternalId());
System.out.println("Name: "+ rref.getName());
}
}
With METHODS 1 and 2, I am not able to obtain results (I print "null"). The third method prints me 16 saved searches, however, none of the printed searches correspond to the ones I have created. When I check the saved search list through the UI, I see that there exist 21 non private saved searches and 4 have been created by me. From the 16 reports that are printed, one corresponds to a private saved search.
So, I don't get why I can't get my saved search result and what determines if a report is accessible through any method. Any help to obtain my savedSearch throough the API would be appreciated. Also, could any one explain how Netsuite determines which saved searches appear through any "get" method?
Thanks!
I solved it. The ID "customsearchreport" I was using is a UI ID. I had to use the InternalID for my report. Also, I was able to print my saved search IDs with the getSavedSearch() method by selecting the "All company members" checkbox in my the "Audience" section of my saved search.
I solved them
Before the second script, we must increase the number pages limit like this:
SearchPreferences sp = new SearchPreferences();
sp.pageSize = 1000;
_service.searchPreferences = sp;
SubsidiarySearch subsidiarySrch = new SubsidiarySearch();
SearchResult srchResult = _service.search(subsidiarySrch);
I'm trying to download www.pandora.com/profile/stations/olin_d_kirkland HTML with Java to match what I get when I select 'view page source' from the context menu of the webpage in Chrome.
Now, I know how to download webpage HTML source code with Java. I have done it with downloads.nl and tested it on other sites. However, Pandora is being a mystery. My ultimate goal is to parse the 'Stations' from a Pandora account.
Specifically, I would like to grab the Station names from a site such as www.pandora.com/profile/stations/olin_d_kirkland
I have attempted using the selenium library and the built in URL getter in Java, but I only get ~4700 lines of code when I should be getting 5300. Not to mention that there is no personalized data in the code, which is what I'm looking for.
I figured it was that I wasn't grabbing the JavaScript or letting the JavaScript execute first, but even though I waited for it to load in my code, I would only always get the same result.
If at all possible, I should have a method called 'grabPageSource()' that returns a String. It should return the source code when called upon.
public class PandoraStationFinder {
public static void main(String[] args) throws IOException, InterruptedException {
String s = grabPageSource();
String[] lines = s.split("\n\r");
String t;
ArrayList stations = new ArrayList();
for (int i = 0; i < lines.length; i++) {
t = lines[i].trim();
Pattern p = Pattern.compile("[\\w\\s]+");
Matcher m = p.matcher(t);
if (m.matches() ? true : false) {
Station someStation = new Station(t);
stations.add(someStation);
// System.out.println("I found a match on line " + i + ".");
// System.out.println(t);
}
}
}
public static String grabPageSource() throws IOException {
String fullTxt = "";
// Get HTML from www.pandora.com/profile/stations/olin_d_kirkland
return fullTxt;
}
}
It is irrelevant how it's done, but I'd like, in the final product, to grab a comprehensive list of ALL songs that have been liked by a user on Pandora.
The Pandora pages are heavily constructed using ajax, so many scrapers struggle. In the case you've shown above, looking at the list of stations, the page actually puts through a secondary request to:
http://www.pandora.com/content/stations?startIndex=0&webname=olin_d_kirkland
If you run your request, but point it to that URL rather than the main site, I think you will have a lot more luck with your scraping.
Similarly, to access the "likes", you want this URL:
http://www.pandora.com/content/tracklikes?likeStartIndex=0&thumbStartIndex=0&webname=olin_d_kirkland
This will pull back the liked tracks in groups of 5, but you can page through the results by increasing the 'thumbStartIndex' parameter.
Not an answer exactly, but hopefully this will get you moving in the correct direction:
Whenever I get into this sort of thing, I always fall back on an HTTP monitoring tool. I use firefox, and I really like the Live HTTP Headers extension. Check out what the headers are that are going back and forth, then tailor your http requests accordingly. As an absolute lowest level test, grab the header from a successful request, then send it to port 80 using telnet and see what comes back.