Class: KillBillClient::Model::Tenant

Inherits:
TenantAttributes show all
Defined in:
lib/killbill_client/models/tenant.rb

Constant Summary collapse

KILLBILL_API_TENANTS_PREFIX =
"#{KILLBILL_API_PREFIX}/tenants"
KILLBILL_API_TENANTS_NOTIFICATION =
"#{KILLBILL_API_TENANTS_PREFIX}/registerNotificationCallback"
KILLBILL_API_TENANTS_SYSTEM_CONFIGURATION =
"#{KILLBILL_API_TENANTS_PREFIX}/uploadPerTenantConfig"
KILLBILL_API_TENANTS_PLUGIN_PAYMENT_STATE_MACHINE =
"#{KILLBILL_API_TENANTS_PREFIX}/uploadPluginPaymentStateMachineConfig"

Constants inherited from Resource

Resource::KILLBILL_API_PAGINATION_PREFIX, Resource::KILLBILL_API_PREFIX

Instance Attribute Summary

Attributes inherited from Resource

#clazz, #etag, #response, #session_id, #uri

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#==, #_to_hash, attribute, create_alias, delete, extract_session_id, from_json, from_response, get, has_many, has_one, #hash, head, #initialize, instantiate_record_from_json, post, put, #refresh, require_multi_tenant_options!, #to_hash, #to_json

Constructor Details

This class inherits a constructor from KillBillClient::Model::Resource

Class Method Details

