sendgrid_toolkit 1.3.0 → 1.4.0

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGYyNTgzNTkxZWQ5MDFjMDZmZTdjZWZhOWU4ZjE2NzVlNTVkZjJiYQ==
4
+ ODE0NWY1ZDllNTk3MjMwZTQ1NzQ3ZDNiZDc5Y2U4YjJlNzllOThhYg==
5
5
  data.tar.gz: !binary |-
6
- NmQ5YjIyNDFiNWJhNzRhNmUyNmU2YmI0NmUyYWNlMDg0NWJhYzBhNA==
6
+ ZjUyMzNiMTJhZjA5MDBhZDU3Y2QwYzg1YWJkM2IwYzczNTJmYzkxNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NzRjMDM4YmU0ZDQ1YjZhYzEyYTI5ZGIyZGM3NzNmYzVlMjg2NGNiMmRlNDdl
10
- NzFjZWE0ZWMyNTI5NTgxZjIwMTIwNTgxNmVhNWM2MzczMTdlZDM0YmQ2ODVk
11
- OWIwMTY4YzQwYTMzNDU1MjQ4YjFiMWQwNzgwYTM4ZjdkYTk5OWI=
9
+ NmFmNmI1ZTAyNzBlODRiYjE1YTIxZDVjYTdkOTIzODEzM2NjYzJhMjQzZDYw
10
+ NDMyMjA4NDI3NmY1NjdlNTgzMWJhOTZjNjFjOGYzMWRlYjEzM2EyNDU0ZmM1
11
+ NDUxZTYxMjkxZGMyOWRjYjQxZmJmYmE2ZTY2MTg0ODkyYTg0OGM=
12
12
  data.tar.gz: !binary |-
13
- YTNlYzY2NmFjOGY0ZWFiNjNjNDY2MjJkZGI4ZGQ2MjY3NjEzMzcyNTY1Zjdj
14
- NWU1NWJiMmIxNjY4N2FmOWQ3MWQyY2ZiNDFlNWRjYWI0YTBhMWFmYjVlNjJi
15
- NDAwNjVkMzhjN2E4MTJjZDhkYzMxNzUzNTkzOWY5MjgzNzMxZDY=
13
+ YTI5MGEyMzdlNGMwMmZhMWU2MTQ4NmY2NTRjN2MxMThiMjAyYzI3OGJmMjYw
14
+ OWY0N2ZmMjU0NTViZGQyYWI5YTJiMzM2N2NiZWE4YmU4ZDE1NDQ5ZDQ5YjZl
15
+ YzNhOWEyNzUzMjU2MTgzMDYyYTEyODIzNTMzNTJlYWJhOGVjMzA=
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-19mode
5
+ - 2.0.0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 1.4.0
@@ -16,7 +16,7 @@ require 'sendgrid_toolkit/newsletter/lists'
16
16
  require 'sendgrid_toolkit/newsletter/list_emails'
17
17
 
18
18
  module SendgridToolkit
19
- BASE_URI = "sendgrid.com/api"
19
+ BASE_URI = "api.sendgrid.com/api"
20
20
 
21
21
  class << self
22
22
  def api_user=(v); @api_user = v; end
@@ -35,7 +35,7 @@ module SendgridToolkit
35
35
  private
36
36
 
37
37
  def parse_message_time(message)
38
- message['created'] = Time.parse(message['created']) if message.has_key?('created')
38
+ message['created'] = Time.parse(message['created']+' UTC') if message.has_key?('created')
39
39
  end
40
40
 
41
41
  end
@@ -1,11 +1,20 @@
1
1
  module SendgridToolkit
2
2
  class Statistics < AbstractSendgridClient
3
+ def advanced(data_type, start_date, options = {})
4
+ options.merge! :data_type => data_type
5
+ options.merge! :start_date => format_date(start_date, options)
6
+
7
+ response = api_post('stats', 'getAdvanced', options)
8
+ response.each { |r| r['date'] = Date.parse(r['date']) if r.kind_of?(Hash) && r.has_key?('date') }
9
+ response
10
+ end
11
+
3
12
  def retrieve(options = {})
4
13
  response = api_post('stats', 'get', options)
5
14
  response.each {|r| r['date'] = Date.parse(r['date']) if r.kind_of?(Hash) && r.has_key?('date')}
6
15
  response
7
16
  end
8
-
17
+
9
18
  def retrieve_aggregate(options = {})
10
19
  options.merge! :aggregate => 1
11
20
  response = retrieve options
@@ -22,11 +31,28 @@ module SendgridToolkit
22
31
  resp[int_field] = resp[int_field].to_i if resp.has_key?(int_field)
23
32
  end
24
33
  end
25
-
34
+
26
35
  def list_categories(options = {})
27
36
  options.merge! :list => true
28
37
  response = retrieve options
29
38
  response
30
39
  end
40
+
41
+ private
42
+
43
+ def format_date(date, options = {})
44
+ if date.is_a? Date
45
+ case options[:aggregated_by].to_s
46
+ when 'week'
47
+ date = date.strftime("%Y-%V")
48
+ when 'month'
49
+ date = date.strftime("%Y-%m")
50
+ else
51
+ date = date.strftime("%Y-%m-%d")
52
+ end
53
+ end
54
+
55
+ date
56
+ end
31
57
  end
32
58
  end
@@ -21,7 +21,7 @@ module SendgridToolkit
21
21
  options.merge! :date => 1
22
22
  response = retrieve options
23
23
  response.each do |unsubscribe|
24
- unsubscribe['created'] = Time.parse(unsubscribe['created']) if unsubscribe.has_key?('created')
24
+ unsubscribe['created'] = Time.parse(unsubscribe['created']+' UTC') if unsubscribe.has_key?('created')
25
25
  end
26
26
  response
27
27
  end
@@ -2,15 +2,15 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: sendgrid_toolkit 1.3.0 ruby lib
5
+ # stub: sendgrid_toolkit 1.4.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "sendgrid_toolkit"
9
- s.version = "1.3.0"
9
+ s.version = "1.4.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Robby Grossman"]
13
- s.date = "2013-12-10"
13
+ s.date = "2014-03-04"
14
14
  s.description = "A Ruby wrapper and utility library for communicating with the Sendgrid API."
15
15
  s.email = "robby@freerobby.com"
16
16
  s.extra_rdoc_files = [
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  ]
20
20
  s.files = [
21
21
  ".rvmrc",
22
+ ".travis.yml",
22
23
  "Gemfile",
23
24
  "Gemfile.lock",
24
25
  "LICENSE.txt",
@@ -4,6 +4,8 @@ require 'rspec'
4
4
 
5
5
  FakeWeb.allow_net_connect = false
6
6
 
7
+ REGEX_ESCAPED_BASE_URI = "api\.sendgrid\.com/api"
8
+
7
9
  def backup_env
8
10
  @env_backup = Hash.new
9
11
  ENV.keys.each {|key| @env_backup[key] = ENV[key]}
@@ -10,21 +10,21 @@ describe SendgridToolkit::AbstractSendgridClient do
10
10
 
11
11
  describe "#api_post" do
12
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"}}')
13
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/profile\.get\.json\?|, :body => '{"error":{"code":401,"message":"Permission denied, wrong credentials"}}')
14
14
  @obj = SendgridToolkit::AbstractSendgridClient.new("fakeuser", "fakepass")
15
15
  lambda {
16
16
  @obj.send(:api_post, "profile", "get", {})
17
17
  }.should raise_error SendgridToolkit::AuthenticationFailed
18
18
  end
19
19
  it "thows error when sendgrid response is a server error" do
20
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/profile\.get\.json\?|, :body => '{}', :status => ['500', 'Internal Server Error'])
20
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/profile\.get\.json\?|, :body => '{}', :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
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'])
27
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/stats\.get\.json\?|, :body => '{"error": "error in end_date: end date is in the future"}', :status => ['400', 'Bad Request'])
28
28
  @obj = SendgridToolkit::AbstractSendgridClient.new("someuser", "somepass")
29
29
  lambda {
30
30
  @obj.send(:api_post, "stats", "get", {})
@@ -8,7 +8,7 @@ describe SendgridToolkit::Blocks do
8
8
 
9
9
  describe "#retrieve" do
10
10
  it "returns array of bounced emails" do
11
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/blocks\.get\.json\?|, :body => '[{"email":"email1@domain.com","status":"5.1.1","reason":"host [127.0.0.1] said: 550 5.1.1 unknown or illegal user: email1@domain.com"},{"email":"email2@domain2.com","status":"5.1.1","reason":"host [127.0.0.1] said: 550 5.1.1 unknown or illegal user: email2@domain2.com"}]')
11
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/blocks\.get\.json\?|, :body => '[{"email":"email1@domain.com","status":"5.1.1","reason":"host [127.0.0.1] said: 550 5.1.1 unknown or illegal user: email1@domain.com"},{"email":"email2@domain2.com","status":"5.1.1","reason":"host [127.0.0.1] said: 550 5.1.1 unknown or illegal user: email2@domain2.com"}]')
12
12
  blocks = @obj.retrieve
13
13
  blocks[0]['email'].should == "email1@domain.com"
14
14
  blocks[0]['status'].should == "5.1.1"
@@ -18,7 +18,7 @@ describe SendgridToolkit::Blocks do
18
18
 
19
19
  describe "#retrieve_with_timestamps" do
20
20
  it "parses timestamps" do
21
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/blocks\.get\.json\?.*date=1|, :body => '[{"email":"email1@domain.com","status":"5.1.1","reason":"host [127.0.0.1] said: 550 5.1.1 unknown or illegal user: email1@domain.com","created":"2009-06-01 19:41:39"},{"email":"email2@domain2.com","status":"5.1.1","reason":"host [127.0.0.1] said: 550 5.1.1 unknown or illegal user: email2@domain2.com","created":"2009-06-12 19:41:39"}]')
21
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/blocks\.get\.json\?.*date=1|, :body => '[{"email":"email1@domain.com","status":"5.1.1","reason":"host [127.0.0.1] said: 550 5.1.1 unknown or illegal user: email1@domain.com","created":"2009-06-01 19:41:39"},{"email":"email2@domain2.com","status":"5.1.1","reason":"host [127.0.0.1] said: 550 5.1.1 unknown or illegal user: email2@domain2.com","created":"2009-06-12 19:41:39"}]')
22
22
  blocks = @obj.retrieve_with_timestamps
23
23
  0.upto(1) do |index|
24
24
  blocks[index]['created'].kind_of?(Time).should == true
@@ -30,19 +30,19 @@ describe SendgridToolkit::Blocks do
30
30
 
31
31
  describe "#delete" do
32
32
  it "raises no errors on success" do
33
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/blocks\.delete\.json\?.*email=.+|, :body => '{"message":"success"}')
33
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/blocks\.delete\.json\?.*email=.+|, :body => '{"message":"success"}')
34
34
  lambda {
35
35
  @obj.delete :email => "user@domain.com"
36
36
  }.should_not raise_error
37
37
  end
38
38
  it "raises error when email address does not exist" do
39
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/blocks\.delete\.json\?.*email=.+|, :body => '{"message":"Email does not exist"}')
39
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/blocks\.delete\.json\?.*email=.+|, :body => '{"message":"Email does not exist"}')
40
40
  lambda {
41
41
  @obj.delete :email => "user@domain.com"
42
42
  }.should raise_error SendgridToolkit::EmailDoesNotExist
43
43
  end
44
44
  it "does not choke if response does not have a 'message' field" do
45
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/blocks\.delete\.json\?.*email=.+|, :body => '{}')
45
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/blocks\.delete\.json\?.*email=.+|, :body => '{}')
46
46
  lambda {
47
47
  @obj.delete :email => "user@domain.com"
48
48
  }.should_not raise_error
@@ -8,7 +8,7 @@ describe SendgridToolkit::Bounces do
8
8
 
9
9
  describe "#retrieve" do
10
10
  it "returns array of bounced emails" do
11
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/bounces\.get\.json\?|, :body => '[{"email":"email1@domain.com","status":"5.1.1","reason":"host [127.0.0.1] said: 550 5.1.1 unknown or illegal user: email1@domain.com"},{"email":"email2@domain2.com","status":"5.1.1","reason":"host [127.0.0.1] said: 550 5.1.1 unknown or illegal user: email2@domain2.com"}]')
11
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/bounces\.get\.json\?|, :body => '[{"email":"email1@domain.com","status":"5.1.1","reason":"host [127.0.0.1] said: 550 5.1.1 unknown or illegal user: email1@domain.com"},{"email":"email2@domain2.com","status":"5.1.1","reason":"host [127.0.0.1] said: 550 5.1.1 unknown or illegal user: email2@domain2.com"}]')
12
12
  bounces = @obj.retrieve
13
13
  bounces[0]['email'].should == "email1@domain.com"
14
14
  bounces[0]['status'].should == "5.1.1"
@@ -18,7 +18,7 @@ describe SendgridToolkit::Bounces do
18
18
 
19
19
  describe "#retrieve_with_timestamps" do
20
20
  it "parses timestamps" do
21
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/bounces\.get\.json\?.*date=1|, :body => '[{"email":"email1@domain.com","status":"5.1.1","reason":"host [127.0.0.1] said: 550 5.1.1 unknown or illegal user: email1@domain.com","created":"2009-06-01 19:41:39"},{"email":"email2@domain2.com","status":"5.1.1","reason":"host [127.0.0.1] said: 550 5.1.1 unknown or illegal user: email2@domain2.com","created":"2009-06-12 19:41:39"}]')
21
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/bounces\.get\.json\?.*date=1|, :body => '[{"email":"email1@domain.com","status":"5.1.1","reason":"host [127.0.0.1] said: 550 5.1.1 unknown or illegal user: email1@domain.com","created":"2009-06-01 19:41:39"},{"email":"email2@domain2.com","status":"5.1.1","reason":"host [127.0.0.1] said: 550 5.1.1 unknown or illegal user: email2@domain2.com","created":"2009-06-12 19:41:39"}]')
22
22
  bounces = @obj.retrieve_with_timestamps
