Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odd bugfixes.. (1.1.4) #78

Merged
merged 2 commits into from
Feb 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
language: ruby
sudo: false
rvm:
- 2.3.1
- 2.2
- 2.1
- 2.0.0
- 2.1
- 2.2
- 2.3.1
script:
- bundle install
- bundle exec rake spec
- '[[ "${TRAVIS_PULL_REQUEST}" == "false" ]] && ( bundle exec rake spec:integration
) || ( echo "Testing PR - No integration tests available")'
deploy:
provider: rubygems
api_key:
secure: QTNP+6720w38b8krtvXM25WDEOUxw9BlUwdXgWLrU0MGAOSvVFgnWTJs+7QvGWODjhrIqAfAm11zc+yEpzgD9P8np9cteWv5K7rMxsUMcb14kaGIA+MKO+RRJXlru4teBNX5jtp2GJiNS2mn7urzn5YhE9x9P7pMjcF+j5usoF0=
secure: DoX3w48gRyhDM1o1OLvtWsTi8ehLIarIsErzg/UlNRoLacQt5l5UzwD+u6wqsCEr4+c2uAHNahafpnw/j1rPG3LBPIXOK5A0SYbjovlckutiAC0330Q4PHwOZb73AFN1DG5JTeg4/fguEjdsEBdZObF7mh5gBMBQtNjo1Fos+4w=
gemspec: mailgun.gemspec
on:
tags: true
condition: "$TRAVIS_RUBY_VERSION == 2.3.1"
notifications:
slack:
rooms:
Expand Down
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ gem install mailgun-ruby
Gemfile:

```ruby
gem 'mailgun-ruby', '~>1.1.2'
gem 'mailgun-ruby', '~>1.1.4'
```

Usage
Expand Down Expand Up @@ -67,6 +67,15 @@ end
```
Or have the initializer read your environment setting if you perfer.

To use as the ActionMailer delivery method, add this to your `config/environments/whatever.yml`
and replace `api-myapikey` and `mydomain.com` with your secret API key and domain, respectively:
```ruby
config.action_mailer.delivery_method = :mailgun
config.action_mailer.mailgun_settings = {
api_key: 'api-myapikey',
domain: 'mydomain.com',
}
```

Response
--------
Expand Down Expand Up @@ -138,15 +147,15 @@ mg_client.send_message("sending_domain.com", message_params)
```

For usage examples on each API endpoint, head over to our official documentation
pages. Or the [Snippets](Snippets.md) file.
pages. Or the [Snippets](docs/Snippets.md) file.

This SDK includes the following components:
- [Message Builder](MessageBuilder.md)
- [Batch Message](MessageBuilder.md)
- [Opt-In Handler](OptInHandler.md)
- [Domains](Domains.md)
- [Webhooks](Webhooks.md)
- [Events](Events.md)
- [Message Builder](docs/MessageBuilder.md)
- [Batch Message](docs/MessageBuilder.md)
- [Opt-In Handler](docs/OptInHandler.md)
- [Domains](docs/Domains.md)
- [Webhooks](docs/Webhooks.md)
- [Events](docs/Events.md)

Message Builder allows you to quickly create the array of parameters, required
to send a message, by calling a methods for each parameter.
Expand Down
File renamed without changes.
File renamed without changes.
24 changes: 20 additions & 4 deletions MessageBuilder.md → docs/MessageBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,41 @@ mb_obj = Mailgun::MessageBuilder.new()

# Define the from address.
mb_obj.from("me@example.com", {"first"=>"Ruby", "last" => "SDK"});

# Define a to recipient.
mb_obj.add_recipient(:to, "john.doe@example.com", {"first" => "John", "last" => "Doe"});

# Define a cc recipient.
mb_obj.add_recipient(:cc, "sally.doe@example.com", {"first" => "Sally", "last" => "Doe"});

# Define the subject.
mb_obj.subject("A message from the Ruby SDK using Message Builder!");

# Define the body of the message.
mb_obj.body_text("This is the text body of the message!");

# Set the Message-Id header, provide a valid Message-Id.
mb_obj.message_id("<20141014000000.11111.11111@example.com>")

# Or clear the Message-Id header, provide nil or empty string.
mb_obj.message_id(nil)
mb_obj.message_id('')
# Campaign and other headers.

