class ProcessOut::Addon

Attributes

amount[R]
created_at[R]
id[R]
metadata[R]
name[R]
plan[R]
plan_id[R]
project[R]
project_id[R]
quantity[R]
sandbox[R]
subscription[R]
subscription_id[R]
type[R]

Public Class Methods

new(client, data = {}) click to toggle source

Initializes the Addon object Params:

client

ProcessOut client instance

data

data that can be used to fill the object

# File lib/processout/addon.rb, line 124
def initialize(client, data = {})
  @client = client

  self.id = data.fetch(:id, nil)
  self.project = data.fetch(:project, nil)
  self.project_id = data.fetch(:project_id, nil)
  self.subscription = data.fetch(:subscription, nil)
  self.subscription_id = data.fetch(:subscription_id, nil)
  self.plan = data.fetch(:plan, nil)
  self.plan_id = data.fetch(:plan_id, nil)
  self.type = data.fetch(:type, nil)
  self.name = data.fetch(:name, nil)
  self.amount = data.fetch(:amount, nil)
  self.quantity = data.fetch(:quantity, nil)
  self.metadata = data.fetch(:metadata, nil)
  self.sandbox = data.fetch(:sandbox, nil)
  self.created_at = data.fetch(:created_at, nil)
  
end

Public Instance Methods

amount=(val) click to toggle source
# File lib/processout/addon.rb, line 99
def amount=(val)
  @amount = val
end
create(options = {}) click to toggle source

Create a new addon to the given subscription ID. Params:

options

Hash of options

