Podio Item task_count not passed in Filter items - api

in the ruby as php library I see the task_count being referenced as an attribute however when doing the API call (only tested in ruby) I always get task_count = null.
Can this be fixed? Or another way to quickly get the task count for a larger amount of items?

There is a call to get tasks.
https://developers.podio.com/doc/tasks/get-task-count-38316458
Its returning perfect count for me. I have done the same with Java SDK.It take ref type and id as a parameter.
In your case reftype = Item and id = item id.
Let me know if it helps or you need more details.

Related

Triggering Zapier on new Shopify order containing a specific product

I have a simple Zap that is triggered on a Shopify New Order (with line details) and then creates a new account in a system called Trainerize. Works perfectly, but it is triggered by ANY new Shopify order. I need to trigger the Zap for a specific product in the Shopify order. Is this possible in Zapier, and how would I go about it? It seems you can't talk to Zapier support unless you have a plan, and I don't want a plan if it is not possible!
Yes, it is possible. The exact implementation depends on how you want to identify the specific product. I am listing 2 possible ways
In case, the criteria to identify product is quite simple, you can use Filter by Zap. For example, if you want to identify product by product Id, you can just add a Filter by Zap and add the following conditions.
Line Items Product ID | Text Contains | Your Product ID - 12345
If you have some complex matching condition for your Product, you can also use Code by Zapier to run JavaScript code. To do so, pass the required data as input to code and return output that can be used later to see if the match was found. A simple example that gets LineItems productIds as input.
const TARGET_PRODUCT_ID = 12345;
const productIds = inputData.productIds.split(",");
output = {targetProductFound: false};
productIds.forEach(id => {
// Add more conditions if needed
if(Number(id) === TARGET_PRODUCT_ID){
output.targetProductFound = true;
}
});
return output
Then use Filter to proceed or abort.

How to use numeric chat IDs to avoid expensive `get_entity(channel_name)` calls?

As per this comment, I'm trying to use numeric channel IDs in my telethon code, so that I don't end up spamming the Telegram API with expensive name lookup calls and getting throttled, but I'm having some difficulty.
e.g. assuming I've already instantiated and connected client:
messages = client.get_messages(numeric_channel_id)
...fails with this error:
ValueError: Could not find the input entity for PeerUser(user_id=[numeric_channel_id]) (PeerUser)
I think there's some cacheing going on, because if I do a get_entity call using the account name first, then the get_messages call works. i.e. something like this:
client.get_entity(channel_name_which_belongs_to_numeric_channel_id)
messages = client.get_messages(numeric_channel_id)
That works just fine, but now I'm doing the expensive get_entity(name) call which is what I'm trying to avoid (because it will result in FloodWaitError problems).
Is there any way I can use the numeric ID of a channel to avoid the expensive get_entity call, in this scenario?
I've also tried forcing the entity type to Channel, like this:
channel = Channel(id=numeric_channel_id, title=None, photo=None, date=None)
messages = client.get_messages(channel)
...but the results are the same, except that the error mentions PeerChannel rather than PeerUser
ID usage is not going to work unless you cached the target as you stated, that's the only way to use the integer id.
you must have met the entity from events or manual requests (say, username fetching).
you should be using client.get_input_entity('username')
it will try to search the local cache first for the saved id + hash that equals the passed username, if found it won't do ResolveUsername (heavy one) and use the local access_hash + id and return you an inputPeer. you pass that to any request you want.
you mustn't use id alone unless you're certain you have met its holder, in other words, id you use has to be something you found out from within the library and within the same session, not something you knew/found out externally.
There is no magical way to fetch something with id you claim you know, if you actually know it, the lib has to create (when the access_hash is present) an InputPeer
As the other answer states, fetching by username will always work but is expensive. However note that such a call will fill the cache so it can later be fetched again much more cheaply by ID.
If you really need a stable reference to some entity and cannot rely on the session cache, and want to avoid usernames, the documentation for Entities vs. Input Entities may be helpful.
What it boils down to is, you can do this:
print(await client.get_input_entity('username'))
...which will show something like:
InputPeerChannel(channel_id=1066197625, access_hash=-6302373944955169144)
...and then, the account that made the get_input_entity call will always be able to use the printed result, without the need for it to be in cache:
from telethon.tl.types import InputPeerChannel
USERNAME = InputPeerChannel(channel_id=1066197625, access_hash=-6302373944955169144)
# ...
await client.send_message(USERNAME, 'Hi') # works without cache

Unable to get a total count of items in the model in the ASP.NET MVC view

