GithubHelp home page GithubHelp logo

currency_layer_api's Introduction

CurrencyLayerApi

Currency Layer API is a light wrapper for currencylayer.com for Rubyists.

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add currency_layer_api

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install currency_layer_api

Usage

API Documentation

The API documentation can be found here.

Get Account Information

Create an account on currencylayer.com and get your API access key. Save the access key in an environment variable named CURRENCY_LAYER_ACCESS_KEY.

Configure

Currency Layer does not allow you ssl endpoint unless you have a paid account. By default ssl is enabled. To disable ssl, set the ssl option to false.

require 'currency_layer_api'
client = CurrencyLayerApi::Client.new(access_key: ENV['CURRENCY_LAYER_ACCESS_KEY'], ssl: true)

params:

  • access_key - Required - String - Your API access key.
  • ssl - Optional - Boolean - Enable or disable ssl. Default is true.

response:

#<CurrencyLayerApi::Client:0x00007f9b0a0b0a00 @access_key="YOUR_ACCESS_KEY", @ssl=true>

Get List of currencies

client.list

response:

[
  #<CurrencyLayerApi::Currency:0x00007f9b0a0b0a00 @code="AED", @name="United Arab Emirates Dirham">,
  #<CurrencyLayerApi::Currency:0x00007f9b0a0b09c0 @code="AFN", @name="Afghan Afghani">,
  ...
]

Get Live Exchange Rates

client.live(from: "USD", to: ["AED", "EUR"])

params:

  • from Required - String - The currency you want to convert from. (default: USD)
  • to Optional - Array[String] - The currencies you want to convert to. (default: nil)

response:

[
  #<CurrencyLayerApi::Conversion:0x00007f9b0a0b0a00 @from_code="USD", @to_code="AED", @value=3.6725, @date="2019-01-01">,
  #<CurrencyLayerApi::Conversion:0x00007f9b0a0b09c0 @from_code="USD", @to_code="EUR", @value=0.888, @date="2019-01-01">,
]

Get Historical Exchange Rates

client.historical(from: "USD", to: ["AED", "EUR"], date: "2019-01-01")

params:

  • from Required - String - The currency you want to convert from. (default: USD)
  • to Optional - Array[String] - The currencies you want to convert to. (default: nil)
  • date Required - String 'YYYY-MM-DD' - The date you want to get the exchange rates for. (default: nil)

response:

[
  #<CurrencyLayerApi::Conversion:0x00007f9b0a0b0a00 @from_code="USD", @to_code="AED", @value=3.6725, @date="2019-01-01">,
  #<CurrencyLayerApi::Conversion:0x00007f9b0a0b09c0 @from_code="USD", @to_code="EUR", @value=0.888, @date="2019-01-01">,
]

Get Conversion Rate given amount

client.convert(from: "USD", to: "AED", amount: 100)

params:

  • from Required - String - The currency you want to convert from. (default: USD)
  • to Required - String - The currency you want to convert to. (default: nil)
  • amount Required - Int - The amount you want to convert. (default: nil)
  • date Optional - String 'YYYY-MM-DD' - The date you want to get the exchange rates for. (default: nil)

response:

367.25

Error Handling

begin
  client.live(from: "USD", to: ["AED", "EUR"])
rescue CurrencyLayerApi::Error => e
    puts e.code
    puts e.message
end

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/currency_layer_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the CurrencyLayerApi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

currency_layer_api's People

Stargazers

 avatar

Watchers

 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.