23
23
  0.upto(1) do |index|
24
24
  bounces[index]['created'].kind_of?(Time).should == true
@@ -30,19 +30,19 @@ describe SendgridToolkit::Bounces do
30
30
 
31
31
  describe "#delete" do
32
32
  it "raises no errors on success" do
33
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/bounces\.delete\.json\?.*email=.+|, :body => '{"message":"success"}')
33
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/bounces\.delete\.json\?.*email=.+|, :body => '{"message":"success"}')
34
34
  lambda {
35
35
  @obj.delete :email => "user@domain.com"
36
36
  }.should_not raise_error
37
37
  end
38
38
  it "raises error when email address does not exist" do
39
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/bounces\.delete\.json\?.*email=.+|, :body => '{"message":"Email does not exist"}')
39
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/bounces\.delete\.json\?.*email=.+|, :body => '{"message":"Email does not exist"}')
40
40
  lambda {
41
41
  @obj.delete :email => "user@domain.com"
42
42
  }.should raise_error SendgridToolkit::EmailDoesNotExist
43
43
  end
44
44
  it "does not choke if response does not have a 'message' field" do
45
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/bounces\.delete\.json\?.*email=.+|, :body => '{}')
45
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/bounces\.delete\.json\?.*email=.+|, :body => '{}')
46
46
  lambda {
47
47
  @obj.delete :email => "user@domain.com"
48
48
  }.should_not raise_error
@@ -6,7 +6,7 @@ describe SendgridToolkit::Common do
6
6
  class FakeClass < SendgridToolkit::AbstractSendgridClient
7
7
  include SendgridToolkit::Common
8
8
  end
9
- @fake_class = FakeClass.new
9
+ @fake_class = FakeClass.new("fakeuser", "fakepass")
10
10
  end
11
11
 
12
12
  it "creates a module_name method that returns the class name downcased" do
@@ -14,10 +14,20 @@ describe SendgridToolkit::Common do
14
14
  end
15
15
 
16
16
  it "does not choke if response does not have a 'message' field" do
17
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/fakeclass\.delete\.json\?.*email=.+|, :body => '{}')
17
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/fakeclass\.delete\.json\?.*email=.+|, :body => '{}')
18
18
  lambda {
19
19
  @fake_class.delete :email => "user@domain.com"
20
20
  }.should_not raise_error
21
21
  end
22
22
 
23
- end
23
+ # this will only really test it on a computer that's on on utc.
24
+ describe 'retrieve_with_timestamps' do
25
+ it 'should parse the created date in utc' do
26
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/fakeclass\.get\.json\?.*date=1|, :body => '[{"created":"2013-11-25 13:00:00"}]')
27
+ fake_class = @fake_class.retrieve_with_timestamps
28
+ fake_class[0]['created'].utc.iso8601.should == "2013-11-25T13:00:00Z"
29
+ end
30
+ end
31
+
32
+ end
33
+
@@ -8,7 +8,7 @@ describe SendgridToolkit::InvalidEmails do
8
8
 
9
9
  describe "#retrieve" do
10
10
  it "returns array of invalid emails" do
11
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/invalidemails\.get\.json\?|, :body => '[{"email":"isaac@hotmail.comm","reason":"Mail domain mentioned in email address is unknown"},{"email":"isaac@hotmail","reason":"Bad Syntax"},{"email":"isaac@example.com","reason":"Known bad domain"}]')
11
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/invalidemails\.get\.json\?|, :body => '[{"email":"isaac@hotmail.comm","reason":"Mail domain mentioned in email address is unknown"},{"email":"isaac@hotmail","reason":"Bad Syntax"},{"email":"isaac@example.com","reason":"Known bad domain"}]')
12
12
  invalid_emails = @obj.retrieve
13
13
  invalid_emails[0]['email'].should == "isaac@hotmail.comm"
14
14
  invalid_emails[0]['reason'].should == "Mail domain mentioned in email address is unknown"
@@ -21,7 +21,7 @@ describe SendgridToolkit::InvalidEmails do
21
21
 
22
22
  describe "#retrieve_with_timestamps" do
23
23
  it "parses timestamps" do
24
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/invalidemails\.get\.json\?.*date=1|, :body => '[{"email":"isaac@hotmail.comm","reason":"Mail domain mentioned in email address is unknown","created":"2009-06-01 19:41:39"},{"email":"isaac@hotmail","reason":"Bad Syntax","created":"2009-06-12 19:41:39"},{"email":"isaac@example.com","reason":"Known bad domain","created":"2009-06-13 09:40:01"}]')
24
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/invalidemails\.get\.json\?.*date=1|, :body => '[{"email":"isaac@hotmail.comm","reason":"Mail domain mentioned in email address is unknown","created":"2009-06-01 19:41:39"},{"email":"isaac@hotmail","reason":"Bad Syntax","created":"2009-06-12 19:41:39"},{"email":"isaac@example.com","reason":"Known bad domain","created":"2009-06-13 09:40:01"}]')
25
25
  invalid_emails = @obj.retrieve_with_timestamps
