sendgrid_toolkit 1.0.5 → 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1,3 @@
1
+ export RUBYOPT="rubygems"
2
+ export RUBYLIB="."
3
+ rvm 1.9.2@sendgrid_toolkit
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "activesupport", ">= 2.3.5"
4
+ gem "httparty", ">= 0.7.6"
5
+
6
+ group :development do
7
+ gem "bundler", "~> 1.0.0"
8
+ gem "fakeweb", "~> 1.3.0"
9
+ gem "jeweler", "~> 1.6.4"
10
+ gem "rspec", "~> 2.7.0"
11
+ end
@@ -0,0 +1,37 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (3.1.1)
5
+ multi_json (~> 1.0)
6
+ diff-lcs (1.1.3)
7
+ fakeweb (1.3.0)
8
+ git (1.2.5)
9
+ httparty (0.8.1)
10
+ multi_json
11
+ multi_xml
12
+ jeweler (1.6.4)
13
+ bundler (~> 1.0)
14
+ git (>= 1.2.5)
15
+ rake
16
+ multi_json (1.0.3)
17
+ multi_xml (0.4.1)
18
+ rake (0.9.2.2)
19
+ rspec (2.7.0)
20
+ rspec-core (~> 2.7.0)
21
+ rspec-expectations (~> 2.7.0)
22
+ rspec-mocks (~> 2.7.0)
23
+ rspec-core (2.7.1)
24
+ rspec-expectations (2.7.0)
25
+ diff-lcs (~> 1.1.2)
26
+ rspec-mocks (2.7.0)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ activesupport (>= 2.3.5)
33
+ bundler (~> 1.0.0)
34
+ fakeweb (~> 1.3.0)
35
+ httparty (>= 0.7.6)
36
+ jeweler (~> 1.6.4)
37
+ rspec (~> 2.7.0)
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Robby Grossman
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -26,7 +26,13 @@ Common actions are documented below under each module. For more details, visit t
26
26
  Contributing
27
27
  ------------
28
28
 
29
- When submitting patches, please be sure you include rspec tests!
29
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
30
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
31
+ * Fork the project
32
+ * Start a feature/bugfix branch
33
+ * Commit and push until you are happy with your contribution
34
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
35
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
30
36
 
31
37
  Big thanks to [James Brennan][1] for refactoring old code and writing the Bounces, InvalidEmails and SpamReports modules.
32
38
 
data/Rakefile CHANGED
@@ -1,22 +1,24 @@
1
1
  require 'rubygems'
2
- require 'rake'
3
-
2
+ require 'bundler'
4
3
  begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gemspec|
7
- gemspec.name = "sendgrid_toolkit"
8
- gemspec.summary = "A Ruby wrapper and utility library for communicating with the Sendgrid API"
9
- gemspec.description = "A Ruby wrapper and utility library for communicating with the Sendgrid API"
10
- gemspec.email = "robby@freerobby.com"
11
- gemspec.homepage = "http://github.com/freerobby/sendgrid_toolkit"
12
- gemspec.authors = ["Robby Grossman"]
13
-
14
- gemspec.add_dependency "httparty"
15
- # Development dependencies: fakeweb, rake, jeweler, rspec
16
- end
17
- Jeweler::GemcutterTasks.new
18
- rescue LoadError
19
- puts "Jeweler must be installed. Use 'sudo gem install jeweler'."
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
20
9
  end
10
+ require 'rake'
21
11
 
22
- Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each {|ext| load ext}
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "sendgrid_toolkit"
16
+ gem.homepage = "http://github.com/freerobby/sendgrid_toolkit"
17
+ gem.license = "MIT"
18
+ gem.summary = "sendgrid_toolkit = Sendgrid + Ruby"
19
+ gem.description = "A Ruby wrapper and utility library for communicating with the Sendgrid API."
20
+ gem.email = "robby@freerobby.com"
21
+ gem.authors = ["Robby Grossman"]
22
+ # dependencies defined in Gemfile
23
+ end
24
+ Jeweler::RubygemsDotOrgTasks.new
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.5
1
+ 1.0.6
@@ -1,3 +1,4 @@
1
+ require 'active_support/all'
1
2
  require 'httparty'
2
3
 
3
4
  require 'sendgrid_toolkit/abstract_sendgrid_client'
@@ -2,22 +2,31 @@ module SendgridToolkit
2
2
  class Statistics < AbstractSendgridClient
3
3
  def retrieve(options = {})
4
4
  response = api_post('stats', 'get', options)
5
+ response.each {|r| r['date'] = Date.parse(r['date']) if r.kind_of?(Hash) && r.has_key?('date')}
5
6
  response
6
7
  end
7
8
 
8
9
  def retrieve_aggregate(options = {})
9
10
  options.merge! :aggregate => 1
10
11
  response = retrieve options
