class MediaWiktory::Wikipedia::Client
Internal low-level client class, used by {Api}.
Uses [Faraday](github.com/lostisland/faraday) library inside (and will expose it's settings in future).
You should not use it directly, all you need is in {Api}.
Constants
- UA
Default
MediaWiktory
User-Agent header.You can set yours as an option to {#initialize}
Attributes
user_agent[RW]
User agent getter/setter.
Default value is {UA}.
You can also use per-instance option, see {#initialize}
url[R]
Public Class Methods
new(url, **options)
click to toggle source
# File lib/mediawiktory/wikipedia/client.rb, line 33 def initialize(url, **options) @url = Addressable::URI.parse(url) @options = options @faraday = Faraday.new(url, headers: headers) do |f| f.request :url_encoded f.use FaradayMiddleware::FollowRedirects, limit: 5 f.use FaradayMiddleware::Gzip f.adapter Faraday.default_adapter end end
Public Instance Methods
get(params)
click to toggle source
# File lib/mediawiktory/wikipedia/client.rb, line 48 def get(params) @faraday.get('', params).body end
post(params)
click to toggle source
# File lib/mediawiktory/wikipedia/client.rb, line 52 def post(params) @faraday.post('', params).body end
user_agent()
click to toggle source
# File lib/mediawiktory/wikipedia/client.rb, line 44 def user_agent @options[:user_agent] || @options[:ua] || self.class.user_agent || UA end
Private Instance Methods
headers()
click to toggle source
# File lib/mediawiktory/wikipedia/client.rb, line 58 def headers {'Accept-Encoding' => 'gzip', 'User-Agent' => user_agent} end