Class: PixabayApi::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/pixabay_api/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#queryObject

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