# Campaigns and headers.
mb_obj.add_campaign_id("My-Awesome-Campaign");
mb_obj.add_custom_parameter("h:Customer-Id", "12345");
mb_obj.header("Customer-Id", "12345");

# Custom variables
mb_obj.variable("Customer-Data", { :first_name => "John", :last_name => "Smith" })

# Attach a file and rename it.
mb_obj.add_attachment("/path/to/file/receipt_123491820.pdf", "Receipt.pdf");
mb_obj.add_attachment "/path/to/file/receipt_123491820.pdf", "Receipt.pdf"

# Attach an image inline.
mb_obj.add_inline_image "/path/to/file/header.png"

# Schedule message in the future
mb_obj.delivery_at("tomorrow 8:00AM PST");
mb_obj.deliver_at("tomorrow 8:00AM PST");

# Finally, send your message using the client
result = mg_client.send_message("sending_domain.com", mb_obj)
Expand All @@ -60,13 +73,16 @@ Here's how to use Batch Message to easily handle batch sending jobs.
```ruby
# First, instantiate the Mailgun Client with your API key
mg_client = Mailgun::Client.new("your-api-key")

# Create a Batch Message object, pass in the client and your domain.
mb_obj = Mailgun::BatchMessage.new(mg_client, "example.com")

# Define the from address.
mb_obj.from("me@example.com", {"first"=>"Ruby", "last" => "SDK"});

# Define the subject.
mb_obj.subject("A message from the Ruby SDK using Message Builder!");

# Define the body of the message.
mb_obj.body_text("This is the text body of the message!");

Expand Down
4 changes: 2 additions & 2 deletions Messages.md → docs/Messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ mb_obj.set_message_id('')

# Other Optional Parameters.
mb_obj.add_campaign_id("My-Awesome-Campaign")
mb_obj.add_custom_parameter("h:Customer-Id", "12345")
mb_obj.add_attachment("@/tron.jpg")
mb_obj.header("Customer-Id", "12345")
mb_obj.add_attachment("./tron.jpg")
mb_obj.set_delivery_time("tomorrow 8:00AM PST")
mb_obj.set_click_tracking(true)

Expand Down
File renamed without changes.
20 changes: 20 additions & 0 deletions Snippets.md → docs/Snippets.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,26 @@ mb_obj.set_text_body "This is the text body."
mg_client.send_message "sending_domain.com", mb_obj
```

**Build a message with attachments, part by part, with Message Builder:**

```ruby
mb_obj = Mailgun::MessageBuilder.new

mb_obj.set_from_address "sender@example.com", {'first' => 'Sending', 'last' => 'User'}
mb_obj.add_recipient :to, "recipient@example.com", {'first' => 'Recipient', 'last' => 'User'}
mb_obj.set_subject "This is the subject!"
mb_obj.set_text_body "This is the text body."

# Add separate attachments
mb_obj.add_attachment "/path/to/file/invoice_8675309.pdf", "Order Invoice - 8675309.pdf"
mb_obj.add_attachment "/path/to/file/datasheet_00001.pdf", "Product Datasheet - 00001.pdf"

# Attach inline image to message
mb_obj.add_inline_image "/path/to/file/product_image_00001.png"

mg_client.send_message "sending_domain.com", mb_obj
```

**Send batches of 1000 messages per post:**

```ruby
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions lib/mailgun/messages/batch_message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def add_recipient(recipient_type, address, variables = nil)
send_message if @counters[:recipients][recipient_type] == Mailgun::Chains::MAX_RECIPIENTS

compiled_address = parse_address(address, variables)
complex_setter(recipient_type, compiled_address)
set_multi_complex(recipient_type, compiled_address)

store_recipient_variables(recipient_type, address, variables) if recipient_type != :from

Expand Down Expand Up @@ -84,7 +84,7 @@ def any_recipients_left?
# @return [Boolean]
def send_message
rkey = 'recipient-variables'
simple_setter rkey, JSON.generate(@recipient_variables)
set_multi_simple rkey, JSON.generate(@recipient_variables)
@message[rkey] = @message[rkey].first if @message.key?(rkey)

response = @client.send_message(@domain, @message).to_h!
Expand Down
Loading