Giter VIP home page Giter VIP logo

ipapi's Introduction

SwiftPM compatible Carthage compatible Build Status CocoaPods Compatible Platform Twitter

IPAPI

http://ip-api.com Geolocation API client written in Swift.

Requirements

  • iOS 8.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 10.2+
  • Swift 5.1+

Installation

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate IPAPI into your Xcode project using Carthage, specify it in your Cartfile:

github "arturgrigor/IPAPI" ~> 3.0

Run carthage update to build the framework and drag the built IPAPI.framework into your Xcode project.

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.1.0+ is required.

To integrate IPAPI into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '10.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'IPAPI', '~> 3.0'
end

Then, run the following command:

$ pod install

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding IPAPI as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .Package(url: "https://github.com/arturgrigor/IPAPI.git", majorVersion: 3)
]

Usage

๐ŸŽฏ Lookup the current IP address

import IPAPI

IPAPI.Service.default.fetch {
    if let result = try? $0.get() {
        print("Geo IP result \(result).")
    }
}

๐Ÿ” Lookup a domain

import IPAPI

Service.default.fetch(query: "apple.com") {
    if let result = try? $0.get() {
        print("Geo IP result \(result).")
    }
}

โœ‚๏ธ Ask only for some specific fields

import IPAPI

Service.default.fetch(fields: [.ip, .latitude, .longitude, .organization]) {
    if let result = try? $0.get() {
        print("Geo IP result \(result).")
    }
}

๐Ÿ‡ท๐Ÿ‡ด Localization

import IPAPI

Service.default.fetch(language: "es") {
    if let result = try? $0.get() {
        print("Geo IP result \(result).")
    }
}

*Checkout this page for the available languages.

๐Ÿ“ฆ Batch request

import IPAPI

Service.default.batch([Service.Request(query: "208.80.152.201",
                                       fields: [.countryName, .countryCode, .latitude, .longitude, .organization, .ip]),
                       Service.Request(query: "91.198.174.192", language: "es")]) {
    if let result = try? $0.get() {
        print("Geo IP result \(result).")
    }
}

๐Ÿ”’ HTTPS requests

In order to use the API via HTTPS you must register for the "Pro" plan to get an API key. After you've done that you can set the API key like this and all your requests will use HTTPS.

import IPAPI

IPAPI.Service(pricingPlan: .pro(apiKey: "test-demo-pro")).fetch {
    if let result = try? $0.get() {
        print("Geo IP result \(result).")
    }
}

Contact

Let me know if you're using or enjoying this product.

ipapi's People

Contributors

arturgrigor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

carabina netcanis

ipapi's Issues

version issue

CocoaPods could not find compatible versions for pod "IPAPI":
In Podfile:
IPAPI (~> 2.1)

None of your spec sources contain a spec satisfying the dependency: IPAPI (~> 2.1).

You have either:

  • out-of-date source repos which you can update with pod repo update or with pod install --repo-update.
  • mistyped the name or version.
  • not added the source repo that hosts the Podspec to your Podfile.

HTTPS

Hi, the site does not have HTTPS. Transport security will block it. In ios12 you cannot disable Transport security.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.