11
- %w(bounces clicks delivered invalid_email opens repeat_bounces repeat_spamreports repeat_unsubscribes requests spamreports unsubscribes).each do |int_field|
12
- response[int_field] = response[int_field].to_i if response.has_key?(int_field)
12
+ if Hash === response.parsed_response
13
+ to_ints(response.parsed_response)
14
+ elsif Array === response.parsed_response
15
+ response.parsed_response.each {|o| to_ints(o) }
13
16
  end
14
17
  response
15
18
  end
16
-
19
+
20
+ def to_ints(resp)
21
+ %w(bounces clicks delivered invalid_email opens repeat_bounces repeat_spamreports repeat_unsubscribes requests spamreports unsubscribes).each do |int_field|
22
+ resp[int_field] = resp[int_field].to_i if resp.has_key?(int_field)
23
+ end
24
+ end
25
+
17
26
  def list_categories(options = {})
18
27
  options.merge! :list => true
19
28
  response = retrieve options
20
29
  response
21
30
  end
22
31
  end
23
- end
32
+ end
@@ -1,6 +1,6 @@
1
1
  require 'fakeweb'
2
2
  require 'sendgrid_toolkit'
3
- require 'spec'
3
+ require 'rspec'
4
4
 
5
5
  FakeWeb.allow_net_connect = false
6
6
 
@@ -17,7 +17,7 @@ describe SendgridToolkit::AbstractSendgridClient do
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 => 'A server error occured', :status => ['500', 'Internal Server Error'])
20
+ FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/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", {})
@@ -42,7 +42,7 @@ describe SendgridToolkit::Bounces do
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 => 'An internal server error occurred. Please try again later.')
45
+ FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/bounces\.delete\.json\?.*email=.+|, :body => '{}')
46
46
  lambda {
47
47
  @obj.delete :email => "user@domain.com"
48
48
  }.should_not raise_error
@@ -14,7 +14,7 @@ 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 => 'An internal server error occurred. Please try again later.')
17
+ FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/fakeclass\.delete\.json\?.*email=.+|, :body => '{}')
18
18
  lambda {
19
19
  @fake_class.delete :email => "user@domain.com"
20
20
  }.should_not raise_error
@@ -27,6 +27,16 @@ describe SendgridToolkit::Statistics do
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
28
28
  end
29
29
  end
30
+
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}]')
33
+ stats = @obj.retrieve_aggregate
34
+ %w(bounces clicks delivered invalid_email opens repeat_bounces repeat_spamreports repeat_unsubscribes requests spamreports unsubscribes).each do |int|
35
+ # We support all fields presently returned, but we are only testing what sendgrid officially documents
36
+ stats[0][int].kind_of?(Integer).should == true if stats[0].has_key?(int)
37
+ stats[1][int].kind_of?(Integer).should == true if stats[1].has_key?(int)
38
+ end
39
+ end
30
40
  end
31
41
 
32
42
  describe "#list_categories" do
@@ -56,18 +56,18 @@ describe SendgridToolkit do
56
56
  @obj = SendgridToolkit::Unsubscribes.new
57
57
  unsubscribes = @obj.retrieve
58
58
  unsubscribes.each do |u|
59
- @obj.delete u['email']
59
+ @obj.delete :email => u['email']
60
60
  end
61
61
  end
62
62
  xit "adds, retrieves and deletes email addresses properly" do
63
- @obj.add "user@domain.com"
64
- @obj.add "user2@domain.com"
63
+ @obj.add :email => "user@domain.com"
64
+ @obj.add :email => "user2@domain.com"
65
65
  unsubs = @obj.retrieve_with_timestamps
66
66
  emails = unsubs.map {|h| h['email']}
67
67
  emails.include?('user@domain.com').should == true
68
68
  emails.include?('user2@domain.com').should == true
69
- @obj.delete 'user@domain.com'
70
- @obj.delete 'user2@domain.com'
69
+ @obj.delete :email => 'user@domain.com'
70
+ @obj.delete :email => 'user2@domain.com'
71
71
  @obj.retrieve.count.should == 0
72
72
  end
73
73
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sendgrid_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,27 +9,87 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-19 00:00:00.000000000Z
12
+ date: 2011-11-01 00:00:00.000000000Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: &70095510282140 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 2.3.5
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70095510282140
14
25
  - !ruby/object:Gem::Dependency
15
26
  name: httparty
16
- requirement: &70103627509080 !ruby/object:Gem::Requirement
27
+ requirement: &70095510281640 !ruby/object:Gem::Requirement
17
28
  none: false
18
29
  requirements:
19
30
  - - ! '>='
20
31
  - !ruby/object:Gem::Version
21
- version: '0'
32
+ version: 0.7.6
22
33
  type: :runtime
23
34
  prerelease: false
24
- version_requirements: *70103627509080
35
+ version_requirements: *70095510281640
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70095510281060 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70095510281060
47
+ - !ruby/object:Gem::Dependency
48
+ name: fakeweb
49
+ requirement: &70095510280440 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.3.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70095510280440
58
+ - !ruby/object:Gem::Dependency
59
+ name: jeweler
60
+ requirement: &70095510279400 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.6.4
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70095510279400
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: &70095510278900 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 2.7.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70095510278900
25
80
  description: A Ruby wrapper and utility library for communicating with the Sendgrid
