Class: Puree::Download
- Inherits:
-
Object
- Object
- Puree::Download
- Defined in:
- lib/puree/download.rb
Overview
Download
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#get(limit: 20, offset: 0, resource: nil) ⇒ Array<Hash>
(also: #find)
Get.
-
#initialize(base_url: nil, username: nil, password: nil, basic_auth: nil) ⇒ Download
constructor
A new instance of Download.
-
#metadata ⇒ Array<Hash>
All metadata.
Constructor Details
#initialize(base_url: nil, username: nil, password: nil, basic_auth: nil) ⇒ Download
Returns a new instance of Download.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/puree/download.rb', line 12 def initialize(base_url: nil, username: nil, password: nil, basic_auth: nil) @resource_type = :download @api_map = Puree::Map.new.get @base_url = base_url.nil? ? Puree.base_url : base_url @basic_auth = basic_auth.nil? ? Puree.basic_auth : basic_auth if @basic_auth === true @username = username.nil? ? Puree.username : username @password = password.nil? ? Puree.password : password end end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
6 7 8 |
# File 'lib/puree/download.rb', line 6 def response @response end |
Instance Method Details
#get(limit: 20, offset: 0, resource: nil) ⇒ Array<Hash> Also known as: find
Get
32 33 34 35 36 37 38 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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/puree/download.rb', line 32 def get(limit: 20, offset: 0, resource: nil) missing = missing_credentials if !missing.empty? missing.each do |m| puts "#{self.class.name}" + '#' + "#{__method__} missing #{m}" end exit end # strip any trailing slash @base_url = @base_url.sub(/(\/)+$/, '') @auth = Base64::strict_encode64(@username + ':' + @password) @options = { basic_auth: @basic_auth, latest_api: true, resource_type: @resource_type.to_sym, rendering: :system, limit: limit, offset: offset, resource: resource.to_sym } headers = { 'Accept' => 'application/xml', 'Authorization' => 'Basic ' + @auth } query = {} query['rendering'] = @options[:rendering] if @options[:limit] query['window.size'] = @options[:limit] end if @options[:offset] query['window.offset'] = @options[:offset] end if @options[:resource] query['contentType'] = service_family end begin url = build_url req = HTTP.headers accept: headers['Accept'] if @options[:basic_auth] req = req.auth headers['Authorization'] end @response = req.get(url, params: query) @doc = Nokogiri::XML @response.body @doc.remove_namespaces! rescue HTTP::Error => e puts 'HTTP::Error '+ e. end get_data? ? : [] end |
#metadata ⇒ Array<Hash>
All metadata
97 98 99 |
# File 'lib/puree/download.rb', line 97 def @metadata end |