sendgrid_toolkit 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -0
- data/VERSION +1 -1
- data/lib/sendgrid_toolkit/abstract_sendgrid_client.rb +8 -1
- data/lib/sendgrid_toolkit/sendgrid_error.rb +1 -0
- data/sendgrid_toolkit.gemspec +60 -0
- data/spec/lib/sendgrid_toolkit/abstract_sendgrid_client_spec.rb +10 -0
- data/spec/webconnect/sendgrid_toolkit_spec.rb +9 -0
- metadata +3 -2
data/README.rdoc
CHANGED
@@ -15,6 +15,8 @@ Each class is initialized with +api_user+ and +api_key+ parameters. +api_user+ i
|
|
15
15
|
|
16
16
|
If you don't supply +api_user+ or +api_key+, SendgridToolkit will look for the SMTP_USERNAME or SMTP_PASSWORD environment variables. If they are not found, SendgridToolkit will throw +NoAPIKeySpecified+ or +NoAPIUserSpecified+, depending on what you omitted.
|
17
17
|
|
18
|
+
If authentication fails during an API request, SendgridToolkit throws AuthenticationFailed.
|
19
|
+
|
18
20
|
== Unsubscribes Class
|
19
21
|
|
20
22
|
Instantiate the Unsubscribes object:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -12,11 +12,18 @@ module SendgridToolkit
|
|
12
12
|
protected
|
13
13
|
|
14
14
|
def api_post(module_name, action_name, opts = {})
|
15
|
-
HTTParty.post("https://#{BASE_URI}/#{module_name}.#{action_name}.json?", :query => get_credentials.merge(opts), :format => :json)
|
15
|
+
response = HTTParty.post("https://#{BASE_URI}/#{module_name}.#{action_name}.json?", :query => get_credentials.merge(opts), :format => :json)
|
16
|
+
raise SendgridToolkit::AuthenticationFailed if has_error?(response) && response['error'].has_key?('code') && response['error']['code'].to_i == 401
|
17
|
+
response
|
16
18
|
end
|
17
19
|
|
18
20
|
def get_credentials
|
19
21
|
{:api_user => @api_user, :api_key => @api_key}
|
20
22
|
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def has_error?(response)
|
26
|
+
response.kind_of?(Hash) && response.has_key?('error')
|
27
|
+
end
|
21
28
|
end
|
22
29
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{sendgrid_toolkit}
|
8
|
+
s.version = "0.1.1"
|
9
|
+
|
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{2010-03-07}
|
13
|
+
s.description = %q{A Ruby wrapper and utility library for communicating with the Sendgrid API}
|
14
|
+
s.email = %q{robby@freerobby.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README.rdoc"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
".gitignore",
|
20
|
+
"README.rdoc",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"lib/sendgrid_toolkit.rb",
|
24
|
+
"lib/sendgrid_toolkit/abstract_sendgrid_client.rb",
|
25
|
+
"lib/sendgrid_toolkit/sendgrid_error.rb",
|
26
|
+
"lib/sendgrid_toolkit/statistics.rb",
|
27
|
+
"lib/sendgrid_toolkit/unsubscribes.rb",
|
28
|
+
"sendgrid_toolkit.gemspec",
|
29
|
+
"spec/helper.rb",
|
30
|
+
"spec/lib/sendgrid_toolkit/abstract_sendgrid_client_spec.rb",
|
31
|
+
"spec/lib/sendgrid_toolkit/statistics_spec.rb",
|
32
|
+
"spec/lib/sendgrid_toolkit/unsubscribes_spec.rb",
|
33
|
+
"spec/lib/sendgrid_toolkit_spec.rb",
|
34
|
+
"spec/webconnect/sendgrid_toolkit_spec.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/freerobby/sendgrid_toolkit}
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.6}
|
40
|
+
s.summary = %q{A Ruby wrapper and utility library for communicating with the Sendgrid API}
|
41
|
+
s.test_files = [
|
42
|
+
"spec/helper.rb",
|
43
|
+
"spec/lib/sendgrid_toolkit/abstract_sendgrid_client_spec.rb",
|
44
|
+
"spec/lib/sendgrid_toolkit/statistics_spec.rb",
|
45
|
+
"spec/lib/sendgrid_toolkit/unsubscribes_spec.rb",
|
46
|
+
"spec/lib/sendgrid_toolkit_spec.rb",
|
47
|
+
"spec/webconnect/sendgrid_toolkit_spec.rb"
|
48
|
+
]
|
49
|
+
|
50
|
+
if s.respond_to? :specification_version then
|
51
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
52
|
+
s.specification_version = 3
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
55
|
+
else
|
56
|
+
end
|
57
|
+
else
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -8,6 +8,16 @@ describe SendgridToolkit::AbstractSendgridClient do
|
|
8
8
|
restore_env
|
9
9
|
end
|
10
10
|
|
11
|
+
describe "#api_post" do
|
12
|
+
it "throws error when authentication fails" do
|
13
|
+
FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/profile\.get\.json\?|, :body => '{"error":{"code":401,"message":"Permission denied, wrong credentials"}}')
|
14
|
+
@obj = SendgridToolkit::AbstractSendgridClient.new("fakeuser", "fakepass")
|
15
|
+
lambda {
|
16
|
+
@obj.send(:api_post, "profile", "get", {})
|
17
|
+
}.should raise_error SendgridToolkit::AuthenticationFailed
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
11
21
|
describe "#initialize" do
|
12
22
|
it "stores api credentials when passed in" do
|
13
23
|
ENV['SMTP_USERNAME'] = "env_username"
|
@@ -22,6 +22,15 @@ describe SendgridToolkit do
|
|
22
22
|
restore_env
|
23
23
|
end
|
24
24
|
|
25
|
+
describe "abstract_sendgrid_client i/o" do
|
26
|
+
xit "throws authentication error when authentication fails" do
|
27
|
+
@obj = SendgridToolkit::AbstractSendgridClient.new("fakeuser", "fakepass")
|
28
|
+
lambda {
|
29
|
+
@obj.send(:api_post, "profile", "get", {})
|
30
|
+
}.should raise_error SendgridToolkit::AuthenticationFailed
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
25
34
|
describe "statistics i/o" do
|
26
35
|
before do
|
27
36
|
@obj = SendgridToolkit::Statistics.new
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Robby Grossman
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- lib/sendgrid_toolkit/sendgrid_error.rb
|
37
37
|
- lib/sendgrid_toolkit/statistics.rb
|
38
38
|
- lib/sendgrid_toolkit/unsubscribes.rb
|
39
|
+
- sendgrid_toolkit.gemspec
|
39
40
|
- spec/helper.rb
|
40
41
|
- spec/lib/sendgrid_toolkit/abstract_sendgrid_client_spec.rb
|
41
42
|
- spec/lib/sendgrid_toolkit/statistics_spec.rb
|