Class: Spaceship::Tunes::IAPDetail

Inherits:
TunesBase show all
Defined in:
spaceship/lib/spaceship/tunes/iap_detail.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, #to_s

Constructor Details

This class inherits a constructor from Spaceship::Base

Instance Attribute Details

#applicationSpaceship::Tunes::Application

Returns A reference to the application.

Returns:



10
11
12
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 10

def application
  @application
end

#cleared_for_saleBool

Returns Cleared for sale flag.

Returns:

  • (Bool)

    Cleared for sale flag



31
32
33
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 31

def cleared_for_sale
  @cleared_for_sale
end

#is_news_subscriptionBool

Returns if it is a news subscription.

Returns:

  • (Bool)

    if it is a news subscription



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

def is_news_subscription
  @is_news_subscription
end

#merch_screenshotHash

Returns Hash containing existing promotional image data.

Returns:

  • (Hash)

    Hash containing existing promotional image data



34
35
36
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 34

def merch_screenshot
  @merch_screenshot
end

#product_idString

Returns the IAP Product-Id.

Returns:

  • (String)

    the IAP Product-Id



22
23
24
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 22

def product_id
  @product_id
end

#purchase_idInteger

Returns the IAP id.

Returns:

  • (Integer)

    the IAP id



13
14
15
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 13

def purchase_id
  @purchase_id
end

#raw_pricing_dataHash

as subscription pricing, intro offers, etc.

Returns:

  • (Hash)

    Relevant only for recurring subscriptions. Holds pricing related data, such



47
48
49
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 47

def raw_pricing_data
  @raw_pricing_data
end

#reference_nameString

Returns the IAP Referencename.

Returns:

  • (String)

    the IAP Referencename



19
20
21
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 19

def reference_name
  @reference_name
end

#review_notesString

Returns the notes for the review team.

Returns:

  • (String)

    the notes for the review team



40
41
42
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 40

def review_notes
  @review_notes
end

#review_screenshotHash

Returns Hash containing existing review screenshot data.

Returns:

  • (Hash)

    Hash containing existing review screenshot data



37
38
39
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 37

def review_screenshot
  @review_screenshot
end

#subscription_durationString

Returns subscription duration.

Returns:

  • (String)

    subscription duration



28
29
30
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 28

def subscription_duration
  @subscription_duration
end

#subscription_free_trialString

Returns free trial period.

Returns:

  • (String)

    free trial period



25
26
27
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 25

def subscription_free_trial
  @subscription_free_trial
end

#subscription_price_targetHash

Returns subscription pricing target.

Returns:

  • (Hash)

    subscription pricing target



43
44
45
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 43

def subscription_price_target
  @subscription_price_target
end

Instance Method Details

#delete!Object

Deletes In-App-Purchase



209
210
211
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 209

def delete!
  client.delete_iap!(app_id: application.apple_id, purchase_id: self.purchase_id)
end

#pricing_info[], ...

Retrieves the actual prices for an iap.

Returns:



221
222
223
224
225
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 221

def pricing_info
  return [] unless cleared_for_sale
  return world_wide_pricing_info if world_wide_pricing?
  territorial_pricing_info
end

#pricing_intervalsArray

@example:

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

Returns:

  • (Array)

    pricing intervals



127
128
129
130
131
132
133
134
135
136
137
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 127

def pricing_intervals
  @pricing_intervals ||= (raw_data["pricingIntervals"] || @raw_pricing_data["subscriptions"] || []).map do |interval|
    {
      tier: interval["value"]["tierStem"].to_i,
      begin_date: interval["value"]["priceTierEffectiveDate"],
      end_date: interval["value"]["priceTierEndDate"],
      grandfathered: interval["value"]["grandfathered"],
      country: interval["value"]["country"]
    }
  end
end

#pricing_intervals=(value = []) ⇒ Object

transforms user-set intervals to iTC ones



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

def pricing_intervals=(value = [])
  raw_pricing_intervals =
    client.transform_to_raw_pricing_intervals(application.apple_id, self.purchase_id, value)
  raw_data.set(["pricingIntervals"], raw_pricing_intervals)
  @raw_pricing_data["subscriptions"] = raw_pricing_intervals if @raw_pricing_data