26
26
  0.upto(2) do |index|
27
27
  invalid_emails[index]['created'].kind_of?(Time).should == true
@@ -34,13 +34,13 @@ describe SendgridToolkit::InvalidEmails do
34
34
 
35
35
  describe "#delete" do
36
36
  it "raises no errors on success" do
37
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/invalidemails\.delete\.json\?.*email=.+|, :body => '{"message":"success"}')
37
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/invalidemails\.delete\.json\?.*email=.+|, :body => '{"message":"success"}')
38
38
  lambda {
39
39
  @obj.delete :email => "user@domain.com"
40
40
  }.should_not raise_error
41
41
  end
42
42
  it "raises error when email address does not exist" do
43
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/invalidemails\.delete\.json\?.*email=.+|, :body => '{"message":"Email does not exist"}')
43
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/invalidemails\.delete\.json\?.*email=.+|, :body => '{"message":"Email does not exist"}')
44
44
  lambda {
45
45
  @obj.delete :email => "user@domain.com"
46
46
  }.should raise_error SendgridToolkit::EmailDoesNotExist
@@ -8,7 +8,7 @@ describe SendgridToolkit::Mail do
8
8
 
9
9
  describe "#send" do
10
10
  it "raises error when sendgrid returns an error" do
11
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/mail\.send\.json\?|, :body => '{"message": "error", "errors": ["Missing destination email"]}')
11
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/mail\.send\.json\?|, :body => '{"message": "error", "errors": ["Missing destination email"]}')
12
12
  lambda {
13
13
  response = @obj.send_mail :from => "testing@fiverr.com", :subject => "Subject", :text => "Text", "x-smtpapi" => {:category => "Testing", :to => ["elad@fiverr.com"]}
14
14
  }.should raise_error SendgridToolkit::SendEmailError
@@ -13,7 +13,7 @@ describe SendgridToolkit::NewsletterSendgridClient do
13
13
  it 'prepends newsletter to the base path' do
14
14
  opts = {a: 1}
15
15
 
16
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/newsletter/lists/add\.json\?.*a=1|,
16
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/newsletter/lists/add\.json\?.*a=1|,
17
17
  :body => '{"message":"success"}')
18
18
 
19
19
  sendgrid_client = SendgridToolkit::NewsletterSendgridClient.new("fakeuser", "fakepass")
@@ -8,7 +8,7 @@ describe SendgridToolkit::SpamReports do
8
8
 
9
9
  describe "#retrieve" do
10
10
  it "returns array of bounced emails" do
11
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/spamreports\.get\.json\?|, :body => '[{"email":"email1@domain.com"},{"email":"email2@domain2.com"}]')
11
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/spamreports\.get\.json\?|, :body => '[{"email":"email1@domain.com"},{"email":"email2@domain2.com"}]')
12
12
  bounces = @obj.retrieve
13
13
  bounces[0]['email'].should == "email1@domain.com"
14
14
  bounces[1]['email'].should == "email2@domain2.com"
@@ -17,7 +17,7 @@ describe SendgridToolkit::SpamReports do
17
17
 
18
18
  describe "#retrieve_with_timestamps" do
19
19
  it "parses timestamps" do
20
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/spamreports\.get\.json\?.*date=1|, :body => '[{"email":"email1@domain.com","created":"2009-06-01 19:41:39"},{"email":"email2@domain2.com","created":"2009-06-12 19:41:39"}]')
20
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/spamreports\.get\.json\?.*date=1|, :body => '[{"email":"email1@domain.com","created":"2009-06-01 19:41:39"},{"email":"email2@domain2.com","created":"2009-06-12 19:41:39"}]')
21
21
  bounces = @obj.retrieve_with_timestamps
22
22
  0.upto(1) do |index|
23
23
  bounces[index]['created'].kind_of?(Time).should == true
@@ -29,13 +29,13 @@ describe SendgridToolkit::SpamReports do
29
29
 
30
30
  describe "#delete" do
31
31
  it "raises no errors on success" do
32
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/spamreports\.delete\.json\?.*email=.+|, :body => '{"message":"success"}')
32
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/spamreports\.delete\.json\?.*email=.+|, :body => '{"message":"success"}')
33
33
  lambda {
34
34
  @obj.delete :email => "user@domain.com"
35
35
  }.should_not raise_error
36
36
  end
37
37
  it "raises error when email address does not exist" do
