Class: Spaceship::Tunes::Availability

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

Instance Attribute Summary collapse

Attributes inherited from Base

#client, #raw_data

Class 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

#app_available_dateString

Returns App available date in format of “YYYY-MM-DD”.

Returns:

  • (String)

    App available date in format of “YYYY-MM-DD”



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

def app_available_date
  @app_available_date
end

#cleared_for_preorderBool

Returns Cleared for preorder.

Returns:

  • (Bool)

    Cleared for preorder



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

def cleared_for_preorder
  @cleared_for_preorder
end

#include_future_territoriesBool

Returns Are future territories included?.

Returns:

  • (Bool)

    Are future territories included?



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

def include_future_territories
  @include_future_territories
end

#territoriesArray of Spaceship::Tunes::Territory objects

Returns A list of the territories.

Returns:



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

def territories
  @territories
end

Class Method Details

.from_territories(territories = [], params = {}) ⇒ Object

Create a new object based on a set of territories.

Parameters:

  • territories (Array of String or Spaceship::Tunes::Territory objects) (defaults to: [])

    : A list of the territories

  • params (Hash) (defaults to: {})

    : Optional parameters (include_future_territories (Bool, default: true) Are future territories included?)



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'spaceship/lib/spaceship/tunes/availability.rb', line 27

def self.from_territories(territories = [], params = {})
  # Initializes the DataHash with our preOrder structure so values
  # that are being modified will be saved
  #
  # Note: A better solution for this in the future might be to improve how
  # Base::DataHash sets values for paths that don't exist
  obj = self.new(
    'preOrder' => {
      'clearedForPreOrder' => {
        'value' => false
      },
      'appAvailableDate' => {
        'value' => nil
      }
    }
  )

  # Detect if the territories attribute is an array of Strings and convert to Territories
  obj.territories =
    if territories[0].kind_of?(String)
      territories.map { |territory| Spaceship::Tunes::Territory.from_code(territory) }
    else
      territories
    end
  obj.include_future_territories = params.fetch(:include_future_territories, true)
  obj.cleared_for_preorder = params.fetch(:cleared_for_preorder, false)
  obj.app_available_date = params.fetch(:app_available_date, nil)
  return obj
end