killbill-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +3 -0
  3. data/README.md +18 -0
  4. data/Rakefile +26 -0
  5. data/killbill_client.gemspec +44 -0
  6. data/lib/killbill_client.rb +93 -0
  7. data/lib/killbill_client/api/api.rb +85 -0
  8. data/lib/killbill_client/api/errors.rb +175 -0
  9. data/lib/killbill_client/api/net_http_adapter.rb +131 -0
  10. data/lib/killbill_client/models/account.rb +36 -0
  11. data/lib/killbill_client/models/gen/account_attributes.rb +51 -0
  12. data/lib/killbill_client/models/gen/account_attributes_simple.rb +33 -0
  13. data/lib/killbill_client/models/gen/account_attributes_with_balance.rb +52 -0
  14. data/lib/killbill_client/models/gen/account_attributes_with_balance_and_c_b_a.rb +53 -0
  15. data/lib/killbill_client/models/gen/account_email_attributes.rb +33 -0
  16. data/lib/killbill_client/models/gen/account_timeline_attributes.rb +35 -0
  17. data/lib/killbill_client/models/gen/analytics_sanity_attributes.rb +36 -0
  18. data/lib/killbill_client/models/gen/audit_log_attributes.rb +37 -0
  19. data/lib/killbill_client/models/gen/bundle_attributes_no_subscriptions.rb +36 -0
  20. data/lib/killbill_client/models/gen/bundle_attributes_simple.rb +34 -0
  21. data/lib/killbill_client/models/gen/bundle_attributes_with_subscriptions.rb +35 -0
  22. data/lib/killbill_client/models/gen/bundle_timeline_attributes.rb +36 -0
  23. data/lib/killbill_client/models/gen/business_account_attributes.rb +41 -0
  24. data/lib/killbill_client/models/gen/business_field_attributes.rb +35 -0
  25. data/lib/killbill_client/models/gen/business_invoice_attributes.rb +43 -0
  26. data/lib/killbill_client/models/gen/business_invoice_item_attributes.rb +46 -0
  27. data/lib/killbill_client/models/gen/business_invoice_payment_attributes.rb +50 -0
  28. data/lib/killbill_client/models/gen/business_overdue_status_attributes.rb +37 -0
  29. data/lib/killbill_client/models/gen/business_snapshot_attributes.rb +38 -0
  30. data/lib/killbill_client/models/gen/business_subscription_transition_attributes.rb +64 -0
  31. data/lib/killbill_client/models/gen/business_tag_attributes.rb +34 -0
  32. data/lib/killbill_client/models/gen/catalog_attributes_simple.rb +33 -0
  33. data/lib/killbill_client/models/gen/chargeback_attributes.rb +37 -0
  34. data/lib/killbill_client/models/gen/chargeback_collection_attributes.rb +33 -0
  35. data/lib/killbill_client/models/gen/credit_attributes.rb +39 -0
  36. data/lib/killbill_client/models/gen/credit_collection_attributes.rb +33 -0
  37. data/lib/killbill_client/models/gen/custom_field_attributes.rb +33 -0
  38. data/lib/killbill_client/models/gen/invoice_attributes_simple.rb +42 -0
  39. data/lib/killbill_client/models/gen/invoice_attributes_with_bundle_keys.rb +44 -0
  40. data/lib/killbill_client/models/gen/invoice_attributes_with_items.rb +43 -0
  41. data/lib/killbill_client/models/gen/invoice_email_attributes.rb +33 -0
  42. data/lib/killbill_client/models/gen/invoice_item_attributes_simple.rb +45 -0
  43. data/lib/killbill_client/models/gen/notification_attributes.rb +35 -0
  44. data/lib/killbill_client/models/gen/overdue_state_attributes.rb +38 -0
  45. data/lib/killbill_client/models/gen/payment_attributes_simple.rb +47 -0
  46. data/lib/killbill_client/models/gen/payment_attributes_with_bundle_keys.rb +50 -0
  47. data/lib/killbill_client/models/gen/payment_method_attributes.rb +36 -0
  48. data/lib/killbill_client/models/gen/payment_method_plugin_detail_attributes.rb +46 -0
  49. data/lib/killbill_client/models/gen/payment_method_properties.rb +34 -0
  50. data/lib/killbill_client/models/gen/phase_attributes.rb +33 -0
  51. data/lib/killbill_client/models/gen/plan_attributes.rb +33 -0
  52. data/lib/killbill_client/models/gen/plan_detail_attributes.rb +36 -0
  53. data/lib/killbill_client/models/gen/product_attributes.rb +36 -0
  54. data/lib/killbill_client/models/gen/refund_attributes.rb +40 -0
  55. data/lib/killbill_client/models/gen/require_gen.rb +80 -0
  56. data/lib/killbill_client/models/gen/subscription_attributes_no_events.rb +41 -0
  57. data/lib/killbill_client/models/gen/subscription_attributes_simple.rb +33 -0
  58. data/lib/killbill_client/models/gen/subscription_attributes_with_events.rb +36 -0
  59. data/lib/killbill_client/models/gen/subscription_deleted_event_attributes.rb +40 -0
  60. data/lib/killbill_client/models/gen/subscription_new_event_attributes.rb +38 -0
  61. data/lib/killbill_client/models/gen/subscription_read_event_attributes.rb +40 -0
  62. data/lib/killbill_client/models/gen/tag_attributes.rb +34 -0
  63. data/lib/killbill_client/models/gen/tag_definition_attributes.rb +36 -0
  64. data/lib/killbill_client/models/gen/tenant_attributes.rb +35 -0
  65. data/lib/killbill_client/models/gen/tenant_key_attributes.rb +33 -0
  66. data/lib/killbill_client/models/gen/time_series_data_attributes.rb +33 -0
  67. data/lib/killbill_client/models/invoice.rb +7 -0
  68. data/lib/killbill_client/models/invoice_item.rb +17 -0
  69. data/lib/killbill_client/models/models.rb +15 -0
  70. data/lib/killbill_client/models/payment.rb +6 -0
  71. data/lib/killbill_client/models/payment_method.rb +92 -0
  72. data/lib/killbill_client/models/resource.rb +125 -0
  73. data/lib/killbill_client/models/tag_definition.rb +6 -0
  74. data/lib/killbill_client/utils.rb +30 -0
  75. data/lib/killbill_client/version.rb +18 -0
  76. data/lib/rails/generators/killbill_client/config_generator.rb +17 -0
  77. data/lib/rails/killbill_client.rb +7 -0
  78. data/spec/killbill_client/remote/api_spec.rb +10 -0
  79. data/spec/killbill_client/remote/model_spec.rb +77 -0
  80. data/spec/spec_helper.rb +31 -0
  81. metadata +165 -0
@@ -0,0 +1,34 @@
1
+ ###################################################################################
2
+ # #
3
+ # Copyright 2010-2013 Ning, Inc. #
4
+ # #
5
+ # Ning licenses this file to you under the Apache License, version 2.0 #
6
+ # (the "License"); you may not use this file except in compliance with the #
7
+ # License. You may obtain a copy of the License at: #
8
+ # #
9
+ # http://www.apache.org/licenses/LICENSE-2.0 #
10
+ # #
11
+ # Unless required by applicable law or agreed to in writing, software #
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT #
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the #
14
+ # License for the specific language governing permissions and limitations #
15
+ # under the License. #
16
+ # #
17
+ ###################################################################################
18
+
19
+
20
+ #
21
+ # DO NOT EDIT!!!
22
+ # File automatically generated by killbill-java-parser (git@github.com:killbill/killbill-java-parser.git)
23
+ #
24
+
25
+
26
+ module KillBillClient
27
+ module Model
28
+ class TagAttributes < Resource
29
+ attribute :tag_definition_id
30
+ attribute :tag_definition_name
31
+ attribute :audit_logs
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ ###################################################################################
2
+ # #
3
+ # Copyright 2010-2013 Ning, Inc. #
4
+ # #
5
+ # Ning licenses this file to you under the Apache License, version 2.0 #
6
+ # (the "License"); you may not use this file except in compliance with the #
7
+ # License. You may obtain a copy of the License at: #
8
+ # #
9
+ # http://www.apache.org/licenses/LICENSE-2.0 #
10
+ # #
11
+ # Unless required by applicable law or agreed to in writing, software #
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT #
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the #
14
+ # License for the specific language governing permissions and limitations #
15
+ # under the License. #
16
+ # #
17
+ ###################################################################################
18
+
19
+
20
+ #
21
+ # DO NOT EDIT!!!
22
+ # File automatically generated by killbill-java-parser (git@github.com:killbill/killbill-java-parser.git)
23
+ #
24
+
25
+
26
+ module KillBillClient
27
+ module Model
28
+ class TagDefinitionAttributes < Resource
29
+ attribute :id
30
+ attribute :is_control_tag
31
+ attribute :name
32
+ attribute :description
33
+ attribute :applicable_object_types
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,35 @@
1
+ ###################################################################################
2
+ # #
3
+ # Copyright 2010-2013 Ning, Inc. #
4
+ # #
5
+ # Ning licenses this file to you under the Apache License, version 2.0 #
6
+ # (the "License"); you may not use this file except in compliance with the #
7
+ # License. You may obtain a copy of the License at: #
8
+ # #
9
+ # http://www.apache.org/licenses/LICENSE-2.0 #
10
+ # #
11
+ # Unless required by applicable law or agreed to in writing, software #
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT #
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the #
14
+ # License for the specific language governing permissions and limitations #
15
+ # under the License. #
16
+ # #
17
+ ###################################################################################
18
+
19
+
20
+ #
21
+ # DO NOT EDIT!!!
22
+ # File automatically generated by killbill-java-parser (git@github.com:killbill/killbill-java-parser.git)
23
+ #
24
+
25
+
26
+ module KillBillClient
27
+ module Model
28
+ class TenantAttributes < Resource
29
+ attribute :tenant_id
30
+ attribute :external_key
31
+ attribute :api_key
32
+ attribute :api_secret
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,33 @@
1
+ ###################################################################################
2
+ # #
3
+ # Copyright 2010-2013 Ning, Inc. #
4
+ # #
5
+ # Ning licenses this file to you under the Apache License, version 2.0 #
6
+ # (the "License"); you may not use this file except in compliance with the #
7
+ # License. You may obtain a copy of the License at: #
8
+ # #
9
+ # http://www.apache.org/licenses/LICENSE-2.0 #
10
+ # #
11
+ # Unless required by applicable law or agreed to in writing, software #
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT #
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the #
14
+ # License for the specific language governing permissions and limitations #
15
+ # under the License. #
16
+ # #
17
+ ###################################################################################
18
+
19
+
20
+ #
21
+ # DO NOT EDIT!!!
22
+ # File automatically generated by killbill-java-parser (git@github.com:killbill/killbill-java-parser.git)
23
+ #
24
+
25
+
26
+ module KillBillClient
27
+ module Model
28
+ class TenantKeyAttributes < Resource
29
+ attribute :key
30
+ attribute :values
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ ###################################################################################
2
+ # #
3
+ # Copyright 2010-2013 Ning, Inc. #
4
+ # #
5
+ # Ning licenses this file to you under the Apache License, version 2.0 #
6
+ # (the "License"); you may not use this file except in compliance with the #
7
+ # License. You may obtain a copy of the License at: #
8
+ # #
9
+ # http://www.apache.org/licenses/LICENSE-2.0 #
10
+ # #
11
+ # Unless required by applicable law or agreed to in writing, software #
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT #
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the #
14
+ # License for the specific language governing permissions and limitations #
15
+ # under the License. #
16
+ # #
17
+ ###################################################################################
18
+
19
+
20
+ #
21
+ # DO NOT EDIT!!!
22
+ # File automatically generated by killbill-java-parser (git@github.com:killbill/killbill-java-parser.git)
23
+ #
24
+
25
+
26
+ module KillBillClient
27
+ module Model
28
+ class TimeSeriesDataAttributes < Resource
29
+ attribute :dates
30
+ attribute :values
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ module KillBillClient
2
+ module Model
3
+ class Invoice < InvoiceAttributesSimple
4
+ KILLBILL_API_INVOICES_PREFIX = "#{KILLBILL_API_PREFIX}/invoices"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ module KillBillClient
2
+ module Model
3
+ class InvoiceItem < InvoiceItemAttributesSimple
4
+ def create(user = nil, reason = nil, comment = nil)
5
+ created_invoice_item = self.class.post "#{Invoice::KILLBILL_API_INVOICES_PREFIX}/charges",
6
+ to_json,
7
+ {},
8
+ {
9
+ :user => user,
10
+ :reason => reason,
11
+ :comment => comment,
12
+ }
13
+ created_invoice_item.refresh(Invoice)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ require 'killbill_client/models/resource'
2
+
3
+ require 'killbill_client/models/gen/require_gen'
4
+
5
+ require 'killbill_client/models/account'
6
+ require 'killbill_client/models/invoice'
7
+ require 'killbill_client/models/invoice_item'
8
+ require 'killbill_client/models/payment'
9
+ require 'killbill_client/models/payment_method'
10
+ require 'killbill_client/models/tag_definition'
11
+
12
+ module KillBillClient
13
+ module Model
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ module KillBillClient
2
+ module Model
3
+ class Payment < PaymentAttributesSimple
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,92 @@
1
+ module KillBillClient
2
+ module Model
3
+ class PaymentMethod < PaymentMethodAttributes
4
+ KILLBILL_API_PAYMENT_METHODS_PREFIX = "#{KILLBILL_API_PREFIX}/paymentMethods"
5
+
6
+ class << self
7
+ def find_by_id(payment_method_id, with_plugin_info = false)
8
+ get "#{KILLBILL_API_PAYMENT_METHODS_PREFIX}/#{payment_method_id}",
9
+ {
10
+ :withPluginInfo => with_plugin_info
11
+ }
12
+ end
13
+
14
+ def find_all_by_account_id(account_id, with_plugin_info = false)
15
+ get "#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/paymentMethods",
16
+ {
17
+ :withPluginInfo => with_plugin_info
18
+ }
19
+ end
20
+
21
+ def set_default(payment_method_id, account_id, user = nil, reason = nil, comment = nil)
22
+ put "#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/paymentMethods/#{payment_method_id}/setDefault",
23
+ nil,
24
+ {},
25
+ {
26
+ :user => user,
27
+ :reason => reason,
28
+ :comment => comment,
29
+ }
30
+ end
31
+
32
+ def destroy(payment_method_id, set_auto_pay_off = false, user = nil, reason = nil, comment = nil)
33
+ delete "#{KILLBILL_API_PAYMENT_METHODS_PREFIX}/#{payment_method_id}",
34
+ {
35
+ :deleteDefaultPmWithAutoPayOff => set_auto_pay_off
36
+ },
37
+ {
38
+ :user => user,
39
+ :reason => reason,
40
+ :comment => comment,
41
+ }
42
+ end
43
+ end
44
+
45
+ def create(set_default = true, user = nil, reason = nil, comment = nil)
46
+ created_pm = self.class.post "#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/paymentMethods",
47
+ to_json,
48
+ {
49
+ :isDefault => set_default
50
+ },
51
+ {
52
+ :user => user,
53
+ :reason => reason,
54
+ :comment => comment,
55
+ }
56
+ created_pm.refresh
57
+ end
58
+
59
+ def destroy(set_auto_pay_off = false, user = nil, reason = nil, comment = nil)
60
+ self.class.destroy(payment_method_id, set_auto_pay_off, user, reason, comment)
61
+ end
62
+
63
+ def plugin_info=(info)
64
+ @plugin_info = PaymentMethodPluginDetailAttributes.new
65
+ @plugin_info.properties = []
66
+ return if info.nil?
67
+
68
+ @plugin_info.external_payment_id = info['externalPaymentId']
69
+
70
+ if info['properties'].nil?
71
+ # Convenience method to create properties to add a payment method
72
+ info.each do |key, value|
73
+ property = PaymentMethodProperties.new
74
+ property.key = key
75
+ property.value = value
76
+ property.is_updatable = false
77
+ @plugin_info.properties << property
78
+ end
79
+ else
80
+ # De-serialization from JSON payload
81
+ info['properties'].each do |property_json|
82
+ property = PaymentMethodProperty.new
83
+ property.key = property_json['key']
84
+ property.value = property_json['value']
85
+ property.is_updatable = property_json['isUpdatable']
86
+ @plugin_info.properties << property
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,125 @@
1
+ require 'json'
2
+
3
+ module KillBillClient
4
+ module Model
5
+ class Resource
6
+
7
+ KILLBILL_API_PREFIX = '/1.0/kb/'
8
+
9
+ class << self
10
+ def head(uri, params = {}, options = {}, clazz = self)
11
+ response = KillBillClient::API.head uri, params, options
12
+ from_response clazz, response
13
+ end
14
+
15
+ def get(uri, params = {}, options = {}, clazz = self)
16
+ response = KillBillClient::API.get uri, params, options
17
+ from_response clazz, response
18
+ end
19
+
20
+ def post(uri, body = nil, params = {}, options = {}, clazz = self)
21
+ response = KillBillClient::API.post uri, body, params, options
22
+ from_response clazz, response
23
+ end
24
+
25
+ def put(uri, body = nil, params = {}, options = {}, clazz = self)
26
+ response = KillBillClient::API.put uri, body, params, options
27
+ from_response clazz, response
28
+ end
29
+
30
+ def delete(uri, params = {}, options = {}, clazz = self)
31
+ response = KillBillClient::API.delete uri, params, options
32
+ from_response clazz, response
33
+ end
34
+
35
+ # Instantiates a record from an HTTP response, setting the record's
36
+ # response attribute in the process.
37
+ #
38
+ # @return [Resource]
39
+ # @param resource_class [Resource]
40
+ # @param response [Net::HTTPResponse]
41
+ def from_response(resource_class, response)
42
+ case response['Content-Type']
43
+ when %r{application/pdf}
44
+ response.body
45
+ when %r{application/json}
46
+ record = from_json resource_class, response.body
47
+ record.instance_eval { @etag, @response = response['ETag'], response }
48
+ record
49
+ else
50
+ raise ArgumentError, "#{response['Content-Type']} is not supported by the library"
51
+ end
52
+ end
53
+
54
+ # Instantiates a record from a JSON blob.
55
+ #
56
+ # @return [Resource]
57
+ # @param resource_class [Resource]
58
+ # @param json [String]
59
+ # @see from_response
60
+ def from_json(resource_class, json)
61
+ # e.g. DELETE
62
+ return nil if json.nil? or json.size == 0
63
+
64
+ data = JSON.parse json
65
+ if data.is_a? Array
66
+ records = []
67
+ data.each do |data_element|
68
+ records << instantiate_record_from_json(resource_class, data_element)
69
+ end
70
+ records
71
+ else
72
+ instantiate_record_from_json(resource_class, data)
73
+ end
74
+ end
75
+
76
+ def instantiate_record_from_json(resource_class, data)
77
+ record = resource_class.send :new
78
+ data.each { |k, v| record.send("#{Utils.underscore k}=", v) }
79
+ record
80
+ end
81
+
82
+ def attribute(name)
83
+ self.send('attr_accessor', name.to_sym)
84
+
85
+ self.instance_variable_set('@json_attributes', []) unless self.instance_variable_get('@json_attributes')
86
+ self.instance_variable_get('@json_attributes') << name.to_s
87
+
88
+ attributes = self.instance_variable_get('@json_attributes')
89
+ (
90
+ class << self;
91
+ self
92
+ end).send(:define_method, :json_attributes) do
93
+ attributes
94
+ end
95
+ end
96
+ end
97
+
98
+ # Set on create call
99
+ attr_accessor :uri
100
+
101
+ def to_hash
102
+ json_hash = {}
103
+ self.class.json_attributes.each do |name|
104
+ value = self.send(name)
105
+ if value
106
+ json_hash[Utils.camelize name, :lower] = value.is_a?(Resource) ? value.to_hash : value
107
+ end
108
+ end
109
+ json_hash
110
+ end
111
+
112
+ def to_json
113
+ to_hash.to_json
114
+ end
115
+
116
+ def refresh(clazz=self.class)
117
+ if @uri
118
+ self.class.get @uri, {}, {}, clazz
119
+ else
120
+ self
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end