Class: Spaceship::Tunes::Availability
- Defined in:
- spaceship/lib/spaceship/tunes/availability.rb
Instance Attribute Summary collapse
-
#app_available_date ⇒ String
App available date in format of “YYYY-MM-DD”.
-
#b2b_app_enabled ⇒ Bool
App enabled for b2b users.
-
#b2b_unavailable ⇒ Bool
B2b available for distribution.
-
#b2b_users ⇒ Array of Spaceship::Tunes::B2bUser objects
A list of users.
-
#cleared_for_preorder ⇒ Bool
Cleared for preorder.
-
#educational_discount ⇒ Bool
App enabled for educational discount.
-
#include_future_territories ⇒ Bool
Are future territories included?.
-
#territories ⇒ Array of Spaceship::Tunes::Territory objects
A list of the territories.
Attributes inherited from Base
Class Method Summary collapse
-
.from_territories(territories = [], params = {}) ⇒ Object
Create a new object based on a set of territories.
Instance Method Summary collapse
-
#add_b2b_users(user_list = []) ⇒ Object
Adds users for b2b enabled apps.
-
#enable_b2b_app! ⇒ Object
Sets ‘b2b_app_enabled` to true and `educational_discount` to false Requires users to be added with `add_b2b_users` otherwise `update_availability` will error.
-
#update_b2b_users(user_list = []) ⇒ Object
Updates users for b2b enabled apps.
Methods inherited from TunesBase
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_date ⇒ String
Returns 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 |
#b2b_app_enabled ⇒ Bool
Returns app enabled for b2b users.
19 20 21 |
# File 'spaceship/lib/spaceship/tunes/availability.rb', line 19 def b2b_app_enabled @b2b_app_enabled end |
#b2b_unavailable ⇒ Bool
Returns b2b available for distribution.
25 26 27 |
# File 'spaceship/lib/spaceship/tunes/availability.rb', line 25 def b2b_unavailable @b2b_unavailable end |
#b2b_users ⇒ Array of Spaceship::Tunes::B2bUser objects
Returns A list of users.
28 29 30 |
# File 'spaceship/lib/spaceship/tunes/availability.rb', line 28 def b2b_users @b2b_users end |
#cleared_for_preorder ⇒ Bool
Returns Cleared for preorder.
13 14 15 |
# File 'spaceship/lib/spaceship/tunes/availability.rb', line 13 def cleared_for_preorder @cleared_for_preorder end |
#educational_discount ⇒ Bool
Returns app enabled for educational discount.
22 23 24 |
# File 'spaceship/lib/spaceship/tunes/availability.rb', line 22 def educational_discount @educational_discount end |
#include_future_territories ⇒ Bool
Returns Are future territories included?.
7 8 9 |
# File 'spaceship/lib/spaceship/tunes/availability.rb', line 7 def include_future_territories @include_future_territories end |
#territories ⇒ Array of Spaceship::Tunes::Territory objects
Returns A list of the territories.
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. This will override any values already set for cleared_for_preorder, app_available_date, b2b_unavailable, b2b_app_enabled, and educational_discount
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'spaceship/lib/spaceship/tunes/availability.rb', line 42 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) obj.b2b_unavailable = params.fetch(:b2b_unavailable, false) obj.b2b_app_enabled = params.fetch(:b2b_app_enabled, false) obj.educational_discount = params.fetch(:educational_discount, true) return obj end |
Instance Method Details
#add_b2b_users(user_list = []) ⇒ Object
Adds users for b2b enabled apps
106 107 108 109 110 |
# File 'spaceship/lib/spaceship/tunes/availability.rb', line 106 def add_b2b_users(user_list = []) raise "Cannot add b2b users if b2b is not enabled" unless b2b_app_enabled @b2b_users = user_list.map { |user| B2bUser.from_username(user) } return self end |
#enable_b2b_app! ⇒ Object
Sets ‘b2b_app_enabled` to true and `educational_discount` to false Requires users to be added with `add_b2b_users` otherwise `update_availability` will error
97 98 99 100 101 102 103 |
# File 'spaceship/lib/spaceship/tunes/availability.rb', line 97 def enable_b2b_app! raise "Not possible to enable b2b on this app" if b2b_unavailable @b2b_app_enabled = true # need to set the educational discount to false @educational_discount = false return self end |
#update_b2b_users(user_list = []) ⇒ Object
Updates users for b2b enabled apps
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'spaceship/lib/spaceship/tunes/availability.rb', line 113 def update_b2b_users(user_list = []) raise "Cannot add b2b users if b2b is not enabled" unless b2b_app_enabled added_users = b2b_users.map(&:ds_username) # Returns if list is unchanged return self if (added_users - user_list) == (user_list - added_users) users_to_add = user_list.reject { |user| added_users.include?(user) } users_to_remove = added_users.reject { |user| user_list.include?(user) } @b2b_users = b2b_users.reject { |user| users_to_remove.include?(user.ds_username) } @b2b_users.concat(users_to_add.map { |user| B2bUser.from_username(user) }) @b2b_users.concat(users_to_remove.map { |user| B2bUser.from_username(user, is_add_type: false) }) return self end |