end

#save!Object

Saves the current In-App-Purchase



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 162

def save!
  # Transform localization versions back to original format.
  versions_array = []
  versions.each do |language, value|
    versions_array << {
              "value" =>  {
                "description" => { "value" => value[:description] },
                "name" => { "value" => value[:name] },
                "localeCode" => language.to_s
              }
    }
  end

  raw_data.set(["versions"], [{ reviewNotes: { value: @review_notes }, contentHosting: raw_data['versions'].first['contentHosting'], "details" => { "value" => versions_array }, id: raw_data["versions"].first["id"], reviewScreenshot: { "value" => review_screenshot } }])

  # transform pricingDetails
  raw_pricing_intervals =
    client.transform_to_raw_pricing_intervals(application.apple_id,
                                              self.purchase_id, pricing_intervals,
                                              subscription_price_target)
  raw_data.set(["pricingIntervals"], raw_pricing_intervals)
  @raw_pricing_data["subscriptions"] = raw_pricing_intervals if @raw_pricing_data

  if @merch_screenshot
    # Upload App Store Promotional image (Optional)
    upload_file = UploadFile.from_path(@merch_screenshot)
    merch_data = client.upload_purchase_merch_screenshot(application.apple_id, upload_file)
    raw_data["versions"][0]["merch"] = merch_data
  end

  if @review_screenshot
    # Upload Screenshot
    upload_file = UploadFile.from_path(@review_screenshot)
    screenshot_data = client.upload_purchase_review_screenshot(application.apple_id, upload_file)
    raw_data["versions"][0]["reviewScreenshot"] = screenshot_data
  end
  # Update the Purchase
  client.update_iap!(app_id: application.apple_id, purchase_id: self.purchase_id, data: raw_data)

  # Update pricing for a recurring subscription.
  if raw_data["addOnType"] == Spaceship::Tunes::IAPType::RECURRING
    client.update_recurring_iap_pricing!(app_id: application.apple_id, purchase_id: self.purchase_id,
                                         pricing_intervals: raw_data["pricingIntervals"])
  end
end

#setupObject



59
60
61
62
63
64
65
66
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 59

def setup
  @raw_pricing_data = @raw_data["pricingData"]
  @raw_data.delete("pricingData")

  if @raw_pricing_data
    @raw_data.set(["pricingIntervals"], @raw_pricing_data["subscriptions"])
  end
end

#statusString

Returns Human Readable status of the purchase.

Returns:

  • (String)

    Human Readable status of the purchase



145
146
147
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 145

def status
  Tunes::IAPStatus.get_from_string(raw_data["versions"].first["status"])
end

#typeString

Returns Human Readable type of the purchase.

Returns:

  • (String)

    Human Readable type of the purchase



140
141
142
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 140

def type
  Tunes::IAPType.get_from_string(raw_data["addOnType"])
end

#versionsHash

@example: {

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

}

}

Returns:

  • (Hash)

    Hash of languages



76
77
78
79
80
81
82
83
84
85
86
87
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 76

def versions
  parsed_versions = {}
  raw_versions = raw_data["versions"].first["details"]["value"]
  raw_versions.each do |localized_version|
    language = localized_version["value"]["localeCode"]
    parsed_versions[language.to_sym] = {
      name: localized_version["value"]["name"]["value"],
      description: localized_version["value"]["description"]["value"]
    }
  end
  return parsed_versions
end

#versions=(value = {}) ⇒ Object

transforms user-set versions to iTC ones



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 90

def versions=(value = {})
  if value.kind_of?(Array)
    # input that comes from iTC api
    return
  end
  new_versions = []
  value.each do |language, current_version|
    new_versions << {
      "value" =>   {
        "name" =>  { "value" => current_version[:name] },
        "description" =>  { "value" => current_version[:description] },
        "localeCode" =>  language.to_s
      }
    }
  end

  raw_data.set(["versions"], [{ reviewNotes: { value: @review_notes }, "contentHosting" => raw_data['versions'].first['contentHosting'], "details" => { "value" => new_versions }, "id" => raw_data["versions"].first["id"], "reviewScreenshot" => { "value" => review_screenshot } }])
end