38
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/spamreports\.delete\.json\?.*email=.+|, :body => '{"message":"Email does not exist"}')
38
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/spamreports\.delete\.json\?.*email=.+|, :body => '{"message":"Email does not exist"}')
39
39
  lambda {
40
40
  @obj.delete :email => "user@domain.com"
41
41
  }.should raise_error SendgridToolkit::EmailDoesNotExist
@@ -8,7 +8,7 @@ describe SendgridToolkit::Statistics do
8
8
 
9
9
  describe "#retrieve" do
10
10
  it "parses daily totals" do
11
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/stats\.get\.json\?|, :body => '[{"date":"2009-06-20","requests":12342,"bounces":12,"clicks":10223,"opens":9992,"spamreports":5},{"date":"2009-06-21","requests":32342,"bounces":10,"clicks":14323,"opens":10995,"spamreports":7},{"date":"2009-06-22","requests":52342,"bounces":11,"clicks":19223,"opens":12992,"spamreports":2}]')
11
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/stats\.get\.json\?|, :body => '[{"date":"2009-06-20","requests":12342,"bounces":12,"clicks":10223,"opens":9992,"spamreports":5},{"date":"2009-06-21","requests":32342,"bounces":10,"clicks":14323,"opens":10995,"spamreports":7},{"date":"2009-06-22","requests":52342,"bounces":11,"clicks":19223,"opens":12992,"spamreports":2}]')
12
12
  stats = @obj.retrieve
13
13
  stats.each do |stat|
14
14
  %w(bounces clicks delivered invalid_email opens repeat_bounces repeat_spamreports repeat_unsubscribes requests spamreports unsubscribes).each do |int|
@@ -21,7 +21,7 @@ describe SendgridToolkit::Statistics do
21
21
 
22
22
  describe "#retrieve_aggregate" do
23
23
  it "parses aggregate statistics" do
24
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/stats\.get\.json\?.*aggregate=1|, :body => '{"requests":12342,"bounces":12,"clicks":10223,"opens":9992,"spamreports":5}')
24
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/stats\.get\.json\?.*aggregate=1|, :body => '{"requests":12342,"bounces":12,"clicks":10223,"opens":9992,"spamreports":5}')
25
25
  stats = @obj.retrieve_aggregate
26
26
  %w(bounces clicks delivered invalid_email opens repeat_bounces repeat_spamreports repeat_unsubscribes requests spamreports unsubscribes).each do |int|
27
27
  stats[int].kind_of?(Integer).should == true if stats.has_key?(int) # We support all fields presently returned, but we are only testing what sendgrid officially documents
@@ -29,7 +29,7 @@ describe SendgridToolkit::Statistics do
29
29
  end
30
30
 
31
31
  it "parses aggregate statistics for array response" do
32
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/stats\.get\.json\?.*aggregate=1|, :body => '[{"requests":12342,"bounces":12,"clicks":10223,"opens":9992,"spamreports":5},{"requests":5,"bounces":10,"clicks":10223,"opens":9992,"spamreports":5}]')
32
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/stats\.get\.json\?.*aggregate=1|, :body => '[{"requests":12342,"bounces":12,"clicks":10223,"opens":9992,"spamreports":5},{"requests":5,"bounces":10,"clicks":10223,"opens":9992,"spamreports":5}]')
33
33
  stats = @obj.retrieve_aggregate
34
34
  %w(bounces clicks delivered invalid_email opens repeat_bounces repeat_spamreports repeat_unsubscribes requests spamreports unsubscribes).each do |int|
35
35
  # We support all fields presently returned, but we are only testing what sendgrid officially documents
@@ -41,11 +41,79 @@ describe SendgridToolkit::Statistics do
41
41
 
42
42
  describe "#list_categories" do
43
43
  it "parses categories list" do
44
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/stats\.get\.json\?.*list=true|, :body => '[{"category":"categoryA"},{"category":"categoryB"},{"category":"categoryC"}]')
44
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/stats\.get\.json\?.*list=true|, :body => '[{"category":"categoryA"},{"category":"categoryB"},{"category":"categoryC"}]')
45
45
  cats = @obj.list_categories
46
46
  cats[0]['category'].should == 'categoryA'
47
47
  cats[1]['category'].should == 'categoryB'
48
48
  cats[2]['category'].should == 'categoryC'
49
49
  end
50
50
  end
