chargebee 1.4.5 → 1.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ### v1.4.6 (2014-09-16)
2
+ * * *
3
+
4
+ **Error Model**:
5
+
6
+ New simpler model for error handling has been implemented. Please see below api document for more details
7
+
8
+ https://apidocs.chargebee.com/docs/api?lang=ruby#error_handling
9
+
10
+ The following attributes in APIError have been deprecated.
11
+ * error_code (Use api_error_code instead).
12
+ * http_code (Use http_status_code instead).
13
+ * http_body
14
+
15
+ The changes are backward compatible. Ensure that your error handling code is tested after you upgrade to this version.
16
+
17
+ **APIs Updated**:
18
+
19
+ Shipping Address support added to *create subscription for a customer* api call.
20
+
1
21
  ### v1.4.5 (2014-08-28)
2
22
  * * *
3
23
  * Customer id can be passed to the checkout new subscription operation.
data/chargebee.gemspec CHANGED
@@ -4,8 +4,8 @@ Gem::Specification.new do |s|
4
4
  s.rubygems_version = '1.3.5'
5
5
 
6
6
  s.name = 'chargebee'
7
- s.version = '1.4.5'
8
- s.date = '2014-08-28'
7
+ s.version = '1.4.6'
8
+ s.date = '2014-09-16'
9
9
 
10
10
  s.summary = "Ruby client for Chargebee API."
11
11
  s.description = "Subscription Billing - Simple. Secure. Affordable. More details at www.chargebee.com."
@@ -34,8 +34,8 @@ Gem::Specification.new do |s|
34
34
  Rakefile
35
35
  chargebee.gemspec
36
36
  lib/chargebee.rb
37
- lib/chargebee/api_error.rb
38
37
  lib/chargebee/environment.rb
38
+ lib/chargebee/errors.rb
39
39
  lib/chargebee/list_result.rb
40
40
  lib/chargebee/models/addon.rb
41
41
  lib/chargebee/models/address.rb
data/lib/chargebee.rb CHANGED
@@ -5,7 +5,7 @@ require File.dirname(__FILE__) + '/chargebee/request'
5
5
  require File.dirname(__FILE__) + '/chargebee/result'
6
6
  require File.dirname(__FILE__) + '/chargebee/list_result'
7
7
 
8
- require File.dirname(__FILE__) + '/chargebee/api_error'
8
+ require File.dirname(__FILE__) + '/chargebee/errors'
9
9
 
10
10
  require File.dirname(__FILE__) + '/chargebee/models/model'
11
11
  require File.dirname(__FILE__) + '/chargebee/models/subscription'
@@ -27,7 +27,7 @@ require File.dirname(__FILE__) + '/chargebee/models/download'
27
27
 
28
28
  module ChargeBee
29
29
 
30
- VERSION = '1.4.5'
30
+ VERSION = '1.4.6'
31
31
 
32
32
  @@default_env = nil
33
33
  @@verify_ca_certs = true
@@ -0,0 +1,43 @@
1
+ module ChargeBee
2
+
3
+ class Error < StandardError
4
+ attr_reader :original_error
5
+
6
+ def initialize(message=nil,original_error = nil)
7
+ super message
8
+ @original_error = original_error
9
+ end
10
+ end
11
+
12
+ class IOError < Error; end
13
+
14
+ class APIError < Error
15
+
16
+ attr_reader :http_status_code, :message, :type, :api_error_code, :param, :json_obj,
17
+ #Deprecated attributes
18
+ :http_code, :http_body, :error_code
19
+
20
+ def initialize(http_code=nil, json_obj = nil)
21
+ super json_obj[:message]
22
+ @json_obj = json_obj
23
+ @http_status_code = http_code
24
+ @type = json_obj[:type]
25
+ @api_error_code = json_obj[:api_error_code]
26
+ @param = json_obj[:param]
27
+
28
+ #Deprecated attributes
29
+ @error_code = json_obj[:error_code]
30
+ @http_code = http_code
31
+ @http_body = json_obj.to_s
32
+ end
33
+
34
+ end
35
+
36
+
37
+ class OperationFailedError < APIError; end
38
+
39
+ class InvalidRequestError < APIError; end
40
+
41
+ class PaymentError < APIError; end
42
+
43
+ end
@@ -5,7 +5,7 @@ module ChargeBee
5
5
  module Rest
6
6
 
7
7
  def self.request(method, url, env, params=nil)
8
- raise APIError.new('No environment configured.') unless env
8
+ raise Error.new('No environment configured.') unless env
9
9
  api_key = env.api_key
10
10
  headers = {}
11
11
 
@@ -44,46 +44,48 @@ module ChargeBee
44
44
 
45
45
  begin
