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,131 @@
1
+ require 'cgi'
2
+ require 'net/https'
3
+
4
+ module KillBillClient
5
+ class API
6
+ module Net
7
+ module HTTPAdapter
8
+ # A hash of Net::HTTP settings configured before the request.
9
+ #
10
+ # @return [Hash]
11
+ def net_http
12
+ @net_http ||= {}
13
+ end
14
+
15
+ # Used to store any Net::HTTP settings.
16
+ #
17
+ # @example
18
+ # KillBillClient::API.net_http = {
19
+ # :verify_mode => OpenSSL::SSL::VERIFY_PEER,
20
+ # :ca_path => "/etc/ssl/certs",
21
+ # :ca_file => "/opt/local/share/curl/curl-ca-bundle.crt"
22
+ # }
23
+ attr_writer :net_http
24
+
25
+ private
26
+
27
+ METHODS = {
28
+ :head => ::Net::HTTP::Head,
29
+ :get => ::Net::HTTP::Get,
30
+ :post => ::Net::HTTP::Post,
31
+ :put => ::Net::HTTP::Put,
32
+ :delete => ::Net::HTTP::Delete
33
+ }
34
+
35
+ def request(method, relative_uri, options = {})
36
+ head = headers.dup
37
+ head.update options[:head] if options[:head]
38
+ head.delete_if { |_, value| value.nil? }
39
+
40
+ uri = base_uri + URI.escape(relative_uri)
41
+
42
+ if options[:params] && !options[:params].empty?
43
+ pairs = options[:params].map { |key, value|
44
+ "#{CGI.escape key.to_s}=#{CGI.escape value.to_s}"
45
+ }
46
+ uri += "?#{pairs.join '&'}"
47
+ end
48
+ request = METHODS[method].new uri.request_uri, head
49
+
50
+ # Configure auth, if enabled
51
+ if KillBillClient.api_key and KillBillClient.api_secret
52
+ request.basic_auth(*[KillBillClient.api_key, KillBillClient.api_secret].flatten[0, 2])
53
+ end
54
+
55
+ if options[:body]
56
+ request['Content-Type'] = content_type
57
+ request.body = options[:body]
58
+ end
59
+ if options[:etag]
60
+ request['If-None-Match'] = options[:etag]
61
+ end
62
+ if options[:locale]
63
+ request['Accept-Language'] = options[:locale]
64
+ end
65
+
66
+ # Add auditing headers, if needed
67
+ if options[:user]
68
+ request['X-Killbill-CreatedBy'] = options[:user]
69
+ end
70
+ if options[:reason]
71
+ request['X-Killbill-Reason'] = options[:reason]
72
+ end
73
+ if options[:comment]
74
+ request['X-Killbill-Comment'] = options[:comment]
75
+ end
76
+
77
+ http = ::Net::HTTP.new uri.host, uri.port
78
+ http.use_ssl = uri.scheme == 'https'
79
+ net_http.each_pair { |key, value| http.send "#{key}=", value }
80
+
81
+ if KillBillClient.logger
82
+ KillBillClient.log :info, '===> %s %s' % [request.method, uri]
83
+ headers = request.to_hash
84
+ headers['authorization'] &&= ['Basic [FILTERED]']
85
+ KillBillClient.log :debug, headers.inspect
86
+ if request.body && !request.body.empty?
87
+ KillBillClient.log :debug, request.body
88
+ end
89
+ start_time = Time.now
90
+ end
91
+
92
+ response = http.start { http.request request }
93
+ code = response.code.to_i
94
+
95
+ if KillBillClient.logger
96
+ #noinspection RubyScope
97
+ latency = (Time.now - start_time) * 1_000
98
+ level = case code
99
+ when 200...300 then
100
+ :info
101
+ when 300...400 then
102
+ :warn
103
+ when 400...500 then
104
+ :error
105
+ else
106
+ :fatal
107
+ end
108
+ KillBillClient.log level, '<=== %d %s (%.1fms)' % [
109
+ code,
110
+ response.class.name[9, response.class.name.length].gsub(
111
+ /([a-z])([A-Z])/, '\1 \2'
112
+ ),
113
+ latency
114
+ ]
115
+ KillBillClient.log :debug, response.to_hash.inspect
116
+ KillBillClient.log :debug, response.body if response.body
117
+ end
118
+
119
+ case code
120
+ when 200...300 then
121
+ response
122
+ else
123
+ raise ERRORS[code].new request, response
124
+ end
125
+ end
126
+ end
127
+ end
128
+
129
+ extend Net::HTTPAdapter
130
+ end
131
+ end
@@ -0,0 +1,36 @@
1
+ module KillBillClient
2
+ module Model
3
+ class Account < AccountAttributesWithBalance
4
+ KILLBILL_API_ACCOUNTS_PREFIX = "#{KILLBILL_API_PREFIX}/accounts"
5
+
6
+ class << self
7
+ def find_by_id(account_id, with_balance = false, with_balance_and_cba = false)
8
+ get "#{KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}",
9
+ {
10
+ :accountWithBalance => with_balance,
11
+ :accountWithBalanceAndCBA => with_balance_and_cba
12
+ }
13
+ end
14
+ end
15
+
16
+ def create(user = nil, reason = nil, comment = nil)
17
+ created_account = self.class.post KILLBILL_API_ACCOUNTS_PREFIX,
18
+ to_json,
19
+ {},
20
+ {
21
+ :user => user,
22
+ :reason => reason,
23
+ :comment => comment,
24
+ }
25
+ created_account.refresh
26
+ end
27
+
28
+ def payments
29
+ self.class.get "#{KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/payments",
30
+ {},
31
+ {},
32
+ Payment
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,51 @@
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 AccountAttributes < Resource
29
+ attribute :account_id
30
+ attribute :name
31
+ attribute :first_name_length
32
+ attribute :external_key
33
+ attribute :email
34
+ attribute :bill_cycle_day_local
35
+ attribute :currency
36
+ attribute :payment_method_id
37
+ attribute :time_zone
38
+ attribute :address1
39
+ attribute :address2
40
+ attribute :postal_code
41
+ attribute :company
42
+ attribute :city
43
+ attribute :state
44
+ attribute :country
45
+ attribute :locale
46
+ attribute :phone
47
+ attribute :is_migrated
48
+ attribute :is_notified_for_invoices
49
+ end
50
+ end
51
+ 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 AccountAttributesSimple < Resource
29
+ attribute :account_id
30
+ attribute :external_key
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,52 @@
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 AccountAttributesWithBalance < Resource
29
+ attribute :account_id
30
+ attribute :name
31
+ attribute :first_name_length
32
+ attribute :external_key
33
+ attribute :email
34
+ attribute :bill_cycle_day_local
35
+ attribute :currency
36
+ attribute :payment_method_id
37
+ attribute :time_zone
38
+ attribute :address1
39
+ attribute :address2
40
+ attribute :postal_code
41
+ attribute :company
42
+ attribute :city
43
+ attribute :state
44
+ attribute :country
45
+ attribute :locale
46
+ attribute :phone
47
+ attribute :is_migrated
48
+ attribute :is_notified_for_invoices
49
+ attribute :account_balance
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,53 @@
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 AccountAttributesWithBalanceAndCBA < Resource
29
+ attribute :account_id
30
+ attribute :name
31
+ attribute :first_name_length
32
+ attribute :external_key
33
+ attribute :email
34
+ attribute :bill_cycle_day_local
35
+ attribute :currency
36
+ attribute :payment_method_id
37
+ attribute :time_zone
38
+ attribute :address1
39
+ attribute :address2
40
+ attribute :postal_code
41
+ attribute :company
42
+ attribute :city
43
+ attribute :state
44
+ attribute :country
45
+ attribute :locale
46
+ attribute :phone
47
+ attribute :is_migrated
48
+ attribute :is_notified_for_invoices
49
+ attribute :account_balance
50
+ attribute :account_c_b_a
51
+ end
52
+ end
53
+ 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 AccountEmailAttributes < Resource
29
+ attribute :account_id
30
+ attribute :email
31
+ end
32
+ end
33
+ 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 AccountTimelineAttributes < Resource
29
+ attribute :account
30
+ attribute :bundles
31
+ attribute :invoices
32
+ attribute :payments
33
+ end
34
+ end
35
+ 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 AnalyticsSanityAttributes < Resource
29
+ attribute :check_entitlement
30
+ attribute :check_invoice
31
+ attribute :check_payment
32
+ attribute :check_tag
33
+ attribute :check_consistency
34
+ end
35
+ end
36
+ end