How to add body parameter in Serel gem (stackoverflow api) - ruby-on-rails

Actually when i try to access a question using serel gem(which is a ruby wrapper for stackoverflow api), i get an object with no body parameter included in it.
questions = Serel::Question.find(id)
see http://api.stackoverflow.com/1.1/usage/methods/questions-by-ids. According to this, we need to turn the body parameter true.
How to turn the parameter "body" true.

So I finally figured it out, this should work for you:
Serel::Question.filter(:withbody).find(id)

Try this:
questions = Serel::Question.find(id).body.get

Related

HighRise API Create a person failing with missing first name while it's there

I'm trying to create a person in highrise using the API. I'm getting a "First name is missing. Contacts must have a name" error message in the response.
Here is my code:
let x = """<?xml version="1.0" encoding="UTF-8"?>
<person>
<first-name>name</first-name>
<last-name>last</last-name>
<contact-data>
<email-addresses type="array">
<email-address>
<address>someEmail#gmail.com</address>
</email-address>
</email-addresses>
</contact-data>
<tags type="array">
<tag>
<id type="integer">6154219</id>
<name>sometag</name>
</tag>
</tags>
</person>"""
let req = new RestRequest("/people.xml", Method.POST)
req.AddParameter("Content-Type", "application/xml")
req.AddParameter("application/xml", x, ParameterType.RequestBody)
let res = client.Execute(req)
The response returns a 422 Status code. Not sure what I'm doing wrong here?
Based on a similar StackOverflow question, it looks like you might get this error when there is something else wrong in your request, such as when it is missing the appropriate Content-Type.
I'm not familiar with Highrise or Restsharp to give a definite answer, but it seems that there might be something wrong with how you create the request. Just from reading your code, I find the use of AddParameter to add the body somewhat unexpected (even though it might be right). It looks like you might be able to use AddBody instead, so I'd try that.
(This is more of a comment than a proper answer, but it got too long to post it as a comment!)
I believe this is a result of attempting to add tags while creating the user. It's not at all clear from the API but at least in my experience no formulation of the tags field can be submitted with a company/person and succeed.
Alternatively, and I don't speak f# so I can't be sure, but the "Content-Type" is supposed to be in headers. Does the parameter component you're using add that explicitly as a header?
The missing name field showed up for me before I got the header working.
Turns out that you cannot add tags when creating a new person. It needs to added in a separate request after adding a contact. This is not explicitly mentioned in the documentation but can be concluded from their examples.

How to get domain root url in Laravel 4?

I'm ready to scream how hard can this be? I've been trying for too long.
If I have http://www.example.com/more/pages/page.php or similar I want to be able to get
www.example.com.
Thats all. So I can use it as I please. This will of course change if on production or development so I want to ascertain it dynamically.
Request::root()
returns http://www.example.com/more/pages/page.php
URL::to('/')
returns http://www.example.com/more/pages/page.php
How do I get this? Why am I having so much trouble to do this??
UPDATE (2017-07-12)
A better solution is actually to use Request::getHost()
Previous answer:
I just checked and Request::root(); does return http://www.example.com in my case, no matter which route I'm on. You can then do the following to strip off the http:// part:
if (starts_with(Request::root(), 'http://'))
{
$domain = substr (Request::root(), 7); // $domain is now 'www.example.com'
}
You may want to double check or post more code (routes.php, controller code, ...) if the problem persists.
Another solution is to simply use $_SERVER['SERVER_NAME'].
You also may test any of these:
Request::server ("SERVER_NAME")
Request::server ("HTTP_HOST")
It seems better than making any treatment of
Request::root()
All right.
In Laravel 5.1 and later you can use
request()->getHost();
or
request()->getHttpHost();
(the second one will add port if it's not standard one)
My hint:
FIND IF EXISTS in .env:
APP_URL=http://yourhost.dev
REPLACE TO (OR ADD)
APP_DOMAIN=yourhost.dev
FIND in config/app.php:
'url' => env('APP_URL'),
REPLACE TO
'domain' => env('APP_DOMAIN'),
'url' => 'http://' . env('APP_DOMAIN'),
USE:
Config::get('app.domain'); // yourhost.dev
Config::get('app.url') // http://yourhost.dev
Do your magic!
This is for Laravel 5.1 and I am not sure does it work for earlier versions but if somebody search on Google and lands here it might be handy in middleware handle function gets $request parameter:
$request->server->get('SERVER_NAME')
outside of middleware handle method you can access it by helper function request()
request()->server->get('SERVER_NAME')
use directly where you want controller or web.php
Request::getHost();
I think you can use asset('/')

How URL works? And what is the relation with GET and POST?

I have question, basic question I guess. But its important for me to learn more about web application.
I've ever seen a url with there are other words. for example:
http://api.openweathermap.org/data/2.5/weather?q=Setapak&mode=xml
there is q=setapak&mode=xml. what it means?
and what relationship with GET or POST?
when I try to create a simple page such which the code are:
<?lc
put $_GET['number'] into number
put number
?>
and I run the url on the browser: livecode/nana/url.lc?number=1
it shows nothing. So I get confuse. Can anyone explain to me?
Thank you..
Get will transfer you Parameter Using URL
all parameters will add to the URL ?number=1 this is one such example. it will carry number variable with value 1.
Post transfer parameters by attaching them to HTTP message body. Refer below link and you can get a good understanding about that.
http://www.w3schools.com/tags/ref_httpmethods.asp
You can't use single quotes in LC. use normal quotes around "number", and it should work.

jqueryUI autocomplete with Slim framework

I'm beginning with php, jquery and Slim PHP framework and I got stuck in making Slim handler (route) for jqeryUI autocomplete request.
jqeryui autocomplete sends data as a term GET parameter, i.e. restapi.php/test/?term=hello
with Slim I can handle requests like restapi.php/test/hello, etc.
How to solve? My own considered solution is to rewrite the URL with the mod-rewrite (anyway basically using it with the Slim), but I'm not sure if this is the right way.
I'll be glad for your revisions and suggestions and if rewriting is the best way, some references with examples will be helpful for me. Thank you.
Actually, you probably shouldn't be using /* to do what you're doing. SLIM provides a method that can get the parameters of your request.
$dataIn = $app->request()->params();
This will give you an array of request parameters. So if your get request was something like this:
restapi.php/test/?term=hello&page=1&limit=15
$dataIn = $app->request()->params();
// $dataIn['term'] = 'hello'
// $dataIn['page'] = 1
// $dataIn['term'] = 15
Furthermore, you can grab specific parameters by throwing in an arg into the param() method.
$term = $app->request()->params('term');
It'll make life easier to have that distinction between your route parameters and request parameters. ;-)

Handling question mark in url in codeigniter

I am using a payment method which on success returns a url like mysite/payment/sucess?auth=SDX53641sSDFSDF, but since i am using codeigniter, question marks in url are not working for me.
I tried routing but it didnt work. As a final resort i created a pre system hook and unset the GET part from the url for with i had to set
$config["uri_protocol"] = "REQUEST_URI";
It worked that way but all other links in my site were not working as intended, tried changing the uri_protocol but could not make it work by any means.
So basically my problem is handling the ?auth=SDFSEFSDFXsdf5345sdf part in my url, whenever the paypment method redirects to my site with the url mentioned above, it gets redirected to homepage instead of the function inside controller.
How can i handle this, i'm using codeIgniter 1.7 version, and couldnt find any way.
Please suggest some solution.
I think I would extend the core URI class, by creating new file at application/libraries/MY_URI.php which will extend the CI_URI class, then copy the _fetch_uri_string method and here you can add your logic if the $_SERVER['QUERY_STRING'] is present:
class MY_URI extends CI_URI
{
function __construct()
{
parent::CI_URI();
}
//Whatever this method returns the router class is using to map controller and action accordingly.
function _fetch_uri_string()
{
if(isset($_SERVER['QUERY_STRING']) AND !empty($_GET['auth']))
{
//Do your logic here, For example you can do something like if you are using REQUEST_URI
$this->uri_string = 'payment/success/'.$_GET['auth'];
return;
//You will set the uri_string to controller/action/param the CI way and process further
}
//Here goes the rest of the method that you copied
}
}
Also please NOTE that you must do security check of your URL and I hope this works for you, otherwise you can try extending the CI_Router class or other methods (experiment little bit with few methods, though the _set_routing is important). These 2 classes are responsible for the intercepted urls and mapping them to controller/action/params in CI.
I believe this thread holds the answer.
Basically add
$config['enable_query_strings'] = TRUE;
to your config.php
hope this will help you ! no need to change htaccess,just change your code.
redirect(base_url()."controller_name/function_name");
Looking at the example code in the Stripe docs:
https://stripe.com/docs/payments/checkout/set-up-a-subscription
one might conclude that you can only retrieve a checkout_session_id as a named GET parameter like this:
'success_url' => 'https://example.com/success?session_id={CHECKOUT_SESSION_ID}',
After playing around with .htaccess and config settings (as in previous answers) and finally getting it to work, it suddenly dawned on me that the DEVELOPER is in control of the success_url format, not Stripe. So one can avoid all the problems with a GET parameter by specifying the success url in the normal, clean Codeigniter format, like this:
'success_url' => 'https://example.com/success/{CHECKOUT_SESSION_ID}',
In my routes file, the incoming CHECKOUT_SESSION_ID string is passed to the Subscription controller's checkout_success method with this route:
$route['success/(:any)'] = 'subscription/checkout_success/$1';
The method accepts the $checkout_session_id like this:
function checkout_success($checkout_session_id)
{
// Do something with the $checkout_session_id...
}
I'm new to Stripe Checkout but this seems to simplify the integration without breaking Codeigniter's GET processing rules.

Resources