51
+
52
+ describe "#advanced" do
53
+ it "parses browser totals" do
54
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/stats\.getAdvanced\.json\?.*data_type=browsers|, :body => '[{"date":"2014-01-21","delivered":{"Chrome":1},"request":{"Chrome":1},"processed":{"Chrome":1}},{"date":"2014-01-22","delivered":{"Chrome":1},"request":{"Chrome":1},"processed":{"Chrome":1}}]')
55
+ stats = @obj.advanced('browsers', Date.new)
56
+ stats.each do |stat|
57
+ %w(delivered processed request).each do |type|
58
+ stat[type].kind_of?(Hash).should == true if stat.has_key?(type)
59
+ end
60
+ stat['date'].kind_of?(Date).should == true
61
+ end
62
+ end
63
+
64
+ it "parses client totals" do
65
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/stats\.getAdvanced\.json\?.*data_type=clients|, :body => '[{"date":"2014-01-21","delivered":{"Gmail":1},"request":{"Gmail":1},"processed":{"Gmail":1}},{"date":"2014-01-22","delivered":{"Gmail":1},"request":{"Gmail":1},"processed":{"Gmail":1}}]')
66
+ stats = @obj.advanced('clients', Date.new)
67
+ stats.each do |stat|
68
+ %w(delivered processed request).each do |type|
69
+ stat[type].kind_of?(Hash).should == true if stat.has_key?(type)
70
+ end
71
+ stat['date'].kind_of?(Date).should == true
72
+ end
73
+ end
74
+
75
+ it "parses device totals" do
76
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/stats\.getAdvanced\.json\?.*data_type=device|, :body => '[{"date":"2014-01-21","delivered":{"Webmail":1},"request":{"Webmail":1},"processed":{"Webmail":1}},{"date":"2014-01-22","delivered":{"Webmail":1},"request":{"Webmail":1},"processed":{"Webmail":1}}]')
77
+ stats = @obj.advanced('devices', Date.new)
78
+ stats.each do |stat|
79
+ %w(delivered processed request).each do |type|
80
+ stat[type].kind_of?(Hash).should == true if stat.has_key?(type)
81
+ end
82
+ stat['date'].kind_of?(Date).should == true
83
+ end
84
+ end
85
+
86
+ it "parses geo totals" do
87
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/stats\.getAdvanced\.json\?.*data_type=geo|, :body => '[{"date":"2014-01-21","delivered":{"US":1},"request":{"US":1},"processed":{"US":1}},{"date":"2014-01-22","delivered":{"US":1},"request":{"US":1},"processed":{"US":1}}]')
88
+ stats = @obj.advanced('geo', Date.new)
89
+ stats.each do |stat|
90
+ %w(delivered processed request).each do |type|
91
+ stat[type].kind_of?(Hash).should == true if stat.has_key?(type)
92
+ end
93
+ stat['date'].kind_of?(Date).should == true
94
+ end
95
+ end
96
+
97
+ it "parses global totals" do
98
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/stats\.getAdvanced\.json\?.*data_type=global|, :body => '[{"delivered":41,"request":41,"unique_open":1,"unique_click":1,"processed":41,"date":"2013-01-01","open":2,"click":1},{"delivered":224,"unique_open":1,"request":224,"processed":224,"date":"2013-01-02","open":3}]')
99
+ stats = @obj.advanced('global', Date.new)
100
+ stats.each do |stat|
101
+ %w(click delivered open processed request unique_click unique_open).each do |type|
102
+ stat[type].kind_of?(Integer).should == true if stat.has_key?(type)
103
+ end
104
+ stat['date'].kind_of?(Date).should == true
105
+ end
106
+ end
107
+
108
+ it "parses ISP totals" do
109
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/stats\.getAdvanced\.json\?.*data_type=isps|, :body => '[{"date":"2014-01-21","delivered":{"Gmail":1},"request":{"Gmail":1},"processed":{"Gmail":1}},{"date":"2014-01-22","delivered":{"Gmail":1},"request":{"Gmail":1},"processed":{"Gmail":1}}]')
110
+ stats = @obj.advanced('isps', Date.new)
111
+ stats.each do |stat|
112
+ %w(delivered processed request).each do |type|
113
+ stat[type].kind_of?(Hash).should == true if stat.has_key?(type)
114
+ end
115
+ stat['date'].kind_of?(Date).should == true
116
+ end
117
+ end
118
+ end
51
119
  end
@@ -8,7 +8,7 @@ describe SendgridToolkit::Unsubscribes do
8
8
 
9
9
  describe "#retrieve" do
10
10
  it "returns array of unsubscribed email addresses" do
11
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/unsubscribes\.get\.json\?|, :body => '[{"email":"user@domain.com"},{"email":"user2@domain2.com"},{"email":"user3@domain2.com"}]')
11
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/unsubscribes\.get\.json\?|, :body => '[{"email":"user@domain.com"},{"email":"user2@domain2.com"},{"email":"user3@domain2.com"}]')
12
12
  emails = @obj.retrieve
13
13
  emails[0]['email'].should == "user@domain.com"
14
14
  emails[1]['email'].should == "user2@domain2.com"
@@ -17,7 +17,7 @@ describe SendgridToolkit::Unsubscribes do
17
17
  end
18
18
  describe "#retrieve_with_timestamps" do
19
19
  it "parses timestamps" do
