source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/adapter_registry_spec.rb | Ruby | mit | 5,928 | main | 816 | # frozen_string_literal: true
RSpec.describe Faraday::AdapterRegistry do
describe '#initialize' do
subject(:registry) { described_class.new }
it { expect { registry.get(:FinFangFoom) }.to raise_error(NameError) }
it { expect { registry.get('FinFangFoom') }.to raise_error(NameError) }
it 'looks up c... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/adapter_spec.rb | Ruby | mit | 5,928 | main | 1,140 | # frozen_string_literal: true
RSpec.describe Faraday::Adapter do
let(:adapter) { Faraday::Adapter.new }
let(:request) { {} }
context '#request_timeout' do
it 'gets :read timeout' do
expect(timeout(:read)).to eq(nil)
request[:timeout] = 5
request[:write_timeout] = 1
expect(timeout(:... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/request_spec.rb | Ruby | mit | 5,928 | main | 3,796 | # frozen_string_literal: true
RSpec.describe Faraday::Request do
let(:conn) do
Faraday.new(url: 'http://httpbingo.org/api',
headers: { 'Mime-Version' => '1.0' },
request: { oauth: { consumer_key: 'anonymous' } })
end
let(:http_method) { :get }
let(:block) { nil }
subject ... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/response_spec.rb | Ruby | mit | 5,928 | main | 2,743 | # frozen_string_literal: true
RSpec.describe Faraday::Response do
subject { Faraday::Response.new(env) }
let(:env) do
Faraday::Env.from(status: 404, body: 'yikes', url: Faraday::Utils.URI('https://lostisland.github.io/faraday'),
response_headers: { 'Content-Type' => 'text/plain' })
end... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/rack_builder_spec.rb | Ruby | mit | 5,928 | main | 9,021 | # frozen_string_literal: true
RSpec.describe Faraday::RackBuilder do
# mock handler classes
(Handler = Struct.new(:app)).class_eval do
def call(env)
env[:request_headers]['X-Middleware'] ||= ''
env[:request_headers]['X-Middleware'] += ":#{self.class.name.split('::').last}"
app.call(env)
e... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/params_encoders/nested_spec.rb | Ruby | mit | 5,928 | main | 4,934 | # frozen_string_literal: true
require 'rack/utils'
RSpec.describe Faraday::NestedParamsEncoder do
it_behaves_like 'a params encoder'
it 'decodes arrays' do
query = 'a[1]=one&a[2]=two&a[3]=three'
expected = { 'a' => %w[one two three] }
expect(subject.decode(query)).to eq(expected)
end
it 'deco... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/params_encoders/flat_spec.rb | Ruby | mit | 5,928 | main | 1,157 | # frozen_string_literal: true
require 'rack/utils'
RSpec.describe Faraday::FlatParamsEncoder do
it_behaves_like 'a params encoder'
it 'decodes arrays' do
query = 'a=one&a=two&a=three'
expected = { 'a' => %w[one two three] }
expect(subject.decode(query)).to eq(expected)
end
it 'decodes boolean va... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/response/json_spec.rb | Ruby | mit | 5,928 | main | 5,674 | # frozen_string_literal: true
RSpec.describe Faraday::Response::Json, type: :response do
let(:options) { {} }
let(:headers) { {} }
let(:middleware) do
described_class.new(lambda { |env|
Faraday::Response.new(env)
}, **options)
end
def process(body, content_type = 'application/json', options = ... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/response/logger_spec.rb | Ruby | mit | 5,928 | main | 10,074 | # frozen_string_literal: true
require 'stringio'
require 'logger'
RSpec.describe Faraday::Response::Logger do
let(:string_io) { StringIO.new }
let(:logger) { Logger.new(string_io) }
let(:logger_options) { {} }
let(:conn) do
rubbles = ['Barney', 'Betty', 'Bam Bam']
Faraday.new do |b|
b.response ... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/response/raise_error_spec.rb | Ruby | mit | 5,928 | main | 12,415 | # frozen_string_literal: true
RSpec.describe Faraday::Response::RaiseError do
let(:conn) do
Faraday.new do |b|
b.response :raise_error
b.adapter :test do |stub|
stub.get('ok') { [200, { 'Content-Type' => 'text/html' }, '<body></body>'] }
stub.get('bad-request') { [400, { 'X-Reason' =>... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/request/url_encoded_spec.rb | Ruby | mit | 5,928 | main | 3,240 | # frozen_string_literal: true
require 'stringio'
RSpec.describe Faraday::Request::UrlEncoded do
let(:conn) do
Faraday.new do |b|
b.request :url_encoded
b.adapter :test do |stub|
stub.post('/echo') do |env|
posted_as = env[:request_headers]['Content-Type']
body = env[:body... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/request/json_spec.rb | Ruby | mit | 5,928 | main | 4,693 | # frozen_string_literal: true
RSpec.describe Faraday::Request::Json do
let(:middleware) { described_class.new(->(env) { Faraday::Response.new(env) }) }
def process(body, content_type = nil)
env = { body: body, request_headers: Faraday::Utils::Headers.new }
env[:request_headers]['content-type'] = content_t... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/request/instrumentation_spec.rb | Ruby | mit | 5,928 | main | 1,930 | # frozen_string_literal: true
RSpec.describe Faraday::Request::Instrumentation do
class FakeInstrumenter
attr_reader :instrumentations
def initialize
@instrumentations = []
end
def instrument(name, env)
@instrumentations << [name, env]
yield
end
end
let(:config) { {} }
... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/request/authorization_spec.rb | Ruby | mit | 5,928 | main | 3,565 | # frozen_string_literal: true
RSpec.describe Faraday::Request::Authorization do
let(:conn) do
Faraday.new do |b|
b.request :authorization, auth_type, *auth_config
b.adapter :test do |stub|
stub.get('/auth-echo') do |env|
[200, {}, env[:request_headers]['Authorization']]
end
... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/utils/headers_spec.rb | Ruby | mit | 5,928 | main | 3,999 | # frozen_string_literal: true
RSpec.describe Faraday::Utils::Headers do
subject { Faraday::Utils::Headers.new }
context 'when Content-Type is set to application/json' do
before { subject['Content-Type'] = 'application/json' }
it { expect(subject.keys).to eq(['Content-Type']) }
it { expect(subject['Co... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/adapter/test_spec.rb | Ruby | mit | 5,928 | main | 14,890 | # frozen_string_literal: true
RSpec.describe Faraday::Adapter::Test do
let(:stubs) do
described_class::Stubs.new do |stub|
stub.get('http://domain.test/hello') do
[200, { 'Content-Type' => 'text/html' }, 'domain: hello']
end
stub.get('http://wrong.test/hello') do
[200, { 'Conte... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/options/options_spec.rb | Ruby | mit | 5,928 | main | 8,528 | # frozen_string_literal: true
RSpec.describe Faraday::Options do
SubOptions = Class.new(Faraday::Options.new(:sub_a, :sub_b))
ParentOptions = Faraday::Options.new(:a, :b, :c) do
options c: SubOptions
end
describe '#merge' do
it 'merges options with hashes' do
options = ParentOptions.new(1)
... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/options/proxy_options_spec.rb | Ruby | mit | 5,928 | main | 2,909 | # frozen_string_literal: true
RSpec.describe Faraday::ProxyOptions do
describe '#from' do
it 'works with string' do
options = Faraday::ProxyOptions.from 'http://user:pass@example.org'
expect(options.user).to eq('user')
expect(options.password).to eq('pass')
expect(options.uri).to be_a_kin... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/options/request_options_spec.rb | Ruby | mit | 5,928 | main | 574 | # frozen_string_literal: true
RSpec.describe Faraday::RequestOptions do
subject(:options) { Faraday::RequestOptions.new }
it 'allows to set the request proxy' do
expect(options.proxy).to be_nil
expect { options[:proxy] = { booya: 1 } }.to raise_error(NoMethodError)
options[:proxy] = { user: 'user' }... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/faraday/options/env_spec.rb | Ruby | mit | 5,928 | main | 1,882 | # frozen_string_literal: true
RSpec.describe Faraday::Env do
subject(:env) { described_class.new }
it 'allows to access members' do
expect(env.method).to be_nil
env.method = :get
expect(env.method).to eq(:get)
end
it 'allows to access symbol non members' do
expect(env[:custom]).to be_nil
... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/external_adapters/faraday_specs_setup.rb | Ruby | mit | 5,928 | main | 443 | # frozen_string_literal: true
require 'webmock/rspec'
WebMock.disable_net_connect!(allow_localhost: true)
require_relative '../support/helper_methods'
require_relative '../support/disabling_stub'
require_relative '../support/streaming_response_checker'
require_relative '../support/shared_examples/adapter'
require_rel... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/support/helper_methods.rb | Ruby | mit | 5,928 | main | 1,863 | # frozen_string_literal: true
module Faraday
module HelperMethods
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def features(*features)
@features = features
end
def on_feature(name)
yield if block_given? && feature?(name)
end
... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/support/fake_safe_buffer.rb | Ruby | mit | 5,928 | main | 312 | # frozen_string_literal: true
# emulates ActiveSupport::SafeBuffer#gsub
FakeSafeBuffer = Struct.new(:string) do
def to_s
self
end
def gsub(regex)
string.gsub(regex) do
match, = Regexp.last_match(0), '' =~ /a/ # rubocop:disable Performance/StringInclude
yield(match)
end
end
end |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/support/streaming_response_checker.rb | Ruby | mit | 5,928 | main | 1,063 | # frozen_string_literal: true
module Faraday
module StreamingResponseChecker
def check_streaming_response(streamed, options = {})
opts = {
prefix: '',
streaming?: true
}.merge(options)
expected_response = opts[:prefix] + big_string
chunks, sizes = streamed.transpose
... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/support/faraday_middleware_subclasses.rb | Ruby | mit | 5,928 | main | 667 | # frozen_string_literal: true
module FaradayMiddlewareSubclasses
class SubclassNoOptions < Faraday::Middleware
end
class SubclassOneOption < Faraday::Middleware
DEFAULT_OPTIONS = { some_other_option: false }.freeze
end
class SubclassTwoOptions < Faraday::Middleware
DEFAULT_OPTIONS = { some_option: ... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/support/disabling_stub.rb | Ruby | mit | 5,928 | main | 205 | # frozen_string_literal: true
# Allows to disable WebMock stubs
module DisablingStub
def disable
@disabled = true
end
def disabled?
@disabled
end
WebMock::RequestStub.prepend self
end |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/support/shared_examples/params_encoder.rb | Ruby | mit | 5,928 | main | 502 | # frozen_string_literal: true
shared_examples 'a params encoder' do
it 'escapes safe buffer' do
monies = FakeSafeBuffer.new('$32,000.00')
expect(subject.encode('a' => monies)).to eq('a=%2432%2C000.00')
end
it 'raises type error for empty string' do
expect { subject.encode('') }.to raise_error(TypeEr... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/support/shared_examples/adapter.rb | Ruby | mit | 5,928 | main | 2,425 | # frozen_string_literal: true
shared_examples 'an adapter' do |**options|
before { skip } if options[:skip]
context 'with SSL enabled' do
before { ENV['SSL'] = 'yes' }
include_examples 'adapter examples', options
end
context 'with SSL disabled' do
before { ENV['SSL'] = 'no' }
include_examples... |
github | lostisland/faraday | https://github.com/lostisland/faraday | spec/support/shared_examples/request_method.rb | Ruby | mit | 5,928 | main | 8,145 | # frozen_string_literal: true
shared_examples 'proxy examples' do
it 'handles requests with proxy' do
res = conn.public_send(http_method, '/')
expect(res.status).to eq(200)
end
it 'handles proxy failures' do
request_stub.to_return(status: 407)
expect { conn.public_send(http_method, '/') }.to r... |
github | lostisland/faraday | https://github.com/lostisland/faraday | examples/client_test.rb | Ruby | mit | 5,928 | main | 3,632 | # frozen_string_literal: true
# Requires Ruby with test-unit and faraday gems.
# ruby client_test.rb
require 'faraday'
require 'json'
require 'test/unit'
# Example API client
class Client
def initialize(conn)
@conn = conn
end
def httpbingo(jname, params: {})
res = @conn.get("/#{jname}", params)
da... |
github | lostisland/faraday | https://github.com/lostisland/faraday | examples/client_spec.rb | Ruby | mit | 5,928 | main | 3,362 | # frozen_string_literal: true
# Requires Ruby with rspec and faraday gems.
# rspec client_spec.rb
require 'faraday'
require 'json'
# Example API client
class Client
def initialize(conn)
@conn = conn
end
def httpbingo(jname, params: {})
res = @conn.get("/#{jname}", params)
data = JSON.parse(res.bod... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday.rb | Ruby | mit | 5,928 | main | 5,387 | # frozen_string_literal: true
require 'cgi/escape'
require 'cgi/util' if RUBY_VERSION < '3.5'
require 'date'
require 'set'
require 'forwardable'
require 'faraday/version'
require 'faraday/methods'
require 'faraday/error'
require 'faraday/middleware_registry'
require 'faraday/utils'
require 'faraday/options'
require 'f... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/error.rb | Ruby | mit | 5,928 | main | 6,386 | # frozen_string_literal: true
# Faraday namespace.
module Faraday
# Faraday error base class.
class Error < StandardError
attr_reader :response, :wrapped_exception
def initialize(exc = nil, response = nil)
@wrapped_exception = nil unless defined?(@wrapped_exception)
@response = nil unless defi... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/rack_builder.rb | Ruby | mit | 5,928 | main | 6,894 | # frozen_string_literal: true
require 'faraday/adapter_registry'
module Faraday
# A Builder that processes requests into responses by passing through an inner
# middleware stack (heavily inspired by Rack).
#
# @example
# Faraday::Connection.new(url: 'http://httpbingo.org') do |builder|
# builder.req... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/utils.rb | Ruby | mit | 5,928 | main | 2,930 | # frozen_string_literal: true
require 'uri'
require 'faraday/utils/headers'
require 'faraday/utils/params_hash'
module Faraday
# Utils contains various static helper methods.
module Utils
module_function
def build_query(params)
FlatParamsEncoder.encode(params)
end
def build_nested_query(pa... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/adapter.rb | Ruby | mit | 5,928 | main | 2,953 | # frozen_string_literal: true
module Faraday
# Base class for all Faraday adapters. Adapters are
# responsible for fulfilling a Faraday request.
class Adapter
extend MiddlewareRegistry
CONTENT_LENGTH = 'Content-Length'
TIMEOUT_KEYS = {
read: :read_timeout,
open: :open_timeout,
wri... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/adapter_registry.rb | Ruby | mit | 5,928 | main | 597 | # frozen_string_literal: true
require 'monitor'
module Faraday
# AdapterRegistry registers adapter class names so they can be looked up by a
# String or Symbol name.
class AdapterRegistry
def initialize
@lock = Monitor.new
@constants = {}
end
def get(name)
klass = @lock.synchroniz... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/middleware_registry.rb | Ruby | mit | 5,928 | main | 2,180 | # frozen_string_literal: true
require 'monitor'
module Faraday
# Adds the ability for other modules to register and lookup
# middleware classes.
module MiddlewareRegistry
def registered_middleware
@registered_middleware ||= {}
end
# Register middleware class(es) on the current module.
#
... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/options.rb | Ruby | mit | 5,928 | main | 4,691 | # frozen_string_literal: true
module Faraday
# Subclasses Struct with some special helpers for converting from a Hash to
# a Struct.
class Options < Struct
# Public
def self.from(value)
value ? new.update(value) : new
end
# Public
def each
return to_enum(:each) unless block_given... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/middleware.rb | Ruby | mit | 5,928 | main | 2,086 | # frozen_string_literal: true
require 'monitor'
module Faraday
# Middleware is the basic base class of any Faraday middleware.
class Middleware
extend MiddlewareRegistry
attr_reader :app, :options
DEFAULT_OPTIONS = {}.freeze
LOCK = Mutex.new
def initialize(app = nil, options = {})
@ap... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/connection.rb | Ruby | mit | 5,928 | main | 18,646 | # frozen_string_literal: true
module Faraday
# Connection objects manage the default properties and the middleware
# stack for fulfilling an HTTP request.
#
# @example
#
# conn = Faraday::Connection.new 'http://httpbingo.org'
#
# # GET http://httpbingo.org/nigiri
# conn.get 'nigiri'
# # => ... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/request.rb | Ruby | mit | 5,928 | main | 3,894 | # frozen_string_literal: true
module Faraday
# Used to setup URLs, params, headers, and the request body in a sane manner.
#
# @example
# @connection.post do |req|
# req.url 'http://localhost', 'a' => '1' # 'http://localhost?a=1'
# req.headers['b'] = '2' # Header
# req.params['c'] = '3' # ... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/response.rb | Ruby | mit | 5,928 | main | 1,883 | # frozen_string_literal: true
require 'forwardable'
module Faraday
# Response represents an HTTP response from making an HTTP request.
class Response
extend Forwardable
extend MiddlewareRegistry
def initialize(env = nil)
@env = Env.from(env) if env
@on_complete_callbacks = []
end
... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/encoders/nested_params_encoder.rb | Ruby | mit | 5,928 | main | 5,143 | # frozen_string_literal: true
module Faraday
# Sub-module for encoding parameters into query-string.
module EncodeMethods
# @param params [nil, Array, #to_hash] parameters to be encoded
#
# @return [String] the encoded params
#
# @raise [TypeError] if params can not be converted to a Hash
d... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/encoders/flat_params_encoder.rb | Ruby | mit | 5,928 | main | 3,077 | # frozen_string_literal: true
module Faraday
# FlatParamsEncoder manages URI params as a flat hash. Any Array values repeat
# the parameter multiple times.
module FlatParamsEncoder
class << self
extend Forwardable
def_delegators :'Faraday::Utils', :escape, :unescape
end
# Encode convert... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/response/json.rb | Ruby | mit | 5,928 | main | 2,125 | # frozen_string_literal: true
require 'json'
module Faraday
class Response
# Parse response bodies as JSON.
class Json < Middleware
def initialize(app = nil, parser_options: nil, content_type: /\bjson$/, preserve_raw: false)
super(app)
@parser_options = parser_options
@content_... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/response/raise_error.rb | Ruby | mit | 5,928 | main | 2,855 | # frozen_string_literal: true
module Faraday
class Response
# RaiseError is a Faraday middleware that raises exceptions on common HTTP
# client or server error responses.
class RaiseError < Middleware
# rubocop:disable Naming/ConstantName
ClientErrorStatuses = (400...500)
ServerErrorSta... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/response/logger.rb | Ruby | mit | 5,928 | main | 1,153 | # frozen_string_literal: true
require 'forwardable'
require 'logger'
require 'faraday/logging/formatter'
module Faraday
class Response
# Logger is a middleware that logs internal events in the HTTP request
# lifecycle to a given Logger object. By default, this logs to STDOUT. See
# Faraday::Logging::For... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/options/ssl_options.rb | Ruby | mit | 5,928 | main | 3,126 | # frozen_string_literal: true
module Faraday
# @!parse
# # SSL-related options.
# #
# # @!attribute verify
# # @return [Boolean] whether to verify SSL certificates or not
# #
# # @!attribute verify_hostname
# # @return [Boolean] whether to enable hostname verification on server certif... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/options/request_options.rb | Ruby | mit | 5,928 | main | 670 | # frozen_string_literal: true
module Faraday
# @!parse
# # RequestOptions contains the configurable properties for a Faraday request.
# class RequestOptions < Options; end
RequestOptions = Options.new(:params_encoder, :proxy, :bind,
:timeout, :open_timeout, :read_timeout,
... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/options/env.rb | Ruby | mit | 5,928 | main | 5,828 | # frozen_string_literal: true
module Faraday
# @!parse
# # @!attribute method
# # @return [Symbol] HTTP method (`:get`, `:post`)
# #
# # @!attribute body
# # @return [String] The request body that will eventually be converted to a
# # string.
# #
# # @!attribute url
# # @r... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/options/proxy_options.rb | Ruby | mit | 5,928 | main | 1,155 | # frozen_string_literal: true
module Faraday
# @!parse
# # ProxyOptions contains the configurable properties for the proxy
# # configuration used when making an HTTP request.
# class ProxyOptions < Options; end
ProxyOptions = Options.new(:uri, :user, :password) do
extend Forwardable
def_delega... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/options/connection_options.rb | Ruby | mit | 5,928 | main | 705 | # frozen_string_literal: true
module Faraday
# @!parse
# # ConnectionOptions contains the configurable properties for a Faraday
# # connection object.
# class ConnectionOptions < Options; end
ConnectionOptions = Options.new(:request, :proxy, :ssl, :builder, :url,
:para... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/adapter/test.rb | Ruby | mit | 5,928 | main | 9,568 | # frozen_string_literal: true
require 'timeout'
module Faraday
class Adapter
# @example
# test = Faraday::Connection.new do
# use Faraday::Adapter::Test do |stub|
# # Define matcher to match the request
# stub.get '/resource.json' do
# # return static content
# ... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/request/json.rb | Ruby | mit | 5,928 | main | 1,946 | # frozen_string_literal: true
require 'json'
module Faraday
class Request
# Request middleware that encodes the body as JSON.
#
# Processes only requests with matching Content-type or those without a type.
# If a request doesn't have a type but has a body, it sets the Content-type
# to JSON MIME... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/request/url_encoded.rb | Ruby | mit | 5,928 | main | 1,742 | # frozen_string_literal: true
module Faraday
class Request
# Middleware for supporting urlencoded requests.
class UrlEncoded < Faraday::Middleware
unless defined?(::Faraday::Request::UrlEncoded::CONTENT_TYPE)
CONTENT_TYPE = 'Content-Type'
end
class << self
attr_accessor :mi... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/request/authorization.rb | Ruby | mit | 5,928 | main | 1,866 | # frozen_string_literal: true
module Faraday
class Request
# Request middleware for the Authorization HTTP header
class Authorization < Faraday::Middleware
KEY = 'Authorization'
# @param app [#call]
# @param type [String, Symbol] Type of Authorization
# @param params [Array<String, P... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/request/instrumentation.rb | Ruby | mit | 5,928 | main | 1,913 | # frozen_string_literal: true
module Faraday
class Request
# Middleware for instrumenting Requests.
class Instrumentation < Faraday::Middleware
# Options class used in Request::Instrumentation class.
Options = Faraday::Options.new(:name, :instrumenter) do
remove_method :name
# @re... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/utils/headers.rb | Ruby | mit | 5,928 | main | 3,431 | # frozen_string_literal: true
module Faraday
module Utils
# A case-insensitive Hash that preserves the original case of a header
# when set.
#
# Adapted from Rack::Utils::HeaderHash
class Headers < ::Hash
def self.from(value)
new(value)
end
def self.allocate
new... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/utils/params_hash.rb | Ruby | mit | 5,928 | main | 1,138 | # frozen_string_literal: true
module Faraday
module Utils
# A hash with stringified keys.
class ParamsHash < Hash
def [](key)
super(convert_key(key))
end
def []=(key, value)
super(convert_key(key), value)
end
def delete(key)
super(convert_key(key))
... |
github | lostisland/faraday | https://github.com/lostisland/faraday | lib/faraday/logging/formatter.rb | Ruby | mit | 5,928 | main | 3,185 | # frozen_string_literal: true
require 'pp' # This require is necessary for Hash#pretty_inspect to work, do not remove it, people rely on it.
module Faraday
module Logging
# Serves as an integration point to customize logging
class Formatter
extend Forwardable
DEFAULT_OPTIONS = { headers: true, ... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | Guardfile | Ruby | mit | 5,889 | main | 360 | rspec_options = {
all_after_pass: false,
all_on_start: false,
failed_mode: :keep,
cmd: 'bundle exec rspec',
}
guard 'rspec', rspec_options do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
end
guard 'bundler' do
watch... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | httparty.gemspec | Ruby | mit | 5,889 | main | 1,241 | # -*- encoding: utf-8 -*-
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
require "httparty/version"
Gem::Specification.new do |s|
s.name = "httparty"
s.version = HTTParty::VERSION
s.platform = Gem::Platform::RUBY
s.licenses = ['MIT']
s.authors = ["John Nunemaker", "Sandro Turriate"... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | Gemfile | Ruby | mit | 5,889 | main | 404 | source 'https://rubygems.org'
gemspec
gem 'base64'
gem 'rake'
gem 'mongrel', '1.2.0.pre2'
gem 'json'
group :development do
gem 'guard'
gem 'guard-rspec'
gem 'guard-bundler'
end
group :test do
gem 'rexml'
gem 'rspec', '~> 3.4'
gem 'simplecov', require: false
gem 'aruba'
gem 'cucumber', '~> 2.3'
... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/tripit_sign_in.rb | Ruby | mit | 5,889 | main | 1,079 | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
class TripIt
include HTTParty
base_uri 'https://www.tripit.com'
debug_output
def initialize(email, password)
@email = email
get_response = self.class.get('/account/login')
get_response_cookie ... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/multipart.rb | Ruby | mit | 5,889 | main | 797 | # If you are uploading file in params, multipart will used as content-type automatically
HTTParty.post(
'http://localhost:3000/user',
body: {
name: 'Foo Bar',
email: 'example@email.com',
avatar: File.open('/full/path/to/avatar.jpg')
}
)
# However, you can force it yourself
HTTParty.post(
'http:/... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/aaws.rb | Ruby | mit | 5,889 | main | 1,125 | require 'rubygems'
require 'active_support'
require 'active_support/core_ext/hash'
require 'active_support/core_ext/string'
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
config = YAML.load(File.read(File.join(ENV['HOME'], '.aaws')))
module AAWS
... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/body_stream.rb | Ruby | mit | 5,889 | main | 298 | # To upload file to a server use :body_stream
HTTParty.put(
'http://localhost:3000/train',
body_stream: File.open('sample_configs/config_train_server_md.yml', 'r')
)
# Actually, it works with any IO object
HTTParty.put(
'http://localhost:3000/train',
body_stream: StringIO.new('foo')
) |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/crack.rb | Ruby | mit | 5,889 | main | 428 | require 'rubygems'
require 'crack'
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
class Rep
include HTTParty
parser(
proc do |body, format|
Crack::XML.parse(body)
end
)
end
pp Rep.get('http://whoismyrepresentative.com/getall... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/custom_parsers.rb | Ruby | mit | 5,889 | main | 1,154 | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
class ParseAtom
include HTTParty
# Support Atom along with the default parsers: xml, json, etc.
class Parser::Atom < HTTParty::Parser
SupportedFormats.merge!({"application/atom+xml" => :ato... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/twitter.rb | Ruby | mit | 5,889 | main | 976 | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
config = YAML.load(File.read(File.join(ENV['HOME'], '.twitter')))
class Twitter
include HTTParty
base_uri 'twitter.com'
def initialize(u, p)
@auth = {username: u, password: p}
end
# wh... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/rescue_json.rb | Ruby | mit | 5,889 | main | 646 | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
# Take note of the "; 1" at the end of the following line. It's required only if
# running this in IRB, because IRB will try to inspect the variable named
# "request", triggering the exception.
request = HTTParty.... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/whoismyrep.rb | Ruby | mit | 5,889 | main | 313 | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
class Rep
include HTTParty
end
pp Rep.get('http://whoismyrepresentative.com/getall_mems.php?zip=46544')
pp Rep.get('http://whoismyrepresentative.com/getall_mems.php', query: { zip: 46544 }) |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/logging.rb | Ruby | mit | 5,889 | main | 994 | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'logger'
require 'pp'
my_logger = Logger.new STDOUT
my_logger.info "Logging can be used on the main HTTParty class. It logs redirects too."
HTTParty.get "http://google.com", logger: my_logger
my_logger.i... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/delicious.rb | Ruby | mit | 5,889 | main | 1,171 | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
config = YAML.load(File.read(File.join(ENV['HOME'], '.delicious')))
class Delicious
include HTTParty
base_uri 'https://api.del.icio.us/v1'
def initialize(u, p)
@auth = { username: u, passwo... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/rubyurl.rb | Ruby | mit | 5,889 | main | 345 | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
class Rubyurl
include HTTParty
base_uri 'rubyurl.com'
def self.shorten(website_url)
post('/api/links.json', query: { link: { website_url: website_url } })
end
end
pp Rubyurl.shorten('htt... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/microsoft_graph.rb | Ruby | mit | 5,889 | main | 1,554 | require 'httparty'
class MicrosoftGraph
MS_BASE_URL = "https://login.microsoftonline.com".freeze
TOKEN_REQUEST_PATH = "oauth2/v2.0/token".freeze
def initialize(tenant_id)
@tenant_id = tenant_id
end
# Make a request to the Microsoft Graph API, for instance https://graph.microsoft.com/v1.0/users
def re... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/peer_cert.rb | Ruby | mit | 5,889 | main | 291 | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
peer_cert = nil
HTTParty.get("https://www.example.com") do |fragment|
peer_cert ||= fragment.connection.peer_cert
end
puts "The server's certificate expires #{peer_cert.not_after}" |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/party_foul_mode.rb | Ruby | mit | 5,889 | main | 1,963 | require 'httparty'
class APIClient
include HTTParty
base_uri 'api.example.com'
def self.fetch_user(id)
begin
get("/users/#{id}", foul: true)
rescue HTTParty::NetworkError => e
handle_network_error(e)
rescue HTTParty::ResponseError => e
handle_api_error(e)
end
end
private
... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/stream_download.rb | Ruby | mit | 5,889 | main | 755 | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
# download file linux-4.6.4.tar.xz without using the memory
response = nil
filename = "linux-4.6.4.tar.xz"
url = "https://cdn.kernel.org/pub/linux/kernel/v4.x/#{filename}"
File.open(filename, "w") do... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/stackexchange.rb | Ruby | mit | 5,889 | main | 533 | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
class StackExchange
include HTTParty
base_uri 'api.stackexchange.com'
def initialize(service, page)
@options = { query: { site: service, page: page } }
end
def questions
self.class... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/headers_and_user_agents.rb | Ruby | mit | 5,889 | main | 450 | # To send custom user agents to identify your application to a web service (or mask as a specific browser for testing), send "User-Agent" as a hash to headers as shown below.
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
response = HTTParty.get(... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/google.rb | Ruby | mit | 5,889 | main | 386 | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
class Google
include HTTParty
format :html
end
# google.com redirects to www.google.com so this is live test for redirection
pp Google.get('http://google.com')
puts '', '*' * 70, ''
# check tha... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/nokogiri_html_parser.rb | Ruby | mit | 5,889 | main | 350 | require 'rubygems'
require 'nokogiri'
dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
class HtmlParserIncluded < HTTParty::Parser
def html
Nokogiri::HTML(body)
end
end
class Page
include HTTParty
parser HtmlParserIncluded
end
pp Page... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/basic.rb | Ruby | mit | 5,889 | main | 807 | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
# You can also use post, put, delete, head, options in the same fashion
response = HTTParty.get('https://api.stackexchange.com/2.2/questions?site=stackoverflow')
puts response.body, response.code, res... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | examples/idn.rb | Ruby | mit | 5,889 | main | 250 | dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
require File.join(dir, 'httparty')
require 'pp'
class Idn
include HTTParty
uri_adapter Addressable::URI
end
pp Idn.get("https://i❤️.ws/emojidomain/💎?format=json") |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | spec/spec_helper.rb | Ruby | mit | 5,889 | main | 1,258 | require "simplecov"
SimpleCov.start
require "httparty"
require 'webmock/rspec'
def file_fixture(filename)
open(File.join(File.dirname(__FILE__), 'fixtures', "#{filename}")).read
end
Dir[File.expand_path(File.join(File.dirname(__FILE__), 'support', '**', '*.rb'))].each {|f| require f}
RSpec.configure do |config|
... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | spec/httparty_spec.rb | Ruby | mit | 5,889 | main | 36,442 | require_relative 'spec_helper'
RSpec.describe HTTParty do
before(:each) do
@klass = Class.new
@klass.instance_eval { include HTTParty }
end
describe "pem" do
it 'should set the pem content' do
@klass.pem 'PEM-CONTENT'
expect(@klass.default_options[:pem]).to eq('PEM-CONTENT')
end
... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | spec/httparty/cookie_hash_spec.rb | Ruby | mit | 5,889 | main | 3,535 | require 'spec_helper'
RSpec.describe HTTParty::CookieHash do
before(:each) do
@cookie_hash = HTTParty::CookieHash.new
end
describe "#add_cookies" do
describe "with a hash" do
it "should add new key/value pairs to the hash" do
@cookie_hash.add_cookies(foo: "bar")
@cookie_hash.add_co... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | spec/httparty/request_spec.rb | Ruby | mit | 5,889 | main | 66,752 | require 'spec_helper'
RSpec.describe HTTParty::Request do
before do
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1', format: :xml)
end
describe "::NON_RAILS_QUERY_STRING_NORMALIZER" do
let(:normalizer) { HTTParty::Request::NON_RAILS_QUERY_STRING_NORMALIZER }
it "doesn't mod... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | spec/httparty/response_fragment_spec.rb | Ruby | mit | 5,889 | main | 578 | require File.expand_path(File.join(File.dirname(__FILE__), '../spec_helper'))
RSpec.describe HTTParty::ResponseFragment do
it "access to fragment" do
fragment = HTTParty::ResponseFragment.new("chunk", nil, nil)
expect(fragment).to eq("chunk")
end
it "has access to delegators" do
response = double(co... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | spec/httparty/connection_adapter_spec.rb | Ruby | mit | 5,889 | main | 21,152 | require 'spec_helper'
RSpec.describe HTTParty::ConnectionAdapter do
describe "initialization" do
let(:uri) { URI 'http://www.google.com' }
it "takes a URI as input" do
HTTParty::ConnectionAdapter.new(uri)
end
it "raises an ArgumentError if the uri is nil" do
expect { HTTParty::Connection... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | spec/httparty/response_spec.rb | Ruby | mit | 5,889 | main | 14,822 | require 'spec_helper'
RSpec.describe HTTParty::Response do
before do
@last_modified = Date.new(2010, 1, 15).to_s
@content_length = '1024'
@request_object = HTTParty::Request.new Net::HTTP::Get, '/'
@response_object = Net::HTTPOK.new('1.1', 200, 'OK')
allow(@response_object).to receive_messages(bo... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | spec/httparty/ssl_spec.rb | Ruby | mit | 5,889 | main | 3,222 | require 'spec_helper'
RSpec.describe HTTParty::Request do
context "SSL certificate verification" do
before do
WebMock.disable!
end
after do
WebMock.enable!
end
it "should fail when no trusted CA list is specified, by default" do
expect do
ssl_verify_test(nil, nil, "sel... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | spec/httparty/hash_conversions_spec.rb | Ruby | mit | 5,889 | main | 1,945 | require 'spec_helper'
RSpec.describe HTTParty::HashConversions do
describe ".to_params" do
it "creates a params string from a hash" do
hash = {
name: "bob",
address: {
street: '111 ruby ave.',
city: 'ruby central',
phones: ['111-111-1111', '222-222-2222']
... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | spec/httparty/exception_spec.rb | Ruby | mit | 5,889 | main | 1,105 | require 'spec_helper'
RSpec.describe HTTParty::Error do
subject { described_class }
describe '#ancestors' do
subject { super().ancestors }
it { is_expected.to include(StandardError) }
end
describe HTTParty::UnsupportedFormat do
describe '#ancestors' do
subject { super().ancestors }
it... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | spec/httparty/parser_spec.rb | Ruby | mit | 5,889 | main | 6,057 | require 'spec_helper'
require 'multi_xml'
RSpec.describe HTTParty::Parser do
describe ".SupportedFormats" do
it "returns a hash" do
expect(HTTParty::Parser::SupportedFormats).to be_instance_of(Hash)
end
end
describe ".call" do
it "generates an HTTParty::Parser instance with the given body and ... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | spec/httparty/headers_processor_spec.rb | Ruby | mit | 5,889 | main | 1,556 | require 'spec_helper'
RSpec.describe HTTParty::HeadersProcessor do
subject(:headers) { options[:headers] }
let(:options) { { headers: {} } }
let(:global_headers) { {} }
before { described_class.new(global_headers, options).call }
context 'when headers are not set at all' do
it 'returns empty hash' do
... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | spec/httparty/decompressor_spec.rb | Ruby | mit | 5,889 | main | 4,331 | require 'spec_helper'
RSpec.describe HTTParty::Decompressor do
describe '.SupportedEncodings' do
it 'returns a hash' do
expect(HTTParty::Decompressor::SupportedEncodings).to be_instance_of(Hash)
end
end
describe '#decompress' do
let(:body) { 'body' }
let(:encoding) { 'none' }
let(:deco... |
github | jnunemaker/httparty | https://github.com/jnunemaker/httparty | spec/httparty/net_digest_auth_spec.rb | Ruby | mit | 5,889 | main | 7,777 | require 'spec_helper'
RSpec.describe Net::HTTPHeader::DigestAuthenticator do
def setup_digest(response)
digest = Net::HTTPHeader::DigestAuthenticator.new("Mufasa",
"Circle Of Life", "GET", "/dir/index.html", response)
allow(digest).to receive(:random).and... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.