Class: Puree::API::Request
- Inherits:
-
Object
- Object
- Puree::API::Request
- Defined in:
- lib/puree/api/request.rb
Overview
Handles requests to Pure.
Instance Method Summary collapse
-
#basic_auth(username:, password:) ⇒ Object
Provide credentials if necessary.
-
#get(uuid: nil, id: nil, rendering: :xml_long, latest_api: true, resource_type:, limit: 20, offset: 0, created_start: nil, created_end: nil, modified_start: nil, modified_end: nil, content_type: nil) ⇒ HTTP::Response
Perform a GET request to Pure.
-
#initialize(url:) ⇒ Request
constructor
A new instance of Request.
Constructor Details
Instance Method Details
#basic_auth(username:, password:) ⇒ Object
Provide credentials if necessary
19 20 21 22 |
# File 'lib/puree/api/request.rb', line 19 def basic_auth(username:, password:) auth = Base64::strict_encode64("#{username}:#{password}") @headers['Authorization'] = 'Basic ' + auth end |
#get(uuid: nil, id: nil, rendering: :xml_long, latest_api: true, resource_type:, limit: 20, offset: 0, created_start: nil, created_end: nil, modified_start: nil, modified_end: nil, content_type: nil) ⇒ HTTP::Response
Perform a GET request to Pure
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/puree/api/request.rb', line 39 def get(uuid: nil, id: nil, rendering: :xml_long, latest_api: true, resource_type:, limit: 20, offset: 0, created_start: nil, created_end: nil, modified_start: nil, modified_end: nil, content_type: nil) @latest_api = latest_api @resource_type = resource_type.to_sym @rendering = rendering @uuid = uuid @id = id @limit = limit @offset = offset @created_start = created_start @created_end = created_end @modified_start = modified_start @modified_end = modified_end @content_type = content_type # strip any trailing slash @url = @url.sub(/(\/)+$/, '') @headers['Accept'] = 'application/xml' @req = HTTP.headers accept: @headers['Accept'] if @headers['Authorization'] @req = @req.auth @headers['Authorization'] end @req.get(build_url, params: params) end |