rmobio 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rmobio/ads/ad_sense.rb +105 -87
- data/lib/rmobio/ads/m_khoj.rb +1 -0
- data/lib/rmobio/ads.rb +3 -5
- data/lib/rmobio/auth.rb +3 -7
- data/lib/rmobio/cas.rb +69 -26
- data/lib/rmobio/utils.rb +73 -65
- metadata +7 -7
    
        data/lib/rmobio/ads/ad_sense.rb
    CHANGED
    
    | @@ -25,11 +25,28 @@ require 'collections/sequenced_hash' | |
| 25 25 |  | 
| 26 26 | 
             
            module Rmobio
         | 
| 27 27 | 
             
              module Ads
         | 
| 28 | 
            -
                module AdSense | 
| 28 | 
            +
                module AdSense
         | 
| 29 29 |  | 
| 30 | 
            +
                  
         | 
| 31 | 
            +
                  @@adsense=$ADSENSE
         | 
| 30 32 | 
             
                  @@adServer="http://pagead2.googlesyndication.com/pagead/ads"
         | 
| 31 33 | 
             
                  @@adClient="ca-mb-pub-0061196910475770"
         | 
| 32 | 
            -
                  @@mobioUseragent="Mobio" # we should probably come up with a better string | 
| 34 | 
            +
                  @@mobioUseragent="Mobio" # we should probably come up with a better string
         | 
| 35 | 
            +
                  
         | 
| 36 | 
            +
                  # Determines whether this request should involve adSense.
         | 
| 37 | 
            +
                  def doAdSense()
         | 
| 38 | 
            +
                    # is adsense enabled for the project?
         | 
| 39 | 
            +
                    if (@@adsense != 1)
         | 
| 40 | 
            +
                      return false
         | 
| 41 | 
            +
                    end
         | 
| 42 | 
            +
                    
         | 
| 43 | 
            +
                    # returns true of false depending on what client is making this request.
         | 
| 44 | 
            +
                    if (@client == 'facebook')
         | 
| 45 | 
            +
                      return false
         | 
| 46 | 
            +
                    else
         | 
| 47 | 
            +
                      return true
         | 
| 48 | 
            +
                    end
         | 
| 49 | 
            +
                  end
         | 
| 33 50 |  | 
| 34 51 | 
             
                  def getAdParms
         | 
| 35 52 | 
             
                    getAd(params[:keywords])
         | 
| @@ -51,100 +68,101 @@ module Rmobio | |
| 51 68 | 
             
                  #$GLOBALS['google']['useragent']=$_SERVER['HTTP_USER_AGENT'];
         | 
| 52 69 |  | 
| 53 70 | 
             
                  def getAdByPage
         | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
                    end
         | 
| 59 | 
            -
             | 
| 60 | 
            -
                    adArgs= SequencedHash.new
         | 
| 61 | 
            -
                    adArgs["ad_type"]="text"
         | 
| 62 | 
            -
                    adArgs["channel"]="8618723264"
         | 
| 63 | 
            -
                    adArgs["client"]="pub-0061196910475770" 
         | 
| 64 | 
            -
                    adArgs["format"]="mobile_single"
         | 
| 65 | 
            -
                    adArgs["host"]=request.host
         | 
| 66 | 
            -
                    adArgs["ip"]=request.remote_ip
         | 
| 67 | 
            -
                    adArgs["markup"]="xhtml"
         | 
| 68 | 
            -
                    adArgs["output"]="xhtml"
         | 
| 69 | 
            -
                    adArgs["oe"]="utf8"
         | 
| 70 | 
            -
                    adArgs["ref"]=request.referer
         | 
| 71 | 
            -
                    adArgs["url"]="http://"+request.env["HTTP_HOST"]+request.env["REQUEST_URI"]
         | 
| 72 | 
            -
                    #adArgs["useragent"]=request.user_agent  
         | 
| 73 | 
            -
                    adArgs["eip"]=Digest::SHA1.hexdigest(@@userId)[0..20]  # oneway hashed userid  
         | 
| 74 | 
            -
             | 
| 75 | 
            -
                    # now built the URL to call out to based upon the base URL and ad hash
         | 
| 76 | 
            -
                    adURL=@@adServer + "?"
         | 
| 77 | 
            -
                    first=1 # dont put ampersand on first one
         | 
| 78 | 
            -
                    adArgs.each_key do |x|
         | 
| 79 | 
            -
                      if adArgs[x]
         | 
| 80 | 
            -
                        (adURL=adURL+"&") unless first
         | 
| 81 | 
            -
                        first=nil # start putting in &s
         | 
| 82 | 
            -
                        adURL = adURL + x + "=" + adArgs[x]   
         | 
| 71 | 
            +
                    if (doAdSense())
         | 
| 72 | 
            +
                      @@userId=request.env['HTTP_USERID'] 
         | 
| 73 | 
            +
                      if (@@userId.nil?)
         | 
| 74 | 
            +
                        @@userId="101"
         | 
| 83 75 | 
             
                      end
         | 
| 84 | 
            -
             | 
| 85 | 
            -
             | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 76 | 
            +
                      
         | 
| 77 | 
            +
                      adArgs= SequencedHash.new
         | 
| 78 | 
            +
                      adArgs["ad_type"]="text"
         | 
| 79 | 
            +
                      adArgs["channel"]="8618723264"
         | 
| 80 | 
            +
                      adArgs["client"]="pub-0061196910475770" 
         | 
