Sha256: e0e932c62ad66b944a5229b26540fa64fd486de2c6792641f48d68a421e4aa3e

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

require "digest/sha1"
require "faraday"
require "faraday_middleware"
require "rash"

module FXStreet
  class Client
    attr_reader :client_id, :client_secret

    def initialize(options={})
      @client_id     = options.fetch(:client_id)     { ENV["FX_STREET_CLIENT_ID"] }
      @client_secret = options.fetch(:client_secret) { ENV["FX_STREET_CLIENT_SECRET"] }
    end

    def event_dates(params={})
      get("eventdate/", params)
    end

    private

    def connection
      @connection ||= Faraday.new(host) do |conn|
        conn.request :json

        conn.response :rashify
        conn.response :json, content_type: /\bjson$/

        conn.adapter Faraday.default_adapter
      end
    end

    def default_params
      {
        f: "json",
        k: client_id,
        s: sha,
        t: timestamp,
        view: "day"
      }
    end

    def get(url, params={})
      connection.get(url, params.merge(default_params)).body
    end

    def host
      "http://calendar.fxstreet.com/"
    end

    def sha
      Digest::SHA1.hexdigest(client_secret + timestamp)
    end

    def timestamp
      @time ||= Time.now.utc.strftime("%Y%m%d%H%M")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fx_street-0.0.1 lib/fx_street/client.rb