Class: Jamf::AppStoreCountryCodes

Inherits:
SingletonResource show all
Extended by:
Immutable
Defined in:
lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb

Overview

The API endpoint for country codes.

Probably more useful is the Jamf.app_store_country_codes method which parses this into a hash of Code => Name

Constant Summary collapse

RSRC_VERSION =

Constants

'v1'.freeze
RSRC_PATH =
'app-store-country-codes'.freeze
OBJECT_MODEL =
{

  # @!attribute checkInFrequency
  #   @return [integer]
  countryCodes: {
    class: Jamf::Country,
    multi: true,
    read_only: true,
    aliases: [:list]
  }

}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Jamf::JSONObject

Class Method Details

.code_for_name(name, refresh = false, cnx: Jamf.cnx) ⇒ Object

Class level wrapper for #code_for_name



92
93
94
# File 'lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb', line 92

def self.code_for_name(name, refresh = false, cnx: Jamf.cnx)
  fetch(refresh, cnx: cnx).code_for_name name
end

.codes(refresh = false, cnx: Jamf.cnx) ⇒ Object

Class level wrapper for #codes



77
78
79
# File 'lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb', line 77

def self.codes(refresh = false, cnx: Jamf.cnx)
  fetch(refresh, cnx: cnx).codes
end

.codes_by_name(refresh = false, cnx: Jamf.cnx) ⇒ Object

Class level wrapper for #codes_by_name



82
83
84
# File 'lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb', line 82

def self.codes_by_name(refresh = false, cnx: Jamf.cnx)
  fetch(refresh, cnx: cnx).codes_by_name
end

.list(refresh = false, cnx: Jamf.cnx) ⇒ Array<Jamf::Country>

Returns all the Countries available.

Returns:



67
68
69
# File 'lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb', line 67

def self.list(refresh = false, cnx: Jamf.cnx)
  fetch(refresh, cnx: cnx).countryCodes
end

.mutable?Boolean Originally defined in module Immutable

Returns:

  • (Boolean)

.name_for_code(code, refresh = false, cnx: Jamf.cnx) ⇒ Object

Class level wrapper for #name_for_code



97
98
99
# File 'lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb', line 97

def self.name_for_code(code, refresh = false, cnx: Jamf.cnx)
  fetch(refresh, cnx: cnx).name_for_code code
end

.names(refresh = false, cnx: Jamf.cnx) ⇒ Object

Class level wrapper for #names



72
73
74
# File 'lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb', line 72

def self.names(refresh = false, cnx: Jamf.cnx)
  fetch(refresh, cnx: cnx).names
end

.names_by_code(refresh = false, cnx: Jamf.cnx) ⇒ Object

Class level wrapper for #names_by_code



87
88
89
# File 'lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb', line 87

def self.names_by_code(refresh = false, cnx: Jamf.cnx)
  fetch(refresh, cnx: cnx).names_by_code
end

Instance Method Details

#code_for_name(name) ⇒ String

return a country code from its name, case-insensitive

Parameters:

  • name (String)

    the name of a country

Returns:



127
128
129
130
# File 'lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb', line 127

def code_for_name(name)
  name = names.select { |n| n.casecmp? name }.first
  codes_by_name[name]
end

#codesArray<String>

Returns the available country codes.

Returns:



110
111
112
# File 'lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb', line 110

def codes
  @codes ||= countryCodes.map(&:code)
end

#codes_by_nameHash

Returns name => code.

Returns:

  • (Hash)

    name => code



115
116
117
# File 'lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb', line 115

def codes_by_name
  @codes_by_name ||= countryCodes.map { |country| [country.name, country.code] }.to_h
end

#name_for_code(code) ⇒ String

return a country name from its code, case-insensitive

Parameters:

  • name (String)

    the name of a country

Returns:



135
136
137
# File 'lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb', line 135

def name_for_code(code)
  names_by_code[code.upcase]
end

#namesArray<String>

Returns the available country names.

Returns:



105
106
107
# File 'lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb', line 105

def names
  @names ||= countryCodes.map(&:name)
end

#names_by_codeHash

Returns code => name.

Returns:

  • (Hash)

    code => name



120
121
122
# File 'lib/jamf/api/resources/singleton_resources/app_store_country_codes.rb', line 120

def names_by_code
  @names_by_code ||= countryCodes.map { |country| [country.code, country.name] }.to_h
end