Class: PostcodeAnywhere::Client
- Inherits:
-
Object
- Object
- PostcodeAnywhere::Client
- Defined in:
- lib/postcode_anywhere/client.rb
Direct Known Subclasses
BankAccountValidation::Client, PostcodeAnywhere::CapturePlus::Client, PostcodeAnywhere::CleansePlus::Client, EmailValidation::Client
Instance Method Summary collapse
- #connection ⇒ Object
- #connection_options ⇒ Object
-
#get(path, body_hash = {}, params = {}) ⇒ Object
Perform an HTTP GET request.
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #middleware ⇒ Object
-
#post(path, body_hash = {}, params = {}) ⇒ Object
Perform an HTTP POST request.
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 |
# File 'lib/postcode_anywhere/client.rb', line 13 def initialize( = {}) = PostcodeAnywhere..merge() Configuration::VALID_CONFIG_KEYS.each do |key| send("#{key}=", [key]) end end |
Instance Method Details
#connection ⇒ Object
46 47 48 |
# File 'lib/postcode_anywhere/client.rb', line 46 def connection @connection ||= Faraday.new(@endpoint, ) end |
#connection_options ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/postcode_anywhere/client.rb', line 31 def @connection_options ||= { builder: middleware, headers: { accept: "application/#{@format}", content_type: "application/#{@format}", user_agent: user_agent }, request: { open_timeout: 10, timeout: 30 } } end |
#get(path, body_hash = {}, params = {}) ⇒ Object
Perform an HTTP GET request
22 23 24 |
# File 'lib/postcode_anywhere/client.rb', line 22 def get(path, body_hash = {}, params = {}) request(:get, path, params, body_hash) end |
#middleware ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/postcode_anywhere/client.rb', line 50 def middleware @middleware ||= Faraday::RackBuilder.new do |faraday| # Checks for files in the payload, otherwise leaves everything untouched faraday.request :multipart # Encodes as "application/x-www-form-urlencoded" if not already encoded faraday.request :url_encoded # Handle error responses faraday.response :postcode_anywhere_raise_error # Parse JSON response bodies faraday.response :postcode_anywhere_parse_json # Set default HTTP adapter faraday.adapter :net_http end end |
#post(path, body_hash = {}, params = {}) ⇒ Object
Perform an HTTP POST request
27 28 29 |
# File 'lib/postcode_anywhere/client.rb', line 27 def post(path, body_hash = {}, params = {}) request(:post, path, params, body_hash) end |