Class: Spaceship::Tunes::IAP

Inherits:
TunesBase show all
Defined in:
spaceship/lib/spaceship/tunes/iap.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#client, #raw_data

Instance Method Summary collapse

Methods inherited from TunesBase

client

Methods inherited from Base

attr_accessor, attr_mapping, attributes, #attributes, factory, #initialize, #inspect, mapping_module, method_missing, set_client, #setup, #to_s

Constructor Details

This class inherits a constructor from Spaceship::Base

Instance Attribute Details

#applicationSpaceship::Tunes::Application



16
17
18
# File 'spaceship/lib/spaceship/tunes/iap.rb', line 16

def application
  @application
end

Instance Method Details

#all(include_deleted: false) ⇒ Object

return all available In-App-Purchase’s of current app this is not paged inside iTC-API so if you have a lot if IAP’s (2k+) it might take some time to load, same as it takes when you load the list via App Store Connect



122
123
124
125
126
127
128
129
130
131
132
133
# File 'spaceship/lib/spaceship/tunes/iap.rb', line 122

def all(include_deleted: false)
  r = client.iaps(app_id: self.application.apple_id)
  return_iaps = []
  r.each do |product|
    attrs = product
    attrs[:application] = self.application
    loaded_iap = Tunes::IAPList.factory(attrs)
    next if loaded_iap.status == "deleted" && !include_deleted
    return_iaps << loaded_iap
  end
  return_iaps
end

#create!(type: "consumable", versions: nil, reference_name: nil, product_id: nil, cleared_for_sale: true, merch_screenshot: nil, review_notes: nil, review_screenshot: nil, pricing_intervals: nil, family_id: nil, subscription_free_trial: nil, subscription_duration: nil, subscription_price_target: nil) ⇒ Object

Creates a new In-App-Purchese on App Store Connect if the In-App-Purchase already exists an exception is raised. Spaceship::TunesClient::ITunesConnectError @example: {

'de-DE': {
  name: "Name shown in AppStore",
  description: "Description of the In app Purchase"

}

} @example:

[
  {
    country: "WW",
    begin_date: nil,
    end_date: nil,
    tier: 1
  }
]

price of all the countries to be roughly the same as the price calculated from the price tier and currency given as input. @example:

{
  currency: "EUR",
  tier: 2
}


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'spaceship/lib/spaceship/tunes/iap.rb', line 63

def create!(type: "consumable",
            versions: nil,
            reference_name: nil,
            product_id: nil,
            cleared_for_sale: true,
            merch_screenshot: nil,
            review_notes: nil,
            review_screenshot: nil,
            pricing_intervals: nil,
            family_id: nil,
            subscription_free_trial: nil,
            subscription_duration: nil,
            subscription_price_target: nil)
  client.create_iap!(app_id: self.application.apple_id,
                     type: type,
                     versions: versions,
                     reference_name: reference_name,
                     product_id: product_id,
                     cleared_for_sale: cleared_for_sale,
                     merch_screenshot: merch_screenshot,
                     review_notes: review_notes,
                     review_screenshot: review_screenshot,
                     pricing_intervals: pricing_intervals,
                     family_id: family_id,
                     subscription_duration: subscription_duration,
                     subscription_free_trial: subscription_free_trial)

  # Update pricing for a recurring subscription.
  if type == Spaceship::Tunes::IAPType::RECURRING &&
     (pricing_intervals || subscription_price_target)
    # There are cases where the product that was just created is not immediately found,
    # and in order to update its pricing the purchase_id is needed. Therefore polling is done
    # for 4 times until it is found. If it's not found after 6 tries, a PotentialServerError
    # exception is raised.
    product = find_product_with_retries(product_id, 6)
    raw_pricing_intervals =
      client.transform_to_raw_pricing_intervals(application.apple_id,
                                                product.purchase_id, pricing_intervals,
                                                subscription_price_target)
    client.update_recurring_iap_pricing!(app_id: self.application.apple_id,
                                         purchase_id: product.purchase_id,
                                         pricing_intervals: raw_pricing_intervals)
  end
end

#familiesSpaceship::Tunes::IAPFamilies



19
20
21
22
23
# File 'spaceship/lib/spaceship/tunes/iap.rb', line 19

def families
  attrs = {}
  attrs[:application] = self.application
  Tunes::IAPFamilies.new(attrs)
end

#find(product_id) ⇒ Object

find a specific product



110
111
112
113
114
115
116
117
# File 'spaceship/lib/spaceship/tunes/iap.rb', line 110

def find(product_id)
  all.each do |product|
    if product.product_id == product_id
      return product
    end
  end
  return nil
end