CreateSend::Subscriber.get doesn't work
Closed this issue · 7 comments
Example for generating error:
@auth = {api_key: "myapikey"}
u = User.last
c = CreateSend::Subscriber.get(@auth, AppCampaignMonitor.list, u.email)
Stack Trace
Psych::SyntaxError: (<unknown>): found unexpected ':' while scanning a plain scalar at line 1 column 71
from /opt/ruby-2.0.0-p0/lib/ruby/2.0.0/psych.rb:205:in `parse'
from /opt/ruby-2.0.0-p0/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'
from /opt/ruby-2.0.0-p0/lib/ruby/2.0.0/psych.rb:153:in `parse'
from /opt/ruby-2.0.0-p0/lib/ruby/2.0.0/psych.rb:129:in `load'
from /var/www/househappy.org/shared/bundle/ruby/2.0.0/gems/crack-0.3.2/lib/crack/json.rb:12:in `parse'
from /var/www/househappy.org/shared/bundle/ruby/2.0.0/gems/tinder-1.4.1/lib/tinder/connection.rb:9:in `json'
from /var/www/househappy.org/shared/bundle/ruby/2.0.0/gems/httparty-0.11.0/lib/httparty/parser.rb:134:in `parse_supported_format'
from /var/www/househappy.org/shared/bundle/ruby/2.0.0/gems/httparty-0.11.0/lib/httparty/parser.rb:100:in `parse'
from /var/www/househappy.org/shared/bundle/ruby/2.0.0/gems/httparty-0.11.0/lib/httparty/parser.rb:64:in `call'
from /var/www/househappy.org/shared/bundle/ruby/2.0.0/gems/httparty-0.11.0/lib/httparty/request.rb:215:in `parse_response'
from /var/www/househappy.org/shared/bundle/ruby/2.0.0/gems/httparty-0.11.0/lib/httparty/request.rb:185:in `block in handle_response'
from /var/www/househappy.org/shared/bundle/ruby/2.0.0/gems/httparty-0.11.0/lib/httparty/response.rb:18:in `call'
from /var/www/househappy.org/shared/bundle/ruby/2.0.0/gems/httparty-0.11.0/lib/httparty/response.rb:18:in `parsed_response'
from /var/www/househappy.org/shared/bundle/ruby/2.0.0/gems/httparty-0.11.0/lib/httparty/response.rb:56:in `method_missing'
from /var/www/househappy.org/shared/bundle/ruby/2.0.0/gems/hashie-2.0.4/lib/hashie/mash.rb:148:in `deep_update'
from /var/www/househappy.org/shared/bundle/ruby/2.0.0/gems/hashie-2.0.4/lib/hashie/mash.rb:66:in `initialize'
from /var/www/househappy.org/shared/bundle/ruby/2.0.0/gems/createsend-3.2.0/lib/createsend/subscriber.rb:18:in `new'
from /var/www/househappy.org/shared/bundle/ruby/2.0.0/gems/createsend-3.2.0/lib/createsend/subscriber.rb:18:in `get'
from (irb):3
from /var/www/househappy.org/shared/bundle/ruby/2.0.0/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in `start'
from /var/www/househappy.org/shared/bundle/ruby/2.0.0/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in `start'
from /var/www/househappy.org/shared/bundle/ruby/2.0.0/gems/railties-3.2.12/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
Using Ruby 2.0.0-p0
Gemfile
* actionmailer (3.2.12)
* actionpack (3.2.12)
* activeadmin (0.6.0 5f5ab0f)
* activemodel (3.2.12)
* activerecord (3.2.12)
* activerecord-postgis-adapter (0.6.2)
* activeresource (3.2.12)
* activesupport (3.2.12)
* arbre (1.0.1)
* arel (3.0.2)
* authlogic (3.3.0 51416fe)
* awesome_print (1.1.0)
* backports (2.6.7)
* bcrypt-ruby (3.0.1)
* bourbon (3.1.6)
* browser (0.1.6)
* bson (1.8.5)
* bson_ext (1.8.5)
* builder (3.0.4)
* bundler (1.3.1)
* campaign_monitor_subscriber (1.0.3)
* capistrano (2.15.2)
* capistrano-campfire (0.2.1)
* carrierwave (0.8.0)
* carrierwave-vips (1.0.4 af85aed)
* celluloid (0.13.0)
* childprocess (0.3.9)
* chronic (0.9.1)
* coderay (1.0.9)
* coffee-rails (3.2.2)
* coffee-script (2.2.0)
* coffee-script-source (1.6.2)
* connection_pool (1.0.0)
* crack (0.3.2)
* createsend (3.2.0)
* curb (0.8.3)
* curb-fu (0.6.2)
* dalli (2.6.2)
* descendants_tracker (0.0.1)
* devise (2.2.3)
* diff-lcs (1.2.4)
* domain_name (0.5.11)
* erubis (2.7.0)
* eventmachine (1.0.3)
* excon (0.20.1)
* execjs (1.4.0)
* factory_girl (4.2.0)
* factory_girl_rails (4.2.1)
* faker (1.1.2)
* faraday (0.8.7)
* fastercsv (1.5.5)
* ffi (1.8.1)
* fog (1.10.1 ca53b99)
* formatador (0.2.4)
* formtastic (2.2.1)
* geocoder (1.1.8)
* god (0.13.2)
* guard (1.8.0)
* guard-spork (1.5.0)
* handlebars_assets (0.12.0)
* has_scope (0.5.1)
* hashie (2.0.4)
* highline (1.6.18)
* hike (1.2.2)
* http_parser.rb (0.5.3)
* httparty (0.11.0)
* httpauth (0.2.0)
* i18n (0.6.4)
* inherited_resources (1.4.0)
* journey (1.0.4)
* jquery-rails (2.2.1)
* json (1.7.7)
* jwt (0.1.8)
* kaminari (0.14.1)
* kgio (2.8.0)
* libv8 (3.11.8.17)
* listen (1.0.3)
* lumberjack (1.0.3)
* mail (2.4.4)
* mail_view (1.0.3)
* mechanize (2.6.0)
* meta_search (1.1.3)
* method_source (0.8.1)
* mime (0.1)
* mime-types (1.23)
* money (5.1.1)
* multi_json (1.7.3)
* multi_xml (0.5.3)
* multipart-post (1.2.0)
* net-http-digest_auth (1.3)
* net-http-persistent (2.8)
* net-scp (1.1.0)
* net-sftp (2.1.1)
* net-ssh (2.6.7)
* net-ssh-gateway (1.2.0)
* newrelic-carrierwave (0.3.0 60d9bdb)
* newrelic_rpm (3.6.1.88)
* nokogiri (1.5.9)
* ntlm-http (0.1.1)
* oauth (0.4.7)
* oauth2 (0.8.1)
* oj (2.0.12)
* omniauth (1.1.4)
* omniauth-facebook (1.4.1)
* omniauth-google-oauth2 (0.1.17)
* omniauth-oauth (1.0.1)
* omniauth-oauth2 (1.1.1)
* omniauth-twitter (0.0.16)
* orm_adapter (0.4.0)
* pg (0.15.1)
* polyamorous (0.5.0)
* polyglot (0.3.3)
* pretender (0.0.3)
* progressbar (0.20.0)
* pry (0.9.12.1)
* rabl (0.8.4)
* rack (1.4.5)
* rack-cache (1.2)
* rack-contrib (1.1.0)
* rack-protection (1.5.0)
* rack-ssl (1.3.3)
* rack-test (0.6.2)
* rails (3.2.12)
* railties (3.2.12)
* raindrops (0.11.0)
* rake (10.0.4)
* rb-fsevent (0.9.3)
* rb-inotify (0.9.0)
* rb-kqueue (0.2.0)
* rdoc (3.12.2)
* redis (3.0.4)
* redis-namespace (1.2.1)
* ref (1.0.4)
* responders (0.9.2)
* rgeo (0.3.20)
* rgeo-activerecord (0.5.0)
* rmagick (2.13.2)
* rspec (2.13.0)
* rspec-core (2.13.1)
* rspec-expectations (2.13.0)
* rspec-mocks (2.13.1)
* rspec-rails (2.13.1)
* ruby-hmac (0.4.0)
* ruby-vips (0.3.5 6abdf48)
* rubyzip (0.9.9)
* rvm-capistrano (1.3.0)
* sass (3.2.8)
* sass-rails (3.2.6)
* selenium-webdriver (2.32.1)
* sidekiq (2.11.1)
* simple_oauth (0.1.9)
* sinatra (1.3.6)
* sitemap_generator (4.0.1)
* slim (1.3.8)
* slop (3.4.4)
* soulmate (1.0.0)
* spork (0.9.2)
* sprockets (2.2.2)
* state_machine (1.2.0)
* temple (0.6.4)
* test-unit (2.5.4)
* therubyracer (0.11.4)
* thor (0.18.1)
* tilt (1.3.7)
* timers (1.1.0)
* tinder (1.4.1)
* treetop (1.4.12)
* twitter-stream (0.1.16)
* tzinfo (0.3.37)
* uglifier (2.0.1)
* unf (0.1.1)
* unf_ext (0.0.6)
* unicorn (4.3.1)
* vcr (2.4.0)
* vegas (0.1.11)
* virtus (0.5.4)
* warden (1.2.1)
* watir-webdriver (0.6.3)
* webrobots (0.1.1)
* websocket (1.0.7)
* whenever (0.8.2)
* wicked_pdf (0.9.6)
* will_paginate (3.0.4)
As well, it's fixed if after this line (https://github.com/campaignmonitor/createsend-ruby/blob/master/lib/createsend/subscriber.rb#L17) you add:
response = JSON.parse(response.body)
This is definitely killing us in production; not sure why or when this started happening but it's happening across all of our environments (dev, staging, production).
Tangent: When I use my suggestion above, I am unable to unsubscribe users. This gem seems to have gotten a huge rework since I last looked (few months ago)... though I never saw a deprecation warning; am I missing something, crazy, or did you leave them out for some reason?
It looks like you're calling CreateSend::Subscriber.get
as though you would call CreateSend::Subscriber.add
.
Assuming you want to add a subscriber by calling CreateSend::Subscriber.add
, can you try this first:
$ gem install createsend
$ irb
>> require 'createsend'
=> true
>> @auth = {api_key: "your api key"}
>> c = CreateSend::Subscriber.add(@auth, "your list id", "your email", "your name", [], true)
And then see if you get the same result in your Rails app.
My apologies, it was a bad copy and paste. I updated to correctly reflect the proper arguments for #get.
So what happens when you do the following?
$ gem install createsend
$ irb
>> require "createsend"
=> true
>> @auth = {api_key: "your api key"}
>> c = CreateSend::Subscriber.get(@auth, "your list id", "your email")
The stack trace I pasted above... While it's from the rails console, it's nearly identical from IRB.
Can you try it in irb
with a fresh gem install createsend
to make sure it works there first (which will not give you the identical stacktrack as above, even if there is an error).
The issue may be related to the dependencies in your Rails app, which is why I'd like to check that this works independently first (which it does for me (and Travis) using the latest version of createsend and Ruby 2.0.0-p0).
This is the output of the gem install on Ruby 2.0.0-p0 which works for me:
2.0.0-p0 in jdennes/
› gem install createsend
Fetching: hashie-2.0.5.gem (100%)
Successfully installed hashie-2.0.5
Fetching: multi_json-1.7.3.gem (100%)
Successfully installed multi_json-1.7.3
Fetching: multi_xml-0.5.3.gem (100%)
Successfully installed multi_xml-0.5.3
Fetching: httparty-0.11.0.gem (100%)
When you HTTParty, you must party hard!
Successfully installed httparty-0.11.0
Fetching: createsend-3.2.0.gem (100%)
Successfully installed createsend-3.2.0
Done installing documentation for hashie, multi_json, multi_xml, httparty, createsend (0 sec).
5 gems installed
Fresh install resolves the Psych error. I'll dig through our dependencies, thanks.
I would like to note that having #get be a class method that returns a Hashie object instead a Subscriber is wholly confusing (at least for me). Why not return an instance of an object that can do stuff? Like #unsubscribe, #delete, or #history.
Anyway, thanks for the prompt responses.