Class: PixabayApi::Request
- Inherits:
-
Object
- Object
- PixabayApi::Request
- Defined in:
- lib/pixabay_api/request.rb
Instance Attribute Summary collapse
-
#query ⇒ Object
Returns the value of attribute query.
Class Method Summary collapse
- .build_query(api_key, params, endpoint) ⇒ Object
- .create(api_key:, params: {}, endpoint: 'xxx') ⇒ Object
Instance Attribute Details
#query ⇒ Object
Returns the value of attribute query.
7 8 9 |
# File 'lib/pixabay_api/request.rb', line 7 def query @query end |
Class Method Details
.build_query(api_key, params, endpoint) ⇒ Object
20 21 22 |
# File 'lib/pixabay_api/request.rb', line 20 def build_query(api_key, params, endpoint) @query = "#{endpoint}?key=#{api_key}&#{params_to_s(params)}" end |
.create(api_key:, params: {}, endpoint: 'xxx') ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/pixabay_api/request.rb', line 10 def create(api_key:, params: {}, endpoint: 'xxx') build_query(api_key, params, endpoint) uri = URI(@query) Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| request = Net::HTTP::Get.new uri http.request(request) end end |