Sha256: fb89d7cd5f58c5fdef5923741f9678232e6f7c73e0a58843573319356ef61050

Contents?: true

Size: 848 Bytes

Versions: 8

Compression:

Stored size: 848 Bytes

Contents

require "rest-client"
require "wego/response"
require "wego/configuration"

module Wego
  class Client
    attr_reader :end_point, :attributes

    def initialize(end_point, attributes = {})
      @end_point = end_point
      @attributes = attributes
    end

    def get
      RestClient.get api_path, params: api_params
    end

    def url
      params = api_params.map { |key, value| "#{key}=#{value}" }.join("&")
      [api_path, params].join("?")
    end

    private

    def api_path
      [Wego.configuration.api_host, end_point].join("/")
    end

    def api_params
      Wego.configuration.api_keys.merge attributes
    end
  end

  def self.get_resource(end_point, api_params = {})
    Wego::Response.parse_json(
      Client.new(end_point, api_params).get
    )
  rescue RestClient::ResourceNotFound, RestClient::BadRequest
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
wego-0.2.1 lib/wego/client.rb
wego-0.2.0 lib/wego/client.rb
wego-0.1.5 lib/wego/client.rb
wego-0.1.4 lib/wego/client.rb
wego-0.1.3 lib/wego/client.rb
wego-0.1.2 lib/wego/client.rb
wego-0.1.1 lib/wego/client.rb
wego-0.1.0 lib/wego/client.rb