GithubHelp home page GithubHelp logo

bronto-ruby's Introduction

Bronto

This is a handy library that wraps the Bronto SOAP API.

Installation

Add this line to your application's Gemfile:

gem 'bronto'

And then execute:

$ bundle

Or install it yourself as:

$ gem install bronto

Usage

Let's setup some contacts, add them to a list, and then send them a message.

  1. Require the library and specify the API Key on the Base class:

    require 'bronto'
    Bronto::Base.api_key = "..."
    
  2. Create two contacts:

    contact_1 = Bronto::Contact.new(email: "[email protected]")
    contact_2 = Bronto::Contact.new(email: "[email protected]")
    
    puts contact_1.id
    # => nil
    
    puts contact_2.id
    # => nil
    
    # You can save multiple objects with one API call using the class `save` method.
    Bronto::Contact.save(contact_1, contact_2)
    
    # Both contacts should now have ids.
    puts contact_1.id
    # => "32da24c..."
    
    puts contact_2.id
    # => "98cd453..."
    
  3. Create a list and the contacts:

    list = Bronto::List.new(name: "A Test List", label: "This is a test list.")
    list.save
    
    list.add_to_list(contact_1, contact_2)
    
  4. Create a new message and add content:

    message = Bronto::Message.new(name: "Test Message")
    message.add_content("html", "HTML Subject", "HTML Content")
    message.add_content("text", "Text Subject", "Text Content")
    message.save
    
  5. Create a new delivery with a message and recipients and send it ASAP:

    delivery = Bronto::Delivery.new(start: Time.now, type: "normal", from_name: "Test", from_email: "[email protected]")
    delivery.message_id = message.id
    delivery.add_recipient(list)
    delivery.save
    

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

bronto-ruby's People

Contributors

athal7 avatar dkoslow avatar jeperkins4 avatar jordan-brough avatar ktusznio avatar manifold0 avatar martingordon avatar nicedawg avatar pospischil avatar rnhurt avatar thede avatar urimikhli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

bronto-ruby's Issues

Bronto::Contact#get_field doesn't work

The method Bronto::Contact#get_field isn't working for me. This is how I'm calling it:

filter = Bronto::Filter.new
filter.add_filter 'email', 'EqualsTo', '[email protected]'
contact = Bronto::Contact.find(filter).first
filter = Bronto::Filter.new
filter.add_filter 'id', 'FIELD_ID'
field = Bronto::Field.find(filter)
puts contact.get_field(field).nil? ? 'NIL' : 'NOT NIL'

This outputs 'NIL' even when I know for a fact that the field has a value set.

Delivery save returns invalid request error (107) from Bronto

Using this gem, and testing a very basic example, the delivery.save command errors returns an error from Bronto: 107: There was an error in your soap request. Please examine the request and try again.

Other calls to the API in this example, such as contact.save and message.save were successful. The only slight difference between my test and the example in the readme, is that I pass in an object of type Bronto::Contact instead of a Bronto::List object to deliver.add_recipient. I've inspected this method and it seems it can handle a contact instead of a list.

My full test is below, followed by the actual http request dumped from Savon (operation.rb:~113). Actual values and IDs have been redacted.

>> Bronto::Base.api_key = '11111111-1111-1111-1111-111111111111'

