sendgrid-web 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d0c66be35eba75ec8a6cfdb0bdf918e2bbe63d3b
4
+ data.tar.gz: d4713a455c5db0915922186a916f271914940092
5
+ SHA512:
6
+ metadata.gz: f8aaf092ef851396f5c829f77fa6d7016d94659674ccba3990a31bb29a468f0d05efb6002d8e03cfddd339f732efc988d335a64f72e6def1a65fc741f1af221c
7
+ data.tar.gz: 51d40f45c36b90c05a3a151a879d96fa07aa649d57692e5de93ce9501dcc98f116bc245dd9fae048a66542403bbe81aefe9b94212d40fba756599393b98f8015
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.0.0-p195
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sendgrid-web.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Darren Coxall
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Sendgrid::Web
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sendgrid-web'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sendgrid-web
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,12 @@
1
+ class Sendgrid::Web::Blocks < Sendgrid::Web::Client
2
+
3
+ def get
4
+ connection.post('blocks.get.json', default_params)
5
+ end
6
+
7
+ def delete(email: nil)
8
+ raise ArgumentError.new('Missing required `email` option') if email.nil?
9
+ connection.post('blocks.delete.json', default_params.merge(email: email))
10
+ end
11
+
12
+ end
@@ -0,0 +1,16 @@
1
+ class Sendgrid::Web::Bounces < Sendgrid::Web::Client
2
+
3
+ def get
4
+ connection.post('bounces.get.json', default_params)
5
+ end
6
+
7
+ def delete(start_date: nil, end_date: nil, type: nil, email: nil)
8
+ connection.post('bounces.delete.json',
9
+ default_params.merge(
10
+ start_date: start_date,
11
+ end_date: end_date,
12
+ type: type,
13
+ email: email))
14
+ end
15
+
16
+ end
@@ -0,0 +1,33 @@
1
+ class Sendgrid::Web::Client
2
+ def self.configure(&block)
3
+ @@config = Sendgrid::Web::Configurator.new(&block)
4
+ end
5
+
6
+ def self.config
7
+ @@config
8
+ end
9
+
10
+ def config
11
+ @@config ||= Sendgrid::Web::Configurator.new
12
+ end
13
+
14
+ private
15
+
16
+ def config=(configurator)
17
+ @@config = configurator
18
+ end
19
+
20
+ def connection
21
+ @connection ||= Faraday.new(:url => config.root_url) do |faraday|
22
+ faraday.request :url_encoded
23
+ faraday.adapter :typhoeus
24
+ end
25
+ end
26
+
27
+ def default_params
28
+ {
29
+ api_user: config.username,
30
+ api_key: config.password
31
+ }
32
+ end
33
+ end
@@ -0,0 +1,8 @@
1
+ class Sendgrid::Web::Configurator
2
+ attr_accessor :username, :password, :root_url
3
+
4
+ def initialize(&block)
5
+ self.root_url = 'https://sendgrid.com/api/'
6
+ yield self if block_given?
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Sendgrid
2
+ module Web
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ require 'faraday'
2
+ require 'typhoeus'
3
+ require 'typhoeus/adapters/faraday'
4
+ require 'sendgrid/web/version'
5
+
6
+ module Sendgrid
7
+ module Web
8
+ autoload :Configurator, 'sendgrid/web/configurator'
9
+ autoload :Client, 'sendgrid/web/client'
10
+ autoload :Blocks, 'sendgrid/web/blocks'
11
+ autoload :Bounces, 'sendgrid/web/bounces'
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sendgrid/web/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sendgrid-web"
8
+ spec.version = Sendgrid::Web::VERSION
9
+ spec.authors = ["Darren Coxall"]
10
+ spec.email = ["darren@darrencoxall.com"]
11
+ spec.description = 'A ruby 2 optimised API client used to communicate with the Sendgrid Web API.'
12
+ spec.summary = 'Interact with the Sendgrid Web API'
13
+ spec.homepage = "https://github.com/FreakyDazio/sendgrid-web"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "typhoeus", ">= 0.6.3"
22
+ spec.add_runtime_dependency "faraday"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec", ">= 2.14.0"
27
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sendgrid::Web::Blocks do
4
+ before(:all) do
5
+ Sendgrid::Web::Client.configure do |config|
6
+ config.username = 'foo'
7
+ config.password = 'bar'
8
+ end
9
+ end
10
+
11
+ describe '#get' do
12
+ let(:test_connection) do
13
+ Faraday::Adapter::Test::Stubs.new do |stub|
14
+ stub.post('blocks.get.json') { [200, {}, 'sent blocks.get'] }
15
+ end
16
+ end
17
+
18
+ before do
19
+ subject.stub(:connection).and_return(test_connection)
20
+ end
21
+
22
+ it 'makes a json request to /blocks.get.json' do
23
+ test_connection.should_receive(:post).
24
+ with('blocks.get.json',
25
+ hash_including(api_user: 'foo', api_key: 'bar')).
26
+ and_call_original
27
+ subject.get
28
+ end
29
+ end
30
+
31
+ describe '#delete' do
32
+ let(:test_connection) do
33
+ Faraday::Adapter::Test::Stubs.new do |stub|
34
+ stub.post('blocks.delete.json') { [200, {}, 'sent blocks.delete'] }
35
+ end
36
+ end
37
+
38
+ before do
39
+ subject.stub(:connection).and_return(test_connection)
40
+ end
41
+
42
+ it 'makes a json request to /blocks.delete.json' do
43
+ test_connection.should_receive(:post).
44
+ with('blocks.delete.json',
45
+ hash_including(api_user: 'foo', api_key: 'bar', email: 'foobar@example.com')).
46
+ and_call_original
47
+ subject.delete(email: 'foobar@example.com')
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sendgrid::Web::Bounces do
4
+ before(:all) do
5
+ Sendgrid::Web::Client.configure do |config|
6
+ config.username = 'foo'
7
+ config.password = 'bar'
8
+ end
9
+ end
10
+
11
+ describe '#get' do
12
+ let(:test_connection) do
13
+ Faraday::Adapter::Test::Stubs.new do |stub|
14
+ stub.post('bounces.get.json') { [200, {}, 'sent bounces.get'] }
15
+ end
16
+ end
17
+
18
+ before do
19
+ subject.stub(:connection).and_return(test_connection)
20
+ end
21
+
22
+ it 'makes a json request to /bounces.get.json' do
23
+ test_connection.should_receive(:post).
24
+ with('bounces.get.json',
25
+ hash_including(api_user: 'foo', api_key: 'bar')).
26
+ and_call_original
27
+ subject.get
28
+ end
29
+ end
30
+
31
+ describe '#delete' do
32
+ let(:test_connection) do
33
+ Faraday::Adapter::Test::Stubs.new do |stub|
34
+ stub.post('bounces.delete.json') { [200, {}, 'sent bounces.delete'] }
35
+ end
36
+ end
37
+
38
+ before do
39
+ subject.stub(:connection).and_return(test_connection)
40
+ end
41
+
42
+ it 'makes a json request to /bounces.delete.json' do
43
+ test_connection.should_receive(:post).
44
+ with('bounces.delete.json',
45
+ hash_including(api_user: 'foo', api_key: 'bar', email: 'foobar@example.com')).
46
+ and_call_original
47
+ subject.delete(email: 'foobar@example.com')
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sendgrid::Web::Client do
4
+ describe '.configure' do
5
+ subject { Sendgrid::Web::Client.config }
6
+
7
+ before do
8
+ Sendgrid::Web::Client.configure do |config|
9
+ config.username = 'foo'
10
+ config.password = 'bar'
11
+ end
12
+ end
13
+
14
+ it 'creates an instance of Sendgrid::Web::Configurator' do
15
+ subject.should be_instance_of(Sendgrid::Web::Configurator)
16
+ end
17
+
18
+ it 'passes the block to the configurator object' do
19
+ subject.username.should eql('foo')
20
+ subject.password.should eql('bar')
21
+ end
22
+ end
23
+
24
+ describe '.new' do
25
+ context 'when pre-configured' do
26
+ before do
27
+ Sendgrid::Web::Client.configure do |config|
28
+ config.username = 'foo'
29
+ config.password = 'bar'
30
+ end
31
+ end
32
+
33
+ it 'will have access to configuration' do
34
+ subject.config.should be_instance_of(Sendgrid::Web::Configurator)
35
+ subject.config.username.should eql('foo')
36
+ subject.config.password.should eql('bar')
37
+ end
38
+ end
39
+
40
+ context 'when not pre-configured' do
41
+ before { subject.send('config=', nil) }
42
+
43
+ it 'will have an empty config object' do
44
+ subject.config.should be_instance_of(Sendgrid::Web::Configurator)
45
+ subject.config.username.should be_nil
46
+ subject.config.password.should be_nil
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sendgrid::Web::Configurator do
4
+ describe 'can store username and password' do
5
+ subject do
6
+ Sendgrid::Web::Configurator.new do |config|
7
+ config.username = 'foo'
8
+ config.password = 'bar'
9
+ end
10
+ end
11
+
12
+ its(:username) { should eql('foo') }
13
+ its(:password) { should eql('bar') }
14
+ end
15
+
16
+ it 'sets a default root_url for sendgrid' do
17
+ subject.root_url.should eql('https://sendgrid.com/api/')
18
+ end
19
+
20
+ it 'can overwrite the api root_url' do
21
+ configurator = Sendgrid::Web::Configurator.new do |config|
22
+ config.root_url = 'https://example.com'
23
+ end
24
+ configurator.root_url.should eql('https://example.com')
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ require 'sendgrid/web'
4
+ # This file was generated by the `rspec --init` command. Conventionally, all
5
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
6
+ # Require this file using `require "spec_helper"` to ensure that it is only
7
+ # loaded once.
8
+ #
9
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ # Run specs in random order to surface order dependencies. If you find an
16
+ # order dependency and want to debug it, you can fix the order by providing
17
+ # the seed, which is printed after each run.
18
+ # --seed 1234
19
+ config.order = 'random'
20
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sendgrid-web
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Darren Coxall
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: typhoeus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 2.14.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 2.14.0
83
+ description: A ruby 2 optimised API client used to communicate with the Sendgrid Web
84
+ API.
85
+ email:
86
+ - darren@darrencoxall.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - .ruby-version
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - lib/sendgrid/web.rb
99
+ - lib/sendgrid/web/blocks.rb
100
+ - lib/sendgrid/web/bounces.rb
101
+ - lib/sendgrid/web/client.rb
102
+ - lib/sendgrid/web/configurator.rb
103
+ - lib/sendgrid/web/version.rb
104
+ - sendgrid-web.gemspec
105
+ - spec/sendgrid/web/blocks_spec.rb
106
+ - spec/sendgrid/web/bounces_spec.rb
107
+ - spec/sendgrid/web/client_spec.rb
108
+ - spec/sendgrid/web/configurator_spec.rb
109
+ - spec/spec_helper.rb
110
+ homepage: https://github.com/FreakyDazio/sendgrid-web
111
+ licenses:
112
+ - MIT
113
+ metadata: {}
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.0.2
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Interact with the Sendgrid Web API
134
+ test_files:
135
+ - spec/sendgrid/web/blocks_spec.rb
136
+ - spec/sendgrid/web/bounces_spec.rb
137
+ - spec/sendgrid/web/client_spec.rb
138
+ - spec/sendgrid/web/configurator_spec.rb
139
+ - spec/spec_helper.rb