rspreedly 0.1.0 → 0.1.1

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -6,7 +6,7 @@ module RSpreedly
6
6
  base_uri "https://spreedly.com/api/v4"
7
7
 
8
8
  def self.api_request(type, path, options={})
9
- path = "#{RSpreedly::Config.site_name}#{path}"
9
+ path = "/#{::RSpreedly::Config.site_name}#{path}"
10
10
  options.merge!({
11
11
  :basic_auth => {:username => RSpreedly::Config.api_key, :password => 'X'},
12
12
  :headers => {"Content-Type" => 'application/xml'}
@@ -19,6 +19,8 @@ module RSpreedly
19
19
  message = "#{response.code}: #{response.body}"
20
20
 
21
21
  case response.code.to_i
22
+ when 401
23
+ raise(RSpreedly::Error::AccessDenied.new, message)
22
24
  when 403
23
25
  raise(RSpreedly::Error::Forbidden.new, message)
24
26
  when 422
@@ -1,3 +1,4 @@
1
+ require 'pp'
1
2
  module RSpreedly
2
3
  module Config
3
4
  class << self
@@ -11,8 +12,8 @@ module RSpreedly
11
12
  {
12
13
  :logger => defined?(RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : Logger.new(STDOUT),
13
14
  :debug => false,
14
- :site_name => nil, # your site name
15
- :key => nil # your API key
15
+ :site_name => "your-site-name",
16
+ :api_key => "your-api-key"
16
17
  }
17
18
  end
18
19
 
@@ -1,6 +1,7 @@
1
1
  module RSpreedly
2
2
  module Error
3
- class Base < StandardError; end
3
+ class Base < StandardError; end
4
+ class AccessDenied < Base; end # 401 errors
4
5
  class Forbidden < Base; end # 403 errors
5
6
  class BadRequest < Base; end # 422 errors
6
7
  class NotFound < Base; end # 404 errors
data/rspreedly.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rspreedly}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Richard Livsey"]
9
- s.date = %q{2009-10-29}
9
+ s.date = %q{2009-10-30}
10
10
  s.email = %q{richard@livsey.org}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  "lib/rspreedly/subscriber.rb",
32
32
  "lib/rspreedly/subscription_plan.rb",
33
33
  "rspreedly.gemspec",
34
+ "spec/base_spec.rb",
34
35
  "spec/config_spec.rb",
35
36
  "spec/fixtures/complimentary_failed_active.xml",
36
37
  "spec/fixtures/complimentary_failed_inactive.xml",
@@ -69,7 +70,8 @@ Gem::Specification.new do |s|
69
70
  s.rubygems_version = %q{1.3.5}
70
71
  s.summary = %q{Ruby library for the Spreedly API}
71
72
  s.test_files = [
72
- "spec/config_spec.rb",
73
+ "spec/base_spec.rb",
74
+ "spec/config_spec.rb",
73
75
  "spec/invoice_spec.rb",
74
76
  "spec/spec_helper.rb",
75
77
  "spec/subscriber_spec.rb",
data/spec/base_spec.rb ADDED
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ describe RSpreedly::Base do
3
+
4
+ describe "#api_request" do
5
+ it "should raise AccessDenied if a 401 is receiver" do
6
+ stub_http_with_code(401)
7
+ lambda{
8
+ RSpreedly::Base.api_request(:put, '/')
9
+ }.should raise_error(RSpreedly::Error::AccessDenied)
10
+ end
11
+ end
12
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,18 +1,14 @@
1
1
  require 'rubygems'
2
2
  require 'spec'
3
-
3
+ require 'net-http-spy'
4
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
5
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
6
  require 'rspreedly'
7
7
 
8
- # setup a config with dummy data
9
- RSpreedly::Config.setup do |config|
10
- config.api_key = "your-api-key-here"
11
- config.site_name = "you-site-name-here"
12
- end
13
-
14
8
  Spec::Runner.configure do |config|
15
-
9
+ config.before(:each) do
10
+ RSpreedly::Config.reset
11
+ end
16
12
  end
17
13
 
18
14
  def load_fixture(file)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspreedly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Livsey
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-29 00:00:00 +01:00
12
+ date: 2009-10-30 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -41,6 +41,7 @@ files:
41
41
  - lib/rspreedly/subscriber.rb
42
42
  - lib/rspreedly/subscription_plan.rb
43
43
  - rspreedly.gemspec
44
+ - spec/base_spec.rb
44
45
  - spec/config_spec.rb
45
46
  - spec/fixtures/complimentary_failed_active.xml
46
47
  - spec/fixtures/complimentary_failed_inactive.xml
@@ -101,6 +102,7 @@ signing_key:
101
102
  specification_version: 3
102
103
  summary: Ruby library for the Spreedly API
103
104
  test_files:
105
+ - spec/base_spec.rb
104
106
  - spec/config_spec.rb
105
107
  - spec/invoice_spec.rb
106
108
  - spec/spec_helper.rb