Code Monkey home page Code Monkey logo

currency-converter's Introduction

Currency Converter

Java library receives current exchange rate
  • 165+ currencies
  • No dependencies
  • Supports 3 sources - CurrencyConverterApi.Com, CurrencyLayer.Com, OpenExchangeRates.Com
  • Documentation

    Download

    Maven
    <dependency>
      <groupId>com.posadskiy</groupId>
      <artifactId>currency-converter</artifactId>
      <version>1.1.3</version>
    </dependency>
    Gradle/Grails
    compile 'com.posadskiy:currency-converter:1.1.3'
    Scala SBT
    libraryDependencies += "com.posadskiy" % "currency-converter" % "1.1.3"

    How to init service

    How to get API Key?

    /**
     * Define your API keys
     * Use at least one key, but we recommend define three:
     * One or even two services can be off, but not three at the same time
    */
    public static final String CURRENCY_CONVERTER_API_API_KEY = "YOUR API KEY FOR CurrencyConverterApi.Com";
    public static final String CURRENCY_LAYER = "YOUR API KEY FOR CurrencyLayer.Com";
    public static final String OPEN_EXCHANGE_RATES = "YOUR API KEY FOR OpenExchangeRates.Com";
    
    // Init converter with your API key
    CurrencyConverter converter = new CurrencyConverter(
        new ConfigBuilder()
            .currencyConverterApiApiKey(CURRENCY_CONVERTER_API_API_KEY)
            .currencyLayerApiKey(CURRENCY_LAYER)
            .openExchangeRatesApiKey(OPEN_EXCHANGE_RATES)
            .build()
    );

    Sure, you are able to use only one service:

    public static final String OPEN_EXCHANGE_RATES = "YOUR API KEY FOR OpenExchangeRates.Com";
    
    CurrencyConverter converter = new CurrencyConverter(
        new ConfigBuilder()
            .openExchangeRatesApiKey(OPEN_EXCHANGE_RATES)
            .build()
    );

    How it works

    // Get rate with Currency Enum
    Double gbrToChfRate = converter.rate(Currency.GBP, Currency.CHF);
    
    // Get rate with half fixed method
    Double usdToEuroRate = converter.rateFromUsd(Currency.EUR);
    
    // Get rate with fixed method
    Double usdToEuroRate = converter.rateFromUsdToEuro();
    
    // Get rate with String parameters
    Double usdToEuroRate = converter.rate("USD", "EUR");

    ApiKey

    Sing up on websites you are going to use:

    and get key for use this services.

    API key looks like symbolic string.

    Android

    The working process for Android is different from the usual Java application. Network requests from the main tread are prohibited for Android, so a possible way to call Currency Converter library is by creating AsyncTask wrapper. See Examples.

    Also, it should be noted, Android application should have permissions to interaction with Network. Add to AndroidManifest.xml:

    <uses-permission android:name="android.permission.INTERNET"/>

    AsyncTask in Android

    License

    Currency Converter is available under the MIT license.

    currency-converter's People

    Contributors

    posadskiy avatar dependabot[bot] avatar

    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.