Sha256: d130790f651357eec5069e9d54e1d461d3a09a9487227bc207d470bfe0b866a6
Contents?: true
Size: 914 Bytes
Versions: 2
Compression:
Stored size: 914 Bytes
Contents
# lib/fxdatapi/weekly_average.rb # frozen_string_literal: true require 'net/http' require 'json' require_relative 'auth' module Fxdatapi class WeeklyAverage BASE_URL = 'https://fxdatapi.com/v1/weekly_average' def self.get_weekly_average(username, password, from_date, to_date) login_result = Authentication.login(username, password) cookie = "user_type=#{login_result['user_type']}; username=#{username}" uri = URI("#{BASE_URL}/#{from_date}/#{to_date}") request = Net::HTTP::Get.new(uri, 'Accept' => 'application/json', 'Cookie' => cookie) response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') { |http| http.request(request) } case response when Net::HTTPSuccess JSON.parse(response.body) else raise "Failed to fetch weekly average data: #{response.code} #{response.message}" end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
fxdatapi-0.1.3 | lib/fxdatapi/weekly_average.rb |
fxdatapi-0.1.2 | lib/fxdatapi/weekly_average.rb |