| 81 | 
            +
                      adArgs["format"]="mobile_single"
         | 
| 82 | 
            +
                      adArgs["host"]=request.host
         | 
| 83 | 
            +
                      adArgs["ip"]=request.remote_ip
         | 
| 84 | 
            +
                      adArgs["markup"]="xhtml"
         | 
| 85 | 
            +
                      adArgs["output"]="xhtml"
         | 
| 86 | 
            +
                      adArgs["oe"]="utf8"
         | 
| 87 | 
            +
                      adArgs["ref"]=request.referer
         | 
| 88 | 
            +
                      adArgs["url"]="http://"+request.env["HTTP_HOST"]+request.env["REQUEST_URI"]
         | 
| 89 | 
            +
                      #adArgs["useragent"]=request.user_agent  
         | 
| 90 | 
            +
                      adArgs["eip"]=Digest::SHA1.hexdigest(@@userId)[0..20]  # oneway hashed userid  
         | 
| 91 | 
            +
                      
         | 
| 92 | 
            +
                      # now built the URL to call out to based upon the base URL and ad hash
         | 
| 93 | 
            +
                      adURL=@@adServer + "?"
         | 
| 94 | 
            +
                      first=1 # dont put ampersand on first one
         | 
| 95 | 
            +
                      adArgs.each_key do |x|
         | 
| 96 | 
            +
                        if adArgs[x]
         | 
| 97 | 
            +
                          (adURL=adURL+"&") unless first
         | 
| 98 | 
            +
                          first=nil # start putting in &s
         | 
| 99 | 
            +
                          adURL = adURL + x + "=" + adArgs[x]   
         | 
| 100 | 
            +
                        end
         | 
| 101 | 
            +
                      end
         | 
| 102 | 
            +
                      # ok, now call google's mobile adSense service and get back the full ad 
         | 
| 103 | 
            +
                      @pagead=open(adURL).read   
         | 
| 104 | 
            +
                    end      
         | 
| 88 105 | 
             
                  end
         | 
| 89 106 |  | 
| 90 107 | 
             
                  # this returns an adfrom Google's mobile AdSense, given a supplied set of keywords
         | 
| 91 108 | 
             
                  def getAd(keywords)
         | 
| 109 | 
            +
                    puts "Adsense"
         | 
| 92 110 | 
             
                    doTinyUrl=true
         | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 95 | 
            -
             | 
| 96 | 
            -
             | 
| 97 | 
            -
                    end
         | 
| 98 | 
            -
                    # build up the various arguments in the adArgs hash
         | 
| 99 | 
            -
                    adArgs= SequencedHash.new
         | 
| 100 | 
            -
                    adArgs["ad_type"]="text"
         | 
| 101 | 
            -
                    adArgs["client"]=@@adClient # get it from gateway instead!
         | 
| 102 | 
            -
                    adArgs["format"]="mobile_single"
         | 
| 103 | 
            -
                    adArgs["ip"]=request.remote_ip
         | 
| 104 | 
            -
                    adArgs["markup"]="xhtml"
         | 
| 105 | 
            -
                    adArgs["output"]="wml"
         | 
| 106 | 
            -
                    adArgs["oe"]="utf-8"
         | 
| 107 | 
            -
                    adArgs["url"]="http:%3A%2Fwww.getmobio.com"  # mobio's home site
         | 
| 108 | 
            -
                    adArgs["useragent"]=@@mobioUseragent # user agent for our browser.  
         | 
| 109 | 
            -
                    adArgs["eip"]=Digest::SHA1.hexdigest(@@userId)[0..20]  # oneway hashed userid
         | 
| 110 | 
            -
                    if (keywords)
         | 
| 111 | 
            -
                      adArgs["kw"]=CGI::escape(keywords) 
         | 
| 112 | 
            -
                      adArgs["kw_type"]="broad"
         | 
| 113 | 
            -
                    end
         | 
| 114 | 
            -
                    # now built the URL to call out to based upon the base URL and ad hash
         | 
| 115 | 
            -
                    adURL=@@adServer + "?"
         | 
| 116 | 
            -
                    first=1 # dont put ampersand on first one
         | 
| 117 | 
            -
                    adArgs.each_key do |x|
         | 
| 118 | 
            -
                      if adArgs[x]
         | 
| 119 | 
            -
                        (adURL=adURL+"&") unless first
         | 
| 120 | 
            -
                        first=nil # start putting in &s
         | 
| 121 | 
            -
                        adURL = adURL + x + "=" + adArgs[x]   
         | 
| 111 | 
            +
                    if (doAdSense())
         | 
| 112 | 
            +
                      @@userId=request.env['HTTP_USERID'] 
         | 
| 113 | 
            +
                      if (@@userId.nil?)
         | 
| 114 | 
            +
                        @@userId="101"
         | 
| 122 115 | 
             
                      end
         | 
| 123 | 
            -
             | 
| 124 | 
            -
             | 
| 125 | 
            -
             | 
| 126 | 
            -
             | 
| 127 | 
            -
                       | 
| 128 | 
            -
                       | 
| 129 | 
            -
                       | 
| 130 | 
            -
                       | 
| 131 | 
            -
             | 
| 132 | 
            -
             | 
| 133 | 
            -
             | 
| 134 | 
            -
             | 
| 135 | 
            -
             | 
| 136 | 
            -
             | 
| 137 | 
            -
                         | 
| 138 | 
            -
             | 
| 139 | 
            -
             | 
| 140 | 
            -
             | 
| 141 | 
            -
             | 
| 142 | 
            -
             | 
| 116 | 
            +
                      # build up the various arguments in the adArgs hash
         | 
| 117 | 
            +
                      adArgs= SequencedHash.new
         | 
| 118 | 
            +
                      adArgs["ad_type"]="text"
         | 
| 119 | 
            +
                      adArgs["client"]=@@adClient # get it from gateway instead!
         | 
| 120 | 
            +
                      adArgs["format"]="mobile_single"
         | 
| 121 | 
            +
                      adArgs["ip"]=request.remote_ip
         | 
| 122 | 
            +
                      adArgs["markup"]="xhtml"
         | 
| 123 | 
            +
                      adArgs["output"]="wml"
         | 
| 124 | 
            +
                      adArgs["oe"]="utf-8"
         | 
| 125 | 
            +
                      adArgs["url"]="http:%3A%2Fwww.getmobio.com"  # mobio's home site
         | 
| 126 | 
            +
                      adArgs["useragent"]=@@mobioUseragent # user agent for our browser.  
         | 
| 127 | 
            +
                      adArgs["eip"]=Digest::SHA1.hexdigest(@@userId)[0..20]  # oneway hashed userid
         | 
| 128 | 
            +
                      if (keywords)
         | 
| 129 | 
            +
                        adArgs["kw"]=CGI::escape(keywords) 
         | 
| 130 | 
            +
                        adArgs["kw_type"]="broad"
         | 
| 131 | 
            +
                      end
         | 
| 132 | 
            +
                      # now built the URL to call out to based upon the base URL and ad hash
         | 
| 133 | 
            +
                      adURL=@@adServer + "?"
         | 
| 134 | 
            +
                      first=1 # dont put ampersand on first one
         | 
| 135 | 
            +
                      adArgs.each_key do |x|
         | 
| 136 | 
            +
                        if adArgs[x]
         | 
| 137 | 
            +
                          (adURL=adURL+"&") unless first
         | 
| 138 | 
            +
                          first=nil # start putting in &s
         | 
| 139 | 
            +
                          adURL = adURL + x + "=" + adArgs[x]   
         | 
| 143 140 | 
             
                        end
         | 
| 144 141 | 
             
                      end
         | 
| 145 | 
            -
             | 
| 146 | 
            -
             | 
| 147 | 
            -
             | 
| 142 | 
            +
                      # ok, now call google's mobile adSense service and get back the full ad 
         | 
| 143 | 
            +
                      @ad=open(adURL).read
         | 
| 144 | 
            +
                      if @ad
         | 
| 145 | 
            +
                        logger.info "Returned ad" + @ad 
         | 
| 146 | 
            +
                        adDoc = REXML::Document.new @ad
         | 
| 147 | 
            +
                        @text = adDoc.elements['//p']
         | 
| 148 | 
            +
                        if @text  # do we have a <p> element
         | 
| 149 | 
            +
                          # ok, now text has the full ad display content including links
         | 
| 150 | 
            +
                          # grab @url, @urltext (link text for url), @phone, @phonetext (link text for call)      
         | 
| 151 | 
            +
                          if defined? @text[1].attributes['href'] and @text[1].attributes['href']
         | 
| 152 | 
            +
                            @adurl = doTinyUrl ? tinyUrl(@text[1].attributes['href']) : @text[1].attributes['href']
         | 
| 153 | 
            +
                          else
         | 
| 154 | 
            +
                            @adurl = "nolink.rwap" 
         | 
| 155 | 
            +
                          end
         | 
| 156 | 
            +
                          @urltext=@text[1].text
         | 
| 157 | 
            +
                          @extratext=@text[2].to_s if @text[2] # this should have everything else that is not a child element
         | 
| 158 | 
            +
                          if (@text.size>3 and @text[3]) # only process @text[3] for phone stuff if it exists
         | 
| 159 | 
            +
                            @phone = (doTinyUrl ? tinyUrl(@text[3].attributes['href']) : @text[3].attributes['href']) if defined? @text[3].attributes['href'] and @text[3].attributes['href']
         | 
| 160 | 
            +
                            @phonetext=@text[3].text if defined? @text[3].text and @text[3].text          
         | 
| 161 | 
            +
                          end
         | 
| 162 | 
            +
                        end
         | 
| 163 | 
            +
                      end # if we get an ad back from adsense
         | 
| 164 | 
            +
                      @ad # return the full ad text 
         | 
| 165 | 
            +
                    end
         | 
| 148 166 | 
             
                  end 
         | 
| 149 167 |  | 
| 150 168 | 
             
                  private
         | 
    
        data/lib/rmobio/ads/m_khoj.rb
    CHANGED
    
    
    
        data/lib/rmobio/ads.rb
    CHANGED
    
    | @@ -19,8 +19,6 @@ | |
| 19 19 | 
             
            note that we require use of the new Mobio config yml schema created by Lars
         | 
| 20 20 | 
             
            and documented at http://opssrv01/wiki/index.php/Mobio_Rails_Application_Framework_2.0#Use_Config_Manager
         | 
| 21 21 | 
             
            =end
         | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
              eval("include " + adlib.camelize)
         | 
| 26 | 
            -
            end
         | 
| 22 | 
            +
            adlib="rmobio/ads/" + MOBIO_CONFIG['ad_network']
         | 
| 23 | 
            +
            require adlib
         | 
