rspreedly 0.1.6 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -63,10 +63,10 @@ View all plans
63
63
 
64
64
  Raise an invoice, and pay it
65
65
 
66
- invoice = Invoice.new(:subscription_plan_id => 5, :subscriber => sub)
66
+ invoice = RSpreedly::Invoice.new(:subscription_plan_id => 5, :subscriber => sub)
67
67
  invoice.save
68
68
 
69
- payment = RSpreedly::PaymentMethod::CreditCard(:card_type => 'visa', :number => '123456', ...)
69
+ payment = RSpreedly::PaymentMethod::CreditCard.new(:card_type => 'visa', :number => '123456', ...)
70
70
  invoice.pay(payment)
71
71
 
72
72
  Error messages
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.8
@@ -8,29 +8,35 @@ module RSpreedly
8
8
  attr_reader :errors
9
9
 
10
10
  def self.api_request(type, path, options={})
11
- path = "/#{::RSpreedly::Config.site_name}#{path}"
11
+ site_name = RSpreedly::Config.site_name.class == Array ? RSpreedly::Config.site_name.first : RSpreedly::Config.site_name
12
+ api_key = RSpreedly::Config.api_key.class == Array ? RSpreedly::Config.api_key.first : RSpreedly::Config.api_key
13
+ path = "/#{site_name}#{path}"
14
+
12
15
  options.merge!({
13
- :basic_auth => {:username => RSpreedly::Config.api_key, :password => 'X'},
16
+ :basic_auth => {:username => api_key, :password => 'X'},
14
17
  :headers => {"Content-Type" => 'application/xml'}
15
18
  })
16
19
  self.do_request(type, path, options)
17
20
  end
18
21
 
19
22
  def self.do_request(type, path, options)
20
- response = self.send(type.to_s, path, options)
21
- message = "#{response.code}: #{response.body}"
23
+ begin
24
+ response = self.send(type.to_s, path, options)
25
+ rescue SocketError
26
+ raise(RSpreedly::Error::ConnectionFailed.new, "Failed to connect to payment gateway.")
27
+ end
22
28
 
23
29
  case response.code.to_i
24
30
  when 401
25
- raise(RSpreedly::Error::AccessDenied.new(response), message)
31
+ raise(RSpreedly::Error::AccessDenied.new(response), response.body)
26
32
  when 403
27
- raise(RSpreedly::Error::Forbidden.new(response), message)
33
+ raise(RSpreedly::Error::Forbidden.new(response), response.body)
28
34
  when 422
29
- raise(RSpreedly::Error::BadRequest.new(response), message)
35
+ raise(RSpreedly::Error::BadRequest.new(response), response.body)
30
36
  when 404
31
- raise(RSpreedly::Error::NotFound.new(response), message)
37
+ raise(RSpreedly::Error::NotFound.new(response), response.body)
32
38
  when 504
33
- raise(RSpreedly::Error::GatewayTimeout.new(response), message)
39
+ raise(RSpreedly::Error::GatewayTimeout.new(response), response.body)
34
40
  end
35
41
 
36
42
  response
@@ -58,6 +64,8 @@ module RSpreedly
58
64
  else
59
65
  @errors = [e.response.body]
60
66
  end
67
+ else
68
+ @errors = [e.message]
61
69
  end
62
70
  raise
63
71
  end
@@ -79,7 +87,7 @@ module RSpreedly
79
87
  xml << "<#{tag}>" unless no_tag
80
88
  xml << "<#{inner}>" if inner
81
89
  self.instance_variables.each do |var|
82
- name = var.gsub('@', '')
90
+ name = var.to_s.gsub('@', '')
83
91
  next if exclude.include?(name.to_sym)
84
92
  value = self.instance_variable_get(var)
85
93
  if value.respond_to?(:to_xml)
@@ -9,10 +9,11 @@ module RSpreedly
9
9
  end
10
10
  end
11
11
 
12
- class AccessDenied < Base; end # 401 errors
13
- class Forbidden < Base; end # 403 errors
14
- class BadRequest < Base; end # 422 errors
15
- class NotFound < Base; end # 404 errors
16
- class GatewayTimeout < Base; end # 504 errors
12
+ class AccessDenied < Base; end # 401 errors
13
+ class Forbidden < Base; end # 403 errors
14
+ class BadRequest < Base; end # 422 errors
15
+ class NotFound < Base; end # 404 errors
16
+ class GatewayTimeout < Base; end # 504 errors
17
+ class ConnectionFailed< Base; end
17
18
  end
18
19
  end
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.6"
5
+ s.version = "0.1.8"
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-11-04}
9
+ s.date = %q{2009-11-25}
10
10
  s.email = %q{richard@livsey.org}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
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.6
4
+ version: 0.1.8
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-11-04 00:00:00 +01:00
12
+ date: 2009-11-25 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15