Skip to content

Commit

Permalink
Add Export tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amro committed Jan 14, 2017
1 parent 910d602 commit b014637
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,4 +1,6 @@
## [Unreleased][unreleased]

## [3.0.0] - 2017-01-13
- Gibbon now returns a `Gibbon::Response` object that exposes `headers` and the parsed response `body`
- Adds Export API support (experimental, needs tests)
- Adds `symbolize_keys`, `debug`, and `faraday_adapter` as class vars
Expand Down
4 changes: 3 additions & 1 deletion lib/gibbon/export.rb
Expand Up @@ -4,6 +4,8 @@ module Gibbon
class Export
include Helpers

attr_accessor :api_key, :timeout

def initialize(api_key: nil, timeout: nil)
@api_key = api_key || self.class.api_key
@timeout = timeout || self.class.timeout || 600
Expand Down Expand Up @@ -75,7 +77,7 @@ def parse_line(line)
private

def ensure_api_key(params)
unless params[:apikey]
unless params[:apikey] && (get_data_center_from_api_key(params[:apikey]) != "")
raise Gibbon::GibbonError, "You must set an api_key prior to making a call"
end
end
Expand Down
32 changes: 32 additions & 0 deletions spec/gibbon/export_spec.rb
@@ -0,0 +1,32 @@
require 'spec_helper'
require 'webmock/rspec'

describe Gibbon::Export do
before do
Gibbon::Export.send(:public, *Gibbon::Export.protected_instance_methods)
@export = Gibbon::Export.new
end

it "doesn't allow empty api key" do
expect {@export.list(id: "123456")}.to raise_error(Gibbon::GibbonError)
end

it "doesn't allow api key without data center" do
@api_key = "123"
@export.api_key = @api_key
expect {@export.list(id: "123456")}.to raise_error(Gibbon::GibbonError)
end

it "sets correct endpoint from api key" do
@api_key = "TESTKEY-us1"
@export.api_key = @api_key
expect(@export.export_api_url).to eq("http://us1.api.mailchimp.com/export/1.0/")
end

it "sets correct timeout" do
@api_key = "TESTKEY-us1"
@export.api_key = @api_key
@export.timeout = 9
expect(@export.timeout).to eq(9)
end
end
1 change: 0 additions & 1 deletion spec/gibbon/gibbon_spec.rb
Expand Up @@ -134,7 +134,6 @@
Gibbon::APIRequest.send(:public, *Gibbon::APIRequest.protected_instance_methods)

@gibbon = Gibbon::Request.new
@url = "https://api.mailchimp.com/3.0/lists/"
end

it "doesn't allow empty api key" do
Expand Down

0 comments on commit b014637

Please sign in to comment.