sendgrid_toolkit 1.0.3 → 1.0.4

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/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.3
1
+ 1.0.4
@@ -13,6 +13,7 @@ module SendgridToolkit
13
13
 
14
14
  def api_post(module_name, action_name, opts = {})
15
15
  response = HTTParty.post("https://#{BASE_URI}/#{module_name}.#{action_name}.json?", :query => get_credentials.merge(opts), :format => :json)
16
+ raise(SendgridToolkit::SendgridServerError, "The sengrid server returned an error. #{response.inspect}") if response.code > 401
16
17
  raise SendgridToolkit::AuthenticationFailed if has_error?(response) && response['error'].has_key?('code') && response['error']['code'].to_i == 401
17
18
  response
18
19
  end
@@ -5,4 +5,5 @@ module SendgridToolkit
5
5
  class UnsubscribeEmailAlreadyExists < StandardError; end
6
6
  class UnsubscribeEmailDoesNotExist < StandardError; end
7
7
  class EmailDoesNotExist < StandardError; end
8
+ class SendgridServerError < StandardError; end
8
9
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sendgrid_toolkit}
8
- s.version = "1.0.3"
8
+ s.version = "1.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Robby Grossman"]
12
- s.date = %q{2011-01-21}
12
+ s.date = %q{2011-02-01}
13
13
  s.description = %q{A Ruby wrapper and utility library for communicating with the Sendgrid API}
14
14
  s.email = %q{robby@freerobby.com}
15
15
  s.extra_rdoc_files = [
@@ -7,7 +7,7 @@ describe SendgridToolkit::AbstractSendgridClient do
7
7
  after do
8
8
  restore_env
9
9
  end
10
-
10
+
11
11
  describe "#api_post" do
12
12
  it "throws error when authentication fails" do
13
13
  FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/profile\.get\.json\?|, :body => '{"error":{"code":401,"message":"Permission denied, wrong credentials"}}')
@@ -16,13 +16,20 @@ describe SendgridToolkit::AbstractSendgridClient do
16
16
  @obj.send(:api_post, "profile", "get", {})
17
17
  }.should raise_error SendgridToolkit::AuthenticationFailed
18
18
  end
19
+ it "thows error when sendgrid response is an error" do
20
+ FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/profile\.get\.json\?|, :body => 'A server error occured', :status => ['500', 'Internal Server Error'])
21
+ @obj = SendgridToolkit::AbstractSendgridClient.new("someuser", "somepass")
22
+ lambda {
23
+ @obj.send(:api_post, "profile", "get", {})
24
+ }.should raise_error SendgridToolkit::SendgridServerError
25
+ end
19
26
  end
20
-
27
+
21
28
  describe "#initialize" do
22
29
  it "stores api credentials when passed in" do
23
30
  ENV['SMTP_USERNAME'] = "env_username"
24
31
  ENV['SMTP_PASSWORD'] = "env_apikey"
25
-
32
+
26
33
  @obj = SendgridToolkit::AbstractSendgridClient.new("username", "apikey")
27
34
  @obj.instance_variable_get("@api_user").should == "username"
28
35
  @obj.instance_variable_get("@api_key").should == "apikey"
@@ -30,7 +37,7 @@ describe SendgridToolkit::AbstractSendgridClient do
30
37
  it "resorts to environment variables when no credentials specified" do
31
38
  ENV['SMTP_USERNAME'] = "env_username"
32
39
  ENV['SMTP_PASSWORD'] = "env_apikey"
33
-
40
+
34
41
  @obj = SendgridToolkit::AbstractSendgridClient.new()
35
42
  @obj.instance_variable_get("@api_user").should == "env_username"
36
43
  @obj.instance_variable_get("@api_key").should == "env_apikey"
@@ -38,15 +45,15 @@ describe SendgridToolkit::AbstractSendgridClient do
38
45
  it "throws error when no credentials are found" do
39
46
  ENV['SMTP_USERNAME'] = nil
40
47
  ENV['SMTP_PASSWORD'] = nil
41
-
48
+
42
49
  lambda {
43
50
  @obj = SendgridToolkit::AbstractSendgridClient.new()
44
51
  }.should raise_error SendgridToolkit::NoAPIUserSpecified
45
-
52
+
46
53
  lambda {
47
54
  @obj = SendgridToolkit::AbstractSendgridClient.new(nil, "password")
48
55
  }.should raise_error SendgridToolkit::NoAPIUserSpecified
49
-
56
+
50
57
  lambda {
51
58
  @obj = SendgridToolkit::AbstractSendgridClient.new("user", nil)
52
59
  }.should raise_error SendgridToolkit::NoAPIKeySpecified
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendgrid_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 3
10
- version: 1.0.3
9
+ - 4
10
+ version: 1.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Robby Grossman
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-21 00:00:00 -05:00
18
+ date: 2011-02-01 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency