killbill-client 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1fb152afe9243696fea3189a25c5639ada554316
4
- data.tar.gz: 9b0a59633af847621e851625b644e8848a6d7e0d
3
+ metadata.gz: 7fa054d6429ec8d29d211fe1d581ecd3e1cb8f90
4
+ data.tar.gz: 9658639f68539f0f6d7ea5d77b96027e3485045d
5
5
  SHA512:
6
- metadata.gz: 919cc47a13b3a8b4cfe9ff8fe4a8bdd17d91b7f09f46a570e2ea20d0a135fabcc7055eb929298a6bd6df12f84b774393e25f13d5a76136f22632a34a3cf92a75
7
- data.tar.gz: 29cdf321a9355f641ad1994c3f2e1fd6442c4e025125819d40a5a88b9a15203a104c38f23b05d63fd978cabcabb94e138774b68eb22c9a1dd185e59b08681ac2
6
+ metadata.gz: 058d93cbc47043cfbaa068f1c15e09ff1c48386768b2af5d85d8a9e903d914d8040feaefe4fbf1b510deeb63e000a2d638a42cab10085f513ada53d90b9f3ecb
7
+ data.tar.gz: aad960ae930ae5057c3c4b3a1a9a0dd87737dafbd588e8572bd5beee1b2e70a1d14954f2f2a681f1d48583b3ecaeb1df50dfec882be72829af89745b757ba41b
@@ -50,6 +50,8 @@ module KillBillClient
50
50
  # Configure auth, if enabled
51
51
  if KillBillClient.api_key and KillBillClient.api_secret
52
52
  request.basic_auth(*[KillBillClient.api_key, KillBillClient.api_secret].flatten[0, 2])
53
+ request['X-Killbill-ApiKey'] = KillBillClient.api_key
54
+ request['X-Killbill-ApiSecret'] = KillBillClient.api_secret
53
55
  end
54
56
 
55
57
  if options[:body]
@@ -0,0 +1,20 @@
1
+ module KillBillClient
2
+ module Model
3
+ class AccountTimeline < AccountTimelineAttributes
4
+
5
+ has_one :account, KillBillClient::Model::Account
6
+ has_many :payments, KillBillClient::Model::Payment
7
+ has_many :bundles, KillBillClient::Model::Bundle
8
+ has_many :invoices, KillBillClient::Model::Invoice
9
+
10
+ class << self
11
+ def find_by_account_id(account_id, audit = 'MINIMAL')
12
+ get "#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/timeline",
13
+ {
14
+ :audit => audit
15
+ }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ module KillBillClient
2
+ module Model
3
+ class AuditLog < AuditLogAttributes
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ module KillBillClient
2
+ module Model
3
+ class Bundle < BundleAttributesSimple
4
+ has_many :subscriptions, KillBillClient::Model::SubscriptionEvent
5
+ has_many :audit_logs, KillBillClient::Model::AuditLog
6
+ end
7
+ end
8
+ end
9
+
10
+
@@ -0,0 +1,7 @@
1
+ module KillBillClient
2
+ module Model
3
+ class Chargeback < ChargebackAttributes
4
+ has_many :audit_logs, KillBillClient::Model::AuditLog
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module KillBillClient
2
+ module Model
3
+ class Credit < CreditAttributes
4
+ has_many :audit_logs, KillBillClient::Model::AuditLog
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ module KillBillClient
2
+ module Model
3
+ class Event < SubscriptionReadEventAttributes
4
+ has_many :audit_logs, KillBillClient::Model::AuditLog
5
+
6
+ create_alias :requested_date, :requested_dt
7
+ create_alias :effective_date, :effective_dt
8
+ end
9
+ end
10
+ end
@@ -1,7 +1,22 @@
1
1
  module KillBillClient
2
2
  module Model
3
- class Invoice < InvoiceAttributesSimple
3
+ class Invoice < InvoiceAttributesWithBundleKeys
4
4
  KILLBILL_API_INVOICES_PREFIX = "#{KILLBILL_API_PREFIX}/invoices"
5
+
6
+ has_many :audit_logs, KillBillClient::Model::AuditLog
7
+ has_many :items, KillBillClient::Model::InvoiceItem
8
+ has_many :credits, KillBillClient::Model::Credit
9
+
10
+ create_alias :bundle_keys, :external_bundle_keys
11
+
12
+ class << self
13
+ def find_by_id_or_number(id_or_number, with_items = true)
14
+ get "#{KILLBILL_API_INVOICES_PREFIX}/#{id_or_number}",
15
+ {
16
+ :withItems => with_items
17
+ }
18
+ end
19
+ end
5
20
  end
6
21
  end
7
22
  end
@@ -2,13 +2,23 @@ require 'killbill_client/models/resource'
2
2
 
3
3
  require 'killbill_client/models/gen/require_gen'
4
4
 
5
+ require 'killbill_client/models/audit_log'
6
+ require 'killbill_client/models/event'
7
+ require 'killbill_client/models/credit'
8
+ require 'killbill_client/models/invoice_item'
9
+ require 'killbill_client/models/subscription_deleted_event'
10
+ require 'killbill_client/models/subscription_new_event'
11
+ require 'killbill_client/models/chargeback'
12
+ require 'killbill_client/models/subscription_event'
13
+ require 'killbill_client/models/bundle'
14
+ require 'killbill_client/models/refund'
5
15
  require 'killbill_client/models/account'
6
16
  require 'killbill_client/models/invoice'
7
- require 'killbill_client/models/invoice_item'
8
17
  require 'killbill_client/models/payment'
9
18
  require 'killbill_client/models/payment_method'
10
19
  require 'killbill_client/models/tag'
11
20
  require 'killbill_client/models/tag_definition'
21
+ require 'killbill_client/models/account_timeline'
12
22
 
13
23
  module KillBillClient
14
24
  module Model
@@ -1,6 +1,11 @@
1
1
  module KillBillClient
2
2
  module Model
3
- class Payment < PaymentAttributesSimple
3
+ class Payment < PaymentAttributesWithBundleKeys
4
+ has_many :refunds, KillBillClient::Model::Refund
5
+ has_many :chargebacks, KillBillClient::Model::Chargeback
6
+ has_many :audit_logs, KillBillClient::Model::AuditLog
7
+
8
+ create_alias :bundle_keys, :external_bundle_keys
4
9
  end
5
10
  end
6
11
  end
@@ -18,6 +18,13 @@ module KillBillClient
18
18
  }
19
19
  end
20
20
 
21
+ def find_all_by_search_key(search_key, with_plugin_info = false)
22
+ get "#{KILLBILL_API_PAYMENT_METHODS_PREFIX}/search/#{search_key}",
23
+ {
24
+ :withPluginInfo => with_plugin_info
25
+ }
26
+ end
27
+
21
28
  def set_default(payment_method_id, account_id, user = nil, reason = nil, comment = nil)
22
29
  put "#{Account::KILLBILL_API_ACCOUNTS_PREFIX}/#{account_id}/paymentMethods/#{payment_method_id}/setDefault",
23
30
  nil,
@@ -0,0 +1,8 @@
1
+ module KillBillClient
2
+ module Model
3
+ class Refund < RefundAttributes
4
+ has_many :audit_logs, KillBillClient::Model::AuditLog
5
+ has_many :adjustments, KillBillClient::Model::InvoiceItem
6
+ end
7
+ end
8
+ end
@@ -5,6 +5,7 @@ module KillBillClient
5
5
  class Resource
6
6
 
7
7
  KILLBILL_API_PREFIX = '/1.0/kb/'
8
+ @@attribute_names = {}
8
9
 
9
10
  class << self
10
11
  def head(uri, params = {}, options = {}, clazz = self)
@@ -40,14 +41,14 @@ module KillBillClient
40
41
  # @param response [Net::HTTPResponse]
41
42
  def from_response(resource_class, response)
42
43
  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"
44
+ when %r{application/pdf}
45
+ response.body
46
+ when %r{application/json}
47
+ record = from_json resource_class, response.body
48
+ record.instance_eval { @etag, @response = response['ETag'], response }
49
+ record
50
+ else
51
+ raise ArgumentError, "#{response['Content-Type']} is not supported by the library"
51
52
  end
52
53
  end
53
54
 
@@ -60,8 +61,8 @@ module KillBillClient
60
61
  def from_json(resource_class, json)
61
62
  # e.g. DELETE
62
63
  return nil if json.nil? or json.size == 0
63
-
64
64
  data = JSON.parse json
65
+
65
66
  if data.is_a? Array
66
67
  records = []
67
68
  data.each do |data_element|
@@ -75,10 +76,34 @@ module KillBillClient
75
76
 
76
77
  def instantiate_record_from_json(resource_class, data)
77
78
  record = resource_class.send :new
78
- data.each { |k, v| record.send("#{Utils.underscore k}=", v) }
79
+
80
+ data.each do |name, value|
81
+ name = Utils.underscore name
82
+ attr_desc = @@attribute_names[record.class.name][name.to_sym] rescue nil
83
+
84
+ unless attr_desc.nil?
85
+ type = attr_desc[:type]
86
+ if attr_desc[:cardinality] == :many && !type.nil? && value.is_a?(Array)
87
+ newValue = []
88
+ value.each do |val|
89
+ if val.is_a?(Hash)
90
+ newValue << instantiate_record_from_json(type, val)
91
+ else
92
+ newValue << val
93
+ end
94
+ end
95
+ value = newValue
96
+ elsif attr_desc[:cardinality] == :one && !type.nil? && value.is_a?(Hash)
97
+ value = instantiate_record_from_json(type, value)
98
+ end
99
+ end #end unless attr_desc.nil? or data_elem.blank?
100
+
101
+ record.send("#{Utils.underscore name}=", value )
102
+ end #end data.each
103
+
79
104
  record
80
105
  end
81
-
106
+
82
107
  def attribute(name)
83
108
  self.send('attr_accessor', name.to_sym)
84
109
 
@@ -86,40 +111,65 @@ module KillBillClient
86
111
  self.instance_variable_get('@json_attributes') << name.to_s
87
112
 
88
113
  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
114
 
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
115
+ (
116
+ class << self;
117
+ self
118
+ end).send(:define_method, :json_attributes) do
119
+ attributes
120
+ end
121
+ end
122
+
123
+ def has_many(attr_name, type = nil)
124
+ send("attr_accessor", attr_name.to_sym)
125
+
126
+ #add it to attribute_names
127
+ @@attribute_names[self.name] = {} unless @@attribute_names[self.name]
128
+ @@attribute_names[self.name][attr_name.to_sym] = {:type => type, :cardinality => :many }
129
+ end
130
+
131
+ def has_one(attr_name, type = nil)
132
+ send("attr_accessor", attr_name.to_sym)
133
+
134
+ #add it to attribute_names
135
+ @@attribute_names[self.name] = {} unless @@attribute_names[self.name]
136
+ @@attribute_names[self.name][attr_name.to_sym] = { :type => type, :cardinality => :one }
137
+ end
138
+
139
+ #hack to cater the api return attributes and javax attributes without editing gen scripts
140
+ #call only after its declared as a instance_method using attr_accessor
141
+ def create_alias(new_name, old_name)
142
+ alias_method new_name.to_sym, old_name.to_sym #getter
143
+ alias_method "#{new_name}=".to_sym, "#{old_name}=".to_sym #setter
144
+ end
145
+
146
+ end #end self methods
147
+
148
+ # Set on create call
149
+ attr_accessor :uri
150
+
151
+ def to_hash
152
+ json_hash = {}
153
+ self.class.json_attributes.each do |name|
154
+ value = self.send(name)
155
+ if value
156
+ json_hash[Utils.camelize name, :lower] = value.is_a?(Resource) ? value.to_hash : value
157
+ end
158
+ end
159
+ json_hash
160
+ end
161
+
162
+ def to_json
163
+ to_hash.to_json
164
+ end
165
+
166
+ def refresh(clazz=self.class)
167
+ if @uri
168
+ self.class.get @uri, {}, {}, clazz
169
+ else
170
+ self
171
+ end
172
+ end
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,6 @@
1
+ module KillBillClient
2
+ module Model
3
+ class SubscriptionDeletedEvent < SubscriptionDeletedEventAttributes
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,9 @@
1
+ module KillBillClient
2
+ module Model
3
+ class SubscriptionEvent < SubscriptionAttributesNoEvents
4
+ has_many :events, KillBillClient::Model::Event
5
+ has_many :deleted_events, KillBillClient::Model::SubscriptionDeletedEvent
6
+ has_many :new_events, KillBillClient::Model::SubscriptionNewEvent
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ module KillBillClient
2
+ module Model
3
+ class SubscriptionNewEvent < SubscriptionNewEventAttributes
4
+ end
5
+ end
6
+ end
@@ -2,7 +2,7 @@ module KillBillClient
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 2
5
+ PATCH = 3
6
6
  PRE = nil
