From 564347652eedf2f134ea300304899b9e6b61a56b Mon Sep 17 00:00:00 2001 From: Amro Mousa Date: Fri, 8 Jun 2012 12:57:33 -0400 Subject: [PATCH] clean up cruft --- Gemfile | 17 +------ LICENSE.txt | 2 +- README.markdown | 18 ++++---- Rakefile | 50 +++------------------ VERSION | 1 - gibbon.gemspec | 103 +++++++++---------------------------------- lib/gibbon.rb | 29 +----------- lib/gibbon_export.rb | 24 ++++++++++ 8 files changed, 62 insertions(+), 182 deletions(-) delete mode 100644 VERSION create mode 100644 lib/gibbon_export.rb diff --git a/Gemfile b/Gemfile index e57ed6c..c80ee36 100644 --- a/Gemfile +++ b/Gemfile @@ -1,18 +1,3 @@ source "http://rubygems.org" -gem "json", "> 1.4.0" -gem "httparty", "> 0.6.0" -gem "rdoc" - -group :development, :test do - gem "shoulda", ">= 0" - gem "bundler", "~> 1.0.0" - gem "jeweler", "~> 1.5.1" - gem 'simplecov', :require => false - gem "mocha", "> 0.9.11" - - unless ENV["CI"] - gem "ruby-debug19", :require => "ruby-debug", :platforms => [:ruby_19] - gem "ruby-debug", :platforms => [:ruby_18] - end -end +gemspec diff --git a/LICENSE.txt b/LICENSE.txt index 31659db..7e2dbf3 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright (c) 2010 Amro Mousa +Copyright (c) 2010-2012 Amro Mousa Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.markdown b/README.markdown index 011699e..c56b1c1 100644 --- a/README.markdown +++ b/README.markdown @@ -1,6 +1,6 @@ # gibbon -Gibbon is a simple API wrapper for interacting with [MailChimp API](http://www.mailchimp.com/api) 1.3. +Gibbon is a simple wrapper for MailChimp's [Primary and Export APIs](http://www.mailchimp.com/api). [![Build Status](https://secure.travis-ci.org/amro/gibbon.png)](http://travis-ci.org/amro/gibbon) @@ -25,7 +25,7 @@ You can set your api_key globally and call class methods: Gibbon.api_key = "your_api_key" Gibbon.lists -You can also set the environment variable 'MC_API_KEY' and Gibbon will use it when you create an instance: +You can also set the environment variable `MC_API_KEY` and Gibbon will use it when you create an instance: u = Gibbon.new @@ -73,16 +73,14 @@ Gibbon defaults to a 30 second timeout. You can optionally set your own timeout ### Export API usage -In addition to the standard API you can make calls to the -[MailChimp Export API](http://apidocs.mailchimp.com/export/1.0/) using a GibbonExport object. Given an existing -Gibbon object you can request a new GibbonExporter object: +In addition to the primary API, you can make calls to the [Export API](http://apidocs.mailchimp.com/export/1.0/) using an instance of GibbonExport. Given an existing instance of Gibbon, you can request a new GibbonExporter object: - g = Gibbon.new(@api_key) + g = Gibbon.new("your_api_key") gibbon_export = g.get_exporter or you can construct a new object directly: - gibbon_export = GibbonExport.new(@api_key) + gibbon_export = GibbonExport.new("your_api_key") Calling Export API functions is identical to making standard API calls but the return value is an Enumerator which loops over the lines returned from the @@ -111,7 +109,7 @@ Gibbon will attempt to intercept the errors and raise an exception. * [Michael Klishin](https://github.com/michaelklishin) * Rails for camelize gsub -##Copyrights +##Copyright -* Copyright (c) 2010 Amro Mousa. See LICENSE.txt for details. -* MailChimp (c) 2001-2010 The Rocket Science Group. +* Copyright (c) 2010-2012 Amro Mousa. See LICENSE.txt for details. +* MailChimp (c) 2001-2012 The Rocket Science Group. diff --git a/Rakefile b/Rakefile index ed5daa9..e56535f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,47 +1,9 @@ -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' - -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 = "gibbon" - gem.homepage = "http://github.com/amro/gibbon" - gem.license = "MIT" - gem.summary = %Q{Gibbon is a simple API wrapper for interacting with MailChimp API 1.3} - gem.description = %Q{Gibbon is a simple API wrapper for interacting with MailChimp API version 1.3.} - gem.email = "amromousa@gmail.com" - gem.authors = ["Amro Mousa"] - # Include your dependencies below. Runtime dependencies are required when using your gem, - # and development dependencies are only needed for development (ie running rake tasks, tests, etc) - gem.add_runtime_dependency 'httparty', '> 0.6.0' - gem.add_runtime_dependency 'json', '> 1.4.0' - gem.add_development_dependency 'mocha', '> 0.9.11' -end -Jeweler::RubygemsDotOrgTasks.new - +require "bundler/gem_tasks" require 'rake/testtask' -Rake::TestTask.new(:test) do |test| - test.libs << 'lib' << 'test' - test.pattern = 'test/**/test_*.rb' - test.verbose = true -end - -task :default => :test -require 'rdoc/task' -Rake::RDocTask.new do |rdoc| - version = File.exist?('VERSION') ? File.read('VERSION') : "" - - rdoc.rdoc_dir = 'rdoc' - rdoc.title = "gibbon #{version}" - rdoc.rdoc_files.include('README*') - rdoc.rdoc_files.include('lib/**/*.rb') +Rake::TestTask.new do |t| + t.libs << 'test' end + +desc "Run tests" +task :default => :test \ No newline at end of file diff --git a/VERSION b/VERSION deleted file mode 100644 index 53b61ec..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.3.6 \ No newline at end of file diff --git a/gibbon.gemspec b/gibbon.gemspec index dc49eda..17813b1 100644 --- a/gibbon.gemspec +++ b/gibbon.gemspec @@ -1,90 +1,29 @@ -# Generated by jeweler -# DO NOT EDIT THIS FILE DIRECTLY -# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' # -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) Gem::Specification.new do |s| - s.name = "gibbon" - s.version = "0.3.5" + s.name = "gibbon" + s.version = "0.4.0" + s.authors = ["Amro Mousa"] + s.email = ["amromousa@gmail.com"] + s.homepage = "http://github.com/amro/gibbon" + s.summary = %q{A simple wrapper for MailChimp's primary and export APIs} + s.description = %q{A simple wrapper for MailChimp's primary and export APIs} + s.license = "MIT" - s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= - s.authors = ["Amro Mousa"] - s.date = "2011-12-09" - s.description = "Gibbon is a simple API wrapper for interacting with MailChimp API version 1.3." - s.email = "amromousa@gmail.com" - s.extra_rdoc_files = [ - "LICENSE.txt", - "README.markdown" - ] - s.files = [ - ".document", - ".travis.yml", - "Gemfile", - "LICENSE.txt", - "README.markdown", - "Rakefile", - "VERSION", - "gibbon.gemspec", - "lib/gibbon.rb", - "test/helper.rb", - "test/test_gibbon.rb" - ] - s.homepage = "http://github.com/amro/gibbon" - s.licenses = ["MIT"] - s.require_paths = ["lib"] - s.rubygems_version = "1.8.10" - s.summary = "Gibbon is a simple API wrapper for interacting with MailChimp API 1.3" - s.test_files = [ - "test/helper.rb", - "test/test_gibbon.rb" - ] + s.rubyforge_project = "gibbon" - if s.respond_to? :specification_version then - s.specification_version = 3 + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.require_paths = ["lib"] - if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_runtime_dependency(%q, ["> 1.4.0"]) - s.add_runtime_dependency(%q, ["> 0.6.0"]) - s.add_runtime_dependency(%q, [">= 0"]) - s.add_development_dependency(%q, [">= 0"]) - s.add_development_dependency(%q, ["~> 1.0.0"]) - s.add_development_dependency(%q, ["~> 1.5.1"]) - s.add_development_dependency(%q, [">= 0"]) - s.add_development_dependency(%q, ["> 0.9.11"]) - s.add_development_dependency(%q, [">= 0"]) - s.add_development_dependency(%q, [">= 0"]) - s.add_runtime_dependency(%q, ["> 0.6.0"]) - s.add_runtime_dependency(%q, ["> 1.4.0"]) - s.add_development_dependency(%q, ["> 0.9.11"]) - else - s.add_dependency(%q, ["> 1.4.0"]) - s.add_dependency(%q, ["> 0.6.0"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, ["~> 1.0.0"]) - s.add_dependency(%q, ["~> 1.5.1"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, ["> 0.9.11"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, ["> 0.6.0"]) - s.add_dependency(%q, ["> 1.4.0"]) - s.add_dependency(%q, ["> 0.9.11"]) - end - else - s.add_dependency(%q, ["> 1.4.0"]) - s.add_dependency(%q, ["> 0.6.0"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, ["~> 1.0.0"]) - s.add_dependency(%q, ["~> 1.5.1"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, ["> 0.9.11"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, [">= 0"]) - s.add_dependency(%q, ["> 0.6.0"]) - s.add_dependency(%q, ["> 1.4.0"]) - s.add_dependency(%q, ["> 0.9.11"]) - end + s.add_dependency('httparty') + s.add_dependency('json') + + s.add_development_dependency('shoulda') + s.add_development_dependency('simplecov') + s.add_development_dependency('mocha') + s.add_development_dependency('debugger') end diff --git a/lib/gibbon.rb b/lib/gibbon.rb index 1a1cf24..7d389b3 100644 --- a/lib/gibbon.rb +++ b/lib/gibbon.rb @@ -28,8 +28,7 @@ def base_api_url "https://#{dc_from_api_key}api.mailchimp.com/1.3/?method=" end -protected - + protected def call(method, params = {}) api_url = base_api_url + method params = @default_params.merge(params) @@ -64,32 +63,6 @@ def dc_from_api_key (@api_key.nil? || @api_key.empty? || @api_key !~ /-/) ? '' : "#{@api_key.split("-").last}." end end - -class GibbonExport < Gibbon - def initialize(api_key = nil, extra_params = {}) - super(api_key, extra_params) - end - -protected - - def export_api_url - "http://#{dc_from_api_key}api.mailchimp.com/export/1.0/" - end - - def call(method, params = {}) - api_url = export_api_url + method + "/" - params = @default_params.merge(params) - response = self.class.post(api_url, :body => params, :timeout => @timeout) - - lines = response.body.lines - if @throws_exceptions - first_line_object = JSON.parse(lines.first) if lines.first - raise "Error from MailChimp Export API: #{first_line_object["error"]} (code #{first_line_object["code"]})" if first_line_object.is_a?(Hash) && first_line_object["error"] - end - - lines - end -end module HTTParty module HashConversions diff --git a/lib/gibbon_export.rb b/lib/gibbon_export.rb new file mode 100644 index 0000000..4a02e33 --- /dev/null +++ b/lib/gibbon_export.rb @@ -0,0 +1,24 @@ +class GibbonExport < Gibbon + def initialize(api_key = nil, extra_params = {}) + super(api_key, extra_params) + end + + protected + def export_api_url + "http://#{dc_from_api_key}api.mailchimp.com/export/1.0/" + end + + def call(method, params = {}) + api_url = export_api_url + method + "/" + params = @default_params.merge(params) + response = self.class.post(api_url, :body => params, :timeout => @timeout) + + lines = response.body.lines + if @throws_exceptions + first_line_object = JSON.parse(lines.first) if lines.first + raise "Error from MailChimp Export API: #{first_line_object["error"]} (code #{first_line_object["code"]})" if first_line_object.is_a?(Hash) && first_line_object["error"] + end + + lines + end +end \ No newline at end of file