BokaMera.API.Host

<back to all web services

GeoDataCitiesQuery

The following routes are available for this service:
GET/geodata/{CountryId}/cities/Get all cities for a specific countryGet all information stored on the customer
import Foundation
import ServiceStack

public class GeoDataCitiesQuery : QueryDb2<City, GeoDataCitiesQueryResponse>
{
    /**
    * Enter the country id you want to search cities. Example SE for Sweden.
    */
    // @ApiMember(Description="Enter the country id you want to search cities. Example SE for Sweden.", IsRequired=true, ParameterType="path")
    public var countryId:String

    required public init(){ super.init() }

    private enum CodingKeys : String, CodingKey {
        case countryId
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        countryId = try container.decodeIfPresent(String.self, forKey: .countryId)
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        if countryId != nil { try container.encode(countryId, forKey: .countryId) }
    }
}

public class City : BaseModel
{
    // @Ignore()
    public var longitude:Double

    // @Ignore()
    public var latitude:Double

    // @Required()
    public var name:String?

    // @Required()
    public var country:String?

    public var iso2:String
    // @Required()
    public var admin:String?

    public var capital:String
    public var population:Int?
    public var populationProper:Int?
    public var modifiedDate:Date?
    // @Required()
    public var id:String?

    required public init(){ super.init() }

    private enum CodingKeys : String, CodingKey {
        case longitude
        case latitude
        case name
        case country
        case iso2
        case admin
        case capital
        case population
        case populationProper
        case modifiedDate
        case id
    }

    required public init(from decoder: Decoder) throws {
        try super.init(from: decoder)
        let container = try decoder.container(keyedBy: CodingKeys.self)
        longitude = try container.decodeIfPresent(Double.self, forKey: .longitude)
        latitude = try container.decodeIfPresent(Double.self, forKey: .latitude)
        name = try container.decodeIfPresent(String.self, forKey: .name)
        country = try container.decodeIfPresent(String.self, forKey: .country)
        iso2 = try container.decodeIfPresent(String.self, forKey: .iso2)
        admin = try container.decodeIfPresent(String.self, forKey: .admin)
        capital = try container.decodeIfPresent(String.self, forKey: .capital)
        population = try container.decodeIfPresent(Int.self, forKey: .population)
        populationProper = try container.decodeIfPresent(Int.self, forKey: .populationProper)
        modifiedDate = try container.decodeIfPresent(Date.self, forKey: .modifiedDate)
        id = try container.decodeIfPresent(String.self, forKey: .id)
    }

    public override func encode(to encoder: Encoder) throws {
        try super.encode(to: encoder)
        var container = encoder.container(keyedBy: CodingKeys.self)
        if longitude != nil { try container.encode(longitude, forKey: .longitude) }
        if latitude != nil { try container.encode(latitude, forKey: .latitude) }
        if name != nil { try container.encode(name, forKey: .name) }
        if country != nil { try container.encode(country, forKey: .country) }
        if iso2 != nil { try container.encode(iso2, forKey: .iso2) }
        if admin != nil { try container.encode(admin, forKey: .admin) }
        if capital != nil { try container.encode(capital, forKey: .capital) }
        if population != nil { try container.encode(population, forKey: .population) }
        if populationProper != nil { try container.encode(populationProper, forKey: .populationProper) }
        if modifiedDate != nil { try container.encode(modifiedDate, forKey: .modifiedDate) }
        if id != nil { try container.encode(id, forKey: .id) }
    }
}

public class BaseModel : Codable
{
    required public init(){}
}

public class GeoDataCitiesQueryResponse : Codable
{
    public var id:String
    public var city:String
    public var longitude:String
    public var latitude:String
    public var country:String
    public var iso2:String
    public var admin:String
    public var capital:String
    public var population:Int?
    public var populationProper:Int?

    required public init(){}
}

public class AccessKeyTypeResponse : Codable
{
    public var id:Int
    public var keyType:String
    public var Description:String

    required public init(){}
}


Swift GeoDataCitiesQuery DTOs

To override the Content-type in your clients, use the HTTP Accept Header, append the .jsv suffix or ?format=jsv

HTTP + JSV

The following are sample HTTP requests and responses. The placeholders shown need to be replaced with actual values.

GET /geodata/{CountryId}/cities/ HTTP/1.1 
Host: testapi.bokamera.se 
Accept: text/jsv
HTTP/1.1 200 OK
Content-Type: text/jsv
Content-Length: length

{
	Offset: 0,
	Total: 0,
	Results: 
	[
		{
			City: String,
			Longitude: String,
			Latitude: String,
			Country: String,
			Iso2: String,
			Admin: String,
			Capital: String,
			Population: 0,
			PopulationProper: 0
		}
	],
	Meta: 
	{
		String: String
	},
	ResponseStatus: 
	{
		ErrorCode: String,
		Message: String,
		StackTrace: String,
		Errors: 
		[
			{
				ErrorCode: String,
				FieldName: String,
				Message: String,
				Meta: 
				{
					String: String
				}
			}
		],
		Meta: 
		{
			String: String
		}
	}
}