Array nested in hash for WP API? - ruby

Here's my call:
result = blog.call('wp.newPost',
1,
'user',
'pw',
{
'post_type' => 'post',
'post_content' => entry[3],
'post_name' => entry[2].downcase.split(" ").join("-"),
'comment_status' => 'closed',
'pinged' => 'closed',
'post_status' => 'publish',
'post_title' => entry[2],
'terms' => ['category' => 9]
})
This is returning an error that this post type post doesn't support one of the taxonomies given category - well, every post should have a category, so I'm thinking that my ruby is malformed. The API asks for an array with the taxonomy as a key and its ID as the value, which I think I've done here.
This is for v3.4 - here is the documentation on wp.newPost

Interestingly enough, the following code worked:
blogcontent = {
:post_type => 'post',
:post_content => entry[3],
:post_name => entry[2].downcase.split(" ").join("-"),
:comment_status => 'closed',
:pinged => 'closed',
:post_status => 'publish',
:post_title => entry[2],
:terms =>
{
:category => [9]
}
}
This converted (via the XMLRPC Writer) to the appropriate XML and registered the posts in WordPress. Turning on the XML-RPC debugging information revealed that a struct wasn't being passed unless the variable 9 was enclosed in brackets, even though it is a single value array.

Related

Stripe webhook test returns empty table on execution, but works on stripe's webhook tester

We're having a problem with our test suite.
When we run this using the test suite we get a 'The table is empty...' response from PHPUnit.
We know it works as we've also tested using Stripe's 'Send a web hook' test function which works, and the response is stored as expected.
Our code is here:
public function test_webhook_received()
{
$this->expectsJobs([StoreStripeWebHookJob::class]);
$this->postJson('/stripeHook', [
'created' => 1326853478,
'livemode' => false,
'id' => 'evt_00000000000000',
'type' => 'account.external_account.created',
'object' => 'event',
'request' => NULL,
'pending_webhooks' => 1,
'api_version' => '2019-12-03',
'data' => [
'object' => [
'id' => 'ba_00000000000000',
'object' => 'bank_account',
'account' => 'acct_00000000000000',
'account_holder_name' => 'Jane Austin',
'account_holder_type' => 'individual',
'bank_name' => 'STRIPE TEST BANK',
'country' => 'US',
'currency' => 'gbp',
'fingerprint' => '8JXtPxqbdX5GnmYz',
'last4' => '6789',
'metadata' => [],
'routing_number' => '110000000',
'status' => 'new',
],
],
]);
$this->assertDatabaseHas('stripe_webhooks', [
'stripe_created_at' => 1326853478,
'type' => 'account.external_account.created',
]);
}
The response received is:
Failed asserting that a row in the table [stripe_webhooks] matches the
attributes {
"stripe_created_at": 1326853478,
"type": "account.external_account.created" }.
The table is empty..
If we remove the
$this->expectsJobs([StoreStripeWebHookJob::class]);
tests succeed. Obviously the expectsJob() call should be where it is though.
ExpectsJob also intercepts the job. Much like expectsException. Judging from your clean naming convention "StoreStripe..." - I'd say it's really not storing under these test circumstances.
You'll need to test separately that your endpoint/controller is queuing a job... and that the job is storing the data. 2 tests.

Guzzle Post Null/Empty Values in Laravel

I've been trying to work with Guzzle and learn my way around it, but I'm a bit confused about using a request in conjunction with empty or null values.
For example:
$response = $client->request('POST',
'https://www.testsite.com/coep/public/api/donations', [
'form_params' => [
'client' => [
'web_id' => NULL,
'name' => 'Test Name',
'address1' => '123 E 45th Avenue',
'address2' => 'Ste. 1',
'city' => 'Nowhere',
'state' => 'CO',
'zip' => '80002'
],
'contact' => [],
'donation' => [
'status_id' => 1,
'amount' => $donation->amount,
'balance' => $donation->balance,
'date' => $donation->date,
'group_id' => $group->id,
],
]
]);
After running a test, I found out that 'web_id' completely disappears from my request if set to NULL. My question is how do I ensure that it is kept around on the request to work with my conditionals?
At this point, if I dd the $request->client, all I get back is everything but the web_id. Thanks!
I ran into this issue yesterday and your question is very well ranked on Google. Shame that it has no answer.
The problem here is that form_params uses http_build_query() under the hood and as stated in this user contributed note, null params are not present in the function's output.
I suggest that you pass this information via a JSON body (by using json as key instead of form_params) or via multipart (by using multipart instead of form_params).
Note: those 2 keys are available as constants, respectively GuzzleHttp\RequestOptions::JSON and GuzzleHttp\RequestOptions::MULTIPART
Try to define anything like form_params, headers or base_uri before creating a client, so:
// set options, data, params BEFORE...
$settings = [
'base_uri' => 'api.test',
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'ajustneedatokenheredontworry'
],
'form_params' => [
'cash' => $request->cash,
'reason' => 'I have a good soul'
]
];
// ...THEN create your client,
$client = new GuzzleClient($settings);
// ...and finally check your response.
$response = $client->request('POST', 'donations');
If you check $request->all() at the controller function that you are calling, you should see that were sent successfully.
For those using laravel, use this:
Http::asJson()