7
7
 
8
8
  VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join('.').freeze
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe KillBillClient::Model::Resource do
4
+ class_var_name = '@@attribute_names'
5
+
6
+ it 'should test has_one property' do
7
+ #test account_timeline has one account
8
+ #has_one :account, KillBillClient::Model::Account
9
+ #expected "KillBillClient::Model::AccountTimeline"=>{:account=>{:type=>KillBillClient::Model::Account, :cardinality=>:one}, :payments=>{:type=>KillBillClient::Model::Payment, :cardinality=>:many}, :bundles=>{:type=>KillBillClient::Model::Bundle, :cardinality=>:many}, :invoices=>{:type=>KillBillClient::Model::Invoice, :cardinality=>:many}}
10
+ test_var = KillBillClient::Model::AccountTimeline.class_variable_defined? class_var_name
11
+ test_var.should_not be_false
12
+
13
+ var = KillBillClient::Model::AccountTimeline.class_variable_get class_var_name
14
+ var.size.should > 0
15
+ var.should have_key "KillBillClient::Model::AccountTimeline"
16
+ var["KillBillClient::Model::AccountTimeline"].should have_key :account
17
+
18
+ attr = var["KillBillClient::Model::AccountTimeline"][:account]
19
+
20
+ attr.should have_key :type
21
+ attr.should have_key :cardinality
22
+
23
+ attr[:type].should == KillBillClient::Model::Account
24
+ attr[:cardinality].should == :one #has one
25
+
26
+ #should also be accessible by attr_accessors
27
+
28
+ methods = KillBillClient::Model::AccountTimeline.instance_methods
29
+ methods.should include :account # attr_reader
30
+ methods.should include :account= #attr_writer
31
+ end
32
+
33
+ it 'should test has_many property' do
34
+ #test event has many audit_logs
35
+ #has_many :audit_logs, KillBillClient::Model::AuditLog
36
+ #expected {"KillBillClient::Model::Event"=>{:audit_logs=>{:type=>KillBillClient::Model::AuditLog, :cardinality=>:many}}}
37
+
38
+ test_var = KillBillClient::Model::Event.class_variable_defined? class_var_name
39
+ test_var.should_not be_false
40
+
41
+ var = KillBillClient::Model::Event.class_variable_get class_var_name
42
+ var.size.should > 0
43
+ var.should have_key "KillBillClient::Model::Event"
44
+ var["KillBillClient::Model::Event"].should have_key :audit_logs
45
+
46
+ attr = var["KillBillClient::Model::Event"][:audit_logs]
47
+
48
+ attr.should have_key :type
49
+ attr.should have_key :cardinality
50
+
51
+ attr[:type].should == KillBillClient::Model::AuditLog
52
+ attr[:cardinality].should == :many #has many
53
+
54
+ #should also be accessible by attr_accessors
55
+
56
+ methods = KillBillClient::Model::Event.instance_methods
57
+ methods.should include :audit_logs # attr_reader
58
+ methods.should include :audit_logs= #attr_writer
59
+ end
60
+
61
+ it 'should create alias attr accessors' do
62
+ KillBillClient::Model::Event.create_alias :alias_date, :requested_dt
63
+
64
+ methods = KillBillClient::Model::Event.instance_methods
65
+ methods.should include :alias_date
66
+ methods.should include :alias_date=
67
+
68
+ evt = KillBillClient::Model::Event.new
69
+ evt.alias_date = "devaroop"
70
+ evt.requested_dt.should == "devaroop"
71
+ evt.alias_date.should == "devaroop"
72
+ end
73
+ end
74
+
@@ -82,6 +82,28 @@ describe KillBillClient::Model do
82
82
 