>> contact = Bronto::Contact.new(email:'[email protected]')
=> #<Bronto::Contact:0x007fb29e32a188 @fields={}, @api_key="11111111-1111-1111-1111-111111111111", @errors=#<Bronto::Errors:0x007fb29e32a110 @messages={}>, @email="[email protected]">
>> contact.save
=> [#<Bronto::Contact:0x007fb29e32a188 @fields={}, @api_key="11111111-1111-1111-1111-111111111111", @errors=#<Bronto::Errors:0x007fb29e32a110 @messages={}>, @email="[email protected]", @id="22222222-2222-2222-2222-222222222222">]

>> message = Bronto::Message.new(name: "Test Message4")
>> message.add_content("html", "HTML Subject", "HTML Content")
>> message.add_content("text", "Text Subject", "Text Content")
>> message.save
=> #<Bronto::Message:0x007fb292f69950 @api_key="11111111-1111-1111-1111-111111111111", @errors=#<Bronto::Errors:0x007fb292f69928 @messages={}>, @name="Test Message4", @content={"html"=>#<Bronto::Message::Content:0x007fb292f62628 @type="html", @subject="HTML Subject", @content="HTML Content">, "text"=>#<Bronto::Message::Content:0x007fb292f5b2d8 @type="text", @subject="Text Subject", @content="Text Content">}, @id="33333333-3333-3333-3333-333333333333">

>> delivery = Bronto::Delivery.new(start: Time.now, type: "normal", from_name: "Test", from_email: "[email protected]")
=> #<Bronto::Delivery:0x007fb293930fd8 @api_key="11111111-1111-1111-1111-111111111111", @errors=#<Bronto::Errors:0x007fb293930fb0 @messages={}>, @start=2015-06-08 14:43:05 -0400, @type="normal", @from_name="Test", @from_email="[email protected]", @recipients=[]>
>> delivery.message_id = message.id
=> "33333333-3333-3333-3333-333333333333"
>> delivery.add_recipient(contact)
=> [{:id=>"22222222-2222-2222-2222-222222222222", :type=>"contact"}]

>> delivery.inspect
=> "#<Bronto::Delivery:0x007fb293930fd8 @api_key=\"11111111-1111-1111-1111-111111111111\", @errors=#<Bronto::Errors:0x007fb293930fb0 @messages={}>, @start=2015-06-08 14:43:05 -0400, @type=\"normal\", @from_name=\"Test\", @from_email=\"[email protected]\", @recipients=[{:id=>\"22222222-2222-2222-2222-222222222222\", :type=>\"contact\"}], @message_id=\"33333333-3333-3333-3333-333333333333\">"

>> delivery.save
Savon::SOAPFault: (soap:Client) 107: There was an error in your soap request. Please examine the request and try again.
  from /Users/waterjump/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/savon-2.11.1/lib/savon/response.rb:85:in `raise_soap_and_http_errors!'
  from /Users/waterjump/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/savon-2.11.1/lib/savon/response.rb:14:in `initialize'
  from /Users/waterjump/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/savon-2.11.1/lib/savon/operation.rb:72:in `new'
  from /Users/waterjump/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/savon-2.11.1/lib/savon/operation.rb:72:in `create_response'
  from /Users/waterjump/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/savon-2.11.1/lib/savon/operation.rb:58:in `call'
  from /Users/waterjump/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/savon-2.11.1/lib/savon/client.rb:36:in `call'
  from /Users/waterjump/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bronto-0.3.1/lib/bronto/base.rb:38:in `request'
  from /Users/waterjump/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bronto-0.3.1/lib/bronto/base.rb:101:in `create'
  from /Users/waterjump/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bronto-0.3.1/lib/bronto/base.rb:191:in `create'
  from /Users/waterjump/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/bronto-0.3.1/lib/bronto/base.rb:186:in `save'
  from (irb):14
  from /Users/waterjump/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/console.rb:110:in `start'
  from /Users/waterjump/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/console.rb:9:in `start'
  from /Users/waterjump/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:68:in `console'
  from /Users/waterjump/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
  from /Users/waterjump/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands.rb:17:in `<top (required)>'
  from script/rails:6:in `require'
  from script/rails:6:in `<main>'>> 

#<HTTPI::Request:0x007fb29e485118 
  @follow_redirect=false, 
  @url=#<URI::HTTPS https://api.bronto.com/v4>, 
  @headers={"SOAPAction"=>"\"addDeliveries\"", "Content-Type"=>"text/xml;charset=UTF-8", "Content-Length"=>"701"}, 
  @body=
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
    <env:Envelope xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:tns=\"http://api.bronto.com/v4\" xmlns:env=\"http://schemas.xmlsoap.org/soap/envelope/\">
      <env:Header>
        <tns:sessionHeader><sessionId>44444444-4444-4444-4444-444444444444</sessionId></tns:sessionHeader>
      </env:Header>
      <env:Body>
        <tns:addDeliveries>
          <deliveries>
            <start>14:43:05</start>
            <messageId>33333333-3333-3333-3333-333333333333</messageId>
            <fromEmail>[email protected]</fromEmail>
            <fromName>Test</fromName>
            <recipients>
              <id>22222222-2222-2222-2222-222222222222</id>
              <type>contact</type>
            </recipients>
          </deliveries>
        </tns:addDeliveries>
      </env:Body>
    </env:Envelope>", 
  @read_timeout=600
>

Handling for Bronto SMS API

Hopefully self explanatory. Bronto now handles sending SMS messages and has expanded their SOAP API to match. Is there any planned support or work in progress on adding this as a feature to the gem? If not, then I can get started on it.

TLS Support?

Bronto just recently announced it is dropping support for SSL v3 and will require TLS on March 8th. Are there any steps we must take to make this library compatible?

Bump version in rubygems

Currently the rubygems version is 0.1.0, but the version on github is 0.1.1. It seems that there have been some bug fixes in 0.1.1, so I was hoping that version could be pushed to rubygems.

Does this work?

I'm trying to Read some Delivery metrics, but I can't even set the

    session = Bronto::Base.soap_header(client_key, true)

I guess I'm used to an api loggin in first... doing stuff, and returning the response.

The error I'm getting makes it look like Nil is being passed to HTTP POST using the net_http adapter

NoMethodError: undefined method `strip' for nil:NilClass
    from /Users/nerb/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:1435:in `block in initialize_http_header'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/utils.rb:380:in `block in each'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/utils.rb:379:in `each'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/utils.rb:379:in `each'
    from /Users/nerb/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:1433:in `initialize_http_header'
    from /Users/nerb/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:1862:in `initialize'
    from /Users/nerb/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:2093:in `initialize'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/httpi-1.1.0/lib/httpi/adapter/net_http.rb:102:in `new'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/httpi-1.1.0/lib/httpi/adapter/net_http.rb:102:in `request_client'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/httpi-1.1.0/lib/httpi/adapter/net_http.rb:76:in `block in do_request'
    from /Users/nerb/.rvm/rubies/ruby-1.9.3-p125/lib/ruby/1.9.1/net/http.rb:745:in `start'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/httpi-1.1.0/lib/httpi/adapter/net_http.rb:75:in `do_request'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/httpi-1.1.0/lib/httpi/adapter/net_http.rb:30:in `post'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/httpi-1.1.0/lib/httpi.rb:96:in `block in post'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/httpi-1.1.0/lib/httpi.rb:193:in `with_adapter'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/httpi-1.1.0/lib/httpi.rb:94:in `post'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/savon-1.1.0/lib/savon/soap/request.rb:34:in `block (2 levels) in response'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/savon-1.1.0/lib/savon/soap/request.rb:66:in `with_logging'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/savon-1.1.0/lib/savon/soap/request.rb:34:in `block in response'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/savon-1.1.0/lib/savon/hooks/group.rb:42:in `call'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/savon-1.1.0/lib/savon/hooks/group.rb:42:in `fire'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/savon-1.1.0/lib/savon/soap/request.rb:34:in `response'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/savon-1.1.0/lib/savon/client.rb:84:in `request'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/bronto-0.1.0/lib/bronto/base.rb:56:in `soap_header'
    from (irb):20
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
    from /Users/nerb/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
    from script/rails:6:in `require'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.