26
- API
81
+ API.
27
82
  email: robby@freerobby.com
28
83
  executables: []
29
84
  extensions: []
30
85
  extra_rdoc_files:
86
+ - LICENSE.txt
31
87
  - README.md
32
88
  files:
89
+ - .rvmrc
90
+ - Gemfile
91
+ - Gemfile.lock
92
+ - LICENSE.txt
33
93
  - README.md
34
94
  - Rakefile
35
95
  - VERSION
@@ -42,7 +102,6 @@ files:
42
102
  - lib/sendgrid_toolkit/spam_reports.rb
43
103
  - lib/sendgrid_toolkit/statistics.rb
44
104
  - lib/sendgrid_toolkit/unsubscribes.rb
45
- - sendgrid_toolkit.gemspec
46
105
  - spec/helper.rb
47
106
  - spec/lib/sendgrid_toolkit/abstract_sendgrid_client_spec.rb
48
107
  - spec/lib/sendgrid_toolkit/bounces_spec.rb
@@ -54,7 +113,8 @@ files:
54
113
  - spec/lib/sendgrid_toolkit_spec.rb
55
114
  - spec/webconnect/sendgrid_toolkit_spec.rb
56
115
  homepage: http://github.com/freerobby/sendgrid_toolkit
57
- licenses: []
116
+ licenses:
117
+ - MIT
58
118
  post_install_message:
59
119
  rdoc_options: []
60
120
  require_paths:
@@ -65,6 +125,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
125
  - - ! '>='
66
126
  - !ruby/object:Gem::Version
67
127
  version: '0'
128
+ segments:
129
+ - 0
130
+ hash: -2993501477893612547
68
131
  required_rubygems_version: !ruby/object:Gem::Requirement
69
132
  none: false
70
133
  requirements:
@@ -73,8 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
136
  version: '0'
74
137
  requirements: []
75
138
  rubyforge_project:
76
- rubygems_version: 1.8.6
139
+ rubygems_version: 1.8.10
77
140
  signing_key:
78
141
  specification_version: 3
79
- summary: A Ruby wrapper and utility library for communicating with the Sendgrid API
142
+ summary: sendgrid_toolkit = Sendgrid + Ruby
80
143
  test_files: []
@@ -1,60 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{sendgrid_toolkit}
8
- s.version = "1.0.5"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Robby Grossman}]
12
- s.date = %q{2011-09-19}
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.md"
17
- ]
18
- s.files = [
19
- "README.md",
20
- "Rakefile",
21
- "VERSION",
22
- "lib/sendgrid_toolkit.rb",
23
- "lib/sendgrid_toolkit/abstract_sendgrid_client.rb",
24
- "lib/sendgrid_toolkit/bounces.rb",
25
- "lib/sendgrid_toolkit/common.rb",
26
- "lib/sendgrid_toolkit/invalid_emails.rb",
27
- "lib/sendgrid_toolkit/sendgrid_error.rb",
28
- "lib/sendgrid_toolkit/spam_reports.rb",
29
- "lib/sendgrid_toolkit/statistics.rb",
30
- "lib/sendgrid_toolkit/unsubscribes.rb",
31
- "sendgrid_toolkit.gemspec",
32
- "spec/helper.rb",
33
- "spec/lib/sendgrid_toolkit/abstract_sendgrid_client_spec.rb",
34
- "spec/lib/sendgrid_toolkit/bounces_spec.rb",
35
- "spec/lib/sendgrid_toolkit/common_spec.rb",
36
- "spec/lib/sendgrid_toolkit/invalid_emails_spec.rb",
37
- "spec/lib/sendgrid_toolkit/spam_reports_spec.rb",
38
- "spec/lib/sendgrid_toolkit/statistics_spec.rb",
39
- "spec/lib/sendgrid_toolkit/unsubscribes_spec.rb",
40
- "spec/lib/sendgrid_toolkit_spec.rb",
41
- "spec/webconnect/sendgrid_toolkit_spec.rb"
42
- ]
43
- s.homepage = %q{http://github.com/freerobby/sendgrid_toolkit}
44
- s.require_paths = [%q{lib}]
45
- s.rubygems_version = %q{1.8.6}
46
- s.summary = %q{A Ruby wrapper and utility library for communicating with the Sendgrid API}
47
-
48
- if s.respond_to? :specification_version then
49
- s.specification_version = 3
50
-
51
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
- s.add_runtime_dependency(%q<httparty>, [">= 0"])
53
- else
54
- s.add_dependency(%q<httparty>, [">= 0"])
55
- end
56
- else
57
- s.add_dependency(%q<httparty>, [">= 0"])
58
- end
59
- end
60
-