sending form data via PHP

I'm trying to submit a form using PHP and the mailchimp 2.0 api.
I'm getting an error that says:
FNAME must be provided
My form has a field for the first name:
<input type="text" name="fname">
So it must have something to do with the way I am handling it the php side.
Here is the bit of php that handles FNAME:
$result = $MailChimp->call('lists/subscribe', array(
'id' => 'myid',
'email' => array( 'email' => $_POST['email']),
'FNAME' => $_POST['fname'],
'LNAME' => $_POST['lname'],
'double_optin' => false,
'update_existing' => true,
'replace_interests' => false
));
I'm not sure if I'm forming the array correctly or not.
By the way, I'm using this wrapper, but I think my error has to do with how I create $result and not the wrapper.
https://github.com/drewm/mailchimp-api
Any help would be appreciated.
Thanks!
Peep the example at the bottom of the page you linked to. I've pasted it here:
$result = $MailChimp->call('lists/subscribe', array(
'id' => 'b1234346',
'email' => array('email'=>'davy#example.com'),
'merge_vars' => array('FNAME'=>'Davy', 'LNAME'=>'Jones'),
'double_optin' => false,
'update_existing' => true,
'replace_interests' => false,
'send_welcome' => false,
));
print_r($result);
Your merge vars (ex. FNAME and LNAME) need to be in its own array. So, add a 'merge_vars' in your array and create an array that contains your field's merge variables.

Adding address to mailchimp using Gibbon gem

Im using the gibbon 0.4.6 with ruby 1.9.3p392, and I tried to add the address of my contacts but I couldn't find the correct format of the parameters.
respuesta = gb.listSubscribe({
:id => lista_id, :email_address => email,
:merge_vars => {'FNAME' => nombre, 'LNAME' => apellido,
'MMERGE3' => ['addr1' => 'aqui', 'addr2' => 'Alla', 'city' => 'Mexico DF',
'zip' => '06700', 'country' => 'MX']
}
})
Update
As Amro suggested, now Im using Gibbon 1.0, but I have the same problem:
I used this
respuesta = gb.lists.subscribe({
:id => lista_id, :email => {:email => email},
:merge_vars => {'FNAME' => nombre, 'LNAME' => apellido,
'MMERGE3' => {'addr1' => 'aqui', 'addr2' => 'Alla', 'city' => 'Mexico DF', 'zip' => '06700', 'country' => 'MX'},
'MMERGE4' => 'Mi nota '
}
})
But the address(MMERGE3) wasn't registered at MailChimp.
Any idea is welcome.
Your current code looks reasonable to me. Have you tried also passing "update_existing" with a value of true? If that address is already subscribed then it won't work otherwise since "update_existing" defaults to false.
Old Answer for API 1.3
I'm Gibbon's maintainer. In this case, MailChimp's docs say the type is an "array," but they mean an associative array (i.e. a Ruby hash). So try something like this:
respuesta = gb.listSubscribe({
:id => lista_id, :email_address => email,
:merge_vars => {'FNAME' => nombre, 'LNAME' => apellido,
'MMERGE3' => {'addr1' => 'aqui', 'addr2' => 'Alla', 'city' => 'Mexico DF',
'zip' => '06700', 'country' => 'MX'}
}
})
Also, API 1.3 has been deprecated. I suggest upgrading to Gibbon 1.0, which hits MailChimp API 2.0. The syntax is a little different so be sure to check out the 2.0 docs and Gibbon's updated README here.

How to get the custom values and image in Magento in Topmenu?

I'm using magento 1.7.0.2. I have add the custom value in database. But how to retrive the custom value and image in Topmanu. I have tried in below mentioned code in the palce of 'my_attribute' to replace my attribute, but i din't get the result.
Model: Mage_Catalog_Model_Observer
Method: _addCategoriesToMenu()
$categoryData = array(
'name' => $category->getName(),
'id' => $nodeId,
//'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
'is_active' => $this->_isActiveMenuCategory($category),
'my_attribute' => $category->getData('my_attribute') // Add our data in...
);
When i print the array i'll get this,
Array ( [name] => Matelas [id] => category-node-31 [is_active] => 1 [my_attribute] => )
Can any one guide me, Thanks in advance...
I am guessing you mean you have added a new custom attribute to the Category entity?
Becuase you are dealing with a Node_collection the full category object won't be loaded, try loading the full object to get what you're after:
$cat = Mage::getModel('catalog/category')->load($category->getId());
$categoryData = array(
name' => $category->getName(),
'id' => $nodeId,
//'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
'is_active' => $this->_isActiveMenuCategory($category),
'my_attribute' => $cat->getData('my_attribute') // Add our data in...
);

Resources