Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bestchange-api

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bestchange-api

  • 1.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

bestchange-api

bestchange-api is a simple library for getting data from Bestchange aggregator

Installation

Add this line to your application's Gemfile:

gem 'bestchange-api'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install bestchange-api

Usage

Bestchange api description

info.zip

require 'bestchange'

api_client = Bestchange::Api.new
response = api_client.request # this will call api.bestchange.ru/info.zip by default
archive = Bestchange::ZipBuilder.new(response.body).call
tempfile = Bestchange::ZipExtractor.new(archive).call('bm_rates.dat')

NOTE: Do not forget to close and unlink files at the end

archive.close
tempfile.close

Using blocks

The Bestchange::ZipBuilder and Bestchange::ZipExtractor classes support using blocks to ensure that tempfiles are closed automatically. This is useful when you want to avoid manual file management and prevent possible leaks

response = Bestchange::Api.new.request

Bestchange::ZipBuilder.new(response.body).call do |archive|
  # Work with archive here
  # archive will be closed automatically when the block finishes
  Bestchange::ZipExtractor.new(archive).call('bm_rates.dat') do |bm_rates|
    # Work with bm_rates here
    # bm_rates will be closed automatically when the block finishes
  end
end

Custom connection

You can pass your own http connection object while initializing an api client. This can be useful if you want to set custom timeouts, for example

require  'bestchange'

uri = URI(Bestchange::Api::BASE_URI)
conn = Net::HTTP.new(uri.host, uri.port)
conn.open_timeout = 5
conn.read_timeout = 10
api_client = Bestchange::Api.new(conn)

Custom request

You can provide your own http request object to the #request method

require  'bestchange'

request = Net::HTTP::Head.new(URI(Bestchange::Api::BASE_URI))
response = api_client.request(request)
created_at = response['Date']

License

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

Code of Conduct

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

FAQs

Package last updated on 24 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc