Sha256: 65827639582989343cfea7214f46e7058dd87182f2038f46ae2ab93b496e9120

Contents?: true

Size: 1.23 KB

Versions: 15

Compression:

Stored size: 1.23 KB

Contents

module Vzaar
  class SignatureExtractor < Struct.new(:data, :format)
    include Vzaar::Helper

    def extract
      _format == :xml ? from_xml : symb_keys(data)
    end

    private

    def _format
      blank?(format) ? :xml : format.to_sym
    end

    def from_xml
      { https: xml_extractor('//vzaar-api/https'),
        signature: xml_extractor('//vzaar-api/signature'),
        expiration_date: xml_extractor('//vzaar-api/expirationdate'),
        acl: xml_extractor('//vzaar-api/acl'),
        success_action_redirect: xml_extractor('//vzaar-api/success_action_redirect'),
        profile: xml_extractor('//vzaar-api/profile'),
        access_key_id: xml_extractor('//vzaar-api/accesskeyid'),
        aws_access_key: xml_extractor('//vzaar-api/accesskeyid'),
        policy: xml_extractor('//vzaar-api/policy'),
        title: xml_extractor('//vzaar-api/title'),
        guid: xml_extractor('//vzaar-api/guid'),
        key: xml_extractor('//vzaar-api/key'),
        bucket: xml_extractor('//vzaar-api/bucket')
      }
    end

    def xml_extractor(xpath)
      return '' if xml_data.to_s == ''
      xml_data.at_xpath(xpath) ? xml_data.at_xpath(xpath).text : ''
    end

    def xml_data
      @xml_data ||= Nokogiri::XML(data)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
vzaar-1.6.2 lib/vzaar/signature_extractor.rb
vzaar-1.6.1 lib/vzaar/signature_extractor.rb
vzaar-1.6.0 lib/vzaar/signature_extractor.rb
vzaar-1.5.3 lib/vzaar/signature_extractor.rb
vzaar-1.5.2 lib/vzaar/signature_extractor.rb
vzaar-1.5.1 lib/vzaar/signature_extractor.rb
vzaar-1.5.0 lib/vzaar/signature_extractor.rb
vzaar-1.4.4 lib/vzaar/signature_extractor.rb
vzaar-1.4.1 lib/vzaar/signature_extractor.rb
vzaar-1.3.1 lib/vzaar/signature_extractor.rb
vzaar-1.3.0 lib/vzaar/signature_extractor.rb
vzaar-1.2.4 lib/vzaar/signature_extractor.rb
vzaar-1.2.3 lib/vzaar/signature_extractor.rb
vzaar-1.2.2 lib/vzaar/signature_extractor.rb
vzaar-1.0.0 lib/vzaar/signature_extractor.rb