Class: RandomGem::Request
- Inherits:
-
Object
- Object
- RandomGem::Request
- Defined in:
- lib/random_gem/request.rb
Constant Summary collapse
- HOST =
"https://rubygems.org"
- PATH =
"/api/v1/search"
Instance Attribute Summary collapse
-
#keyword ⇒ Object
readonly
Returns the value of attribute keyword.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
- #do ⇒ Object
-
#initialize(keyword:, page:) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(keyword:, page:) ⇒ Request
Returns a new instance of Request.
12 13 14 15 |
# File 'lib/random_gem/request.rb', line 12 def initialize(keyword:, page:) @keyword = keyword @page = page end |
Instance Attribute Details
#keyword ⇒ Object (readonly)
Returns the value of attribute keyword.
10 11 12 |
# File 'lib/random_gem/request.rb', line 10 def keyword @keyword end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
10 11 12 |
# File 'lib/random_gem/request.rb', line 10 def page @page end |
Instance Method Details
#do ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/random_gem/request.rb', line 17 def do uri = URI("#{HOST}#{PATH}") params = { query: keyword, page: page } uri.query = URI.encode_www_form(params) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true res = http.get(uri.request_uri) respond(res: res) end |