Sha256: f45aafd7f819f3ff488a4f7c2eab94c106d5bbb30516a9970f29d40ca70a8955

Contents?: true

Size: 1.36 KB

Versions: 13

Compression:

Stored size: 1.36 KB

Contents

require 'faraday'
require 'faraday_middleware'

require 'emojidex/api/categories'
require 'emojidex/api/emoji'
require 'emojidex/api/search/emoji'

module Emojidex
  # get the data from emojidex.com
  class Client
    attr_accessor :api_key, :api_username
    attr_reader :host

    include Emojidex::API::Categories
    include Emojidex::API::Emoji
    include Emojidex::API::Search::Emoji

    def initialize(opts = {})
      @api_key = opts[:api_key]
      @api_username = opts[:api_username]
      @host = opts[:host] || 'https://www.emojidex.com/'
    end

    def connection_options
      @connection_options ||= {
        url: @host,
        headers: {
          accept: 'application/json',
          user_agent: user_agent
        }
      }
    end

    def user_agent
      @user_agent ||= 'Emojidex Toolkit Client'
    end

    def get(path, params = {})
      request(:get, path, params)
    end

    private

    def connection
      @connection ||= Faraday.new connection_options do |conn|
        conn.request :url_encoded
        conn.response :json
        # conn.response :logger
        conn.adapter Faraday.default_adapter
      end
    end

    def request(method, path, params = {})
      response = connection.send(method.to_sym, path, params)
      response.env
    rescue Faraday::Error::ClientError, JSON::ParserError
      raise Emojidex::Error
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
emojidex-0.0.23 lib/emojidex/client.rb
emojidex-0.0.22 lib/emojidex/client.rb
emojidex-0.0.21 lib/emojidex/client.rb
emojidex-0.0.20 lib/emojidex/client.rb
emojidex-0.0.19 lib/emojidex/client.rb
emojidex-0.0.18 lib/emojidex/client.rb
emojidex-0.0.17 lib/emojidex/client.rb
emojidex-0.0.16 lib/emojidex/client.rb
emojidex-0.0.15 lib/emojidex/client.rb
emojidex-0.0.14 lib/emojidex/client.rb
emojidex-0.0.13 lib/emojidex/client.rb
emojidex-0.0.12 lib/emojidex/client.rb
emojidex-0.0.11 lib/emojidex/client.rb