sendgrid_toolkit 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.4
1
+ 1.0.5
@@ -1,30 +1,38 @@
1
1
  module SendgridToolkit
2
2
  class AbstractSendgridClient
3
-
3
+
4
4
  def initialize(api_user = nil, api_key = nil)
5
5
  @api_user = (api_user.nil?) ? ENV['SMTP_USERNAME'] : api_user
6
6
  @api_key = (api_key.nil?) ? ENV['SMTP_PASSWORD'] : api_key
7
-
7
+
8
8
  raise SendgridToolkit::NoAPIUserSpecified if @api_user.blank?
9
9
  raise SendgridToolkit::NoAPIKeySpecified if @api_key.blank?
10
10
  end
11
-
11
+
12
12
  protected
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
17
- raise SendgridToolkit::AuthenticationFailed if has_error?(response) && response['error'].has_key?('code') && response['error']['code'].to_i == 401
16
+ if response.code > 401
17
+ raise(SendgridToolkit::SendgridServerError, "The sengrid server returned an error. #{response.inspect}")
18
+ elsif has_error?(response) and
19
+ response['error'].respond_to?(:has_key?) and
20
+ response['error'].has_key?('code') and
21
+ response['error']['code'].to_i == 401
22
+ raise SendgridToolkit::AuthenticationFailed
23
+ elsif has_error?(response)
24
+ raise(SendgridToolkit::APIError, response['error'])
25
+ end
18
26
  response
19
27
  end
20
-
28
+
21
29
  def get_credentials
22
30
  {:api_user => @api_user, :api_key => @api_key}
23
31
  end
24
-
32
+
25
33
  private
26
34
  def has_error?(response)
27
35
  response.kind_of?(Hash) && response.has_key?('error')
28
36
  end
29
37
  end
30
- end
38
+ end
@@ -6,4 +6,5 @@ module SendgridToolkit
6
6
  class UnsubscribeEmailDoesNotExist < StandardError; end
7
7
  class EmailDoesNotExist < StandardError; end
8
8
  class SendgridServerError < StandardError; end
9
- end
9
+ class APIError < StandardError; end
10
+ 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.4"
8
+ s.version = "1.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Robby Grossman"]
12
- s.date = %q{2011-02-01}
11
+ s.authors = [%q{Robby Grossman}]
12
+ s.date = %q{2011-09-19}
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 = [
@@ -41,24 +41,11 @@ Gem::Specification.new do |s|
41
41
  "spec/webconnect/sendgrid_toolkit_spec.rb"
42
42
  ]
43
43
  s.homepage = %q{http://github.com/freerobby/sendgrid_toolkit}
44
- s.require_paths = ["lib"]
45
- s.rubygems_version = %q{1.3.7}
44
+ s.require_paths = [%q{lib}]
45
+ s.rubygems_version = %q{1.8.6}
46
46
  s.summary = %q{A Ruby wrapper and utility library for communicating with the Sendgrid API}
47
- s.test_files = [
48
- "spec/helper.rb",
49
- "spec/lib/sendgrid_toolkit/abstract_sendgrid_client_spec.rb",
50
- "spec/lib/sendgrid_toolkit/bounces_spec.rb",
51
- "spec/lib/sendgrid_toolkit/common_spec.rb",
52
- "spec/lib/sendgrid_toolkit/invalid_emails_spec.rb",
53
- "spec/lib/sendgrid_toolkit/spam_reports_spec.rb",
54
- "spec/lib/sendgrid_toolkit/statistics_spec.rb",
55
- "spec/lib/sendgrid_toolkit/unsubscribes_spec.rb",
56
- "spec/lib/sendgrid_toolkit_spec.rb",
57
- "spec/webconnect/sendgrid_toolkit_spec.rb"
58
- ]
59
47
 
60
48
  if s.respond_to? :specification_version then
61
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
62
49
  s.specification_version = 3
63
50
 
64
51
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -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
19
+ it "thows error when sendgrid response is a server error" do
20
20
  FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/profile\.get\.json\?|, :body => 'A server error occured', :status => ['500', 'Internal Server Error'])
21
21
  @obj = SendgridToolkit::AbstractSendgridClient.new("someuser", "somepass")
22
22
  lambda {
23
23
  @obj.send(:api_post, "profile", "get", {})
24
24
  }.should raise_error SendgridToolkit::SendgridServerError
25
25
  end
26
+ it "thows error when sendgrid response is an API error" do
27
+ FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/stats\.get\.json\?|, :body => '{"error": "error in end_date: end date is in the future"}', :status => ['400', 'Bad Request'])
28
+ @obj = SendgridToolkit::AbstractSendgridClient.new("someuser", "somepass")
29
+ lambda {
30
+ @obj.send(:api_post, "stats", "get", {})
31
+ }.should raise_error SendgridToolkit::APIError
32
+ end
26
33
  end
27
34
 
28
35
  describe "#initialize" do
@@ -59,4 +66,4 @@ describe SendgridToolkit::AbstractSendgridClient do
59
66
  }.should raise_error SendgridToolkit::NoAPIKeySpecified
60
67
  end
61
68
  end
62
- end
69
+ end
metadata CHANGED
@@ -1,46 +1,35 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sendgrid_toolkit
3
- version: !ruby/object:Gem::Version
4
- hash: 31
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 0
9
- - 4
10
- version: 1.0.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.5
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Robby Grossman
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-02-01 00:00:00 -05:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2011-09-19 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: httparty
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70103627509080 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- description: A Ruby wrapper and utility library for communicating with the Sendgrid API
23
+ prerelease: false
24
+ version_requirements: *70103627509080
25
+ description: A Ruby wrapper and utility library for communicating with the Sendgrid
26
+ API
36
27
  email: robby@freerobby.com
37
28
  executables: []
38
-
39
29
  extensions: []
40
-
41
- extra_rdoc_files:
30
+ extra_rdoc_files:
42
31
  - README.md
43
- files:
32
+ files:
44
33
  - README.md
45
34
  - Rakefile
46
35
  - VERSION
@@ -64,48 +53,28 @@ files:
64
53
  - spec/lib/sendgrid_toolkit/unsubscribes_spec.rb
65
54
  - spec/lib/sendgrid_toolkit_spec.rb
66
55
  - spec/webconnect/sendgrid_toolkit_spec.rb
67
- has_rdoc: true
68
56
  homepage: http://github.com/freerobby/sendgrid_toolkit
69
57
  licenses: []
70
-
71
58
  post_install_message:
72
59
  rdoc_options: []
73
-
74
- require_paths:
60
+ require_paths:
75
61
  - lib
76
- required_ruby_version: !ruby/object:Gem::Requirement
62
+ required_ruby_version: !ruby/object:Gem::Requirement
77
63
  none: false
78
- requirements:
79
- - - ">="
80
- - !ruby/object:Gem::Version
81
- hash: 3
82
- segments:
83
- - 0
84
- version: "0"
85
- required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
69
  none: false
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- hash: 3
91
- segments:
92
- - 0
93
- version: "0"
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
94
74
  requirements: []
95
-
96
75
  rubyforge_project:
97
- rubygems_version: 1.3.7
76
+ rubygems_version: 1.8.6
98
77
  signing_key:
99
78
  specification_version: 3
100
79
  summary: A Ruby wrapper and utility library for communicating with the Sendgrid API
101
- test_files:
102
- - spec/helper.rb
103
- - spec/lib/sendgrid_toolkit/abstract_sendgrid_client_spec.rb
104
- - spec/lib/sendgrid_toolkit/bounces_spec.rb
105
- - spec/lib/sendgrid_toolkit/common_spec.rb
106
- - spec/lib/sendgrid_toolkit/invalid_emails_spec.rb
107
- - spec/lib/sendgrid_toolkit/spam_reports_spec.rb
108
- - spec/lib/sendgrid_toolkit/statistics_spec.rb
109
- - spec/lib/sendgrid_toolkit/unsubscribes_spec.rb
110
- - spec/lib/sendgrid_toolkit_spec.rb
111
- - spec/webconnect/sendgrid_toolkit_spec.rb
80
+ test_files: []