0
En revisión
New to API's
Hello,
I am a technology intern and am new to REST/SOAP API's in general
We recently have developed an API for a platform and were wanting to test it through RareWire and see if we are able to get the responses we want. There is a certain format that the request must be in of the following:
http://example.com/search_action/search_merchant/<timestamp>/<user_latch>/<hash_value>/<search_keyword>/<search_latitude>/<search_longitue>/<page_number_of_search_result>/<page_size_of_search_result>
All fields of the format are required and how would I implement the hash value, which can be calculated for authentication?
for an example:
http://school.bitspayment.com/search_action/search_organization/1406863032/myapitestuserlatch/955b85e721749d8f3043898bb1691da0cea20f877528fa6776860f632dbb2ee5/%20/37.641654/-118.964568/0/10
will return appropriate JSON format for a successful request.
How would I go about implementing a request of this sort. Sorry for being new, I know there are tutorials, but cycling through them trying to done specific thing can be a pain.
I am a technology intern and am new to REST/SOAP API's in general
We recently have developed an API for a platform and were wanting to test it through RareWire and see if we are able to get the responses we want. There is a certain format that the request must be in of the following:
http://example.com/search_action/search_merchant/<timestamp>/<user_latch>/<hash_value>/<search_keyword>/<search_latitude>/<search_longitue>/<page_number_of_search_result>/<page_size_of_search_result>
All fields of the format are required and how would I implement the hash value, which can be calculated for authentication?
for an example:
http://school.bitspayment.com/search_action/search_organization/1406863032/myapitestuserlatch/955b85e721749d8f3043898bb1691da0cea20f877528fa6776860f632dbb2ee5/%20/37.641654/-118.964568/0/10
will return appropriate JSON format for a successful request.
How would I go about implementing a request of this sort. Sorry for being new, I know there are tutorials, but cycling through them trying to done specific thing can be a pain.
Servicio de atención al cliente por UserEcho
Thanks for the post. I understand not wanting to dig through documentation for something specific, but when learning a new language such as WIRE, it isn't a bad idea to get acquainted with the basics.
I would encourage you to look at this snippet for a basic JSON implementation: https://files.rarewire.com/wordpress/2013/05/json-...
Also you should watch this video on how to set up an integration with a json feed that allows you to modify the url to get different info: http://player.vimeo.com/video/62367352
As for your has value needing to change based on user, if you can pull that value from another source, you can set it as a variable and plug it in to the URL like this:
<assign property="var:hash" value="12121212" />
...
<assign property="datasource:feed.source" value="http://school.bitspayment.com/search_action/search..." />
I am trying to create a list of json format to display through the app. This is to mainly test the API. Could I maybe get a pointer or two on what is wrong with my Wire and why I do not get expected an expected list of json. If I use the arstechnica API example in the tutorial I was following, I get expected results. The URL for the value in the action that has been implemetened on initialization is an example URL provided by the API development team. If the URL is put into your browsers search bar, the expected json return is given.
Where did I go wrong. Sorry for questions. This is just an urgent testing project for me. I don't have the time to read/watch tutorials. Otherwise I would love to! I like this Wire language.
<wire>
<datasources>
<!-- datasources go here -->
<datasource name="default" source="" providertype="json" query="result_rows" parsenamespace="yes">
</datasource>
</datasources>
<styles>
<!-- styles go here -->
</styles>
<classes>
<!-- classes go here -->
<class name="jsonList">
<panel name="" width="95%" height="20%" lheight="25%" dataSourceIndex="" align="center" background="#ff0000" bordercolor="00ee00" borderwidth="3">
<text name="merchant" width="100%" height="50%" color="#eeeeee" font="helvetica" size="20" align="center" valign="top" alignment="center" text=""></text>
<text name="clip" width="90%" height="50%" color="#eeeeee" font="helvetica" size="15" align="center" valign="bottom" alignment="center" text=""></text>
</panel>
</class>
</classes>
<main>
<!-- main wire hierarchy -->
<panel name="background" width="100%" height="100%" background="#000000"></panel>
<panel name="list" width="100%" height="95%" align="center" valign="center" background="#ffffff">
<list name="json-results" datasource="default" width="85%" height="100%" orientation="vertical" paginate="no">
<object dataSourceIndex="[ds:dataSourceIndex]" headline="[ds:result_rows.name]" author="[ds:result_rows.merchant_id]"></object>
</list>
</panel>
</main>
<actions>
<!-- actions go here -->
<action name="oninit" datasource="default" oninit="yes">
">http://school.bitspayment.com/search_action/search...
</action>
</actions>
</wire>
I would love to troubleshoot this, the URL in your action cut off when you posted it, can you post it again as text?
For starters, you did not have params set for the text objects in your class, this is what the datasource uses to replace the data.
Second, you didn't have a class defined in your object tag to populate. Once these were in place, I added a querycomplete action to confirm that the datasource was getting polled properly and then adjusted the query on the datasource tag for this data feed. Then I was able to get data back. Once I see your URL, I can adjust this example to work with your feed. It usually comes down to the query and pathing to the right portion of the feed you want to pull in.
http://school.bitspayment.com/search_action/search_organization/<timestamp>
/<user_latch>/<hash_value>/<search_keyword>/<search_latitude>/<search_longitue>/
<page_number_of_search_result>/<page_size_of_search_result>
in this format, an example URL would be http
://school.bitspayment.com/search_action/search_organization/1406863032/myapitestuserlatch
/955b85e721749d8f3043898bb1691da0cea20f877528fa6776860f632dbb2ee5/%20/37.641654/-118.964568/0/10
955b85e721749d8f3043898bb1691da0cea20f877528fa6776860f632dbb2ee5/%20/37.641654/-118.964568/0/10
Note the timestamp must be within +- current time in UNIX format. Is there also a way I can assign this to a variable in the action that uses this in the URL
something like
<action name="on" oninit="yes">
<!-- I left http off of the source to keep from being a link -->
<assign property="datasource.default.source" value="://school.bitspayment.com/search_action/search_organization/[var:timestamp]/myapitestuserlatch
With your code, I now understand what I needed to do to finish the program. Being thrown into a new language for a small project is sometimes tedious.
Although I am getting an error now when trying of invalid API user. This must be on our side I will have this looked into.
<action name="on" oninit="yes">
<assign property="var:time" value="[js:timeStamp()]"
(Note http is left out of the link)
<assign property="datasource.default.source" value="://school.bitspayment.com/search_action/search_organization/[var:time]/myapitestuserlatch
/955b85e721749d8f3043898bb1691da0cea20f877528fa6776860f632dbb2ee5/%20/37.641654/-118.964568/0/10"
I created an html file in order to try and capture the javascript function of the current epoch time but I cannot seem to make this work. Im not sure why it wouldn't. Is my syntax wrong again or am I just plain wrong?
<html>
<head>
<script type="text/javascript">
function timeStamp ()
{
var unix = Math.round(new Date().getTime()/1000.0);
return unix;
}
</script>
</head>
<body>
</body>
</html>
That looks correct. Did you place this JS function in a file called functions.html at the root of your project? This is required for custom functions like this.
The problem with this function is that it is recursive and I'm not entirely sure on how I would call this function. The HTML itself is pulling the correct information from 3 sources. Here is the function. It is pulling data from an HTML table of input values and making the correct calculations as well. I want to do this with the button in RareWire without the recursion. Is there a way I could possibly do this?
Sorry for the tricky problem here. That function is quite over-cleverly done with the recursion. It would be much simpler if they made one function that got the job done instead of 3 functions in one. sigh..
In your functions.html file, just put a function like:
function getUrl(user_latch, sec_code /*, ...*/ ) {
var timestamp = Math.floor((new Date()).getTime() / 1000);
/* ... */
return hyperlink;
}
And, in your wire, just do something like:
<assign property="var:hyperlink" value="[eval: getUrl('[var:userlatch]', '[var:seccode]', ... )]" />
Good luck,
Kevin
My current problem I am having now is using buttons to get two different types of responses determined by 2 different API's in which I have one defined for now.
I am currently generating the link through the HTML and just grabbing it and manually inputting it into the Wire for now until another variant of the function is written.
here is the Wire, the alert message continuous loops and I have looked around the Wire definitions and tried to come up with something to make it stop looping and only display once but I couldn't quite figure it out.
<action name="merchant_on" datasource="merchant">
the engine defaults the datasourceevent to querycomplete.
This means that every time the datasource comes back, you're setting the source of the merchant datasource, and causing it to refresh. Once it's complete, it starts over again.
If you remove the datasource="merchant" portion of that line of code, and make it simply
<action name="merchant_on">, then your loop will not happen.