Class: MediaWiktory::Wikipedia::Client
- Inherits:
-
Object
- Object
- MediaWiktory::Wikipedia::Client
- Defined in:
- lib/mediawiktory/wikipedia/client.rb
Overview
Constant Summary collapse
- UA =
Default MediaWiktory User-Agent header.
You can set yours as an option to #initialize
'MediaWiktory/0.1.0 '\ '(https://github.com/molybdenum-99/mediawiktory; [email protected])'
Class Attribute Summary collapse
-
.user_agent ⇒ Object
User agent getter/setter.
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #get(params) ⇒ Object
-
#initialize(url, **options) ⇒ Client
constructor
A new instance of Client.
- #post(params) ⇒ Object
- #user_agent ⇒ Object
Constructor Details
#initialize(url, **options) ⇒ Client
Returns a new instance of Client.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mediawiktory/wikipedia/client.rb', line 33 def initialize(url, **) @url = Addressable::URI.parse(url) @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 |
Class Attribute Details
.user_agent ⇒ Object
User agent getter/setter.
Default value is UA.
You can also use per-instance option, see #initialize
28 29 30 |
# File 'lib/mediawiktory/wikipedia/client.rb', line 28 def user_agent @user_agent end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
31 32 33 |
# File 'lib/mediawiktory/wikipedia/client.rb', line 31 def url @url end |
Instance Method Details
#get(params) ⇒ Object
48 49 50 |
# File 'lib/mediawiktory/wikipedia/client.rb', line 48 def get(params) @faraday.get('', params).body end |
#post(params) ⇒ Object
52 53 54 |
# File 'lib/mediawiktory/wikipedia/client.rb', line 52 def post(params) @faraday.post('', params).body end |
#user_agent ⇒ Object
44 45 46 |
# File 'lib/mediawiktory/wikipedia/client.rb', line 44 def user_agent @options[:user_agent] || @options[:ua] || self.class.user_agent || UA end |