CreateSend Ruby Gem using api_key fails

Hello,

I'm trying to find subscribers through the api using the ruby CreateSend gem.
I have the client id and the api_key and the inital request works. But when I try to query further into the api It appears to fail trying to access the @auth_details as an hash. That fails because when using the api_key the @auth_details is a string, if I was using OAuth then @auth_details would be a hash.

That is at least what I think is the problem.

>>client = CreateSend::Client.new CM_CLIENT_ID, :api_key => CM_API_KEY
>>client.lists //Fails with the error "undefined method `has_key?' for @auth_details"

Maybe I'm doing it wrong.

I have tried sending the api_key with the client.lists function.

I was hoping to do something like this:

>>client = CreateSend::Client.new CM_CLIENT_ID, :api_key => CM_API_KEY
>>list = client.lists.first
>>subscriber = CreateSend::Subscriber.get list.id, "email@address.com", :api_key=>CM_API_KEY

But I need the list.id.

Could you tell me if I'm just doing it wrong ?
Kind regards,
Birgir

Birgir, 3 years ago

I see now in my terminal that I'm definitively doing this wrong. Lack of sleep I guess :)
Could you guys point me in the right direction though ?

Kind and sleepy regards :)
Birgir

Birgir, 3 years ago

YEAH 

CreateSend::Client.new({:api_key=>CM_API_KEY},CM_CLIENT_ID)

good night :)

Birgir, 3 years ago

Update:: The gem works perfectly. I just didn't realize I had to put curly brackets around `:api_key=>'key'`

It isn't  shown in the example on http://campaignmonitor.github.io/createsend-ruby/

Anywho, thanks for the help and here Is my ruby code if anyone want's it.

  def subscribed_to_emails
    cm = CreateSend::Client.new({:api_key=>CM_API_KEY},CM_CLIENT_ID)
    active_subscriptions = cm.lists_for_email(self.email).select{|i| i.SubscriberState.downcase=="active"}
    !active_subscriptions.empty?
  end

  def unsubscribe_from_emails
    cm = CreateSend::Client.new({:api_key=>CM_API_KEY},CM_CLIENT_ID)
    lists = cm.lists_for_email(self.email)
    lists.each do |list|
      if list.SubscriberState.downcase == "active"
        begin
          CreateSend::Subscriber.new({:api_key=>CM_API_KEY},list.ListID,self.email).unsubscribe
          success = true
        rescue
          #FAILED
          success = false
        end
      end
    end
    return success
  end
roshodgekiss roshodgekiss, 3 years ago

Awesome, glad you got it working, Birgir! Let us know if you have any further questions :D


Get in touch with us on Twitter: http://twitter.com/campaignmonitor
We're also on Facebook: http://facebook.com/campaignmonitor

200,000 companies around the world can't be wrong.

From Australia to Zimbabwe, and everywhere in between, companies count on 
Campaign Monitor for email campaigns that drive real business results.

Get started for free
1-888-533-8098