Module: Vk::DSL::Database

Included in:
Vk::DSL
Defined in:
lib/vk/dsl/database.rb

Instance Method Summary collapse

Instance Method Details

#get_cities(options = {}) ⇒ Object

Parameters:

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

Options Hash (options):

  • :country_id (<String>)

    required attribute. Country identifier

  • :region_id (<String>)

    optional attribute. Region identifier

  • :q (String)

    search query

  • :offset (Fixnum)

    offset for loaded countries

  • :count (Fixnum) — default: 100

    amount of countries to load



98
99
100
101
102
103
104
105
# File 'lib/vk/dsl/database.rb', line 98

def get_cities(options = {})
  require 'vk/city'
  raise 'No country_id attribute given for database.getRegions' unless options[:country_id]
  options[:code] = options[:code].join(',') if options[:code]
  Vk::Result.new('database.getCities', Vk::City, options,
                 country_id: options[:country_id],
                 region_id: options[:region_id])
end

#get_cities_by_id(city_ids) ⇒ Array<Hash>

Cities’ names

Parameters:

  • city_ids (Array<Fixnum>, Fixnum)

    cities identifiers

Returns:

  • (Array<Hash>)

    hash with city identifier and it’s name

Raises:



76
77
78
79
80
81
82
83
# File 'lib/vk/dsl/database.rb', line 76

def get_cities_by_id(city_ids)
  require 'vk/city'
  city_ids = Array(city_ids)
  raise Vk::TooMuchArguments.new('database.getCitiesById', 'city_ids', 1000) if city_ids > 1000
  request('database.getCitiesById', city_ids: city_ids.join(',')).map do |city|
    Vk::City.new(city)
  end
end

#get_city_by_id(cid) ⇒ Vk::City Also known as: get_city

Returns:



86
87
88
# File 'lib/vk/dsl/database.rb', line 86

def get_city_by_id(cid)
  get_cities_by_id(cid).first
end

#get_countries(options = {}) ⇒ Object

Parameters:

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

Options Hash (options):

  • :need_all (Boolean, 1)

    load all countries

  • :code (<String>)

    country codes to load

  • :offset (Fixnum)

    offset for loaded countries

  • :count (Fixnum) — default: 100

    amount of countries to load



11
12
13
14
15
# File 'lib/vk/dsl/database.rb', line 11

def get_countries(options = {})
  options[:need_all] = 1 if options[:need_all]
  options[:code] = options[:code].join(',') if options[:code]
  Vk::Result.new('database.getCountries', Vk::Country, options)
end

#get_countries_by_id(country_ids) ⇒ Array<Vk::Country>

Countries’ names

Parameters:

  • country_ids (Array<Fixnum>, Fixnum)

    cities identifiers

Returns:

Raises:



20
21
22
23
24
25
26
27
# File 'lib/vk/dsl/database.rb', line 20

def get_countries_by_id(country_ids)
  require 'vk/country'
  country_ids = Array(country_ids)
  raise Vk::TooMuchArguments.new('database.getCountriesById', 'country_ids', 1000) if country_ids > 1000
  request('database.getCountriesById', country_ids: country_ids.join(',')).map do |country|
    Vk::Country.new(country)
  end
end

#get_country_by_id(country_id) ⇒ Vk::Country Also known as: get_country

Parameters:

  • country_id (String)

Returns:



31
32
33
# File 'lib/vk/dsl/database.rb', line 31

def get_country_by_id(country_id)
  get_countries_by_id(country_id).first
end

#get_regions(country_id, options = {}) ⇒ Vk::Result<Vk::Region>

Parameters:

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

Options Hash (options):

  • :country_id (<String>)

    required attribute. Country identifier

  • :q (String)

    search query

  • :offset (Fixnum)

    offset for loaded countries

  • :count (Fixnum) — default: 100

    amount of countries to load

Returns:



43
44
45
46
47
48
49
50
51
52
# File 'lib/vk/dsl/database.rb', line 43

def get_regions(country_id, options = {})
  if country_id.is_a?(:hash)
    country_id = options.delete(:country_id) do
      raise 'No country_id attribute given for database.getRegions'
    end
  end
  require 'vk/region'
  options[:code] = options[:code].join(',') if options[:code]
  Vk::Result.new('database.getRegions', Vk::Region, options, country_id: country_id)
end

#get_street_by_id(street_id) ⇒ Object Also known as: get_street

Parameters:

  • street_id (Fixnum)


67
68
69
# File 'lib/vk/dsl/database.rb', line 67

def get_street_by_id(street_id)
  get_streets_by_id(street_id).first
end

#get_streets_by_id(street_ids) ⇒ Array<Vk::Country>

Countries’ names

Parameters:

  • street_ids (Array<Fixnum>, Fixnum)

    cities identifiers

Returns:

Raises:



57
58
59
60
61
62
63
64
# File 'lib/vk/dsl/database.rb', line 57

def get_streets_by_id(street_ids)
  require 'vk/street'
  street_ids = Array(street_ids)
  raise Vk::TooMuchArguments.new('database.getCountriesById', 'street_ids', 1000) if street_ids > 1000
  request('database.getCountriesById', street_ids: street_ids.join(',')).map do |street|
    Vk::Street.new(street)
  end
end