| 24 | 
            +
            eval("include " + adlib.camelize)
         | 
    
        data/lib/rmobio/auth.rb
    CHANGED
    
    | @@ -98,13 +98,9 @@ module Rmobio | |
| 98 98 | 
             
                  #end
         | 
| 99 99 | 
             
                  surl=request.protocol + request.host_with_port + request.request_uri
         | 
| 100 100 | 
             
                  logger.debug(" surl 0-=== #{surl}")
         | 
| 101 | 
            -
                   | 
| 102 | 
            -
                  domain | 
| 103 | 
            -
                   | 
| 104 | 
            -
            	if(w=='w')       
         | 
| 105 | 
            -
                       domain =uritokens[index+1]		  
         | 
| 106 | 
            -
                    end 
         | 
| 107 | 
            -
                  end 
         | 
| 101 | 
            +
                  
         | 
| 102 | 
            +
                  # Retrieve the domain from the request_uri
         | 
| 103 | 
            +
                  domain = Rmobio::Utils.get_domain(request.request_uri)
         | 
| 108 104 |  | 
| 109 105 | 
             
                  no_auth_domains =MOBIO_CONFIG['no_auth_domains']
         | 
| 110 106 | 
             
                  if (no_auth_domains != nil)
         | 
    
        data/lib/rmobio/cas.rb
    CHANGED
    
    | @@ -33,35 +33,16 @@ | |
| 33 33 | 
             
            require 'rubycas-client'
         | 
| 34 34 | 
             
            require 'casclient/frameworks/rails/filter'
         | 
| 35 35 | 
             
            require 'casclient'
         | 
| 36 | 
            +
            require 'rmobio/utils'
         | 
| 36 37 |  | 
| 37 38 | 
             
            module Rmobio
         | 
| 38 39 | 
             
              module Cas
         | 
| 39 | 
            -
                class  | 
| 40 | 
            -
                  attr_accessor :xml_response
         | 
| 41 | 
            -
                  
         | 
| 42 | 
            -
                  # Override service ticket validation so we use our XmlResponse
         | 
| 43 | 
            -
                  def validate_service_ticket(st)
         | 
| 44 | 
            -
                    RAILS_DEFAULT_LOGGER.debug 'CAS: Starting to validate service ticket...' unless not defined? RAILS_DEFAULT_LOGGER
         | 
| 45 | 
            -
                    uri = URI.parse(validate_url)
         | 
| 46 | 
            -
                    h = uri.query ? query_to_hash(uri.query) : {}
         | 
| 47 | 
            -
                    h['service'] = st.service
         | 
| 48 | 
            -
                    h['ticket'] = st.ticket
         | 
| 49 | 
            -
                    h['renew'] = 1 if st.renew
         | 
| 50 | 
            -
                    h['pgtUrl'] = proxy_callback_url if proxy_callback_url
         | 
| 51 | 
            -
                    uri.query = hash_to_query(h)
         | 
| 52 | 
            -
                  
         | 
| 53 | 
            -
                    st.response = request_cas_response(uri, MobioValidationResponse)
         | 
| 54 | 
            -
                    @xml_response = st.response
         | 
| 55 | 
            -
                    return st
         | 
| 56 | 
            -
                  end
         | 
| 57 | 
            -
                end
         | 
| 58 | 
            -
                
         | 
| 59 | 
            -
                class MobioValidationResponse < CASClient::ValidationResponse 
         | 
| 40 | 
            +
                class MobioValidationResponse < CASClient::ValidationResponse
         | 
| 60 41 | 
             
                  attr_reader :uuid
         | 
| 61 42 |  | 
| 62 43 | 
             
                  # Parse out our custom attributes
         | 
| 63 44 | 
             
                  def initialize(raw_text)
         | 
| 64 | 
            -
                     | 
| 45 | 
            +
                    parse(raw_text)
         | 
| 65 46 | 
             
                    parse_uuid(raw_text)
         | 
| 66 47 | 
             
                  end
         | 
| 67 48 |  | 
| @@ -81,6 +62,65 @@ module Rmobio | |
| 81 62 | 
             
                      raise BadResponseException, "BAD CAS RESPONSE:\n#{raw_text.inspect}\n\nXML DOC:\n#{@xml.inspect}"
         | 
| 82 63 | 
             
                    end 
         | 
| 83 64 | 
             
                  end
         | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
                
         | 
| 67 | 
            +
                class Client < CASClient::Client      
         | 
| 68 | 
            +
                  attr_accessor :xml_response
         | 
| 69 | 
            +
                  
         | 
| 70 | 
            +
                  # Override service ticket validation so we use our XmlResponse
         | 
| 71 | 
            +
                  def validate_service_ticket(st)
         | 
| 72 | 
            +
                    RAILS_DEFAULT_LOGGER.debug 'CAS: Starting to validate service ticket...' unless not defined? RAILS_DEFAULT_LOGGER
         | 
| 73 | 
            +
                    uri = URI.parse(validate_url)
         | 
| 74 | 
            +
                    h = uri.query ? query_to_hash(uri.query) : {}
         | 
| 75 | 
            +
                    h['service'] = st.service
         | 
| 76 | 
            +
                    h['ticket'] = st.ticket
         | 
| 77 | 
            +
                    h['renew'] = 1 if st.renew
         | 
| 78 | 
            +
                    h['pgtUrl'] = proxy_callback_url if proxy_callback_url
         | 
| 79 | 
            +
                      
         | 
| 80 | 
            +
                    # Add our domain parameter
         | 
| 81 | 
            +
                    h['domain'] = Rmobio::Utils.get_domain(st.service)
         | 
| 82 | 
            +
                    uri.query = hash_to_query(h)
         | 
| 83 | 
            +
             | 
| 84 | 
            +
                    # Override the validation response
         | 
| 85 | 
            +
                    st.response = request_cas_response(uri, Rmobio::Cas::MobioValidationResponse)
         | 
| 86 | 
            +
                    @xml_response = st.response
         | 
| 87 | 
            +
                    return st
         | 
| 88 | 
            +
                  end
         | 
| 89 | 
            +
                  
         | 
| 90 | 
            +
                  # We have to override this method because MobioValidationResponse is
         | 
| 91 | 
            +
                  # uninitialized in the base class
         | 
| 92 | 
            +
                  def request_cas_response(uri, type)
         | 
| 93 | 
            +
                    log.debug "Requesting CAS response form URI #{uri.inspect}"
         | 
| 94 | 
            +
                  
         | 
| 95 | 
            +
                    uri = URI.parse(uri) unless uri.kind_of? URI
         | 
| 96 | 
            +
                    https = Net::HTTP.new(uri.host, uri.port)
         | 
| 97 | 
            +
                    https.use_ssl = (uri.scheme == 'https')
         | 
| 98 | 
            +
                    raw_res = https.start do |conn|
         | 
| 99 | 
            +
                      conn.get("#{uri.path}?#{uri.query}")
         | 
| 100 | 
            +
                    end
         | 
| 101 | 
            +
                  
         | 
| 102 | 
            +
                    # TODO: check to make sure that response code is 200 and handle errors
         | 
| 103 | 
            +
                    # otherwise
         | 
| 104 | 
            +
                  
         | 
| 105 | 
            +
                    RAILS_DEFAULT_LOGGER.debug "CAS Responded with " + 
         | 
| 106 | 
            +
                      "#{raw_res.inspect}:\n#{raw_res.body}" unless not defined? RAILS_DEFAULT_LOGGER
         | 
| 107 | 
            +
                  
         | 
| 108 | 
            +
                    type.new(raw_res.body)
         | 
| 109 | 
            +
                  end
         | 
| 110 | 
            +
                  
         | 
| 111 | 
            +
                  # Override to add the domain param
         | 
| 112 | 
            +
                  def add_service_to_login_url(service_url)
         | 
| 113 | 
            +
                    uri = super(service_url)
         | 
| 114 | 
            +
                    domain = Rmobio::Utils.get_domain(service_url)
         | 
| 115 | 
            +
                    
         | 
| 116 | 
            +
                    if not domain.nil?
         | 
| 117 | 
            +
                      RAILS_DEFAULT_LOGGER.debug 'CAS: Adding domain parameter ' +
         | 
| 118 | 
            +
                        domain + '...' unless not defined? RAILS_DEFAULT_LOGGER
         | 
| 119 | 
            +
                      param_token = uri.index("?").nil? ? '?' : '&'
         | 
| 120 | 
            +
                      uri << param_token + 'domain=' + domain
         | 
| 121 | 
            +
                    end
         | 
| 122 | 
            +
                    uri.to_s
         | 
| 123 | 
            +
                  end
         | 
| 84 124 | 
             
                end   
         | 
| 85 125 |  | 
| 86 126 | 
             
                class MobioCasFilter < CASClient::Frameworks::Rails::Filter
         | 
| @@ -92,13 +132,13 @@ module Rmobio | |
| 92 132 | 
             
                    @@client = Rmobio::Cas::Client.new(config)
         | 
| 93 133 | 
             
                    @@log = client.log
         | 
| 94 134 | 
             
                  end
         | 
| 95 | 
            -
             | 
| 135 | 
            +
                  
         | 
| 136 | 
            +
                  # Here's where we override the filter
         | 
| 96 137 | 
             
                  def self.filter(controller)
         | 
| 97 | 
            -
                   
         | 
| 98 138 | 
             
                    RAILS_DEFAULT_LOGGER.debug 'CAS: Starting filter...' unless not defined? RAILS_DEFAULT_LOGGER
         | 
| 99 139 |  | 
| 100 140 | 
             
                    # Call filter on the base class
         | 
| 101 | 
            -
                    CASClient::Frameworks::Rails::Filter.filter(controller)
         | 
| 141 | 
            +
                    CASClient::Frameworks::Rails::Filter.filter(controller)        
         | 
| 102 142 |  | 
| 103 143 | 
             
                    @handset_id = controller.params[:handsetid]
         | 
| 104 144 |  | 
| @@ -123,5 +163,8 @@ module Rmobio | |
| 123 163 | 
             
                    end
         | 
| 124 164 | 
             
                  end
         | 
| 125 165 | 
             
                end
         | 
| 166 | 
            +
                class BadResponseException < Exception
         | 
| 167 | 
            +
                end
         | 
| 126 168 | 
             
              end
         | 
| 127 | 
            -
            end
         | 
| 169 | 
            +
            end
         | 
| 170 | 
            +
            include Rmobio::Cas
         | 
    
        data/lib/rmobio/utils.rb
    CHANGED
    
    | @@ -1,69 +1,68 @@ | |
| 1 | 
            -
            #
         | 
| 1 | 
            +
            # 
         | 
| 2 2 | 
             
            # Copyright (C) 2007 Mobio Networks, Inc.
         | 
| 3 | 
            -
            #
         | 
| 4 | 
            -
            # This program is free software: you can redistribute it and/or modify
         | 
| 5 | 
            -
            #  | 
| 6 | 
            -
            #  | 
| 7 | 
            -
            #  | 
| 8 | 
            -
            #
         | 
| 9 | 
            -
            # This program is distributed in the hope that it will be useful,
         | 
| 10 | 
            -
            #  | 
| 11 | 
            -
            #  | 
| 12 | 
            -
            #  | 
| 13 | 
            -
            #
         | 
| 14 | 
            -
            # You should have received a copy of the GNU General Public License
         | 
| 15 | 
            -
            #  | 
| 16 | 
            -
            #
         | 
| 3 | 
            +
            # 
         | 
| 4 | 
            +
            # This program is free software: you can redistribute it and/or modify it under
         | 
| 5 | 
            +
            # the terms of the GNU General Public License as published by the Free Software
         | 
| 6 | 
            +
            # Foundation, either version 3 of the License, or (at your option) any later
         | 
| 7 | 
            +
            # version.
         | 
| 8 | 
            +
            # 
         | 
| 9 | 
            +
            # This program is distributed in the hope that it will be useful, but WITHOUT
         | 
| 10 | 
            +
            # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
         | 
| 11 | 
            +
            # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
         | 
| 12 | 
            +
            # details.
         | 
| 13 | 
            +
            # 
         | 
| 14 | 
            +
            # You should have received a copy of the GNU General Public License along with
         | 
| 15 | 
            +
            # this program.  If not, see <http://www.gnu.org/licenses/>.
         | 
| 16 | 
            +
            # 
         | 
| 17 17 |  | 
| 18 18 | 
             
            =begin
         | 
| 19 19 | 
             
            Some summary should go here
         | 
| 20 20 | 
             
            =end
         | 
| 21 21 |  | 
| 22 | 
            -
            #require 'rexml/document'
         | 
| 22 | 
            +
            # #require 'rexml/document'
         | 
| 23 23 | 
             
            require 'open-uri' 
         | 
| 24 24 | 
             
            require 'hpricot'
         | 
| 25 25 |  | 
| 26 26 | 
             
            module Rmobio
         | 
| 27 27 | 
             
              module Utils
         | 
| 28 28 |  | 
| 29 | 
            -
                #== cachControl
         | 
| 30 | 
            -
                #=== Adding cache control to response header 
         | 
| 29 | 
            +
                # #== cachControl #=== Adding cache control to response header
         | 
| 31 30 | 
             
                def cacheControl(cacheStr='priority=P3;max-age=604800')  
         | 
| 32 31 | 
             
                  headers.delete("Cache-Control");
         | 
| 33 32 | 
             
                  headers["Cache-Control"] = cacheStr;   
         | 
| 34 33 | 
             
                end
         | 
| 35 34 |  | 
| 36 35 |  | 
| 37 | 
            -
                #== cacheloader
         | 
| 38 | 
            -
                 | 
| 39 | 
            -
                #  | 
| 40 | 
            -
                # filename and header. Here is a ample configuration:
         | 
| 36 | 
            +
                # #== cacheloader #=== A utility method to add cache control to images,
         | 
| 37 | 
            +
                # styles and files To add a cache control, edit the configuration file
         | 
| 38 | 
            +
                # 'cachehints.txt' with filename and header. Here is a ample configuration:
         | 
| 41 39 | 
             
                # 
         | 
| 42 40 | 
             
                # 
         | 
| 43 | 
            -
                #<tt>logo.png: priority=P2;max-age=1296000</tt>
         | 
| 44 | 
            -
                #
         | 
| 45 | 
            -
                #<tt>base.rhtml: priority=P2;max-age=1296000</tt>
         | 
| 46 | 
            -
                #
         | 
| 47 | 
            -
                # | 
| 48 | 
            -
                # The utility assumes base directory for images files in | 
| 49 | 
            -
                # and other files in RAILS_ROOT/apps/views.
         | 
| 41 | 
            +
                # #<tt>logo.png: priority=P2;max-age=1296000</tt>
         | 
| 42 | 
            +
                # 
         | 
| 43 | 
            +
                # #<tt>base.rhtml: priority=P2;max-age=1296000</tt>
         | 
| 44 | 
            +
                # 
         | 
| 45 | 
            +
                # 
         | 
| 46 | 
            +
                # The utility assumes base directory for images files in
         | 
| 47 | 
            +
                # RAILS_ROOT/public/images and other files in RAILS_ROOT/apps/views.
         | 
| 50 48 | 
             
                # 
         | 
| 51 49 | 
             
                # 
         | 
| 52 50 | 
             
                # To access the image in your xform, use the following pattern:
         | 
| 53 | 
            -
                #<tt><icon>recipe/loader?name=logo.png</icon></tt>
         | 
| 54 | 
            -
                #  | 
| 55 | 
            -
                 | 
| 56 | 
            -
                #
         | 
| 57 | 
            -
                #  | 
| 58 | 
            -
                #  | 
| 51 | 
            +
                # #<tt><icon>recipe/loader?name=logo.png</icon></tt> To access the style in
         | 
| 52 | 
            +
                # your xform, use the following pattern: #<tt><style
         | 
| 53 | 
            +
                # xmlns="http://www.mobio.com/ext"
         | 
| 54 | 
            +
                # src="recipe/loader?name=layouts/base.rhtml"/></tt>
         | 
| 55 | 
            +
                # 
         | 
| 56 | 
            +
                # where the controller 'recipe' should provide a method 'loader' that calls
         | 
