Class: Spaceship::Tunes::IAPFamilyDetails

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

Returns A reference to the application.

Returns:



7
8
9
# File 'spaceship/lib/spaceship/tunes/iap_family_details.rb', line 7

def application
  @application
end

#family_idIntger

Returns the Family Id.

Returns:

  • (Intger)

    the Family Id



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

def family_id
  @family_id
end

#nameString

Returns the family name.

Returns:

  • (String)

    the family name



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

def name
  @name
end

Instance Method Details

#save!Object

modify existing family



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'spaceship/lib/spaceship/tunes/iap_family_details.rb', line 54

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

  raw_data.set(["details"], { "value" => versions_array })

  client.update_iap_family!(app_id: application.apple_id, family_id: self.family_id, data: raw_data)
end

#versionsHash

Returns localized names.

Returns:

  • (Hash)

    localized names



40
41
42
43
44
45
46
47
48
49
50
51
# File 'spaceship/lib/spaceship/tunes/iap_family_details.rb', line 40

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

#versions=(value = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'spaceship/lib/spaceship/tunes/iap_family_details.rb', line 20

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" =>   {
        "subscriptionName" =>  { "value" => current_version[:subscription_name] },
        "name" =>  { "value" => current_version[:name] },
        "localeCode" => { "value" => language }
      }
    }
  end

  raw_data.set(["details"], { "value" => new_versions })
end