Sha256: da1c0b5240f1dc9fec9b40a14c93783a16ec07a09f6cf8c6d962e72e91d90ae3

Contents?: true

Size: 729 Bytes

Versions: 2

Compression:

Stored size: 729 Bytes

Contents

module ChhMoretext
  module Request
    def fetch_moretext(number, limit)
      number = {:n => "#{number}".to_i}
      limit  = parse(limit)
      condition = limit.nil? ? number : number.merge(limit)

      connection.get("sentences.json", condition).body["sentences"]
    end

    private

      def connection
        options = {
          :headers => { "Accept" => "application/json",
                        "User-Agent" => "ChhMoretext Ruby Gem #{ChhMoretext::VERSION}" },
          :url => Configuration::MORETEXT_DEFAULT_ENDPOINT,
        }

        Faraday.new(options) do |conn|
          conn.request  :json
          conn.response :json
          conn.adapter Faraday.default_adapter
        end
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
chh_moretext-0.1.7 lib/chh_moretext/request.rb
chh_moretext-0.1.6 lib/chh_moretext/request.rb