| 57 | 
            +
                # this utility:
         | 
| 59 58 | 
             
                #  def loader
         | 
| 60 59 | 
             
                #    cacheloader
         | 
| 61 60 | 
             
                #  end
         | 
| 62 61 | 
             
                # 
         | 
| 63 62 | 
             
                def cacheloader 
         | 
| 64 63 | 
             
                  if (name=params[:name]).nil?
         | 
| 65 | 
            -
                    # Can't do anything, just return empty content so we don't get 
         | 
| 66 | 
            -
                    #  | 
| 64 | 
            +
                    # Can't do anything, just return empty content so we don't get 'no
         | 
| 65 | 
            +
                    # template' error.
         | 
| 67 66 | 
             
                    render :text => ''
         | 
| 68 67 | 
             
                    return
         | 
| 69 68 | 
             
                  end
         | 
| @@ -107,20 +106,18 @@ module Rmobio | |
| 107 106 | 
             
                  render :template => name   
         | 
| 108 107 | 
             
                end
         | 
| 109 108 |  | 
| 110 | 
            -
                #== cacheimg
         | 
| 111 | 
            -
                 | 
| 112 | 
            -
                 | 
| 113 | 
            -
                #  | 
| 114 | 
            -
                # the configuration file "cachehints.txt with image name and header. Ex:
         | 
| 109 | 
            +
                # #== cacheimg #=== A utility method to add cache control to images #===
         | 
| 110 | 
            +
                # This utility is deprecated, use cacheloader instead To add a cache control
         | 
| 111 | 
            +
                # for an image file in RAILS_ROOT/public/images, edit the configuration file
         | 
| 112 | 
            +
                # "cachehints.txt with image name and header. Ex:
         | 
| 115 113 | 
             
                # 
         | 
| 116 114 | 
             
                # logo.png: priority=P2;max-age=1296000
         | 
| 117 115 | 
             
                # 
         | 
| 118 116 | 
             
                # To access the image in your xforms, use the following pattern:
         | 
| 119 | 
            -
                # <icon>img?name=logo.png</icon>
         | 
| 120 | 
            -
                #  | 
| 121 | 
            -
                # | 
| 122 | 
            -
                # Sample cachehints.txt:
         | 
| 123 | 
            -
                # Skins_176A2-a.png: priority=P2;max-age=1296000
         | 
| 117 | 
            +
                # <icon>img?name=logo.png</icon> Where the controller should provide an img
         | 
| 118 | 
            +
                # method that just call this cacheimg utility.
         | 
| 119 | 
            +
                # 
         | 
| 120 | 
            +
                # Sample cachehints.txt: Skins_176A2-a.png: priority=P2;max-age=1296000
         | 
| 124 121 | 
             
                # logo.png: priority=P2;max-age=1296000
         | 
| 125 122 | 
             
                # 
         | 
| 126 123 | 
             
                def cacheimg
         | 
| @@ -152,32 +149,31 @@ module Rmobio | |
| 152 149 | 
             
                  render :text => filecontents
         | 
| 153 150 | 
             
                end
         | 
| 154 151 |  | 
| 155 | 
            -
                #== backURL(key)
         | 
| 156 | 
            -
                #  | 
| 157 | 
            -
                #  | 
| 158 | 
            -
                # the following xml data back to the caller: 
         | 
| 152 | 
            +
                # #== backURL(key) This utility handles back url to GLP if page is cached.
         | 
| 153 | 
            +
                # It expects params[:burl] or a session key and renders the following xml
         | 
| 154 | 
            +
                # data back to the caller:
         | 
| 159 155 | 
             
                # 
         | 
| 160 156 | 
             
                # <data xmlns="">
         | 
| 161 157 | 
             
                #  <burl>blah blah url</burl>
         | 
| 162 158 | 
             
                # </data>
         | 
| 163 | 
            -
                #  
         | 
| 164 | 
            -
                # The returned instance data <burl> is determined by the following rules:
         | 
| 165 | 
            -
                #* params[:burl] if parameter exists, the url in the session is also updated
         | 
| 166 | 
            -
                #* session[:key] if params[:burl] is nil
         | 
| 167 | 
            -
                #* empty string if none of the above
         | 
| 168 159 | 
             
                # 
         | 
| 169 | 
            -
                #
         | 
| 160 | 
            +
                # The returned instance data <burl> is determined by the following rules: #*
         | 
| 161 | 
            +
                # params[:burl] if parameter exists, the url in the session is also updated
         | 
| 162 | 
            +
                # #* session[:key] if params[:burl] is nil #* empty string if none of the
         | 
| 163 | 
            +
                # above
         | 
| 164 | 
            +
                # 
         | 
| 165 | 
            +
                # 
         | 
| 170 166 | 
             
                # To access the backurl from your xfroms, use the following pattern:
         | 
| 171 167 | 
             
                # 
         | 
| 172 | 
            -
                #   <xf:instance id="homepage" src="storeBackurl?burl=SOMEURL" /> | 
| 173 | 
            -
                # | 
| 174 | 
            -
                # Where the controller should provide a "storeBackurl" method that just call | 
| 168 | 
            +
                #   <xf:instance id="homepage" src="storeBackurl?burl=SOMEURL" />
         | 
| 169 | 
            +
                # 
         | 
| 170 | 
            +
                # Where the controller should provide a "storeBackurl" method that just call
         | 
| 171 | 
            +
                # this backURL utility:
         | 
