I'm using the mailchimp-api gem in a rails 4 project. I can successfully subscribe a users email to a list, but can't get users into the group I'm specifying.
In Mailchimp I setup a Group with the name "UserType" as a checkbox. It has two groups within "User" and "Tech".
Here is my subscribe code:
#mc.lists.subscribe(list_id, {'email' => email}, {'merge_vars' => { 'groupings' => [{'name' => 'UserType', 'groups' => ['User']}]}})
I'm not receiving any errors and the email is still successfully being inserted into the list. Any ideas on why the user isn't being inserted into the "User" group?
Try add an array for each group into groupings.. In your case you should count 4 arrays....
See if my PHP code can help you:
'merge_vars' => array('fname' => $firstName, 'lname' => $lastName, 'groupings' => array(array('name'=> 'Test', 'groups' => array('Test1'))));
Related
I'm using Eventbrite API to create events from my application, what I need are private events and I create them with this code:
$event_params = array(
'title' => $event->name,
'description' => $event->description,
'start_date' => $event->start_at,
'end_date' => $event->end_at,
'timezone' => 'Europe/Paris',
'privacy' => '0',
'venue_id' => $venue_id,
'organizer_id' => $organizer_id,
'capacity' => $event->capacity,
'currency' => 'EUR',
'locale' => 'fr_FR',
'status' => $event->status,
'custom_header' => '<img src="'.asset($event->placeholder_img).'" width="100%"/>'
);
$resp = $this->eb_client->event_new($event_params);
so the event is created in Eventbrite but it can be shared via social media: http://prntscr.com/6w0b20 and I don't want this thing, I was wondering if this social sharing could be avoid via Eventbrite API.
Thank you,
Adrian
Answered in our forum, but I'll leave it here as well.
By setting the 'event.shareable' parameter to False you will be able to shut off this feature via the API.
You can see the request parameters for Event Details (event_new's parity endpoint) here http://www.eventbrite.com/developer/v3/endpoints/events/#ebapi-post-events
So recently I was helped out finding a way of using detect in rails to grab a url from text... however that would come very useful for me also in a controller if its possible.
My controller grabs some info and created a new entry into the DB based on incoming params, looks something like this;
#received_msg = Message.create(:content => params[:Text], :user_id => user.id, :status => 'new')
Now, I was hoping that using detect in my controller on the create action, I could search the :content for specific text or symbol and allow my users to define few things in content but I would assign that to a different column. I'm sure this isn't clear so let me show by example.
EXAMPLE:
Let's say my user send a message with content like so;
"Hey there, you should check this type of website out and make sure that its good to go"
Now, I'm assigning a USER_ID for the user that submitted this message, but the original owner could be someone else before the user submitted it. So I thought I would allow my user_id to enter #John into their message, meaning the original owner of the message was JOHN.. the new message would look something like this;
"Hey there, you should check this type of website out and make sure that its good to go #John"
Now in my controller when that message is created as a record, I'd like to take JOHN and assign it to the column username for example; I thought something like this would work but its giving me error .detect undefined..
#received_msg = Message.create(:content => params[:Text], :user_id => user.id, :status => 'new', :username => (params[:Text].detect {|original_sender| original_sender.start_with? "#"))
Maybe too many brackets?
you are missing } at the end
#received_msg = Message.create(:content => params[:Text], :user_id => user.id, :status => 'new', :username => (params[:Text].detect {|original_sender| original_sender.start_with? "#"}))
you can also use the below for what you want
#received_msg = Message.create(:content => params[:Text], :user_id => user.id, :status => 'new', :username => params[:Text].split.find{|w| w.start_with?("#")})
I have such code of searching (with metasearch rails gem):
#pre_oils = Oil.search({:manufacturer_like => params[:oilbrand], :description_like => params[:oiloiliness], :description_like => params[:oilstructure], :capacity_eq => params[:oilsize]})
But i must to search via description with like on two params: oiloiliness, oilstructure... In some cases i could have first, but didn'r have oilstructure or have oilstructure but didn't have oiloiliness...
if i leave
#pre_oils = Oil.search({:manufacturer_like => params[:oilbrand], :description_like => params[:oiloiliness], :capacity_eq => params[:oilsize]})
all is ok
Now it is not searching via oiloiliness, but why ? How to do it? How to search via both fields?
The following code seems to work if there is one user, but truncate the email for multiple users:
users.each do |user|
mail(
:to => user.email,
:subject => 'Hi',
:template_name => 'notification'
).deliver
Is this the proper way to send a few emails?
Ruby on Rails 3.2.2
Heroku
SendGrid
I think this is what you're looking for:
def my_mailer_method
users = User.find({ ... })
headers['X-SMTPAPI'] = { :to => users.to_a }.to_json
mail(
:to => "this.will#be.ignored.com",
:subject => "Hi",
:template_name => "notification"
).deliver
end
This sends a message to any number of recipients use the SendGrid's SMTP API. You can find further information on the docs page.
You might also want to take a look at the sendgrid rails gem
To send email to multiple users: pass an array
Replace
:to => user.email
with
:to => users.map(&:email)
more > rails guide
If it is not important for you to hide email addresses from each other, you can specify recipients in a comma delimited string.
It seems that the problem is that each instance of the Mailer can only send one email. Perhaps the mail object is falling out of scope and getting cleaned up by the garbage collector...
The solution that worked was to iterate over the users outside of the Mailer, and call it once for each user. It may be slow but it should happen in the background anyway so it's fine.
Hi I have read all the other post relating to this but I think I am missing something fundamental. I am using mini_fb in my ruby on rails application for handling the facebook api. I have the following code:
current_user.session.post('me', :type => :feed, :params => {:name => "name",
:to => "{\"data\":[{\"name\":\"#{friend.facebook_name}\",\"id\":\"#{friend.facebook_id}\"}]}",
:link => url_of_app,
:description => "desc",
:actions => "{\"name\": \"action name\", \"link\": \"url\"}"})
The above posts to the current user's wall with or without the "to" parameter set. Everything works, except for the "to" parameter. I have read the graph post to wall over and over again and I can't figure out what is wrong with this code of mine. I would really appreciate it if someone could point out my mistake.
I've never used ruby's version, but probably the problem is in the first parameter. You are targeting 'me' feed, while should be targeting your friends feed. Try fetching your friend id and doing something like
current_user.session.post(friend.facebook_id, :type => :feed, :params => ...)
Wow, mini_fb looks so verbose :)
Telémako is right, you need to use your friends id. I give you another alternative for more nice code. Use Koala.
https://github.com/arsduo/koala/wiki/Graph-API
#graph.put_wall_post("explodingdog!", {:name => "i love loving you", :link => "http://www.explodingdog.com/title/ilovelovingyou.html"}, "tmiley")
=> {"id"=>"83901496_520908898070"}
I use it in my projects and works very well.