Class: WpApiClient::Connection
- Inherits:
-
Object
- Object
- WpApiClient::Connection
- Defined in:
- lib/wp_api_client/connection.rb
Instance Attribute Summary collapse
-
#concurrent ⇒ Object
readonly
Returns the value of attribute concurrent.
-
#headers ⇒ Object
Returns the value of attribute headers.
Instance Method Summary collapse
-
#get(url, params = {}) ⇒ Object
translate requests into wp-api urls.
-
#get_concurrently(requests) ⇒ Object
requests come in as url/params pairs.
-
#initialize(configuration) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(configuration) ⇒ Connection
Returns a new instance of Connection.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/wp_api_client/connection.rb', line 13 def initialize(configuration) @configuration = configuration @queue = [] @conn = Faraday.new(url: configuration.endpoint) do |faraday| if configuration.oauth_credentials faraday.use FaradayMiddleware::OAuth, configuration.oauth_credentials end if configuration.basic_auth faraday.basic_auth(configuration.basic_auth[:username], configuration.basic_auth[:password]) end if configuration.debug faraday.response :logger faraday.use :instrumentation end if configuration.cache faraday.use :http_cache, store: configuration.cache, shared_cache: false end if configuration.proxy faraday.proxy configuration.proxy end faraday.use Faraday::Response::RaiseError faraday.response :json, :content_type => /\bjson$/ faraday.adapter :typhoeus end end |
Instance Attribute Details
#concurrent ⇒ Object (readonly)
Returns the value of attribute concurrent.
11 12 13 |
# File 'lib/wp_api_client/connection.rb', line 11 def concurrent @concurrent end |
#headers ⇒ Object
Returns the value of attribute headers.
10 11 12 |
# File 'lib/wp_api_client/connection.rb', line 10 def headers @headers end |
Instance Method Details
#get(url, params = {}) ⇒ Object
translate requests into wp-api urls
46 47 48 |
# File 'lib/wp_api_client/connection.rb', line 46 def get(url, params = {}) @conn.get url, parse_params(params) end |
#get_concurrently(requests) ⇒ Object
requests come in as url/params pairs
51 52 53 54 55 56 57 58 59 |
# File 'lib/wp_api_client/connection.rb', line 51 def get_concurrently(requests) responses = [] @conn.in_parallel do requests.map do |r| responses << get(r[0], r[1]) end end responses end |