20
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/unsubscribes\.get\.json\?.*date=1|, :body => '[{"email":"user@domain.com","created":"2010-03-03 11:00:00"},{"email":"user2@domain2.com","created":"2010-03-04 21:00:00"},{"email":"user3@domain2.com","created":"2010-03-05 23:00:00"}]')
20
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/unsubscribes\.get\.json\?.*date=1|, :body => '[{"email":"user@domain.com","created":"2010-03-03 11:00:00"},{"email":"user2@domain2.com","created":"2010-03-04 21:00:00"},{"email":"user3@domain2.com","created":"2010-03-05 23:00:00"}]')
21
21
  emails = @obj.retrieve_with_timestamps
22
22
  0.upto(2) do |index|
23
23
  emails[index]['created'].kind_of?(Time).should == true
@@ -30,13 +30,13 @@ describe SendgridToolkit::Unsubscribes do
30
30
 
31
31
  describe "#add" do
32
32
  it "raises no errors on success" do
33
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/unsubscribes\.add\.json\?.*email=.+|, :body => '{"message":"success"}')
33
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/unsubscribes\.add\.json\?.*email=.+|, :body => '{"message":"success"}')
34
34
  lambda {
35
35
  @obj.add :email => "user@domain.com"
36
36
  }.should_not raise_error
37
37
  end
38
38
  it "raises error when email already exists" do
39
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/unsubscribes\.add\.json\?.*email=.+|, :body => '{"message":"Unsubscribe email address already exists"}')
39
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/unsubscribes\.add\.json\?.*email=.+|, :body => '{"message":"Unsubscribe email address already exists"}')
40
40
  lambda {
41
41
  @obj.add :email => "user@domain.com"
42
42
  }.should raise_error SendgridToolkit::UnsubscribeEmailAlreadyExists
@@ -45,13 +45,13 @@ describe SendgridToolkit::Unsubscribes do
45
45
 
46
46
  describe "#delete" do
47
47
  it "raises no errors on success" do
48
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/unsubscribes\.delete\.json\?.*email=.+|, :body => '{"message":"success"}')
48
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/unsubscribes\.delete\.json\?.*email=.+|, :body => '{"message":"success"}')
49
49
  lambda {
50
50
  @obj.delete :email => "user@domain.com"
51
51
  }.should_not raise_error
52
52
  end
53
53
  it "raises error when email address does not exist" do
54
- FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/unsubscribes\.delete\.json\?.*email=.+|, :body => '{"message":"Email does not exist"}')
54
+ FakeWeb.register_uri(:post, %r|https://#{REGEX_ESCAPED_BASE_URI}/unsubscribes\.delete\.json\?.*email=.+|, :body => '{"message":"Email does not exist"}')
55
55
  lambda {
56
56
  @obj.delete :email => "user@domain.com"
57
57
  }.should raise_error SendgridToolkit::UnsubscribeEmailDoesNotExist
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendgrid_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: !binary |-
5
- MS4zLjA=
4
+ version: 1.4.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Robby Grossman
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-12-10 00:00:00.000000000 Z
11
+ date: 2014-03-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: httparty
@@ -33,16 +32,14 @@ dependencies:
33
32
  requirements:
34
33
  - - ~>
35
34
  - !ruby/object:Gem::Version
36
- version: !binary |-
37
- MS4zLjA=
35
+ version: 1.3.0
38
36
  type: :development
39
37
  prerelease: false
40
38
  version_requirements: !ruby/object:Gem::Requirement
41
39
  requirements:
42
40
  - - ~>
43
41
  - !ruby/object:Gem::Version
44
- version: !binary |-
45
- MS4zLjA=
42
+ version: 1.3.0
46
43
  - !ruby/object:Gem::Dependency
47
44
  name: jeweler
48
45
  requirement: !ruby/object:Gem::Requirement
@@ -63,16 +60,14 @@ dependencies:
63
60
  requirements:
64
61
  - - ~>
65
62
  - !ruby/object:Gem::Version
66
- version: !binary |-
67
- Mi43LjA=
63
+ version: 2.7.0
68
64
  type: :development
69
65
  prerelease: false
70
66
  version_requirements: !ruby/object:Gem::Requirement
71
67
  requirements:
72
68
  - - ~>
73
69
  - !ruby/object:Gem::Version
74
- version: !binary |-
75
- Mi43LjA=
70
+ version: 2.7.0
76
71
  description: A Ruby wrapper and utility library for communicating with the Sendgrid
77
72
  API.
78
73
  email: robby@freerobby.com
@@ -83,6 +78,7 @@ extra_rdoc_files:
83
78
  - README.md
84
79
  files:
85
80
  - .rvmrc
81
+ - .travis.yml
86
82
  - Gemfile
87
83
  - Gemfile.lock
88
84
  - LICENSE.txt