46
46
  response = RestClient::Request.execute(opts)
47
- rescue Exception => e
48
- case(e)
49
- when SocketError
50
- raise APIError.new("Error while connecting to chargebee. If you see this repeatedly, contact us at support@chargebee.com")
51
- when RestClient::ExceptionWithResponse
52
- if rcode = e.http_code and rbody = e.http_body
47
+ rescue RestClient::ExceptionWithResponse => e
48
+ if rcode = e.http_code and rbody = e.http_body
53
49
  raise handle_for_error(e, rcode, rbody)
54
- else
55
- raise APIError.new(e.message)
56
- end
57
- when RestClient::Exception
58
- raise APIError.new("Unexpected error received: #{e.message}", e.http_code, e.http_body)
59
50
  else
60
- raise APIError.new(e.message)
51
+ raise IOError.new("IO Exception when trying to connect to chargebee with url #{opts[:url]} . Reason #{e}",e)
61
52
  end
53
+ rescue Exception => e
54
+ raise IOError.new("IO Exception when trying to connect to chargebee with url #{opts[:url]} . Reason #{e}",e)
62
55
  end
63
56
  rbody = response.body
64
57
  rcode = response.code
65
58
  begin
66
59
  resp = JSON.parse(rbody)
67
- rescue JSON::ParserError
68
- raise APIError.new("Invalid response object from API", rcode, rbody)
60
+ rescue Exception => e
61
+ raise Error.new("Response not in JSON format. Probably not a ChargeBee response \n #{rbody.inspect}",e)
69
62
  end
70
-
71
63
  resp = Util.symbolize_keys(resp)
72
64
  resp
73
65
  end
74
66
 
75
67
  def self.handle_for_error(e, rcode=nil, rbody=nil)
76
68
  if(rcode == 204)
77
- raise APIError.new("No response returned by the chargebee api", rcode)
69
+ raise Error.new("No response returned by the chargebee api. The http status code is #{rcode}")
78
70
  end
79
71
  begin
80
72
  error_obj = JSON.parse(rbody)
81
73
  error_obj = Util.symbolize_keys(error_obj)
82
- rescue JSON::ParseError
83
- raise APIError.new("Invalid JSON response #{rbody.inspect} received with HTTP response code #{rcode}", rcode, rbody)
74
+ rescue Exception => e
75
+ raise Error.new("Error response not in JSON format. The http status code is #{rcode} \n #{rbody.inspect}",e)
76
+ end
77
+ type = error_obj[:type]
78
+ if("payment" == type)
79
+ raise PaymentError.new(rcode, error_obj)
80
+ elsif("operation_failed" == type)
81
+ raise OperationFailedError.new(rcode, error_obj)
82
+ elsif("invalid_request" == type)
83
+ raise InvalidRequestError.new(rcode, error_obj)
84
+ else
85
+ raise APIError.new(rcode, error_obj)
84
86
  end
85
- raise APIError.new(error_obj.to_s, rcode, rbody, error_obj)
87
+
86
88
  end
87
89
 
88
90
  end
89
- end
91
+ end
@@ -27,9 +27,9 @@ describe "chargebee" do
27
27
  "id"=>"sub_KyVq7DNSNM7CSD",
28
28
  "plan_id"=>"free",
29
29
  "addons[id][0]"=>"monitor",
30
- "addons[quantity][0]"=>2,
30
+ "addons[quantity][0]"=>"2",
31
31
  "addons[id][1]"=>"ssl",
32
- "addon_ids[0"=>"addon_one",
32
+ "addon_ids[0]"=>"addon_one",
33
33
  "addon_ids[1]"=>"addon_two",
34
34
  "card[first_name]"=>"Rajaraman",
35
35
  "card[last_name]"=>"Santhanam",
@@ -95,15 +95,5 @@ describe "chargebee" do
95
95
  s.id.should eq('sample_subscription')
96
96
  end
97
97
 
98
- it "should raise APIError when error response is received" do
99
- response = mock_response(sample_error, 400)
100
- begin
101
- @request.expects(:execute).once.raises(RestClient::ExceptionWithResponse.new(response, 400))
102
- ChargeBee::Subscription.create({:id => "invalid_subscription"})
103
- rescue ChargeBee::APIError => e
104
- e.http_code.should eq(400)
105
- end
106
- end
107
-
108
98
  end
109
99
 
@@ -71,12 +71,3 @@ def sample_event()
71
71
  }
72
72
  }
73
73
  end
74
-
75
- def sample_error
76
- {
77
- :http_code => "400",
78
- :error_code => "param_not_present",
79
- :message => "plan_id is not present",
80
- :param => "plan_id"
81
- }
82
- end
metadata CHANGED
@@ -1,82 +1,79 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: chargebee
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.6
4
5
  prerelease:
5
- version: 1.4.5
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Rajaraman S
9
9
  - Thiyagarajan T
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2014-08-28 00:00:00 Z
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
13
+ date: 2014-09-16 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
17
16
  name: json_pure
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &9519980 !ruby/object:Gem::Requirement
20
18
  none: false
21
- requirements:
19
+ requirements:
22
20
  - - ~>
23
- - !ruby/object:Gem::Version
24
- version: "1.5"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.5'
25
23
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: rest-client
29
24
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *9519980
26
+ - !ruby/object:Gem::Dependency
27
+ name: rest-client
28
+ requirement: &9519220 !ruby/object:Gem::Requirement
31
29
  none: false
32
- requirements:
30
+ requirements:
33
31
  - - ~>
34
- - !ruby/object:Gem::Version
35
- version: "1.4"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
36
34
  type: :runtime
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: rpsec
40
35
  prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *9519220
37
+ - !ruby/object:Gem::Dependency
38
+ name: rpsec
39
+ requirement: &9518120 !ruby/object:Gem::Requirement
42
40
  none: false
43
- requirements:
41
+ requirements:
44
42
  - - ~>
45
- - !ruby/object:Gem::Version
43
+ - !ruby/object:Gem::Version
46
44
  version: 2.9.0
47
45
  type: :development
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
50
- name: mocha
51
46
  prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
47
+ version_requirements: *9518120
48
+ - !ruby/object:Gem::Dependency
49
+ name: mocha
50
+ requirement: &9516880 !ruby/object:Gem::Requirement
53
51
  none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: "0"
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
58
56
  type: :development
59
- version_requirements: *id004
57
+ prerelease: false
58
+ version_requirements: *9516880
60
59
  description: Subscription Billing - Simple. Secure. Affordable. More details at www.chargebee.com.
61
- email:
60
+ email:
62
61
  - rr@chargebee.com
63
62
  - thiyagu@chargebee.com
64
63
  executables: []
65
-
66
64
  extensions: []
67
-
68
- extra_rdoc_files:
65
+ extra_rdoc_files:
69
66
  - README.rdoc
70
67
  - LICENSE
71
- files:
68
+ files:
72
69
  - CHANGELOG.md
73
70
  - LICENSE
74
71
  - README.rdoc
75
72
  - Rakefile
76
73
  - chargebee.gemspec
77
74
  - lib/chargebee.rb
78
- - lib/chargebee/api_error.rb
79
75
  - lib/chargebee/environment.rb
76
+ - lib/chargebee/errors.rb
80
77
  - lib/chargebee/list_result.rb
81
78
  - lib/chargebee/models/addon.rb
82
79
  - lib/chargebee/models/address.rb
@@ -106,32 +103,30 @@ files:
106
103
  - spec/spec_helper.rb
107
104
  homepage: https://apidocs.chargebee.com/api/docs?lang=ruby
108
105
  licenses: []
109
-
110
106
  post_install_message:
111
- rdoc_options:
107
+ rdoc_options:
112
108
  - --charset=UTF-8
113
- require_paths:
109
+ require_paths:
114
110
  - lib
115
- required_ruby_version: !ruby/object:Gem::Requirement
111
+ required_ruby_version: !ruby/object:Gem::Requirement
116
112
  none: false
117
- requirements:
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- version: "0"
121
- required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
118
  none: false
123
- requirements:
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- version: "0"
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
127
123
  requirements: []
128
-
129
124
  rubyforge_project:
130
- rubygems_version: 1.8.15
125
+ rubygems_version: 1.8.10
131
126
  signing_key:
132
127
  specification_version: 2
133
128
  summary: Ruby client for Chargebee API.
134
- test_files:
129
+ test_files:
135
130
  - spec/chargebee/list_result_spec.rb
136
131
  - spec/chargebee_spec.rb
137
132
  - spec/sample_response.rb
@@ -1,23 +0,0 @@
1
- module ChargeBee
2
- class APIError < StandardError
3
-
4
- attr_reader :message, :http_code, :http_body, :json_obj, :error_code, :param
5
-
6
- def initialize(message=nil, http_code=nil, http_body=nil, json_obj = nil)
7
- @message = message
8
- @http_code = http_code
9
- @http_body = http_body
10
- @json_obj = json_obj
11
- if(json_obj != nil)
12
- @error_code = json_obj[:error_code]
13
- @param = json_obj[:param]
14
- end
15
- end
16
-
17
- def to_s
18
- hc = @http_code.nil? ? "" : "(Http Code #{@http_code}) "
19
- "#{hc}#{@message}"
20
- end
21
-
22
- end
23
- end