.add_payment_state_machine(plugin_name, state_machine_config, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/killbill_client/models/tenant.rb', line 170

def add_payment_state_machine(plugin_name, state_machine_config, user = nil, reason = nil, comment = nil, options = {})
  require_multi_tenant_options!(options, "Payment state machine is only supported in multi-tenant mode")
  post "#{KILLBILL_API_TENANTS_PLUGIN_PAYMENT_STATE_MACHINE}/#{plugin_name}",
        state_machine_config,
        {},
        {
          :content_type => 'text/plain',
          :user => user,
          :reason => reason,
          :comment => comment,
        }.merge(options)
end

.add_system_configuration(configuration, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/killbill_client/models/tenant.rb', line 140

def add_system_configuration(configuration, user = nil, reason = nil, comment = nil, options = {})
  require_multi_tenant_options!(options, "System configuration is only supported in multi-tenant mode")
  post "#{KILLBILL_API_TENANTS_SYSTEM_CONFIGURATION}",
        configuration,
        {},
        {
          :content_type => 'text/plain',
          :user => user,
          :reason => reason,
          :comment => comment,
        }.merge(options)
end

.delete_payment_state_machine(plugin_name, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



188
189
190
191
192
193
194
195
196
197
198
# File 'lib/killbill_client/models/tenant.rb', line 188

def delete_payment_state_machine(plugin_name, user = nil, reason = nil, comment = nil, options = {})
  require_multi_tenant_options!(options, "Payment state machine is only supported in multi-tenant mode")
  delete "#{KILLBILL_API_TENANTS_PLUGIN_PAYMENT_STATE_MACHINE}/#{plugin_name}",
          {},
          {},
          {
            :user => user,
            :reason => reason,
            :comment => comment,
          }.merge(options)
end

.delete_push_notification(user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
# File 'lib/killbill_client/models/tenant.rb', line 128

def delete_push_notification(user = nil, reason = nil, comment = nil, options = {})
  require_multi_tenant_options!(options, "Push notification is only supported in multi-tenant mode")
  delete "#{KILLBILL_API_TENANTS_NOTIFICATION}",
          {},
          {},
          {
            :user => user,
            :reason => reason,
            :comment => comment,
          }.merge(options)
end

.delete_system_configurations(user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
# File 'lib/killbill_client/models/tenant.rb', line 158

def delete_system_configurations(user = nil, reason = nil, comment = nil, options = {})
  require_multi_tenant_options!(options, "System configuration is only supported in multi-tenant mode")
  delete "#{KILLBILL_API_TENANTS_SYSTEM_CONFIGURATION}",
          {},
          {},
          {
            :user => user,
            :reason => reason,
            :comment => comment,
          }.merge(options)
end

.delete_tenant_key_value(key_name, key_path, error_id_str, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/killbill_client/models/tenant.rb', line 93

def delete_tenant_key_value(key_name, key_path, error_id_str, user = nil, reason = nil, comment = nil, options = {})

  require_multi_tenant_options!(options, "Deleting a #{error_id_str} is only supported in multi-tenant mode")

  uri =  KILLBILL_API_TENANTS_PREFIX + "/#{key_path}/" + key_name
  delete uri,
         {},
         {
         },
         {
             :content_type => 'text/plain',
             :user => user,
             :reason => reason,
             :comment => comment,
         }.merge(options)

end

.delete_tenant_plugin_config(plugin_name, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



32
33
34
# File 'lib/killbill_client/models/tenant.rb', line 32

def delete_tenant_plugin_config(plugin_name, user = nil, reason = nil, comment = nil, options = {})
  delete_tenant_key_value(plugin_name, "uploadPluginConfig", "plugin config", user, reason, comment, options)
end

.delete_tenant_user_key_value(key_name, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



45
46
47
# File 'lib/killbill_client/models/tenant.rb', line 45

def delete_tenant_user_key_value(key_name, user = nil, reason = nil, comment = nil, options = {})
  delete_tenant_key_value(key_name, "userKeyValue", "tenant key/value", user, reason, comment, options)
end

.find_by_api_key(api_key, options = {}) ⇒ Object



18
19
20
21
22
# File 'lib/killbill_client/models/tenant.rb', line 18

def find_by_api_key(api_key, options = {})
  get "#{KILLBILL_API_TENANTS_PREFIX}/?apiKey=#{api_key}",
      {},
      options
end

.find_by_id(tenant_id, options = {}) ⇒ Object



12
13
14
15
16
# File 'lib/killbill_client/models/tenant.rb', line 12

def find_by_id(tenant_id, options = {})
  get "#{KILLBILL_API_TENANTS_PREFIX}/#{tenant_id}",
      {},
      options
end

.get_tenant_key_value(key_name, key_path, error_id_str, options = {}) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/killbill_client/models/tenant.rb', line 62

def get_tenant_key_value(key_name, key_path, error_id_str, options = {})

  require_multi_tenant_options!(options, "Retrieving a #{error_id_str} is only supported in multi-tenant mode")

  uri =  KILLBILL_API_TENANTS_PREFIX + "/#{key_path}/" + key_name
  get uri,
      {},
      {
      }.merge(options),
      KillBillClient::Model::TenantKeyValueAttributes
end

.get_tenant_plugin_config(plugin_name, options = {}) ⇒ Object



24
25
26
# File 'lib/killbill_client/models/tenant.rb', line 24

def get_tenant_plugin_config(plugin_name, options = {})
  get_tenant_key_value(plugin_name, "uploadPluginConfig", "plugin config", options)
end

.get_tenant_user_key_value(key_name, options = {}) ⇒ Object



36
37
38
# File 'lib/killbill_client/models/tenant.rb', line 36

def get_tenant_user_key_value(key_name, options = {})
  get_tenant_key_value(key_name, "userKeyValue", "tenant key/value", options)
end

.register_push_notification(cb, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
# File 'lib/killbill_client/models/tenant.rb', line 111

def register_push_notification(cb, user = nil, reason = nil, comment = nil, options = {})
  require_multi_tenant_options!(options, "Push notification is only supported in multi-tenant mode")
  post "#{KILLBILL_API_TENANTS_NOTIFICATION}",
        {},
        {:cb => cb},
        {
          :user => user,
          :reason => reason,
          :comment => comment,
        }.merge(options)
end

.retrieve_payment_state_machine(plugin_name, options = {}) ⇒ Object



183
184
185
186
# File 'lib/killbill_client/models/tenant.rb', line 183

def retrieve_payment_state_machine(plugin_name, options = {})
  require_multi_tenant_options!(options, "Payment state machine is only supported in multi-tenant mode")
  get "#{KILLBILL_API_TENANTS_PLUGIN_PAYMENT_STATE_MACHINE}/#{plugin_name}", {}, options
end

.retrieve_push_notification(options = {}) ⇒ Object



123
124
125
126
# File 'lib/killbill_client/models/tenant.rb', line 123

def retrieve_push_notification(options = {})
  require_multi_tenant_options!(options, "Push notification is only supported in multi-tenant mode")
  get "#{KILLBILL_API_TENANTS_NOTIFICATION}", {}, options
end

.retrieve_system_configurations(options = {}) ⇒ Object



153
154
155
156
# File 'lib/killbill_client/models/tenant.rb', line 153

def retrieve_system_configurations(options = {})
  require_multi_tenant_options!(options, "System configuration is only supported in multi-tenant mode")
  get "#{KILLBILL_API_TENANTS_SYSTEM_CONFIGURATION}", {}, options
end

.search_tenant_config(key_prefix, options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/killbill_client/models/tenant.rb', line 49

def search_tenant_config(key_prefix, options = {})

  require_multi_tenant_options!(options, "Searching for plugin config is only supported in multi-tenant mode")

  uri =  KILLBILL_API_TENANTS_PREFIX + "/uploadPerTenantConfig/" + key_prefix + "/search"
   get uri,
      {},
      {
      }.merge(options),
      KillBillClient::Model::TenantKeyValueAttributes
end

.upload_tenant_key_value(key_name, key_value, key_path, get_method, error_id_str, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/killbill_client/models/tenant.rb', line 75

def upload_tenant_key_value(key_name, key_value, key_path, get_method, error_id_str, user = nil, reason = nil, comment = nil, options = {})

  require_multi_tenant_options!(options, "Uploading a #{error_id_str} is only supported in multi-tenant mode")

  uri =  KILLBILL_API_TENANTS_PREFIX + "/#{key_path}/" + key_name
  post uri,
       key_value,
       {
       },
       {
           :content_type => 'text/plain',
           :user => user,
           :reason => reason,
           :comment => comment,
       }.merge(options)
  send(get_method.to_sym, key_name, options)
end

.upload_tenant_plugin_config(plugin_name, plugin_config, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



28
29
30
# File 'lib/killbill_client/models/tenant.rb', line 28

def upload_tenant_plugin_config(plugin_name, plugin_config, user = nil, reason = nil, comment = nil, options = {})
  upload_tenant_key_value(plugin_name, plugin_config, "uploadPluginConfig", "get_tenant_plugin_config", "plugin config", user, reason, comment, options)
end

.upload_tenant_user_key_value(key_name, key_value, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



40
41
42
# File 'lib/killbill_client/models/tenant.rb', line 40

def upload_tenant_user_key_value(key_name, key_value, user = nil, reason = nil, comment = nil, options = {})
  upload_tenant_key_value(key_name, key_value, "userKeyValue", "get_tenant_user_key_value", "tenant key/value", user, reason, comment, options)
end

Instance Method Details

#create(use_global_default = true, user = nil, reason = nil, comment = nil, options = {}) ⇒ Object



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/killbill_client/models/tenant.rb', line 202

def create(use_global_default=true, user = nil, reason = nil, comment = nil, options = {})

  created_tenant = self.class.post KILLBILL_API_TENANTS_PREFIX,
                                   to_json, 
                                   {:useGlobalDefault => use_global_default},
                                   {
                                       :user => user,
                                       :reason => reason,
                                       :comment => comment,
                                   }.merge(options)
  #
  # Specify api_key and api_secret before making the call to retrieve the tenant object
  # otherwise that would fail with a 401
  #
  options[:api_key] = @api_key
  options[:api_secret] = @api_secret
  created_tenant.refresh(options)
end