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



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

def application
  @application
end

#cleared_for_saleBool



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

def cleared_for_sale
  @cleared_for_sale
end

#is_news_subscriptionBool



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

def is_news_subscription
  @is_news_subscription
end

#product_idString



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

def product_id
  @product_id
end

#purchase_idInteger



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.



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

def raw_pricing_data
  @raw_pricing_data
end

#reference_nameString



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

def reference_name
  @reference_name
end

#review_notesString



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

def review_notes
  @review_notes
end

#review_screenshotHash



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

def review_screenshot
  @review_screenshot
end

#subscription_durationString



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

def subscription_duration
  @subscription_duration
end

#subscription_free_trialString



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

def subscription_free_trial
  @subscription_free_trial
end

#subscription_price_targetHash



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

def subscription_price_target
  @subscription_price_target
end

Instance Method Details

#delete!Object

Deletes In-App-Purchase



192
193
194
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 192

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.



204
205
206
207
208
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 204

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
  }
]


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

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



106
107
108
109
110
111
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 106

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



152
153
154
155
156
157
158
159
160
161
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
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 152

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 @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



55
56
57
58
59
60
61
62
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 55

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



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

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

#typeString



136
137
138
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 136

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"

}

}



72
73
74
75
76
77
78
79
80
81
82
83
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 72

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



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'spaceship/lib/spaceship/tunes/iap_detail.rb', line 86

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