Skip to content

Commit

Permalink
Merge branch 'master' into rohankh-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkingserious authored Oct 22, 2018
2 parents 953ab84 + 046a098 commit c6d3a3a
Show file tree
Hide file tree
Showing 24 changed files with 504 additions and 24 deletions.
21 changes: 21 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
engines:
duplication:
enabled: true
config:
languages:
- ruby
fixme:
enabled: true
rubocop:
enabled: true
bundler-audit:
enabled: true
ratings:
paths:
- "**.rb"
exclude_paths:
- examples/
- spec/
- test/
- gemfiles/
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# Change Log
All notable changes to this project will be documented in this file.

## [5.3.0] - 2018-10-12 ##
### Added
- [PR #300](https://github.com/sendgrid/sendgrid-ruby/pull/300): Support for Dynamic Templates. Big thanks to [@nedcampion](https://github.com/nedcampion) for the PR!
- [PR #178](https://github.com/sendgrid/sendgrid-ruby/pull/178): Convert key/value arguments to CustomArgs to strings. Big thanks to [@sitaramshelke](https://github.com/sitaramshelke) for the PR!
- [PR #258](https://github.com/sendgrid/sendgrid-ruby/pull/258): Added unittest to check for specific repo files. Big thanks to [@mptap](https://github.com/mptap) for the PR!
- [PR #255](https://github.com/sendgrid/sendgrid-ruby/pull/255): Add a unittest to check the license.md file date range. Big thanks to [@prashuchaudhary](https://github.com/prashuchaudhary) for the PR!
- [PR #181](https://github.com/sendgrid/sendgrid-ruby/pull/181): Add Docker. Big thanks to [@shrivara](https://github.com/shrivara) for the PR!
- [PR #248](https://github.com/sendgrid/sendgrid-ruby/pull/248): Added .codeclimate.yml. Big thanks to [@proton](https://github.com/proton) for the PR!
- [PR #260](https://github.com/sendgrid/sendgrid-ruby/pull/260): Update ruby-http-client dependency to support v3.3.0. Big thanks to [@mptap](https://github.com/mptap) for the PR!
- [PR #304](https://github.com/sendgrid/sendgrid-ruby/pull/304): Readability update for documentation. Big thanks to [@af4ro](https://github.com/af4ro) for the PR!
- [PR #306](https://github.com/sendgrid/sendgrid-ruby/pull/306): Update example to work in Rails console. Big thanks to [@RogerPodacter](https://github.com/RogerPodacter) for the PR!

### Fixes
- [PR #252](https://github.com/sendgrid/sendgrid-ruby/pull/252): Update LICENSE, set correct year. Big thanks to [@pushkyn](https://github.com/pushkyn) for the PR!
- [PR #257](https://github.com/sendgrid/sendgrid-ruby/pull/257): README.md typo fix. Big thanks to [@shucon](https://github.com/shucon) for the PR!

## [5.2.0] - 2017-10-30 ##
### Added
- PR #234: Helpers for email statistics - global, category, subuser
Expand Down
18 changes: 13 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
Hello! Thank you for choosing to help contribute to one of the SendGrid open source libraries. There are many ways you can contribute and help is always welcome. We simply ask that you follow the following contribution policies.

- [CLAs and CCLAs](#cla)
- [Roadmap & Milestones](#roadmap)
- [CLAs and CCLAs](#clas-and-cclas)
- [Feature Request](#feature-request)
- [Submit a Bug Report](#submit-a-bug-report)
- [Please use our Bug Report Template](#please-use-our-bug-report-template)
- [Improvements to the Codebase](#improvements-to-the-codebase)
- [Understanding the Code Base](#understanding-the-codebase)
- [Development Environment](#development-environment)
- [Install and Run Locally](#install-and-run-locally)
- [Prerequisites](#prerequisites)
- [Initial setup:](#initial-setup)
- [Environment Variables](#environment-variables)
- [Execute:](#execute)
- [Understanding the Code Base](#understanding-the-code-base)
- [Testing](#testing)
- [Style Guidelines & Naming Conventions](#style-guidelines-and-naming-conventions)
- [Style Guidelines & Naming Conventions](#style-guidelines--naming-conventions)
- [Creating a Pull Request](#creating-a-pull-request)

<a name="roadmap"></a>
Expand Down Expand Up @@ -83,7 +89,7 @@ We welcome direct contributions to the sendgrid-ruby code base. Thank you!
bundle install
```

## Environment Variables
### Environment Variables

First, get your free SendGrid account [here](https://sendgrid.com/free?source=sendgrid-ruby).

Expand Down Expand Up @@ -163,8 +169,10 @@ Please run your code through:
```bash
# Clone your fork of the repo into the current directory
git clone https://github.com/sendgrid/sendgrid-ruby
# Navigate to the newly cloned directory
cd sendgrid-ruby
# Assign the original repo to a remote called "upstream"
git remote add upstream https://github.com/sendgrid/sendgrid-ruby
```
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2014-2017 SendGrid, Inc.
Copyright (c) 2014-2018 SendGrid, Inc.

MIT License

Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Version 3.X.X+ of this library provides full support for all SendGrid [Web API v

This library represents the beginning of a new path for SendGrid. We want this library to be community driven and SendGrid led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create [issues](https://github.com/sendgrid/sendgrid-ruby/issues) and [pull requests](https://github.com/sendgrid/sendgrid-ruby/blob/master/CONTRIBUTING.md) or simply upvote or comment on existing issues or pull requests.

Please browse the rest of this README for further detail.
Please browse the rest of this README for further details.

We appreciate your continued support, thank you!

Expand Down Expand Up @@ -83,16 +83,17 @@ The following is the minimum needed code to send an email with the [/mail/send H
require 'sendgrid-ruby'
include SendGrid

from = Email.new(email: '[email protected]')
to = Email.new(email: '[email protected]')
from = SendGrid::Email.new(email: '[email protected]')
to = SendGrid::Email.new(email: '[email protected]')
subject = 'Sending with SendGrid is Fun'
content = Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
content = SendGrid::Content.new(type: 'text/plain', value: 'and easy to do anywhere, even with Ruby')
mail = SendGrid::Mail.new(from, subject, to, content)

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
response = sg.client.mail._('send').post(request_body: mail.to_json)
puts response.status_code
puts response.body
puts response.parsed_body
puts response.headers
```

Expand Down Expand Up @@ -131,6 +132,7 @@ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
response = sg.client.mail._("send").post(request_body: data)
puts response.status_code
puts response.body
puts response.parsed_body
puts response.headers
```

Expand All @@ -142,6 +144,7 @@ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
response = sg.client.suppression.bounces.get()
puts response.status_code
puts response.body
puts response.parsed_body
puts response.headers
```

Expand All @@ -153,6 +156,7 @@ sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
response = sg.client._("suppression/bounces").get()
puts response.status_code
puts response.body
puts response.parsed_body
puts response.headers
```

Expand Down
158 changes: 151 additions & 7 deletions USE_CASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ This documentation provides examples for specific use cases. Please [open an iss
# Table of Contents

* [Transactional Templates](#transactional-templates)
* [Legacy Templates](#legacy-templates)
* [How to Setup a Domain Whitelabel](#domain-whitelabel)
* [How to View Email Statistics](#email-statistics)

Expand All @@ -13,6 +14,106 @@ For this example, we assume you have created a [transactional template](https://

Template ID (replace with your own):

```text
d-2c214ac919e84170b21855cc129b4a5f
```
Email Subject:
```text
{{subject}}
```

Template Body:

```html
<html>
<head>
<title></title>
</head>
<body>
Hello {{name}},
<br/><br/>
I'm glad you are trying out the template feature!
<br/><br/>
I hope you are having a great day in {{city}} :)
<br/><br/>
</body>
</html>
```

## With Mail Helper Class
```ruby
require 'sendgrid-ruby'
include SendGrid

mail = Mail.new
mail.from = Email.new(email: '[email protected]')
personalization = Personalization.new
personalization.add_to(Email.new(email: '[email protected]'))
personalization.add_dynamic_template_data({
"subject" => "Testing Templates",
"name" => "Example User",
"city" => "Denver"
})
mail.add_personalization(personalization)
mail.template_id = 'd-2c214ac919e84170b21855cc129b4a5f'

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
begin
response = sg.client.mail._("send").post(request_body: mail.to_json)
rescue Exception => e
puts e.message
end
puts response.status_code
puts response.body
puts response.parsed_body
puts response.headers
```

## Without Mail Helper Class

```ruby
require 'sendgrid-ruby'
include SendGrid

data = JSON.parse('{
"personalizations": [
{
"to": [
{
"email": "[email protected]"
}
],
"dynamic_template_data": {
"subject": "Testing Templates",
"name": "Example User",
"city": "Denver"
}
}
],
"from": {
"email": "[email protected]"
},
"template_id": "d-2c214ac919e84170b21855cc129b4a5f"
}')
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
begin
response = sg.client.mail._("send").post(request_body: data)
rescue Exception => e
puts e.message
end
puts response.status_code
puts response.body
puts response.parsed_body
puts response.headers
```

<a name="legacy-templates"></a>
# Legacy Templates

For this example, we assume you have created a [legacy template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). Following is the template content we used for testing.

Template ID (replace with your own):

```text
13b8f94f-bcae-4ec6-b752-70d6cb59f932
```
Expand Down Expand Up @@ -57,7 +158,6 @@ personalization.add_to(Email.new(email: '[email protected]'))
personalization.add_substitution(Substitution.new(key: '-name-', value: 'Example User'))
personalization.add_substitution(Substitution.new(key: '-city-', value: 'Denver'))
mail.add_personalization(personalization)
mail.add_content(Content.new(type: 'text/html', value: 'I\'m replacing the <strong>body tag</strong>'))
mail.template_id = '13b8f94f-bcae-4ec6-b752-70d6cb59f932'

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
Expand All @@ -68,6 +168,7 @@ rescue Exception => e
end
puts response.status_code
puts response.body
puts response.parsed_body
puts response.headers
```

Expand Down Expand Up @@ -95,12 +196,6 @@ data = JSON.parse('{
"from": {
"email": "[email protected]"
},
"content": [
{
"type": "text/html",
"value": "I\'m replacing the <strong>body tag</strong>"
}
],
"template_id": "13b8f94f-bcae-4ec6-b752-70d6cb59f932"
}')
sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
Expand All @@ -111,6 +206,7 @@ rescue Exception => e
end
puts response.status_code
puts response.body
puts response.parsed_body
puts response.headers
```

Expand Down Expand Up @@ -141,3 +237,51 @@ Find more information about all of SendGrid's whitelabeling related documentatio
You can find documentation for how to view your email statistics via the UI [here](https://app.sendgrid.com/statistics) and via API [here](https://github.com/sendgrid/sendgrid-ruby/blob/master/USAGE.md#stats).

Alternatively, we can post events to a URL of your choice via our [Event Webhook](https://sendgrid.com/docs/API_Reference/Webhooks/event.html) about events that occur as SendGrid processes your email.

You can also use the email statistics helper to make it easier to interact with the API.

```ruby
require 'sendgrid-ruby'
require 'date'

include SendGrid

sg_client = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY']).client
stats = SendGrid::EmailStats.new(sendgrid_client: sg_client)

# Fetch stats by day, between 2 dates
from = Date.new(2017, 10, 01)
to = Date.new(2017, 10, 12)

email_stats = stats.by_day(from, to)

email_stats.metrics

if !email_stats.error?
email_stats.metrics.each do |metric|
puts "Date - #{metric.date}"
puts "Number of Requests - #{metric.requests}"
puts "Bounces - #{metric.bounces}"
puts "Opens - #{metric.opens}"
puts "Clicks - #{metric.clicks}"
end
end

# Fetch stats by week, between 2 dates for a category
from = Date.new(2017, 10, 01)
to = Date.new(2017, 10, 12)
category = 'abcd'

email_stats = stats.by_week(from, to, category)

if !email_stats.error?
email_stats.metrics.each do |metric|
puts "Date - #{metric.date}"
puts "Number of Requests - #{metric.requests}"
puts "Bounces - #{metric.bounces}"
puts "Opens - #{metric.opens}"
puts "Clicks - #{metric.clicks}"
end
end

```
12 changes: 12 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM ruby:2.4.2-jessie

# Clone sendgrid-ruby
WORKDIR /sources
RUN git clone https://github.com/sendgrid/sendgrid-ruby.git

# Bundle
WORKDIR /sources/sendgrid-ruby
RUN bundle install

# Install prism
RUN curl https://raw.githubusercontent.com/stoplightio/prism/master/install.sh | sh
30 changes: 30 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Docker image for sendgrid-ruby

## Quickstart
1. [Install Docker](https://docs.docker.com/engine/installation/) on your machine.
2. Run `docker run --rm -it sendgrid/sendgrid-ruby irb`.
3. Run `require './lib/sendgrid-ruby.rb'`.

## Poke around

If you would like to just poke around in the image and check some examples:
```sh
docker run --rm -it sendgrid/sendgrid-ruby bash
```

If you want to mount your fork or specific version of the gem:
```sh
docker run --rm -v /path/to/local/sendgrid-ruby:/sources/sendgrid-ruby -it sendgrid/sendgrid-ruby bash
```

## Running tests

If you would like to run the tests present in the image:
```sh
docker run --rm sendgrid/sendgrid-ruby rake
```

If you want to run tests on your fork or a specific version, mount the codebase onto the image:
```sh
docker run --rm -v /path/to/local/sendgrid-ruby:/sources/sendgrid-ruby sendgrid/sendgrid-ruby rake
```
Loading

0 comments on commit c6d3a3a

Please sign in to comment.