83
83
  account = KillBillClient::Model::Account.find_by_id account.account_id
84
84
  account.payment_method_id.should be_nil
85
+
86
+ # Get its timeline
87
+ timeline = KillBillClient::Model::AccountTimeline.find_by_account_id account.account_id
88
+
89
+ timeline.account.external_key.should == external_key
90
+ timeline.account.account_id.should_not be_nil
91
+
92
+ timeline.invoices.should be_a_kind_of Array
93
+ timeline.invoices.should_not be_empty
94
+ timeline.payments.should be_a_kind_of Array
95
+ timeline.bundles.should be_a_kind_of Array
96
+
97
+ # Let's find the invoice by two methods
98
+ invoice = timeline.invoices.first
99
+ invoice_id = invoice.invoice_id
100
+ invoice_number = invoice.invoice_number
101
+
102
+ invoice_with_id = KillBillClient::Model::Invoice.find_by_id_or_number invoice_id
103
+ invoice_with_number = KillBillClient::Model::Invoice.find_by_id_or_number invoice_number
104
+
105
+ invoice_with_id.invoice_id.should == invoice_with_number.invoice_id
106
+ invoice_with_id.invoice_number.should == invoice_with_number.invoice_number
85
107
  end
86
108
 
87
109
  it 'should manipulate tag definitions' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: killbill-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Killbill core team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-29 00:00:00.000000000 Z
11
+ date: 2013-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -55,6 +55,12 @@ files:
55
55
  - lib/killbill_client/api/errors.rb
56
56
  - lib/killbill_client/api/net_http_adapter.rb
57
57
  - lib/killbill_client/models/account.rb
58
+ - lib/killbill_client/models/account_timeline.rb
59
+ - lib/killbill_client/models/audit_log.rb
60
+ - lib/killbill_client/models/bundle.rb
61
+ - lib/killbill_client/models/chargeback.rb
62
+ - lib/killbill_client/models/credit.rb
63
+ - lib/killbill_client/models/event.rb
58
64
  - lib/killbill_client/models/gen/account_attributes.rb
59
65
  - lib/killbill_client/models/gen/account_attributes_simple.rb
60
66
  - lib/killbill_client/models/gen/account_attributes_with_balance.rb
@@ -109,13 +115,18 @@ files:
109
115
  - lib/killbill_client/models/models.rb
110
116
  - lib/killbill_client/models/payment.rb
111
117
  - lib/killbill_client/models/payment_method.rb
118
+ - lib/killbill_client/models/refund.rb
112
119
  - lib/killbill_client/models/resource.rb
120
+ - lib/killbill_client/models/subscription_deleted_event.rb
121
+ - lib/killbill_client/models/subscription_event.rb
122
+ - lib/killbill_client/models/subscription_new_event.rb
113
123
  - lib/killbill_client/models/tag.rb
114
124
  - lib/killbill_client/models/tag_definition.rb
115
125
  - lib/killbill_client/utils.rb
116
126
  - lib/killbill_client/version.rb
117
127
  - lib/rails/generators/killbill_client/config_generator.rb
118
128
  - lib/rails/killbill_client.rb
129
+ - spec/killbill_client/model_relation_spec.rb
119
130
  - spec/killbill_client/remote/api_spec.rb
120
131
  - spec/killbill_client/remote/model_spec.rb
121
132
  - spec/spec_helper.rb
@@ -146,6 +157,7 @@ signing_key:
146
157
  specification_version: 4
147
158
  summary: Kill Bill client library.
148
159
  test_files:
160
+ - spec/killbill_client/model_relation_spec.rb
149
161
  - spec/killbill_client/remote/api_spec.rb
150
162
  - spec/killbill_client/remote/model_spec.rb
151
163
  - spec/spec_helper.rb