Does the Datadog API support a "partial" update? - ruby

I'm looking for a way to do a "partial" update on an existing screenboard/timeboard. By "partial", I mean adding some widget to the existing screenboard/timeboard without wiping out the existing widget that already exist.
Consider the following example:
Create screenboard:
require 'dogapi'
api_key = "..."
application_key = "..."
board = {
"width" => 1024,
"height" => 768,
"board_title" => "bjusufbe dogapi test",
"widgets" => [
{
"type" => "image",
"height" => 20,
"width" => 32,
"y" => 7,
"x" => 32,
"url" => "https://path/to/create_image.jpg"
}
]
}
dog = Dogapi::Client.new(api_key, application_key)
result = dog.create_screenboard(board)
Update screenboard:
require 'dogapi'
api_key = "..."
application_key = "..."
board_id = "..."
board = {
"width" => 1024,
"height" => 768,
"board_title" => "bjusufbe dogapi test",
"widgets" => [
{
"type" => "image",
"height" => 20,
"width" => 32,
"y" => 7,
"x" => 32,
"url" => "https://path/to/update_image.jpg"
}
]
}
dog = Dogapi::Client.new(api_key, application_key)
result = dog.update_screenboard(board_id, board)
When I run the create and then the update example, the update_image widget will overwrite the create_image widget and that is the problem I'm trying to avoid.

Related

adding taxes to a checkout api transaction

I'm having trouble adding taxes to a square checkout api transaction. Everything else is working, but I can't make the taxes part work. It would be appreciated if someone could post a few lines of the relevant php code that adds taxes at the item or order level. Thank you in advance.
Here's an example of a PHP Checkout request that create a $5.00 charge, with a 10% tax (50 cent) at the order level:
$checkout_api = new \SquareConnect\Api\CheckoutApi();
$request_body = new \SquareConnect\Model\CreateCheckoutRequest(
[
"idempotency_key" => uniqid(),
"order" => [
"line_items" => [
[
"name" => "Test Payment",
"quantity" => "1",
"base_price_money" => [
"amount" => 500,
"currency" => "USD"
]
]],
"taxes" => [
[
"name" => "This is so taxing",
"type" => "ADDITIVE",
"percentage" => "10"
]
]
]
]
);
$response = $checkout_api->createCheckout($location_id, $request_body);
If you want to add it at the item level, you would just move the taxes array to inside the line_items object. Example of 2 items, one with tax and one without:
$checkout_api = new \SquareConnect\Api\CheckoutApi();
$request_body = new \SquareConnect\Model\CreateCheckoutRequest(
[
"idempotency_key" => uniqid(),
"order" => [
"line_items" => [
[
"name" => "Test Payment",
"quantity" => "1",
"base_price_money" => [
"amount" => 500,
"currency" => "USD"
],
"taxes" => [
[
"name" => "This is so taxing",
"type" => "ADDITIVE",
"percentage" => "10"
]
]
],
[
"name" => "Test Payment Without Tax",
"quantity" => "1",
"base_price_money" => [
"amount" => 500,
"currency" => "USD"
]
]],
]
]
);
$response = $checkout_api->createCheckout($location_id, $request_body);

How Get Index If Object In Array Contains Desired Value in Ruby

So this is an array I get from somewhere and I wanted to get the index of the object that contains "text" => "Assets". How can i do that in Ruby?
Example
[{
"class" => "android.support.v7.widget.AppCompatTextView",
"tag" => nil,
"description" => "android.support.v7.widget.AppCompatTextView{b777d8c V.ED..... ........ 0,39-355,168 #7f0e007f app:id/textview_sectiontitle}",
"id" => "textview_sectiontitle",
"text" => "Assets",
"visible" => true,
"rect" => {
"height" => 129,
"width" => 355,
"y" => 2088,
"x" => 80,
"center_x" => 257,
"center_y" => 2152
},
"enabled" => true,
"contentDescription" => nil
},
{
"class" => "android.support.v7.widget.AppCompatImageButton",
"tag" => nil,
"description" => "android.support.v7.widget.AppCompatImageButton{ae57704 VFED..C.. ........ 1056,0-1280,208 #7f0e0109 app:id/imagebutton_amount}",
"id" => "imagebutton_amount",
"visible" => true,
"rect" => {
"height" => 208,
"width" => 224,
"y" => 2049,
"x" => 1136,
"center_x" => 1248,
"center_y" => 2153
},
"enabled" => true,
"contentDescription" => nil
}]
Try this one
arr.index { |item| item["text"] == "Assets" }

