sendgrid-api 0.0.1 → 0.0.2
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.
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +6 -3
- data/Gemfile.lock +35 -1
- data/README.md +48 -4
- data/Rakefile +3 -1
- data/lib/sendgrid/api.rb +3 -2
- data/lib/sendgrid/api/client.rb +27 -0
- data/lib/sendgrid/api/entities/entity.rb +83 -0
- data/lib/sendgrid/api/entities/profile.rb +14 -0
- data/lib/sendgrid/api/entities/response.rb +21 -0
- data/lib/sendgrid/api/entities/stats.rb +14 -0
- data/lib/sendgrid/api/rest/errors/error.rb +60 -0
- data/lib/sendgrid/api/rest/resource.rb +56 -0
- data/lib/sendgrid/api/rest/response/parse_error.rb +19 -0
- data/lib/sendgrid/api/rest/response/parse_json.rb +18 -0
- data/lib/sendgrid/api/service.rb +23 -0
- data/lib/sendgrid/api/version.rb +2 -2
- data/lib/sendgrid/api/web/profile.rb +38 -0
- data/lib/sendgrid/api/web/stats.rb +36 -0
- data/sendgrid-api.gemspec +4 -1
- data/spec/fixtures/forbidden.json +3 -0
- data/spec/fixtures/profile.json +18 -0
- data/spec/fixtures/stats.json +50 -0
- data/spec/fixtures/success.json +3 -0
- data/spec/fixtures/unauthorized.json +6 -0
- data/spec/sendgrid/api/client_spec.rb +22 -0
- data/spec/sendgrid/api/entities/entity_spec.rb +279 -0
- data/spec/sendgrid/api/entities/profile_spec.rb +26 -0
- data/spec/sendgrid/api/entities/response_spec.rb +28 -0
- data/spec/sendgrid/api/entities/stats_spec.rb +25 -0
- data/spec/sendgrid/api/rest/errors/error_spec.rb +97 -0
- data/spec/sendgrid/api/rest/resource_spec.rb +143 -0
- data/spec/sendgrid/api/rest/response/parse_error_spec.rb +39 -0
- data/spec/sendgrid/api/rest/response/parse_json_spec.rb +45 -0
- data/spec/sendgrid/api/service_spec.rb +44 -0
- data/spec/sendgrid/api/version_spec.rb +2 -2
- data/spec/sendgrid/api/web/profile_spec.rb +126 -0
- data/spec/sendgrid/api/web/stats_spec.rb +100 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/helpers.rb +15 -0
- data/spec/support/mock.rb +26 -0
- data/spec/support/shared_examples.rb +11 -0
- metadata +78 -9
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Sendgrid
|
4
|
+
module API
|
5
|
+
module Web
|
6
|
+
module Profile
|
7
|
+
describe Services do
|
8
|
+
|
9
|
+
subject { service }
|
10
|
+
let(:service) { described_class.new(resource) }
|
11
|
+
let(:resource) { REST::Resource.new(user, key) }
|
12
|
+
let(:user) { 'my_user' }
|
13
|
+
let(:key) { 'my_key' }
|
14
|
+
let(:sg_mock) { Sendgrid::Mock.new(user, key) }
|
15
|
+
|
16
|
+
describe '#get' do
|
17
|
+
let(:url) { 'profile.get.json' }
|
18
|
+
|
19
|
+
context 'when request is successfull' do
|
20
|
+
before do
|
21
|
+
sg_mock.stub_post(url).to_return(:body => fixture('profile.json'))
|
22
|
+
end
|
23
|
+
|
24
|
+
subject { service.get }
|
25
|
+
|
26
|
+
it 'should perform the request' do
|
27
|
+
subject
|
28
|
+
sg_mock.a_post(url).should have_been_made
|
29
|
+
end
|
30
|
+
|
31
|
+
it { should be_instance_of Entities::Profile }
|
32
|
+
|
33
|
+
its(:username) { should == 'sendgrid' }
|
34
|
+
its(:email) { should == 'contact@sendgrid.com' }
|
35
|
+
its(:active) { should == 'true' }
|
36
|
+
its(:first_name) { should == 'Jim' }
|
37
|
+
its(:last_name) { should == 'Franklin' }
|
38
|
+
its(:address) { should == '1065 N Pacificenter Drive, Suite 425' }
|
39
|
+
its(:address2) { should == '' }
|
40
|
+
its(:city) { should == 'Anaheim' }
|
41
|
+
its(:state) { should == 'CA' }
|
42
|
+
its(:zip) { should == '92806' }
|
43
|
+
its(:country) { should == 'US' }
|
44
|
+
its(:phone) { should == '123456789' }
|
45
|
+
its(:website) { should == 'http://www.sendgrid.com' }
|
46
|
+
its(:website_access) { should == 'true' }
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'when permission failed' do
|
50
|
+
before do
|
51
|
+
sg_mock.stub_post(url).to_return(:body => fixture('unauthorized.json'))
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should raise error' do
|
55
|
+
expect { service.get }.to raise_error(REST::Errors::Unauthorized)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#set' do
|
61
|
+
let(:url) { 'profile.set.json' }
|
62
|
+
let(:profile) { Entities::Profile.new(:first_name => 'Brian', :last_name => 'O\'Neill') }
|
63
|
+
|
64
|
+
context 'when request is successfull' do
|
65
|
+
before do
|
66
|
+
sg_mock.stub_post(url, profile.as_json).to_return(:body => fixture('success.json'))
|
67
|
+
end
|
68
|
+
|
69
|
+
subject { service.set(profile) }
|
70
|
+
|
71
|
+
its(:success?) { should be_true }
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'when permission failed' do
|
75
|
+
before do
|
76
|
+
sg_mock.stub_post(url, profile.as_json).to_return(:body => fixture('unauthorized.json'))
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should raise error' do
|
80
|
+
expect { service.set(profile) }.to raise_error(REST::Errors::Unauthorized)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe 'online tests', :online => true do
|
86
|
+
include_examples 'online tests'
|
87
|
+
|
88
|
+
context 'when credentials are valid' do
|
89
|
+
let(:resource) { REST::Resource.new(env_user, env_key) }
|
90
|
+
|
91
|
+
describe '#get' do
|
92
|
+
it 'should get profile' do
|
93
|
+
subject.get.should be_instance_of(Entities::Profile)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#set' do
|
98
|
+
it 'should update profile' do
|
99
|
+
profile = subject.get
|
100
|
+
subject.set(profile).success?.should be_true
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
context 'when credentials are invalid' do
|
106
|
+
describe '#get' do
|
107
|
+
it 'should raise error' do
|
108
|
+
expect { subject.get }.to raise_error(REST::Errors::Unauthorized)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#set' do
|
113
|
+
let(:profile) { Entities::Profile.new(:first_name => 'Brian', :last_name => 'O\'Neill') }
|
114
|
+
|
115
|
+
it 'should raise error' do
|
116
|
+
expect { subject.set(profile) }.to raise_error(REST::Errors::Unauthorized)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Sendgrid
|
4
|
+
module API
|
5
|
+
module Web
|
6
|
+
module Stats
|
7
|
+
describe Services do
|
8
|
+
|
9
|
+
subject { service }
|
10
|
+
let(:service) { described_class.new(resource) }
|
11
|
+
let(:resource) { REST::Resource.new(user, key) }
|
12
|
+
let(:user) { 'my_user' }
|
13
|
+
let(:key) { 'my_key' }
|
14
|
+
let(:sg_mock) { Sendgrid::Mock.new(user, key) }
|
15
|
+
|
16
|
+
describe '#advanced' do
|
17
|
+
let(:url) { 'stats.getAdvanced.json' }
|
18
|
+
|
19
|
+
context 'when request is successfull' do
|
20
|
+
before do
|
21
|
+
sg_mock.stub_post(url).to_return(:body => fixture('stats.json'))
|
22
|
+
end
|
23
|
+
|
24
|
+
subject { service.advanced }
|
25
|
+
|
26
|
+
it 'should perform the request' do
|
27
|
+
subject
|
28
|
+
sg_mock.a_post(url).should have_been_made
|
29
|
+
end
|
30
|
+
|
31
|
+
it { should_not be_empty }
|
32
|
+
|
33
|
+
describe 'first result' do
|
34
|
+
subject { service.advanced.first }
|
35
|
+
|
36
|
+
its(:delivered) { should == 4792 }
|
37
|
+
its(:unique_open) { should == 308 }
|
38
|
+
its(:spamreport) { should == 3 }
|
39
|
+
its(:unique_click) { should == 11 }
|
40
|
+
its(:drop) { should == 57 }
|
41
|
+
its(:request) { should == 5359 }
|
42
|
+
its(:bounce) { should == 622 }
|
43
|
+
its(:deferred) { should == 1975 }
|
44
|
+
its(:processed) { should == 5302 }
|
45
|
+
its(:date) { should == '2013-06-18' }
|
46
|
+
its(:open) { pending('should debug open method') }
|
47
|
+
its(:click) { should == 11 }
|
48
|
+
its(:blocked) { should == 29 }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when permission failed' do
|
53
|
+
before do
|
54
|
+
sg_mock.stub_post(url).to_return(:body => fixture('forbidden.json'), :status => 403)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should raise error' do
|
58
|
+
expect { service.advanced }.to raise_error(REST::Errors::Forbidden)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'online tests', :online => true do
|
64
|
+
include_examples 'online tests'
|
65
|
+
|
66
|
+
context 'when credentials are valid' do
|
67
|
+
let(:resource) { REST::Resource.new(env_user, env_key) }
|
68
|
+
|
69
|
+
describe '#advanced' do
|
70
|
+
context 'with required params' do
|
71
|
+
# 90 days from now
|
72
|
+
let(:start_date) { (Time.now - (90*24*60*60)).strftime("%Y-%m-%d") }
|
73
|
+
|
74
|
+
it 'should get stats' do
|
75
|
+
subject.advanced(:start_date => start_date, :data_type => :global).should_not be_empty
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context 'without required params' do
|
80
|
+
it 'should raise error' do
|
81
|
+
expect { subject.advanced }.to raise_error(REST::Errors::BadRequest)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'when credentials are invalid' do
|
88
|
+
describe '#advanced' do
|
89
|
+
it 'should raise error' do
|
90
|
+
expect { subject.advanced }.to raise_error(REST::Errors::Forbidden)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,23 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
Coveralls::SimpleCov::Formatter
|
7
|
+
]
|
8
|
+
SimpleCov.start do
|
9
|
+
add_filter "/vendor/"
|
10
|
+
add_filter "/spec/"
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'sendgrid/api'
|
14
|
+
require 'rspec'
|
15
|
+
require 'webmock/rspec'
|
16
|
+
|
17
|
+
Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
|
18
|
+
|
1
19
|
RSpec.configure do |config|
|
20
|
+
config.filter_run_excluding :online => true unless ENV['ALL']
|
2
21
|
end
|
22
|
+
|
23
|
+
disable_http
|
@@ -0,0 +1,15 @@
|
|
1
|
+
def fixture_path
|
2
|
+
File.expand_path("../../fixtures", __FILE__)
|
3
|
+
end
|
4
|
+
|
5
|
+
def fixture(file)
|
6
|
+
File.new(fixture_path + '/' + file)
|
7
|
+
end
|
8
|
+
|
9
|
+
def enable_http
|
10
|
+
WebMock.allow_net_connect!
|
11
|
+
end
|
12
|
+
|
13
|
+
def disable_http
|
14
|
+
WebMock.disable_net_connect!(:allow => 'coveralls.io')
|
15
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Sendgrid
|
2
|
+
class Mock
|
3
|
+
include WebMock::API
|
4
|
+
|
5
|
+
def initialize(user, key)
|
6
|
+
@user = user
|
7
|
+
@key = key
|
8
|
+
end
|
9
|
+
|
10
|
+
def stub_post(path, params = {})
|
11
|
+
stub_request(:post, Sendgrid::API::REST::Resource::ENDPOINT + '/' + path).
|
12
|
+
with(:body => params.merge(authentication_params))
|
13
|
+
end
|
14
|
+
|
15
|
+
def a_post(path, params = {})
|
16
|
+
a_request(:post, Sendgrid::API::REST::Resource::ENDPOINT + '/' + path).
|
17
|
+
with(:body => params.merge(authentication_params))
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def authentication_params
|
23
|
+
{ :api_key => @key, :api_user => @user }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendgrid-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,30 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
13
|
-
dependencies:
|
12
|
+
date: 2013-10-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: &70097569981620 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.8.8
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70097569981620
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: json
|
27
|
+
requirement: &70097569981060 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.8.0
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70097569981060
|
14
36
|
description: A Ruby interface to the SendGrid API
|
15
37
|
email:
|
16
38
|
- renatosnrg@gmail.com
|
@@ -20,16 +42,49 @@ extra_rdoc_files: []
|
|
20
42
|
files:
|
21
43
|
- .gitignore
|
22
44
|
- .rspec
|
45
|
+
- .travis.yml
|
23
46
|
- Gemfile
|
24
47
|
- Gemfile.lock
|
25
48
|
- LICENSE
|
26
49
|
- README.md
|
27
50
|
- Rakefile
|
28
51
|
- lib/sendgrid/api.rb
|
52
|
+
- lib/sendgrid/api/client.rb
|
53
|
+
- lib/sendgrid/api/entities/entity.rb
|
54
|
+
- lib/sendgrid/api/entities/profile.rb
|
55
|
+
- lib/sendgrid/api/entities/response.rb
|
56
|
+
- lib/sendgrid/api/entities/stats.rb
|
57
|
+
- lib/sendgrid/api/rest/errors/error.rb
|
58
|
+
- lib/sendgrid/api/rest/resource.rb
|
59
|
+
- lib/sendgrid/api/rest/response/parse_error.rb
|
60
|
+
- lib/sendgrid/api/rest/response/parse_json.rb
|
61
|
+
- lib/sendgrid/api/service.rb
|
29
62
|
- lib/sendgrid/api/version.rb
|
63
|
+
- lib/sendgrid/api/web/profile.rb
|
64
|
+
- lib/sendgrid/api/web/stats.rb
|
30
65
|
- sendgrid-api.gemspec
|
66
|
+
- spec/fixtures/forbidden.json
|
67
|
+
- spec/fixtures/profile.json
|
68
|
+
- spec/fixtures/stats.json
|
69
|
+
- spec/fixtures/success.json
|
70
|
+
- spec/fixtures/unauthorized.json
|
71
|
+
- spec/sendgrid/api/client_spec.rb
|
72
|
+
- spec/sendgrid/api/entities/entity_spec.rb
|
73
|
+
- spec/sendgrid/api/entities/profile_spec.rb
|
74
|
+
- spec/sendgrid/api/entities/response_spec.rb
|
75
|
+
- spec/sendgrid/api/entities/stats_spec.rb
|
76
|
+
- spec/sendgrid/api/rest/errors/error_spec.rb
|
77
|
+
- spec/sendgrid/api/rest/resource_spec.rb
|
78
|
+
- spec/sendgrid/api/rest/response/parse_error_spec.rb
|
79
|
+
- spec/sendgrid/api/rest/response/parse_json_spec.rb
|
80
|
+
- spec/sendgrid/api/service_spec.rb
|
31
81
|
- spec/sendgrid/api/version_spec.rb
|
82
|
+
- spec/sendgrid/api/web/profile_spec.rb
|
83
|
+
- spec/sendgrid/api/web/stats_spec.rb
|
32
84
|
- spec/spec_helper.rb
|
85
|
+
- spec/support/helpers.rb
|
86
|
+
- spec/support/mock.rb
|
87
|
+
- spec/support/shared_examples.rb
|
33
88
|
homepage: ''
|
34
89
|
licenses:
|
35
90
|
- MIT
|
@@ -43,18 +98,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
43
98
|
- - ! '>='
|
44
99
|
- !ruby/object:Gem::Version
|
45
100
|
version: '0'
|
46
|
-
segments:
|
47
|
-
- 0
|
48
|
-
hash: -3235194297472111754
|
49
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
102
|
none: false
|
51
103
|
requirements:
|
52
104
|
- - ! '>='
|
53
105
|
- !ruby/object:Gem::Version
|
54
106
|
version: '0'
|
55
|
-
segments:
|
56
|
-
- 0
|
57
|
-
hash: -3235194297472111754
|
58
107
|
requirements: []
|
59
108
|
rubyforge_project:
|
60
109
|
rubygems_version: 1.8.16
|
@@ -62,5 +111,25 @@ signing_key:
|
|
62
111
|
specification_version: 3
|
63
112
|
summary: A Ruby interface to the SendGrid API
|
64
113
|
test_files:
|
114
|
+
- spec/fixtures/forbidden.json
|
115
|
+
- spec/fixtures/profile.json
|
116
|
+
- spec/fixtures/stats.json
|
117
|
+
- spec/fixtures/success.json
|
118
|
+
- spec/fixtures/unauthorized.json
|
119
|
+
- spec/sendgrid/api/client_spec.rb
|
120
|
+
- spec/sendgrid/api/entities/entity_spec.rb
|
121
|
+
- spec/sendgrid/api/entities/profile_spec.rb
|
122
|
+
- spec/sendgrid/api/entities/response_spec.rb
|
123
|
+
- spec/sendgrid/api/entities/stats_spec.rb
|
124
|
+
- spec/sendgrid/api/rest/errors/error_spec.rb
|
125
|
+
- spec/sendgrid/api/rest/resource_spec.rb
|
126
|
+
- spec/sendgrid/api/rest/response/parse_error_spec.rb
|
127
|
+
- spec/sendgrid/api/rest/response/parse_json_spec.rb
|
128
|
+
- spec/sendgrid/api/service_spec.rb
|
65
129
|
- spec/sendgrid/api/version_spec.rb
|
130
|
+
- spec/sendgrid/api/web/profile_spec.rb
|
131
|
+
- spec/sendgrid/api/web/stats_spec.rb
|
66
132
|
- spec/spec_helper.rb
|
133
|
+
- spec/support/helpers.rb
|
134
|
+
- spec/support/mock.rb
|
135
|
+
- spec/support/shared_examples.rb
|