# File lib/processout/addon.rb, line 281
def create(options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/subscriptions/" + CGI.escape(@subscription_id) + "/addons"
  data    = {
    "plan_id" => @plan_id, 
    "type" => @type, 
    "name" => @name, 
    "amount" => @amount, 
    "quantity" => @quantity, 
    "metadata" => @metadata, 
    "prorate" => options.fetch(:prorate, nil), 
    "proration_date" => options.fetch(:proration_date, nil), 
    "preview" => options.fetch(:preview, nil)
  }

  response = Response.new(request.post(path, data, options))
  return_values = Array.new
  
  body = response.body
  body = body["addon"]
  
  
  return_values.push(self.fill_with_data(body))
  

  
  return_values[0]
end
created_at=(val) click to toggle source
# File lib/processout/addon.rb, line 115
def created_at=(val)
  @created_at = val
end
delete(options = {}) click to toggle source

Delete an addon applied to a subscription. Params:

options

Hash of options

# File lib/processout/addon.rb, line 379
def delete(options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/subscriptions/" + CGI.escape(@subscription_id) + "/addons/" + CGI.escape(@id) + ""
  data    = {
    "prorate" => options.fetch(:prorate, nil), 
    "proration_date" => options.fetch(:proration_date, nil), 
    "preview" => options.fetch(:preview, nil)
  }

  response = Response.new(request.delete(path, data, options))
  return_values = Array.new
  
  return_values.push(response.success)

  
  return_values[0]
end
fetch_subscription_addons(subscription_id, options = {}) click to toggle source

Get the addons applied to the subscription. Params:

subscription_id

ID of the subscription

options

Hash of options

# File lib/processout/addon.rb, line 251
def fetch_subscription_addons(subscription_id, options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/subscriptions/" + CGI.escape(subscription_id) + "/addons"
  data    = {

  }

  response = Response.new(request.get(path, data, options))
  return_values = Array.new
  
  a    = Array.new
  body = response.body
  for v in body['addons']
    tmp = Addon.new(@client)
    tmp.fill_with_data(v)
    a.push(tmp)
  end

  return_values.push(a)
  

  
  return_values[0]
end
fill_with_data(data) click to toggle source

Fills the object with data coming from the API Params:

data

Hash of data coming from the API

# File lib/processout/addon.rb, line 172
def fill_with_data(data)
  if data.nil?
    return self
  end
  if data.include? "id"
    self.id = data["id"]
  end
  if data.include? "project"
    self.project = data["project"]
  end
  if data.include? "project_id"
    self.project_id = data["project_id"]
  end
  if data.include? "subscription"
    self.subscription = data["subscription"]
  end
  if data.include? "subscription_id"
    self.subscription_id = data["subscription_id"]
  end
  if data.include? "plan"
    self.plan = data["plan"]
  end
  if data.include? "plan_id"
    self.plan_id = data["plan_id"]
  end
  if data.include? "type"
    self.type = data["type"]
  end
  if data.include? "name"
    self.name = data["name"]
  end
  if data.include? "amount"
    self.amount = data["amount"]
  end
  if data.include? "quantity"
    self.quantity = data["quantity"]
  end
  if data.include? "metadata"
    self.metadata = data["metadata"]
  end
  if data.include? "sandbox"
    self.sandbox = data["sandbox"]
  end
  if data.include? "created_at"
    self.created_at = data["created_at"]
  end
  
  self
end
find(subscription_id, addon_id, options = {}) click to toggle source

Find a subscription's addon by its ID. Params:

subscription_id

ID of the subscription on which the addon was applied

addon_id

ID of the addon

options

Hash of options

# File lib/processout/addon.rb, line 317
def find(subscription_id, addon_id, options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/subscriptions/" + CGI.escape(subscription_id) + "/addons/" + CGI.escape(addon_id) + ""
  data    = {

  }

  response = Response.new(request.get(path, data, options))
  return_values = Array.new
  
  body = response.body
  body = body["addon"]
  
  
  obj = Addon.new(@client)
  return_values.push(obj.fill_with_data(body))
  

  
  return_values[0]
end
id=(val) click to toggle source
# File lib/processout/addon.rb, line 27
def id=(val)
  @id = val
end
metadata=(val) click to toggle source
# File lib/processout/addon.rb, line 107
def metadata=(val)
  @metadata = val
end
name=(val) click to toggle source
# File lib/processout/addon.rb, line 95
def name=(val)
  @name = val
end
new(data = {}) click to toggle source

Create a new Addon using the current client

# File lib/processout/addon.rb, line 145
def new(data = {})
  Addon.new(@client, data)
end
plan=(val) click to toggle source
# File lib/processout/addon.rb, line 71
def plan=(val)
  if val.nil?
    @plan = val
    return
  end

  if val.instance_of? Plan
    @plan = val
  else
    obj = Plan.new(@client)
    obj.fill_with_data(val)
    @plan = obj
  end
  
end
plan_id=(val) click to toggle source
# File lib/processout/addon.rb, line 87
def plan_id=(val)
  @plan_id = val
end
prefill(data) click to toggle source

Prefills the object with the data passed as parameters Params:

data

Hash of data

# File lib/processout/addon.rb, line 225
def prefill(data)
  if data.nil?
    return self
  end
  self.id = data.fetch(:id, self.id)
  self.project = data.fetch(:project, self.project)
  self.project_id = data.fetch(:project_id, self.project_id)
  self.subscription = data.fetch(:subscription, self.subscription)
  self.subscription_id = data.fetch(:subscription_id, self.subscription_id)
  self.plan = data.fetch(:plan, self.plan)
  self.plan_id = data.fetch(:plan_id, self.plan_id)
  self.type = data.fetch(:type, self.type)
  self.name = data.fetch(:name, self.name)
  self.amount = data.fetch(:amount, self.amount)
  self.quantity = data.fetch(:quantity, self.quantity)
  self.metadata = data.fetch(:metadata, self.metadata)
  self.sandbox = data.fetch(:sandbox, self.sandbox)
  self.created_at = data.fetch(:created_at, self.created_at)
  
  self
end
project=(val) click to toggle source
# File lib/processout/addon.rb, line 31
def project=(val)
  if val.nil?
    @project = val
    return
  end

  if val.instance_of? Project
    @project = val
  else
    obj = Project.new(@client)
    obj.fill_with_data(val)
    @project = obj
  end
  
end
project_id=(val) click to toggle source
# File lib/processout/addon.rb, line 47
def project_id=(val)
  @project_id = val
end
quantity=(val) click to toggle source
# File lib/processout/addon.rb, line 103
def quantity=(val)
  @quantity = val
end
sandbox=(val) click to toggle source
# File lib/processout/addon.rb, line 111
def sandbox=(val)
  @sandbox = val
end
save(options = {}) click to toggle source

Save the updated addon attributes. Params:

options

Hash of options

# File lib/processout/addon.rb, line 344
def save(options = {})
  self.prefill(options)

  request = Request.new(@client)
  path    = "/subscriptions/" + CGI.escape(@subscription_id) + "/addons/" + CGI.escape(@id) + ""
  data    = {
    "plan_id" => @plan_id, 
    "type" => @type, 
    "name" => @name, 
    "amount" => @amount, 
    "quantity" => @quantity, 
    "metadata" => @metadata, 
    "prorate" => options.fetch(:prorate, nil), 
    "proration_date" => options.fetch(:proration_date, nil), 
    "preview" => options.fetch(:preview, nil), 
    "increment_quantity_by" => options.fetch(:increment_quantity_by, nil)
  }

  response = Response.new(request.put(path, data, options))
  return_values = Array.new
  
  body = response.body
  body = body["addon"]
  
  
  return_values.push(self.fill_with_data(body))
  

  
  return_values[0]
end
subscription=(val) click to toggle source
# File lib/processout/addon.rb, line 51
def subscription=(val)
  if val.nil?
    @subscription = val
    return
  end

  if val.instance_of? Subscription
    @subscription = val
  else
    obj = Subscription.new(@client)
    obj.fill_with_data(val)
    @subscription = obj
  end
  
end
subscription_id=(val) click to toggle source
# File lib/processout/addon.rb, line 67
def subscription_id=(val)
  @subscription_id = val
end
to_json(options) click to toggle source

Overrides the JSON marshaller to only send the fields we want

# File lib/processout/addon.rb, line 150
def to_json(options)
  {
      "id": self.id,
      "project": self.project,
      "project_id": self.project_id,
      "subscription": self.subscription,
      "subscription_id": self.subscription_id,
      "plan": self.plan,
      "plan_id": self.plan_id,
      "type": self.type,
      "name": self.name,
      "amount": self.amount,
      "quantity": self.quantity,
      "metadata": self.metadata,
      "sandbox": self.sandbox,
      "created_at": self.created_at,
  }.to_json
end
type=(val) click to toggle source
# File lib/processout/addon.rb, line 91
def type=(val)
  @type = val
end