How to verify buttons which are like images

when i give a query in terminal like
query "* id:'btn_addRemove'"
Then i am getting an output like
[0] {
"id" => "btn_addRemove",
"enabled" => true,
"contentDescription" => nil,
"class" => "android.widget.ImageView",
"rect" => {
"center_y" => 353,
"center_x" => 622,
"height" => 120,
"y" => 293,
"width" => 140,
"x" => 552
},
"tag" => nil,
"description" => "android.widget.ImageView{4307ec68 V.ED..C. ........ 552,35-692,155 #7f06006e app:id/btn_addRemove}"
},
[1] {
"id" => "btn_addRemove",
"enabled" => true,
"contentDescription" => nil,
"class" => "android.widget.ImageView",
"rect" => {
"center_y" => 559,
"center_x" => 622,
"height" => 120,
"y" => 499,
"width" => 140,
"x" => 552
},
"tag" => nil,
"description" => "android.widget.ImageView{430557b8 V.ED..C. ........ 552,35-692,155 #7f06006e app:id/btn_addRemove}"
},
Now problem is the "id" is same for both the buttons and when i click on the button , then it will change to green with some image in it and when i click again, the buttton changed to normal one which shows before.
How do i verify this ?
If you have multiple element with same IDs.
Then you can click or verify element using index.
query("ImageView css:'#'btn_addRemove'")[0]
Let me know, if you issue get resolved.

ruby one-liner from two hashes

a = {"rows" => [{"id" => "231-z", "name" => 'jon', "age"=> 27, "state" => 'AL'},
{"id" => "4121-x", "name" => 'ton', "age"=> 37, "state" => 'VA'}
]
}
b = {"rows" => [{"key" => ["xyz","4121-x"], "value" =>{"sum" => 12312, "realage" => 29}},
{"key" => ["xyz","231-z"], "value" =>{"sum" => 1212, "realage" => 33}}
]
}
In hash a, age is incorrect
In hash b, realage is correct. Also in hash b id is the second value in the first array that maps to id of hash a . Those are 4121-x, 231-z correspond to hash a
I want to correct the age in hash a and swap it with the realage of hash b
I can do it in multiple steps, but is it possible to do it in one liner or very short? So finally correct hash a should look like
a = {"rows" => [{"id" => "231-z", "name" => 'jon', "age"=> 33, "state" => 'AL'},
{"id" => "4121-x", "name" => 'ton', "age"=> 29, "state" => 'VA'}
]
}
does this look reasonable?
a['rows'].each_with_index do |ah, i|
(bh = b['rows'].select {|h| h['key'].last == ah['id'] }.first) &&
a['rows'][i] = ah.update('age' => bh['value']['realage'])
end
p a
{
"rows" => [
[0] {
"id" => "231-z",
"name" => "jon",
"age" => 33,
"state" => "AL"
},
[1] {
"id" => "4121-x",
"name" => "ton",
"age" => 29,
"state" => "VA"
}
]
}
Please note it will update a only if corresponding id found in b.
Also, the rows order does not matter, nor matter the rows number, it is only important b to have a row with same id as processed row in a
Here is a Working Demo

Magento API version incompatibility

I am creating catalog products using Magento's core API. It works fine on Magento version 1.4.1.1, but the same code doesn't work on Magento ver 1.5.0.1.
Here's my code:
require 'rubygems'
require 'soap/wsdlDriver'
WSDL_URL = 'http://example.code/api/v2_soap/?wsdl=1'
soap = SOAP::WSDLDriverFactory.new(WSDL_URL).create_rpc_driver
session = soap.login('theuser','theuser123')
data = { "name" => "BARRACUDA", "description" => "fill", "short_description" => "fill", "weight" => "12", "status" => 1, "visibility" => 4, "price" => 350.00 , "tax_class_id" => "2", "qty" => 10, "stock_availability" => "0", "category_ids" => [3] }
a1 = soap.call('catalogProductCreate',session,"simple",1,"black: ONT-920-B",data)
Is there any problem with my code, or any new things added to Magento version 1.5.0.1?
Thanks
The problem is missing one attribute in date field
data = { "name" => "BARRACUDA", "description" => "fill", "short_description" => "fill", "weight" => "12", "status" => 1, "visibility" => 4, "price" => 350.00 , "tax_class_id" => "2", "qty" => 10, "stock_availability" => "0", "category_ids" => [3], "websites" => [1] }
Need to mention the websites id in the array of data in magento 1.5.
This is works for me!

Resources