{"id":16793494,"url":"https://github.com/mdp/divining_rod","last_synced_at":"2025-03-17T03:30:52.357Z","repository":{"id":62557249,"uuid":"522239","full_name":"mdp/divining_rod","owner":"mdp","description":"A mobile phone web request profiler","archived":false,"fork":false,"pushed_at":"2011-05-12T17:22:36.000Z","size":1148,"stargazers_count":48,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-14T08:49:27.903Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mdp.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-02-17T18:34:49.000Z","updated_at":"2019-07-14T12:27:39.000Z","dependencies_parsed_at":"2022-11-03T06:30:23.307Z","dependency_job_id":null,"html_url":"https://github.com/mdp/divining_rod","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdp%2Fdivining_rod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdp%2Fdivining_rod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdp%2Fdivining_rod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mdp%2Fdivining_rod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mdp","download_url":"https://codeload.github.com/mdp/divining_rod/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221671314,"owners_count":16861234,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T08:49:28.634Z","updated_at":"2024-10-27T11:51:18.313Z","avatar_url":"https://github.com/mdp.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Divining Rod\n\u003cimg src='http://public.mpercival.com.s3.amazonaws.com/images/divining_rod.jpg' /\u003e\n\nA tool to profile web requests. Especially useful for mobile site development\n\n## Installation\n\n    gem install divining_rod\n\n## Example\n\n  Using the example configuration (found in [example_config.rb](http://github.com/markpercival/divining_rod/blob/master/example_config.rb))\n\n    # For a request with the user agent\n    # \"Mozilla/5.0 (iPhone; U; CPU iPhone OS 2_2_1 like Mac OS X; en-us) AppleWebKit/525.18.1 (KHTML, like Gecko) Version/3.1.1 Mobile/5H11 Safari/525.20\"\n\n    profile = DiviningRod::Profile.new(request)\n    profile.iphone?           #=\u003e true\n    profile.name              #=\u003e 'iPhone'\n    profile.youtube_capable?  #=\u003e true\n    profile.format            #=\u003e :webkit\n\n## Mappings\n\nMatches happen in the order they are defined, and then proceed down to the subsequent block. So for example:\n\n    DiviningRod::Mappings.define do |map|\n      map.ua /Apple/, :format =\u003e :webkit, :tags =\u003e [:apple, :iphone_os] do\n        iphone.ua /iPad/, :tags =\u003e :ipad, :name =\u003e 'iPad', :format =\u003e nil\n        iphone.ua /iPod/, :tags =\u003e :ipod, :name =\u003e 'iPod Touch'\n        iphone.ua /iPhone/, :tags =\u003e :iphone, :name =\u003e 'iPhone'\n      end\n    end\n\nWill match \"Apple iPad\" first with the /Apple/ matcher, then with the /iPad/ matcher, and the tags will be\n\n    [:apple, :iphone_os, :ipad] # Notice tags get appended, *not* overridden.\n\nAnd _:format_ will be set to _nil_\n\nWhy _nil_? Because when :format is set to _nil_ and you ask for it, DiviningRod will return the original _request_ objects format.\n\n## Usage\n\n_initializers/divining\\_rod.rb_\n\n    DiviningRod::Mappings.define do |map|\n        # Android based phones\n        map.ua /Android/, :format =\u003e :webkit, :name =\u003e 'Android', :tags =\u003e [:android, :youtube_capable, :google_gears]\n\n        # Apple iPhone OS\n        map.ua /Apple.*Mobile.*Safari/, :format =\u003e :webkit, :tags =\u003e [:apple, :iphone_os, :youtube_capable] do |iphone|\n          iphone.ua /iPad/, :tags =\u003e :ipad, :name =\u003e 'iPad', :format =\u003e nil\n          iphone.ua /iPod/, :tags =\u003e :ipod, :name =\u003e 'iPod Touch'\n          iphone.ua /iPhone/, :tags =\u003e :iphone, :name =\u003e 'iPhone'\n        end\n\n        #Blackberry, needs more detail here\n        map.ua /BlackBerry/, :tags =\u003e :blackberry, :name =\u003e 'BlackBerry'\n        map.subdomain /wap/, :format =\u003e :wap, :tags =\u003e [:crappy_old_phone]\n\n        # Enable this to forces a default format if unmatched\n        # otherwise it will return the request.format\n        # map.default :format =\u003e :html\n    end\n\n_initializers/mime\\_types.rb_\n\n    Mime::Type.register_alias \"text/html\", :webkit\n\n_app/controllers/mobile\\_controller.rb_\n\n    class MobileController \u003c ApplicationController\n      before_filter :detect_mobile_type\n\n      ....\n\n      private\n\n      def detect_mobile_type\n        # If the profile isn't matched it defaults to request.format\n        @profile = DiviningRod::Profile.new(request)\n        request.format = @profile.format\n      end\n\n    end\n\n_app/views/mobile/show.webkit.html_\n\n    \u003c%- if @profile.iphone? %\u003e\n      \u003c%= link_to \"Install our iPhone App in the AppStore\", @iPhone_appstore_url %\u003e\n    \u003c%- elsif @profile.android? %\u003e\n      \u003c%= link_to \"Direct download\", @android_app_url %\u003e\n    \u003c% end %\u003e\n\n## Writing your own custom profiler\n\nYou can also include the DiviningRod::Profiler mixin in your own custom class\n\n_lib/browser_profile.rb_\n\n    class BrowserProfile\n      include DivingingRod::Profiler\n\n      def has_an_app_store?\n        android? || iphone? || windows_phone?\n      end\n\n    end\n\nUsage\n\n    prof = BrowserProfile.new(request)\n    prof.has_an_app_store?\n\n## Todo\n\n### Copyright\n\nCopyright (c) 2010 Mark Percival. See LICENSE for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdp%2Fdivining_rod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmdp%2Fdivining_rod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmdp%2Fdivining_rod/lists"}