diff --git a/.gitignore b/.gitignore index 38c268b..15df629 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,15 @@ -pkg/ -doc/ -.idea/* \ No newline at end of file +# rcov generated +coverage + +# rdoc generated +rdoc + +# yard generated +doc +.yardoc + +# bundler +.bundle + +# jeweler generated +pkg diff --git a/.rvmrc b/.rvmrc new file mode 100644 index 0000000..50fb415 --- /dev/null +++ b/.rvmrc @@ -0,0 +1,3 @@ +export RUBYOPT="rubygems" +export RUBYLIB="." +rvm 1.9.2@sendgrid_toolkit \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..4c34ede --- /dev/null +++ b/Gemfile @@ -0,0 +1,11 @@ +source "http://rubygems.org" + +gem "activesupport", ">= 2.3.5" +gem "httparty", ">= 0.7.6" + +group :development do + gem "bundler", "~> 1.0.0" + gem "fakeweb", "~> 1.3.0" + gem "jeweler", "~> 1.6.4" + gem "rspec", "~> 2.7.0" +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..5284819 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,37 @@ +GEM + remote: http://rubygems.org/ + specs: + activesupport (3.1.1) + multi_json (~> 1.0) + diff-lcs (1.1.3) + fakeweb (1.3.0) + git (1.2.5) + httparty (0.8.1) + multi_json + multi_xml + jeweler (1.6.4) + bundler (~> 1.0) + git (>= 1.2.5) + rake + multi_json (1.0.3) + multi_xml (0.4.1) + rake (0.9.2.2) + rspec (2.7.0) + rspec-core (~> 2.7.0) + rspec-expectations (~> 2.7.0) + rspec-mocks (~> 2.7.0) + rspec-core (2.7.1) + rspec-expectations (2.7.0) + diff-lcs (~> 1.1.2) + rspec-mocks (2.7.0) + +PLATFORMS + ruby + +DEPENDENCIES + activesupport (>= 2.3.5) + bundler (~> 1.0.0) + fakeweb (~> 1.3.0) + httparty (>= 0.7.6) + jeweler (~> 1.6.4) + rspec (~> 2.7.0) diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..b21a5bb --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,20 @@ +Copyright (c) 2011 Robby Grossman + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 88464e5..53b5218 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,13 @@ Common actions are documented below under each module. For more details, visit t Contributing ------------ -When submitting patches, please be sure you include rspec tests! +* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet +* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it +* Fork the project +* Start a feature/bugfix branch +* Commit and push until you are happy with your contribution +* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. +* 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. Big thanks to [James Brennan][1] for refactoring old code and writing the Bounces, InvalidEmails and SpamReports modules. diff --git a/Rakefile b/Rakefile index 77215f6..8020bcf 100644 --- a/Rakefile +++ b/Rakefile @@ -1,22 +1,34 @@ require 'rubygems' +require 'bundler' +begin + Bundler.setup(:default, :development) +rescue Bundler::BundlerError => e + $stderr.puts e.message + $stderr.puts "Run `bundle install` to install missing gems" + exit e.status_code +end require 'rake' -begin - require 'jeweler' - Jeweler::Tasks.new do |gemspec| - gemspec.name = "sendgrid_toolkit" - gemspec.summary = "A Ruby wrapper and utility library for communicating with the Sendgrid API" - gemspec.description = "A Ruby wrapper and utility library for communicating with the Sendgrid API" - gemspec.email = "robby@freerobby.com" - gemspec.homepage = "http://github.com/freerobby/sendgrid_toolkit" - gemspec.authors = ["Robby Grossman"] - - gemspec.add_dependency "httparty" - # Development dependencies: fakeweb, rake, jeweler, rspec - end - Jeweler::GemcutterTasks.new -rescue LoadError - puts "Jeweler must be installed. Use 'sudo gem install jeweler'." +require 'jeweler' +Jeweler::Tasks.new do |gem| + # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options + gem.name = "sendgrid_toolkit" + gem.homepage = "http://github.com/freerobby/sendgrid_toolkit" + gem.license = "MIT" + gem.summary = "sendgrid_toolkit = Sendgrid + Ruby" + gem.description = "A Ruby wrapper and utility library for communicating with the Sendgrid API." + gem.email = "robby@freerobby.com" + gem.authors = ["Robby Grossman"] + # dependencies defined in Gemfile end +Jeweler::RubygemsDotOrgTasks.new -Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each {|ext| load ext} \ No newline at end of file +require 'rake/rdoctask' +Rake::RDocTask.new do |rdoc| + version = File.exist?('VERSION') ? File.read('VERSION') : "" + + rdoc.rdoc_dir = 'rdoc' + rdoc.title = "testing1213 #{version}" + rdoc.rdoc_files.include('README*') + rdoc.rdoc_files.include('lib/**/*.rb') +end diff --git a/lib/sendgrid_toolkit.rb b/lib/sendgrid_toolkit.rb index d18c7d5..25f9cfd 100644 --- a/lib/sendgrid_toolkit.rb +++ b/lib/sendgrid_toolkit.rb @@ -1,3 +1,4 @@ +require 'active_support/all' require 'httparty' require 'sendgrid_toolkit/abstract_sendgrid_client' diff --git a/lib/sendgrid_toolkit/statistics.rb b/lib/sendgrid_toolkit/statistics.rb index 80512ed..113f528 100644 --- a/lib/sendgrid_toolkit/statistics.rb +++ b/lib/sendgrid_toolkit/statistics.rb @@ -2,6 +2,7 @@ module SendgridToolkit class Statistics < AbstractSendgridClient def retrieve(options = {}) response = api_post('stats', 'get', options) + response.each {|r| r['date'] = Date.parse(r['date']) if r.kind_of?(Hash) && r.has_key?('date')} response end diff --git a/sendgrid_toolkit.gemspec b/sendgrid_toolkit.gemspec deleted file mode 100644 index 92e5b3b..0000000 --- a/sendgrid_toolkit.gemspec +++ /dev/null @@ -1,60 +0,0 @@ -# Generated by jeweler -# DO NOT EDIT THIS FILE DIRECTLY -# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' -# -*- encoding: utf-8 -*- - -Gem::Specification.new do |s| - s.name = %q{sendgrid_toolkit} - s.version = "1.0.5" - - s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= - s.authors = [%q{Robby Grossman}] - s.date = %q{2011-09-19} - s.description = %q{A Ruby wrapper and utility library for communicating with the Sendgrid API} - s.email = %q{robby@freerobby.com} - s.extra_rdoc_files = [ - "README.md" - ] - s.files = [ - "README.md", - "Rakefile", - "VERSION", - "lib/sendgrid_toolkit.rb", - "lib/sendgrid_toolkit/abstract_sendgrid_client.rb", - "lib/sendgrid_toolkit/bounces.rb", - "lib/sendgrid_toolkit/common.rb", - "lib/sendgrid_toolkit/invalid_emails.rb", - "lib/sendgrid_toolkit/sendgrid_error.rb", - "lib/sendgrid_toolkit/spam_reports.rb", - "lib/sendgrid_toolkit/statistics.rb", - "lib/sendgrid_toolkit/unsubscribes.rb", - "sendgrid_toolkit.gemspec", - "spec/helper.rb", - "spec/lib/sendgrid_toolkit/abstract_sendgrid_client_spec.rb", - "spec/lib/sendgrid_toolkit/bounces_spec.rb", - "spec/lib/sendgrid_toolkit/common_spec.rb", - "spec/lib/sendgrid_toolkit/invalid_emails_spec.rb", - "spec/lib/sendgrid_toolkit/spam_reports_spec.rb", - "spec/lib/sendgrid_toolkit/statistics_spec.rb", - "spec/lib/sendgrid_toolkit/unsubscribes_spec.rb", - "spec/lib/sendgrid_toolkit_spec.rb", - "spec/webconnect/sendgrid_toolkit_spec.rb" - ] - s.homepage = %q{http://github.com/freerobby/sendgrid_toolkit} - s.require_paths = [%q{lib}] - s.rubygems_version = %q{1.8.6} - s.summary = %q{A Ruby wrapper and utility library for communicating with the Sendgrid API} - - if s.respond_to? :specification_version then - s.specification_version = 3 - - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_runtime_dependency(%q, [">= 0"]) - else - s.add_dependency(%q, [">= 0"]) - end - else - s.add_dependency(%q, [">= 0"]) - end -end - diff --git a/spec/helper.rb b/spec/helper.rb index 625518c..5aefb27 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -1,6 +1,6 @@ require 'fakeweb' require 'sendgrid_toolkit' -require 'spec' +require 'rspec' FakeWeb.allow_net_connect = false diff --git a/spec/lib/sendgrid_toolkit/abstract_sendgrid_client_spec.rb b/spec/lib/sendgrid_toolkit/abstract_sendgrid_client_spec.rb index eefc477..4cb07d7 100644 --- a/spec/lib/sendgrid_toolkit/abstract_sendgrid_client_spec.rb +++ b/spec/lib/sendgrid_toolkit/abstract_sendgrid_client_spec.rb @@ -17,7 +17,7 @@ }.should raise_error SendgridToolkit::AuthenticationFailed end it "thows error when sendgrid response is a server error" do - FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/profile\.get\.json\?|, :body => 'A server error occured', :status => ['500', 'Internal Server Error']) + FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/profile\.get\.json\?|, :body => '{}', :status => ['500', 'Internal Server Error']) @obj = SendgridToolkit::AbstractSendgridClient.new("someuser", "somepass") lambda { @obj.send(:api_post, "profile", "get", {}) diff --git a/spec/lib/sendgrid_toolkit/bounces_spec.rb b/spec/lib/sendgrid_toolkit/bounces_spec.rb index 4341af9..d9ca145 100644 --- a/spec/lib/sendgrid_toolkit/bounces_spec.rb +++ b/spec/lib/sendgrid_toolkit/bounces_spec.rb @@ -42,7 +42,7 @@ }.should raise_error SendgridToolkit::EmailDoesNotExist end it "does not choke if response does not have a 'message' field" do - FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/bounces\.delete\.json\?.*email=.+|, :body => 'An internal server error occurred. Please try again later.') + FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/bounces\.delete\.json\?.*email=.+|, :body => '{}') lambda { @obj.delete :email => "user@domain.com" }.should_not raise_error diff --git a/spec/lib/sendgrid_toolkit/common_spec.rb b/spec/lib/sendgrid_toolkit/common_spec.rb index a25e4b2..bc04cfd 100644 --- a/spec/lib/sendgrid_toolkit/common_spec.rb +++ b/spec/lib/sendgrid_toolkit/common_spec.rb @@ -14,7 +14,7 @@ class FakeClass < SendgridToolkit::AbstractSendgridClient end it "does not choke if response does not have a 'message' field" do - FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/fakeclass\.delete\.json\?.*email=.+|, :body => 'An internal server error occurred. Please try again later.') + FakeWeb.register_uri(:post, %r|https://sendgrid\.com/api/fakeclass\.delete\.json\?.*email=.+|, :body => '{}') lambda { @fake_class.delete :email => "user@domain.com" }.should_not raise_error