How do I call SetHITTypeNotification in Amazon Mechanical Turk (MTurk) using RTurk? - mechanicalturk

I'm trying to make this kind of request:
https://mechanicalturk.amazonaws.com/?Service=AWSMechanicalTurkRequester
&AWSAccessKeyId=[the Requester's Access Key ID]
&Operation=SetHITTypeNotification
&Signature=[signature for this request]
&Timestamp=[your system's local time]
&HITTypeId=T100CN9P324W00EXAMPLE
&Notification.1.Destination=janedoe#example.com
&Notification.1.Transport=Email
&Notification.1.Version=2006-05-05
&Notification.1.EventType=AssignmentSubmitted
based on the documentation here: http://docs.aws.amazon.com/AWSMechTurk/latest/AWSMturkAPI/ApiReference_SetHITTypeNotificationOperation.html
Here's my code:
RTurk.SetHITTypeNotification(:hit_type_id => "3M36IJVRR974ABAC76WQ0TCVKX9SIA", :notification => { :destination => "https://sqs.us-east-1.amazonaws.com/971351813114/MechanicalTurk", :transport => "SQS", :version => "2006-05-05", :event_type => "assignment_accepted" }, :active => true)
and here's the error that I'm seeing:
NoMethodError: undefined method `to_param_hash' for #<Hash:0x007ffe1ed82858>
Anyone know what the to_param_hash error means or how to address it?

Spent a couple hours on this problem. Answering here in case it helps others with the same situation. It turns out that I need to create a Notification object, which makes a lot of sense when you look at how to work with Notifications in RTurk in other contexts. Here's a snippet that works:
n = RTurk::Notification.new("https://sqs.us-east-1.amazonaws.com/971351813114/MechanicalTurk", "SQS", "2006-05-05", "AssignmentAccepted")
a = RTurk.SetHITTypeNotification(:hit_type_id => "3M36IJVRR974ABAC76WQ0TCVKX9SIA", :notification => n, :active => true)
t = RTurk.SendTestEventNotification(:notification => n, :test_event_type => "AssignmentAccepted")
Hope this helps others in the same situation!

Related

phpbb 3.2.x user_add including custom Profile field

This has been driving me nuts for 2 days and I can't find an answer anywhere on Google so would really appreciate a little help..
I have a custom registration form on my website, which sends the data to a fairly standard PHPBB3 user_add process as follows:
$user_row = array(
'username' => request_var('createUsername',''),
'user_password' => phpbb_hash(request_var('createPassword','')),
'user_email' => request_var('createEmail',''),
'group_id' => '2',
'user_timezone' => '1.00',
// 'user_dst' => '0',
'user_lang' => 'en',
'user_type' => $user_type,
'user_actkey' => $user_actkey,
'user_ip' => $user->ip,
'user_regdate' => time(),
'user_inactive_reason' => $user_inactive_reason,
'user_inactive_time' => $user_inactive_time,
);
// Register user...
$user_id = user_add($user_row, $cp_data);
// If creating the user failed, display an error
if ($user_id === false)
{
trigger_error('NO_USER', E_USER_ERROR);
}
That works fine and I'm happy with it, however, I have created a custom profile field in the Admin Control Panel called 'ea_real_name' which I want to hold the user's real name. This corresponds to a field on the registration form called 'createRealName' (sent through as $_POST['createRealName'])
I know that user_add takes an optional field called 'cp_data', but I can't for the life of me work out how to format this data... Should it be an array (something like 'ea_real_name' => request_var('createRealName','') or something else?
PHPBB's wiki for the field is empty (https://wiki.phpbb.com/Custom_profile::submit_cp_field) so not much help...
Thanks! :-)
I was right in my assumption! It's an array with the field name prefixed by pf_.
Finally found an answer here: https://www.phpbb.com/community/viewtopic.php?f=71&t=1638905
$cp_data = array(
'pf_ea_real_name' => request_var('createRealName','')
);
Is the correct way to do it...

Shopify Order API - Passing Discount

I'm getting some very strange results from Shopify API and I'm hoping someone can help me out.
I'm trying to create an order, with a discount. Its actually saving the order, with the discount information... however the amount is ALWAYS wrong
order_params = {
:browser_ip => webhook[:browser_ip],
:buyer_accepts_marketing => webhook[:buyer_accepts_marketing],
:currency => webhook[:currency],
:email => webhook[:email],
:financial_status => webhook[:financial_status],
:landing_site => webhook[:landing_site],
:note => webhook[:note],
:referring_site => webhook[:referring_site],
:line_items => line_items,
:tag => tags,
:transactions => transactions,
:discount_codes => webhook[:discount_codes],
:total_discounts => webhook[:total_discounts],
:shipping_address => webhook[:shipping_address],
:shipping_lines => webhook[:shipping_lines],
:customer_id => #options[:customer_id],
:billing_address => webhook[:billing_address]
}
#shopify_order = ShopifyAPI::Order.create(order_params)
As you can see its created from webhook data. This is giving me back...(truncated)
"reference"=>nil,
"user_id"=>nil,
"subtotal_price"=>"55.00",
"total_discounts"=>"55.00",
"location_id"=>nil,
"source_identifier"=>nil,
"source_url"=>nil,
"processed_at"=>"2017-05-31T15:53:03-04:00",
"device_id"=>nil,
"phone"=>nil,
"browser_ip"=>nil,
"landing_site_ref"=>nil,
"order_number"=>1140,
"discount_codes"=>
[#<ShopifyAPI::Order::DiscountCode:0x007ffbec42ccb0
#attributes={"code"=>"50% OFF", "amount"=>"55.00", "type"=>""},
#persisted=true,
#prefix_options={}>]
So far, so good all data is correct.. then I save and this happens.. the amount discounted is incorrect... it should be £55.
I haven't dug too deep into this, but I'm pretty sure the code needs to be unique.
i.e. you probably already have a Discount Code with the same code 50% OFF with amount: 60.50 defined somewhere else on that shop.
Try using a new, unique discount code and testing with that.
I would suggest creating a new discount code like 50OFF that has amount: 50 with type: percentage, then you can re-use that for orders with a 50% discount.
See the Price Rules reference for more information >

silverstripe query does not work, best way to debug?

I have this silverstripe query that does not work ( it outputs all messages and not the ones with the date range )
What would be the best way to tackle this query?
Im fairly new to silverstripe and havent been able to find information on how to print the raw query.
return = Message::get()
->filter(array(
'IsPublished' => true,
'StartPublication:LessThanOrEqual' => date('Y-m-d'),
'Priority' => array('High', 'Normal')
))
->where("\"StopPublication\" >= ".date('Y-m-d')." OR \"StopPublication\" IS NULL")
->sort('StartPublication', 'DESC')->limit($this->getLimit());
The correct answer is to not use where() - this is a trap method that a lot of learners fall into (presumably due to the name). It's intended basically only for very complex things that the ORM just can't handle.
You're calling filter at least, which is the correct thing. But what you want instead of where() is filterAny():
Message::get()
->filter([
'IsPublished' => true,
'StartPublication:LessThanOrEqual' => 'now',
'Priority' => ['High', 'Normal']
])
->filterAny([
'StopPublication:GreaterThanOrEqual' => 'now',
'StopPublication' => null
])
->sort('StartPublication', 'DESC')
->limit($this->getLimit());
As the other answer already specifies, do not use an = on the return (or put a $ in front of return to make it a variable), and to return the query itself use $datalist->sql() http://api.silverstripe.org/3.1/class-DataList.html#_sql
But - seeing the docs on SQLQuery is wrong, because you're not using SQLQuery. You're using the ORM, so this doc page is far more relevant: http://docs.silverstripe.org/en/3.1/developer_guides/model/data_model_and_orm/#filterany
For starts return = Message::get() its just return Message::get()
I assume that you have set php error reporting so that it outputs errors and SS is also in development mode so it won't hide error outputs.
The answer to your question is to to do either:
to output it to the output html:
Debug::dump(Message::get()
->filter(array(
'IsPublished' => true,
'StartPublication:LessThanOrEqual' => date('Y-m-d'),
'Priority' => array('High', 'Normal')
))
->where("\"StopPublication\" >= ".date('Y-m-d')." OR \"StopPublication\" IS NULL")
->sort('StartPublication', 'DESC')->limit($this->getLimit())->sql());
or output it to the project roots log file
Debug::log(Message::get()
->filter(array(
'IsPublished' => true,
'StartPublication:LessThanOrEqual' => date('Y-m-d'),
'Priority' => array('High', 'Normal')
))
->where("\"StopPublication\" >= ".date('Y-m-d')." OR \"StopPublication\" IS NULL")
->sort('StartPublication', 'DESC')->limit($this->getLimit())->sql());
See http://docs.silverstripe.org/en/developer_guides/model/sql_query/

Rspec testing complex code with undefined variables

Just need alittle bit of help with rspec testing... very new to it and dont quite know how to test this piece of code
# Get a list of tasks recently used by the user
recent_task_ids = Effort.all( :select => "project_task_id",
:conditions => { :user_id => #user_id },
:group => "project_task_id",
:order => "MAX( week_commencing )" )
# For each of the task ids, get the actual project task records
#recent_tasks = []
recent_task_ids.each do |effort|
if ProjectTask.find_by_id( effort.project_task_id ) != nil
#recent_tasks.push( ProjectTask.find( effort.project_task_id ) )
end
end
Not sure if your even supposed to test undefined variables this way but any help would be great
You can stub out the Effort.all method.
it "tests with nil values" do
Effort.stub(:all).and_return(nil)
end
Source: http://rspec.info/documentation/mocks/stubs.html and http://rspec.info/documentation/mocks/

Is this the right way of using ThenFetch() to load multiple collections?

I'm trying to load all the collections eagerly, using NHibernate 3 alpha 1. I'm wondering if this the right way of using ThenFetch()?
Properties with plural names are collections. The others are just a single object.
IQueryable<T> milestoneInstances = Db.Find<T, IQueryable<T>>(db =>
from mi in db
where mi.RunDate == runDate
select mi).Fetch(mi => mi.Milestone)
.ThenFetch(m => m.PrimaryOwners)
.Fetch(mi => mi.Milestone)
.ThenFetch(m => m.SecondaryOwners)
.Fetch(mi => mi.Milestone)
.ThenFetch(m => m.Predecessors)
.Fetch(mi => mi.Milestone)
.ThenFetch(m => m.Function)
.Fetch(mi => mi.Milestone)
.ThenFetchMany(m => m.Jobs)
.ThenFetch(j => j.Source)
;
I thought of asking this in the NHibernate forums but unfortunately access to google groups is forbidden from where I am. I know Fabio is here, so maybe the guys from the NHibernate team can shed some light on this?
Thanks
Apparently, there's no "right" way to use ThenFetch in such a case. Your example works fine but SQL produced contains many joins to Milestone, which isn't that right.
Using IQueryOver instead of IQueryable allows you to use complex syntax in Fetch:
Fetch(p => p.B)
Fetch(p => p.B.C) // if B is not a collection ... or
Fetch(p => p.B[0].C) // if B is a collection ... or
Fetch(p => p.B.First().C) // if B is an IEnumerable (using .First() extension method)
So in your case it would be:
query // = session.QueryOver<X>()
.Fetch(mi => mi.Milestone).Eager
.Fetch(mi => mi.Milestone.PrimaryOwners).Eager
.Fetch(mi => mi.Milestone.SecondaryOwners).Eager
.Fetch(mi => mi.Milestone.Predecessors).Eager
.Fetch(mi => mi.Milestone.Function).Eager
.Fetch(mi => mi.Milestone.Jobs).Eager
.Fetch(mi => mi.Milestone.Jobs.First().Source).Eager
The one thing you are missing is that you should use FetchMany() and ThenFetchMany() is the child property is a collection.
IQueryable<T> milestoneInstances = Db.Find<T, IQueryable<T>>(db =>
from mi in db
where mi.RunDate == runDate
select mi);
var fetch = milestoneInstances.Fetch(f => f.Milestone);
fetch.ThenFetch(f => f.PrimaryOwners);
fetch.ThenFetch(f => f.SecondaryOwners);
//...
As leora said, make sure when fetching children collections that you use
FetchMany()
ThenFetchMany()
A new Fetch, should pick up from the root, but this does not always happen. Sometimes you need to create them as separate queries or use Criteria Futures to batch up a multiple fetch.