Subscribing users to a list through the ruby API wrapper

Is anyone successfully using the ruby API wrapper to subscribe users to a list?

I'm on rails 3.0.10 and am getting the same error with both ruby 1.8.7 and 1.9.2.

my code:

require 'createsend'
CreateSend.api_key 'XXX'
list_id = 'XXX'
CreateSend::Subscriber.add(list_id,'kevin@email.com', 'Kevin Smith', nil, false)

I get this error:

MultiJson::DecodeError: 745: unexpected token at '"kevin@email.com"'
    from /Users/KSmith/.rvm/gems/ruby-1.8.7-p352/gems/json-1.5.3/lib/json/common.rb:148:in `parse'
    from /Users/KSmith/.rvm/gems/ruby-1.8.7-p352/gems/json-1.5.3/lib/json/common.rb:148:in `parse'
    from /Users/KSmith/.rvm/gems/ruby-1.8.7-p352/gems/multi_json-1.0.3/lib/multi_json/engines/json_gem.rb:13:in `decode'
    from /Users/KSmith/.rvm/gems/ruby-1.8.7-p352/gems/multi_json-1.0.3/lib/multi_json.rb:65:in `decode'
    from /Users/KSmith/.rvm/gems/ruby-1.8.7-p352/gems/httparty-0.8.0/lib/httparty/parser.rb:116:in `json'
    from /Users/KSmith/.rvm/gems/ruby-1.8.7-p352/gems/httparty-0.8.0/lib/httparty/parser.rb:136:in `send'
    from /Users/KSmith/.rvm/gems/ruby-1.8.7-p352/gems/httparty-0.8.0/lib/httparty/parser.rb:136:in `parse_supported_format'
    from /Users/KSmith/.rvm/gems/ruby-1.8.7-p352/gems/httparty-0.8.0/lib/httparty/parser.rb:103:in `parse'
    from /Users/KSmith/.rvm/gems/ruby-1.8.7-p352/gems/httparty-0.8.0/lib/httparty/parser.rb:66:in `call'
    from /Users/KSmith/.rvm/gems/ruby-1.8.7-p352/gems/httparty-0.8.0/lib/httparty/request.rb:221:in `parse_response'
    from /Users/KSmith/.rvm/gems/ruby-1.8.7-p352/gems/httparty-0.8.0/lib/httparty/request.rb:193:in `handle_response'
    from /Users/KSmith/.rvm/gems/ruby-1.8.7-p352/gems/httparty-0.8.0/lib/httparty/request.rb:75:in `perform'
    from /Users/KSmith/.rvm/gems/ruby-1.8.7-p352/gems/httparty-0.8.0/lib/httparty.rb:391:in `perform_request'
    from /Users/KSmith/.rvm/gems/ruby-1.8.7-p352/gems/httparty-0.8.0/lib/httparty.rb:359:in `post'
    from /Users/KSmith/.rvm/gems/ruby-1.8.7-p352/gems/createsend-0.3.2/lib/createsend.rb:110:in `post'
    from /Users/KSmith/.rvm/gems/ruby-1.8.7-p352/gems/createsend-0.3.2/lib/createsend/subscriber.rb:29:in `add'
    from /Users/KSmith/Sites/rails-project/app/models/user.rb:10:in `sub_to_createsend'
    from (irb):1ruby-1.8.7-p352 :002 > exit

Thanks,
Kevin

jamesd jamesd, 6 years ago

Hey Kevin,

I can't reproduce this with a fresh install of the createsend gem, in plain irb.

The problem you're experiencing may be related to the fact that you're using a newer version of httparty than is in the Gemfile.lock at the GitHub repo.

I would be interested to know whether you still experience this problem if you use the version of httparty specified in the Gemfile.

jamesd jamesd, 6 years ago

Just following up again Kevin.

I've released an update to the createsend gem, which uses the latest version of httparty (0.8.0), which should fix this problem for you.

Please see this issue (and the associated commit) for details.

See why 200,000 companies worldwide love Campaign Monitor.

From Australia to Zimbabwe, and everywhere in between, companies count on Campaign Monitor for email campaigns that boost the bottom line.

Get started for free