Class: Wikimelon::Request
- Inherits:
-
Object
- Object
- Wikimelon::Request
- Defined in:
- lib/wikimelon/request.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#options ⇒ Object
Returns the value of attribute options.
-
#q ⇒ Object
Returns the value of attribute q.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#initialize(**args) ⇒ Request
constructor
A new instance of Request.
- #perform ⇒ Object
Constructor Details
#initialize(**args) ⇒ Request
Returns a new instance of Request.
14 15 16 17 18 19 20 21 |
# File 'lib/wikimelon/request.rb', line 14 def initialize(**args) @url = args[:url] @verbose = args[:verbose] @query = args[:query] @limit = args[:limit] @offset = args[:offset] @options = args[:options] # TODO: not added at wikimelon.rb end |
Instance Attribute Details
#endpoint ⇒ Object
Returns the value of attribute endpoint.
8 9 10 |
# File 'lib/wikimelon/request.rb', line 8 def endpoint @endpoint end |
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/wikimelon/request.rb', line 12 def @options end |
#q ⇒ Object
Returns the value of attribute q.
9 10 11 |
# File 'lib/wikimelon/request.rb', line 9 def q @q end |
#verbose ⇒ Object
Returns the value of attribute verbose.
10 11 12 |
# File 'lib/wikimelon/request.rb', line 10 def verbose @verbose end |
Instance Method Details
#perform ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/wikimelon/request.rb', line 23 def perform args = {'query': @query, 'format': 'json'} opts = args.delete_if { |_k, v| v.nil? } Faraday::Utils.default_space_encoding = "+" conn = Faraday.new(url: @url) do |f| f.response :logger if verbose f.use Faraday::WikimelonErrors::Middleware f.adapter Faraday.default_adapter end conn.headers['Accept'] = 'application/json,*/*' conn.headers[:user_agent] = make_user_agent conn.headers["X-USER-AGENT"] = make_user_agent res = conn.get(endpoint, opts) MultiJson.load(res.body) end |