| 175 172 | 
             
                #   def storeBackurl
         | 
| 176 173 | 
             
                #     backURL("recipe_burl")
         | 
| 177 | 
            -
                #   end | 
| 174 | 
            +
                #   end
         | 
| 178 175 | 
             
                # 
         | 
| 179 | 
            -
                #=== Parameter
         | 
| 180 | 
            -
                # key  =>  a unique session key to store the burl for the app
         | 
| 176 | 
            +
                # #=== Parameter key  =>  a unique session key to store the burl for the app
         | 
| 181 177 | 
             
                # 
         | 
| 182 178 | 
             
                def backURL(key) 
         | 
| 183 179 | 
             
                  url = backurl_xml(key)
         | 
| @@ -185,7 +181,8 @@ module Rmobio | |
| 185 181 | 
             
                  render :text => "<data xmlns=\"\">" + url  + "</data>"
         | 
| 186 182 | 
             
                end  # end backURLg
         | 
| 187 183 |  | 
| 188 | 
            -
                # if you want to just return partial backurl without headers and no | 
| 184 | 
            +
                # if you want to just return partial backurl without headers and no
         | 
| 185 | 
            +
                # rendering
         | 
| 189 186 | 
             
                def backurl_xml(key)
         | 
| 190 187 | 
             
                  if params[:burl]
         | 
| 191 188 | 
             
                    url =  params[:burl].gsub(/&/,'&')
         | 
| @@ -208,7 +205,18 @@ module Rmobio | |
| 208 205 | 
             
                  logger.debug("End of Headers...")
         | 
| 209 206 | 
             
                end
         | 
| 210 207 |  | 
| 211 | 
            -
             | 
| 208 | 
            +
                # Retrieve the domain string from a given uri
         | 
| 209 | 
            +
                def self.get_domain(uri)
         | 
| 210 | 
            +
                  uritokens = uri.split('/')
         | 
| 211 | 
            +
                  uritokens.each_with_index  do |token,index|
         | 
| 212 | 
            +
                    if(token == 'w')       
         | 
| 213 | 
            +
                      @domain = uritokens[index + 1]
         | 
| 214 | 
            +
                      RAILS_DEFAULT_LOGGER.debug 'Utils: Setting domain to ' +
         | 
| 215 | 
            +
                        @domain + '...' unless not defined? RAILS_DEFAULT_LOGGER
         | 
| 216 | 
            +
                    end
         | 
| 217 | 
            +
                  end
         | 
| 218 | 
            +
                  @domain
         | 
| 219 | 
            +
                end
         | 
| 212 220 | 
             
              end #end Utils
         | 
| 213 221 | 
             
            end  #end Rmobio
         | 
| 214 222 | 
             
            include Rmobio::Utils
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: rmobio
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              version: 1.1. | 
| 4 | 
            +
              version: 1.1.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - Mobio Networks
         | 
| @@ -31,11 +31,8 @@ extra_rdoc_files: [] | |
| 31 31 |  | 
| 32 32 | 
             
            files: 
         | 
| 33 33 | 
             
            - lib/rmobio
         | 
| 34 | 
            +
            - lib/rmobio.rb
         | 
| 34 35 | 
             
            - lib/rmobio/ads
         | 
| 35 | 
            -
            - lib/rmobio/ads/ad_mobs.rb
         | 
| 36 | 
            -
            - lib/rmobio/ads/ad_sense.rb
         | 
| 37 | 
            -
            - lib/rmobio/ads/m_khoj.rb
         | 
| 38 | 
            -
            - lib/rmobio/ads/smaato.rb
         | 
| 39 36 | 
             
            - lib/rmobio/ads.rb
         | 
| 40 37 | 
             
            - lib/rmobio/auth.rb
         | 
| 41 38 | 
             
            - lib/rmobio/cas.rb
         | 
| @@ -44,6 +41,11 @@ files: | |
| 44 41 | 
             
            - lib/rmobio/raketasks.rb
         | 
| 45 42 | 
             
            - lib/rmobio/utils.rb
         | 
| 46 43 | 
             
            - lib/rmobio/webservices
         | 
| 44 | 
            +
            - lib/rmobio/webservices.rb
         | 
| 45 | 
            +
            - lib/rmobio/ads/ad_mobs.rb
         | 
| 46 | 
            +
            - lib/rmobio/ads/ad_sense.rb
         | 
| 47 | 
            +
            - lib/rmobio/ads/m_khoj.rb
         | 
| 48 | 
            +
            - lib/rmobio/ads/smaato.rb
         | 
| 47 49 | 
             
            - lib/rmobio/webservices/rest
         | 
| 48 50 | 
             
            - lib/rmobio/webservices/soap
         | 
| 49 51 | 
             
            - lib/rmobio/webservices/soap/drivers.rb
         | 
| @@ -52,8 +54,6 @@ files: | |
| 52 54 | 
             
            - lib/rmobio/webservices/soap/platform.rb
         | 
| 53 55 | 
             
            - lib/rmobio/webservices/soap/registration.rb
         | 
| 54 56 | 
             
            - lib/rmobio/webservices/soap/rss.rb
         | 
| 55 | 
            -
            - lib/rmobio/webservices.rb
         | 
| 56 | 
            -
            - lib/rmobio.rb
         | 
| 57 57 | 
             
            has_rdoc: false
         | 
| 58 58 | 
             
            homepage: http://rmobio.rubyforge.org/
         | 
| 59 59 | 
             
            post_install_message: 
         |