I am using the following code to render a pager:
#Html.BootstrapPager(Request.QueryString("Page"), Function(index) Url.Action("Index", "Posts", New With {.page = index}), 14000, System.Web.Configuration.WebConfigurationManager.AppSettings("PageSize"), 15)
My problem is that If I use Model.Count in place of the 14000 then I only get 1 page of records since I am using skip and take in the repository to pull only the need records. How can i in the view access the total number of published records so that I don't have to hard code the value into the view right now?
The original pager code is here. I converted it to VBNET am using it. It works fine if the record count is hardcoded.
This is the repo:
Dim posts As IEnumerable(Of PostSummaryDTO)
Using db As BetterBlogContext = New BetterBlogContext
posts = db.be_Posts.OrderByDescending(Function(x) x.DateCreated).Select(Function(s) New PostSummaryDTO With {.Id = s.PostRowID, .PostDateCreated = s.DateCreated, .PostSummary = s.Description, .PostTitle = s.Title, .IsPublished = s.IsPublished}).Skip((Page - 1) * PageSize).Take(PageSize).ToList()
Return posts.ToList
End Using
You need two different methods in the lower layer - one to get the total count and one to get the desired page - and then call them both from your controller, passing both results in the model to the view. As such, the model cannot be a collection of records; it must be an object with a property for a collection of records and a property for the count. Either that or use the ViewBag to pass the count.
What we do in my office is have a service layer to contain the business logic and repository to handle the data access. There is a single method in the repository to return an IQueryable that provides access to all the records for a particular table. There are then one or more methods in the service that call that repository method and use it in different ways. In this case, there might be a GetTotalCount method and a GetPage method in the service. Both would call the same repository method to get the same IQueryable and then the first method would call Count on the result while the second method would call Skip and Take. As Skip and Take don't force execution of the query, you'd also call ToArray or the like in that second method. The service might also have a GetRecord method that you would pass an ID and call FirstOrDefault inside to get a single record with a matching ID. You can roll the service and repository into a single class if you want but I'd recommend separating the business logic from the data access.

Expand() method doesn't bind all Data to the object

I'm trying to query a WCF Data Service with oData. Everything works fine, but in a many to many relation the expand Function doesn't work. The Relation is: Product 1-* ProductOrder *-1 Order Here is my code to query the service:
var queryProductOrder = (DataServiceQuery<ProductOrder>)SessionHelper.context.ProductOrder.Expand(x=>x.Product);
var allProductOrders = await queryProductOrder.ExecuteAsync();
If I run this in debug mode and check the allProductOrder Object, there is no Product. The interesting fact is, that when I check the generated OData Query and run it over the browser, the Product gets expanded.
The query looks like this:
http://localhost:10000/ProductOrder()?$expand=Product
And the JSON-Result is expanded:
{"odata.metadata":"http://localhost:10000/$metadata#ProductOrder","value":[{"Product":{"id":1,"Name":"Die Sims","Tax_fk":1,"Price":"44.99","Description":"Lebenssimulation","Stock":"99.00","TotalOrder":"0.00","ProductUnit_fk":1,"Barcode":"121212121","MainImage_fk":null,"Tenant_fk":1,"PurchasePrice":null},"id":1,"Product_fk":1,"Order_fk":1,"Tenant_fk":1,"Amount":"10"}]}
Also confusing is the fact, that on other many to many relations the expand method works like it should.
Why it doesn't expand the allProductOrders Object? Why is the allProductOrders.First().Product object null but the generated OData query returns the Expanded data?

Rails3: Cascading Select Writer's Block

I have a big, flat table:
id
product_id
attribute1
attribute2
attribute3
attribute4
Here is how I want users to get to products:
See a list of unique values for attribute1.
Clicking one of those gets you a list of unique values for attribute2.
Clicking one of those gets you a list of unique values for attribute3.
Clicking one of those gets you a list of unique values for attribute4.
Clicking one of those shows you the relevant products.
I have been coding Rails for about 4 years now. I just can't unthink my current approach to this problem.
I have major writer's block. Seems like such an easy problem. But I either code it with 4 different "step" methods in my controller, or I try to write one "search" method that attempts to divine the last level you selected, and all the previous values that you selected.
Both are major YUCK and I keep deleting my work.
What is the most elegant way to do this?
Here is a solution that may be an option. Just off the top of my head and not tested (so there is probably a bit more elegant solution). You could use chained scopes in your model:
class Product < ActiveRecord::Base
scope :with_capacity, lambda { |*args| args.first.nil? ? nil : where(:capacity=>args.first) }
scope :with_weight, lambda { |*args| args.first.nil? ? nil : where(:weight=>args.first) }
scope :with_color, lambda { |*args| args.first.nil? ? nil : where(:color=>args.first) }
scope :with_manufacturer, lambda { |*args| args.first.nil? ? nil : where(:manufacturer=>args.first) }
self.available_attributes(products,attribute)
products.collect{|product| product.send(attribute)}.uniq
end
end
The code above will give you a scope for each attribute. If you pass a parameter to the scope, then it will give you the products with that attribute value. If the argument is nil, then the scope will return the full set (I think ;-). You could keep track of the attributes they are drilling down in in the session with 2 variables (page_attribute and page_attribute_value) in your controller. Then you call the entire chain to get your list of products (if you want to use them on the page). Next you can get the attribute values by passing in the set of products and the attribute name to Product.available_attributes. Note that this method (Product.available_attributes) is a total hack and would be inefficient for a large set of data, so you may want to make this another scope and use :select=>"DISTINCT(your_attribute)" or something more database efficient instead of iterating thru the full set of products as I did in the hack method.
class ProductsController < ApplicationController
def show
session[params[:page_attribute].to_sym] = params[:page_attribute_value]
#products = Product.all.with_capacity(session[:capacity]).with_weight(session[:weight]).with_color(session[:color]).with_manufacturer(session[:manufacturer])
#attr_values = Product.available_attributes(#products,params[:page_attribute])
end
end
Again, I want to warn you that I did not test this code, so its totally possible that some of the syntax is incorrect, but hopefully this will give you a starting point. Holla if you have any questions about my (psuedo) code.