netprospex 0.0.1 → 0.0.2

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.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ .rvmrc
data/Rakefile CHANGED
@@ -1 +1,4 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ RSpec::Core::RakeTask.new('spec')
4
+ task :default => :spec
@@ -26,9 +26,9 @@ module NetProspex
26
26
  def api_base
27
27
  @api_base ||= case NetProspex.environment
28
28
  when :production
29
- "http://api.netprospex.com/1.1"
29
+ "http://api.netprospex.com/#{NetProspex.version}"
30
30
  when :sandbox
31
- "http://api-sb.netprospex.com/1.1"
31
+ "http://api-sb.netprospex.com/#{NetProspex.version}"
32
32
  end
33
33
  end
34
34
 
@@ -1,15 +1,21 @@
1
1
  module NetProspex
2
2
  module Configuration
3
3
  attr_accessor :consumer_key, :consumer_secret
4
- attr_reader :environment
4
+ attr_reader :environment, :version
5
+
5
6
  def environment=(env)
6
- if [:production, :sandbox].include? env
7
+ env = env.to_sym
8
+ if [:production, :sandbox].include?(env)
7
9
  @environment = env
8
10
  else
9
- raise NetProspex::ConfigurationError.new("Unknown environment")
11
+ raise NetProspex::ConfigurationError.new("Unknown environment #{env}")
10
12
  end
11
13
  end
12
14
 
15
+ def version=(v)
16
+ @version = v
17
+ end
18
+
13
19
  def self.extended(base)
14
20
  base.reset
15
21
  end
@@ -18,6 +24,7 @@ module NetProspex
18
24
  self.consumer_key = nil
19
25
  self.consumer_secret = nil
20
26
  self.environment = :production
27
+ self.version = "1.1"
21
28
  end
22
29
 
23
30
  def configure
@@ -5,7 +5,8 @@ module NetProspex
5
5
  class RaiseExceptions < Faraday::Middleware
6
6
  def call(environment)
7
7
  @app.call(environment).on_complete do |env|
8
- next unless env[:body].is_a?(Hash) && (error = env[:body][:response][:error])
8
+ next unless env[:body].is_a?(Hash) && env[:body][:response][:error]
9
+ error = env[:body][:response][:error]
9
10
  case error[:code]
10
11
  when "ACL"
11
12
  raise NetProspex::AccessDenied.new(error[:message])
@@ -23,6 +24,8 @@ module NetProspex
23
24
  raise NetProspex::ZeroBalanceError.new(error[:message])
24
25
  when "FAULT","UNX"
25
26
  raise NetProspex::ApiError.new(error[:message])
27
+ else
28
+ raise NetProspex::ApiError.new(error[:message])
26
29
  end
27
30
  end
28
31
  end
@@ -1,3 +1,3 @@
1
1
  module NetProspex
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -10,9 +10,17 @@ describe NetProspex::Client do
10
10
  c.environment = :sandbox
11
11
  end
12
12
  end
13
+ after(:each) { NetProspex.reset }
13
14
 
14
15
  let(:client) { NetProspex::Client.new(ENV['NETPROSPEX_USER_TOKEN'], ENV['NETPROSPEX_USER_SECRET']) }
15
16
 
17
+ it "builds the version into the api url" do
18
+ NetProspex.configure { |c| c.version = "9.9" }
19
+ stub = stub_request(:get, %r(api-sb\.netprospex\.com/9\.9/.*)).to_return(body: '{"response":{}}', headers: {'Content-Type' => 'application/json'})
20
+ client.get("/industries.json")
21
+ stub.should have_been_requested
22
+ end
23
+
16
24
  it "makes GET requests" do
17
25
  VCR.use_cassette("industries") do
18
26
  client.get("/industries.json")
@@ -2,16 +2,24 @@ require "spec_helper"
2
2
  require_relative "../../lib/netprospex.rb"
3
3
 
4
4
  describe NetProspex::Configuration do
5
+ after(:each) { NetProspex.reset }
6
+
5
7
  it "can be configured" do
6
8
  expect {
7
9
  NetProspex.configure do |config|
8
10
  config.consumer_key = "foo"
9
11
  config.consumer_secret = "bar"
10
12
  config.environment = :sandbox
13
+ config.version = "1.1"
11
14
  end
12
15
  }.to_not raise_exception
13
16
  end
14
17
 
18
+ it "stores the api version" do
19
+ NetProspex.configure { |config| config.version = "9.9" }
20
+ NetProspex.version.should == "9.9"
21
+ end
22
+
15
23
  it "validates environment" do
16
24
  expect {
17
25
  NetProspex.configure do |config|
@@ -19,4 +27,9 @@ describe NetProspex::Configuration do
19
27
  end
20
28
  }.to raise_exception(NetProspex::ConfigurationError)
21
29
  end
30
+
31
+ it "accepts environment as a string" do
32
+ NetProspex.configure { |config| config.environment = "sandbox" }
33
+ NetProspex.environment.should == :sandbox
34
+ end
22
35
  end
@@ -80,4 +80,14 @@ describe NetProspex::Middleware::RaiseExceptions do
80
80
  puts client.get('/person/list.json', organization_name: 'Pardot')
81
81
  }.to raise_exception(NetProspex::ApiError)
82
82
  end
83
+
84
+ it "raises ApiError for version error" do
85
+ stub_request(:get, %r(api-sb\.netprospex\.com/1\.1/person/list\.json)).to_return(
86
+ body: '{"response":{"version":"1.1","responseId":"8A3837BF-AB10-F3B4-EA19-0606207939CE","responseType":"error","request":{"startTime":"2013-09-04 09:18:21","requestType":"person_list","url":"\/1.1\/person\/list.json?firstName=Bob&lastName=Colananni&preview=1","userId":"1aebe6ed-6c79-11e2-a4df-f04da23ce7b0"},"transaction":{"accountId":"1ad39da8-6c79-11e2-a4df-f04da23ce7b0","accountStartBalance":100000,"accountEndBalance":null},"error":{"message":"invalid API version=1.1","code":"ARG"},"debug":{"requestTime":0.0185089111328}}}',
87
+ headers: {'Content-Type' => 'application/json'}
88
+ )
89
+ expect {
90
+ puts client.get('/person/list.json', organization_name: 'Pardot')
91
+ }.to raise_exception(NetProspex::ApiError)
92
+ end
83
93
  end
data/spec/vcr_helper.rb CHANGED
@@ -3,7 +3,7 @@ require "vcr"
3
3
  VCR.configure do |c|
4
4
  c.cassette_library_dir = "fixtures/cassettes"
5
5
  c.hook_into :webmock
6
- c.default_cassette_options = { :record => :new_episodes }
6
+ c.default_cassette_options = { :record => :once }
7
7
  c.configure_rspec_metadata!
8
8
  c.filter_sensitive_data('<NETPROSPEX_KEY>') { ENV['NETPROSPEX_KEY'] }
9
9
  c.filter_sensitive_data('<NETPROSPEX_SECRET>') { ENV['NETPROSPEX_SECRET'] }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netprospex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-21 00:00:00.000000000 Z
12
+ date: 2013-09-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler