google_maps_service_ruby 0.6.3 → 0.7.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/CONTRIBUTING.md +29 -0
- data/README.md +24 -11
- data/lib/google_maps_service/apis/directions.rb +0 -1
- data/lib/google_maps_service/apis/places.rb +0 -2
- data/lib/google_maps_service/apis/routes.rb +217 -0
- data/lib/google_maps_service/client.rb +35 -1
- data/lib/google_maps_service/validator.rb +1 -1
- data/lib/google_maps_service/version.rb +1 -1
- metadata +50 -10
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 651ee8dbc068582df401c0504894e364990b1ca0e246f72f421ca0d0a7010829
         | 
| 4 | 
            +
              data.tar.gz: a802fec4e670dab3fcb56c5c5988d1255121a909798b204af265bc4bacfdc37e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: f1336fa544bf170a6304cdd9e96006c7bd2a6b810e4ce7000f49bd79f658895c841bf6d1f3ad996a1ac2733c9eb70e4a03a59bb3e6644f278463ec2d5bc8b732
         | 
| 7 | 
            +
              data.tar.gz: bba938de0653a91533f991eb74b7b62ec9d957798715b5e65e87cd9a1b838d22396d0226fa3fe390bde49e8b3fe61c511de3a0525036e71b056523cde72e37e0
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -2,6 +2,11 @@ | |
| 2 2 |  | 
| 3 3 | 
             
            ## Unreleased
         | 
| 4 4 |  | 
| 5 | 
            +
            ## 0.7.0 - 2025-02-23
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            * Add Support for Routes API including compute_routes and compute_route_matrix
         | 
| 8 | 
            +
            * Explicitly require base64 gem as required by ruby 3.4
         | 
| 9 | 
            +
             | 
| 5 10 | 
             
            ## 0.6.3 - 2023-06-04
         | 
| 6 11 |  | 
| 7 12 | 
             
            * Add Places API place, places, places_nearby and places_photo support
         | 
    
        data/CONTRIBUTING.md
    ADDED
    
    | @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            # Contributing
         | 
| 2 | 
            +
            We welcome contributions to the google_maps_service_ruby gem!
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            ## Give us a star
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            You can contribute by starring the project to show your appreciation. This will help more people discover the project.
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            ## Reporting issues
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            If you find a bug or have a feature request, please [log an issue](https://github.com/langsharpe/google-maps-services-ruby/issues). The more details you can provide, the better.
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            ## Contributing code
         | 
| 13 | 
            +
             | 
| 14 | 
            +
            The goal of this gem is to follow the API and implementation of the [Python client](https://github.com/googlemaps/google-maps-services-python) as much as possible. If you would like to add support for an API please consider porting the python implementation.
         | 
| 15 | 
            +
             | 
| 16 | 
            +
            If you want to hack a quick fix or extension, please feel free to do so in a fork of the project. Please consider creating a [draft PR](https://github.blog/2019-02-14-introducing-draft-pull-requests/) so we can see what improvements the community is interested in and eventually merge them into the project.
         | 
| 17 | 
            +
             | 
| 18 | 
            +
            Changes that get merged will:
         | 
| 19 | 
            +
            * Follow the existing code style (standard.rb needs to pass)
         | 
| 20 | 
            +
            * Add tests for any new features
         | 
| 21 | 
            +
            * Update the documentation and readme as needed
         | 
| 22 | 
            +
            * Add a line to the CHANGELOG.md file
         | 
| 23 | 
            +
             | 
| 24 | 
            +
            To create a new pull request:
         | 
| 25 | 
            +
            1. Fork it (https://github.com/langsharpe/google-maps-services-ruby/fork).
         | 
| 26 | 
            +
            2. Create your feature branch (`git checkout -b my-new-feature`).
         | 
| 27 | 
            +
            3. Commit your changes (`git commit -am 'Add some feature'`).
         | 
| 28 | 
            +
            4. Push to the branch (`git push origin my-new-feature`).
         | 
| 29 | 
            +
            5. Create a new Pull Request. Change the base repository of the PR to langsharpe/google-maps-services-ruby.
         | 
    
        data/README.md
    CHANGED
    
    | @@ -19,6 +19,7 @@ The Ruby gem for Google Maps Web Service APIs is a gem for the following Google | |
| 19 19 | 
             
             - [Google Maps Places API][Places API]
         | 
| 20 20 | 
             
             - [Google Maps Time Zone API][Time Zone API]
         | 
| 21 21 | 
             
             - [Google Maps Roads API][Roads API]
         | 
| 22 | 
            +
             - [Google Maps Routes API][Routes API]
         | 
| 22 23 |  | 
| 23 24 | 
             
            Keep in mind that the same [terms and conditions](https://developers.google.com/maps/terms) apply
         | 
| 24 25 | 
             
            to usage of the APIs when they're accessed through this gem.
         | 
| @@ -48,17 +49,7 @@ This gem return a Ruby Hash/Array object as the API result. The result format st | |
| 48 49 |  | 
| 49 50 | 
             
            ## Contributing
         | 
| 50 51 |  | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
            The goal of this gem is to follow the API and implementation of the [python client](https://github.com/googlemaps/google-maps-services-python) as much as possible. If you would like to add support for an API please consider porting the python implementation.
         | 
| 54 | 
            -
             | 
| 55 | 
            -
            To create a new pull request:
         | 
| 56 | 
            -
             | 
| 57 | 
            -
            1. Fork it (https://github.com/langsharpe/google-maps-services-ruby/fork).
         | 
| 58 | 
            -
            2. Create your feature branch (`git checkout -b my-new-feature`).
         | 
| 59 | 
            -
            3. Commit your changes (`git commit -am 'Add some feature'`).
         | 
| 60 | 
            -
            4. Push to the branch (`git push origin my-new-feature`).
         | 
| 61 | 
            -
            5. Create a new Pull Request.
         | 
| 52 | 
            +
            See [CONTRIBUTING.md](https://github.com/langsharpe/google-maps-services-ruby/blob/master/CONTRIBUTING.md) for details on contributing to this project.
         | 
| 62 53 |  | 
| 63 54 | 
             
            ## Requirements
         | 
| 64 55 |  | 
| @@ -175,6 +166,27 @@ latlng = {'lat' => 40.714224, 'lng' => -73.961452} | |
| 175 166 | 
             
            latlng = {'latitude' => 40.714224, 'longitude' => -73.961452}
         | 
| 176 167 | 
             
            ```
         | 
| 177 168 |  | 
| 169 | 
            +
            ### Routes API
         | 
| 170 | 
            +
             | 
| 171 | 
            +
            ```ruby
         | 
| 172 | 
            +
            route = gmaps.compute_routes(
         | 
| 173 | 
            +
              {address: 'South Brisbane, QLD, AU'},
         | 
| 174 | 
            +
              {address: 'Fitzroy, VIC, AU'}
         | 
| 175 | 
            +
            )
         | 
| 176 | 
            +
             | 
| 177 | 
            +
            routes = gmaps.compute_route_matrix(
         | 
| 178 | 
            +
              [
         | 
| 179 | 
            +
                {waypoint: {'South Brisbane, QLD, AU'}},
         | 
| 180 | 
            +
              ],
         | 
| 181 | 
            +
              [
         | 
| 182 | 
            +
                {waypoint: {address: 'Fitzroy, VIC, AU'}},
         | 
| 183 | 
            +
                {waypoint: {address: 'Richmond, VIC, AU'}}
         | 
| 184 | 
            +
              ],
         | 
| 185 | 
            +
            )
         | 
| 186 | 
            +
            ```
         | 
| 187 | 
            +
             | 
| 188 | 
            +
            For more usage examples and result format, check out [gem documentation](https://www.rubydoc.info/gems/google_maps_service_ruby/GoogleMapsService/Apis/Routes), [test script](https://github.com/langsharpe/google-maps-services-ruby/tree/master/spec/google_maps_service/apis/routes_spec.rb), and [Google Maps Routes API documentation][Routes API].
         | 
| 189 | 
            +
             | 
| 178 190 | 
             
            ### Directions API
         | 
| 179 191 |  | 
| 180 192 | 
             
            ```ruby
         | 
| @@ -392,6 +404,7 @@ encoded_path = GoogleMapsService::Polyline.encode(path) | |
| 392 404 | 
             
            [Places API]: https://developers.google.com/maps/documentation/places/
         | 
| 393 405 | 
             
            [Time Zone API]: https://developers.google.com/maps/documentation/timezone/
         | 
| 394 406 | 
             
            [Roads API]: https://developers.google.com/maps/documentation/roads/
         | 
| 407 | 
            +
            [Routes API]: https://developers.google.com/maps/documentation/routes/
         | 
| 395 408 |  | 
| 396 409 | 
             
            [Google Encoded Polyline]: https://developers.google.com/maps/documentation/utilities/polylinealgorithm
         | 
| 397 410 |  | 
| @@ -64,7 +64,6 @@ module GoogleMapsService::Apis | |
| 64 64 | 
             
                  language: nil, units: nil, region: nil, departure_time: nil,
         | 
| 65 65 | 
             
                  arrival_time: nil, optimize_waypoints: false, transit_mode: nil,
         | 
| 66 66 | 
             
                  transit_routing_preference: nil, response_slice: :routes)
         | 
| 67 | 
            -
             | 
| 68 67 | 
             
                  params = {
         | 
| 69 68 | 
             
                    origin: GoogleMapsService::Convert.waypoint(origin),
         | 
| 70 69 | 
             
                    destination: GoogleMapsService::Convert.waypoint(destination)
         | 
| @@ -29,7 +29,6 @@ module GoogleMapsService::Apis | |
| 29 29 | 
             
                #         next_page_token: token for retrieving the next page of results
         | 
| 30 30 | 
             
                def places(query, location: nil, radius: nil, language: nil, min_price: nil,
         | 
| 31 31 | 
             
                  max_price: nil, open_now: false, type: nil, page_token: nil)
         | 
| 32 | 
            -
             | 
| 33 32 | 
             
                  _places("text", query: query, location: location, radius: radius,
         | 
| 34 33 | 
             
                    language: language, min_price: min_price, max_price: max_price,
         | 
| 35 34 | 
             
                    open_now: open_now, type: type, page_token: page_token)
         | 
| @@ -132,7 +131,6 @@ module GoogleMapsService::Apis | |
| 132 131 | 
             
                  query: nil, location: nil, radius: nil, keyword: nil, language: nil,
         | 
| 133 132 | 
             
                  min_price: 0, max_price: 4, name: nil, open_now: nil,
         | 
| 134 133 | 
             
                  rank_by: nil, type: nil, page_token: nil)
         | 
| 135 | 
            -
             | 
| 136 134 | 
             
                  params = {}
         | 
| 137 135 | 
             
                  params[:query] = query if query
         | 
| 138 136 | 
             
                  params[:minprice] = min_price if min_price
         | 
| @@ -0,0 +1,217 @@ | |
| 1 | 
            +
            module GoogleMapsService::Apis
         | 
| 2 | 
            +
              # Performs requests to the Google Maps Routes API.
         | 
| 3 | 
            +
              module Routes
         | 
| 4 | 
            +
                # Base URL of Google Maps Routes API
         | 
| 5 | 
            +
                ROUTES_BASE_URL = "https://routes.googleapis.com"
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                # Compute a route matrix
         | 
| 8 | 
            +
                #
         | 
| 9 | 
            +
                # Only origins and destinations are required. The formats for each of the paramters are defined at
         | 
| 10 | 
            +
                # https://developers.google.com/maps/documentation/routes/reference/rest/v2/TopLevel/computeRouteMatrix
         | 
| 11 | 
            +
                #
         | 
| 12 | 
            +
                # @example Simple route matrix
         | 
| 13 | 
            +
                # matrix = gmaps.compute_route_matrix(
         | 
| 14 | 
            +
                #   [
         | 
| 15 | 
            +
                #     {waypoint: {address: 'South Brisbane, QLD, AU'}}
         | 
| 16 | 
            +
                #   ],
         | 
| 17 | 
            +
                #   [
         | 
| 18 | 
            +
                #     {waypoint: {address: 'Fitzroy, VIC, AU'}},
         | 
| 19 | 
            +
                #     {waypoint: {address: 'Richmond, VIC, AU'}}
         | 
| 20 | 
            +
                #   ],
         | 
| 21 | 
            +
                # )
         | 
| 22 | 
            +
                #
         | 
| 23 | 
            +
                # @example Complex route matrix
         | 
| 24 | 
            +
                # matrix = gmaps.compute_route_matrix(
         | 
| 25 | 
            +
                #   [{waypoint: {address: 'South Brisbane, QLD, AU'}}],
         | 
| 26 | 
            +
                #   [{waypoint: {address: 'Fitzroy, VIC, AU'}},{waypoint: {address: 'Richmond, VIC, AU'}}],
         | 
| 27 | 
            +
                #   travel_mode: "TRANSIT",
         | 
| 28 | 
            +
                #   departure_time: Time.now,
         | 
| 29 | 
            +
                #   language_code: "en",
         | 
| 30 | 
            +
                #   region_code: "AU",
         | 
| 31 | 
            +
                #   units: "METRIC",
         | 
| 32 | 
            +
                #   extra_computations: ["TOLLS"],
         | 
| 33 | 
            +
                #   transit_preferences: {
         | 
| 34 | 
            +
                #     allowedTravelModes: [ "RAIL" ],
         | 
| 35 | 
            +
                #     routingPreference: "FEWER_TRANSFERS"
         | 
| 36 | 
            +
                #   }
         | 
| 37 | 
            +
                # )
         | 
| 38 | 
            +
                #
         | 
| 39 | 
            +
                # @param [Array] origins One or more RouteMatrixOrigin
         | 
| 40 | 
            +
                # @param [Array] destinations One or more RouteMatrixDestination
         | 
| 41 | 
            +
                # @param [String] field_mask The fields that should be returned in the response. The default is "*"
         | 
| 42 | 
            +
                # @param [String] travel_mode
         | 
| 43 | 
            +
                # @param [String] routing_preference
         | 
| 44 | 
            +
                # @param [String, Time] departure_time
         | 
| 45 | 
            +
                # @param [String, Time] arrival_time
         | 
| 46 | 
            +
                # @param [String] language_code
         | 
| 47 | 
            +
                # @param [String] region_code
         | 
| 48 | 
            +
                # @param [String] units
         | 
| 49 | 
            +
                # @param [Array] extra_computations
         | 
| 50 | 
            +
                # @param [String] traffic_model
         | 
| 51 | 
            +
                # @param [Hash] transit_preferences
         | 
| 52 | 
            +
                #
         | 
| 53 | 
            +
                def compute_route_matrix(origins, destinations,
         | 
| 54 | 
            +
                  field_mask: nil,
         | 
| 55 | 
            +
                  travel_mode: nil,
         | 
| 56 | 
            +
                  routing_preference: nil,
         | 
| 57 | 
            +
                  departure_time: nil,
         | 
| 58 | 
            +
                  arrival_time: nil,
         | 
| 59 | 
            +
                  language_code: nil,
         | 
| 60 | 
            +
                  region_code: nil,
         | 
| 61 | 
            +
                  units: nil,
         | 
| 62 | 
            +
                  extra_computations: nil,
         | 
| 63 | 
            +
                  traffic_model: nil,
         | 
| 64 | 
            +
                  transit_preferences: nil)
         | 
| 65 | 
            +
                  params = {
         | 
| 66 | 
            +
                    origins: origins,
         | 
| 67 | 
            +
                    destinations: destinations
         | 
| 68 | 
            +
                  }
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                  params[:travelMode] = travel_mode if travel_mode
         | 
| 71 | 
            +
                  params[:routingPreference] = routing_preference if routing_preference
         | 
| 72 | 
            +
                  params[:departureTime] = time_convert(departure_time) if departure_time
         | 
| 73 | 
            +
                  params[:arrivalTime] = time_convert(arrival_time) if arrival_time
         | 
| 74 | 
            +
                  params[:languageCode] = language_code if language_code
         | 
| 75 | 
            +
                  params[:regionCode] = region_code if region_code
         | 
| 76 | 
            +
                  params[:units] = units if units
         | 
| 77 | 
            +
                  params[:extraComputations] = extra_computations if extra_computations
         | 
| 78 | 
            +
                  params[:trafficModel] = traffic_model if traffic_model
         | 
| 79 | 
            +
                  params[:transitPreferences] = transit_preferences if transit_preferences
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                  field_mask ||= "*"
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                  post("/distanceMatrix/v2:computeRouteMatrix", params,
         | 
| 84 | 
            +
                    base_url: ROUTES_BASE_URL,
         | 
| 85 | 
            +
                    custom_response_decoder: method(:extract_routes_body),
         | 
| 86 | 
            +
                    field_mask: field_mask)
         | 
| 87 | 
            +
                end
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                # Compute routes between locations
         | 
| 90 | 
            +
                #
         | 
| 91 | 
            +
                # Returns the primary route along with optional alternate routes, given a set of terminal
         | 
| 92 | 
            +
                # and intermediate waypoints.
         | 
| 93 | 
            +
                #
         | 
| 94 | 
            +
                # Only the origin and destination is required. The formats for each of the paramters are defined at
         | 
| 95 | 
            +
                # https://developers.google.com/maps/documentation/routes/reference/rest/v2/TopLevel/computeRoutes
         | 
| 96 | 
            +
                #
         | 
| 97 | 
            +
                # @example Simple route request
         | 
| 98 | 
            +
                # route = gmaps.compute_routes(
         | 
| 99 | 
            +
                #   {address: 'South Brisbane, QLD, AU'},
         | 
| 100 | 
            +
                #   {address: 'Fitzroy, VIC, AU'}
         | 
| 101 | 
            +
                # )
         | 
| 102 | 
            +
                #
         | 
| 103 | 
            +
                # @example Complex route request with options
         | 
| 104 | 
            +
                # route = gmaps.compute_routes(
         | 
| 105 | 
            +
                #   {location: {latLng: {latitude: -27.4698, longitude: 153.0251}}},
         | 
| 106 | 
            +
                #   {address: 'Fitzroy, VIC, AU'},
         | 
| 107 | 
            +
                #   intermediates: [{address: 'Ultimo, NSW, AU'}],
         | 
| 108 | 
            +
                #   travel_mode: 'DRIVE',
         | 
| 109 | 
            +
                #   routing_preference: 'TRAFFIC_AWARE',
         | 
| 110 | 
            +
                #   departure_time: Time.now + 3600,
         | 
| 111 | 
            +
                #   language_code: 'en',
         | 
| 112 | 
            +
                #   region_code: 'AU',
         | 
| 113 | 
            +
                #   units: 'METRIC',
         | 
| 114 | 
            +
                #   extra_computations: ['TOLLS'],
         | 
| 115 | 
            +
                #   compute_alternative_routes: true
         | 
| 116 | 
            +
                # )
         | 
| 117 | 
            +
                #
         | 
| 118 | 
            +
                # @param [Hash] origin Required. Origin waypoint
         | 
| 119 | 
            +
                # @param [Hash] destination Required. Destination waypoint
         | 
| 120 | 
            +
                # @param [Array] intermediates
         | 
| 121 | 
            +
                # @param [String] travel_mode
         | 
| 122 | 
            +
                # @param [String] routing_preference
         | 
| 123 | 
            +
                # @param [String] polyline_quality
         | 
| 124 | 
            +
                # @param [String] polyline_encoding
         | 
| 125 | 
            +
                # @param [String, Time] departure_time
         | 
| 126 | 
            +
                # @param [String, Time] arrival_time
         | 
| 127 | 
            +
                # @param [Boolean] compute_alternative_routes
         | 
| 128 | 
            +
                # @param [Hash] route_modifiers
         | 
| 129 | 
            +
                # @param [String] language_code
         | 
| 130 | 
            +
                # @param [String] region_code
         | 
| 131 | 
            +
                # @param [String] units
         | 
| 132 | 
            +
                # @param [Boolean] optimize_waypoint_order
         | 
| 133 | 
            +
                # @param [Array] requested_reference_routes
         | 
| 134 | 
            +
                # @param [Array] extra_computations
         | 
| 135 | 
            +
                # @param [String] traffic_model
         | 
| 136 | 
            +
                # @param [Hash] transit_preferences
         | 
| 137 | 
            +
                # @param [String] field_mask
         | 
| 138 | 
            +
                #
         | 
| 139 | 
            +
                def compute_routes(origin, destination,
         | 
| 140 | 
            +
                  intermediates: nil,
         | 
| 141 | 
            +
                  travel_mode: nil,
         | 
| 142 | 
            +
                  routing_preference: nil,
         | 
| 143 | 
            +
                  polyline_quality: nil,
         | 
| 144 | 
            +
                  polyline_encoding: nil,
         | 
| 145 | 
            +
                  departure_time: nil,
         | 
| 146 | 
            +
                  arrival_time: nil,
         | 
| 147 | 
            +
                  compute_alternative_routes: nil,
         | 
| 148 | 
            +
                  route_modifiers: nil,
         | 
| 149 | 
            +
                  language_code: nil,
         | 
| 150 | 
            +
                  region_code: nil,
         | 
| 151 | 
            +
                  units: nil,
         | 
| 152 | 
            +
                  optimize_waypoint_order: nil,
         | 
| 153 | 
            +
                  requested_reference_routes: nil,
         | 
| 154 | 
            +
                  extra_computations: nil,
         | 
| 155 | 
            +
                  traffic_model: nil,
         | 
| 156 | 
            +
                  transit_preferences: nil,
         | 
| 157 | 
            +
                  field_mask: nil)
         | 
| 158 | 
            +
                  params = {
         | 
| 159 | 
            +
                    origin: origin,
         | 
| 160 | 
            +
                    destination: destination
         | 
| 161 | 
            +
                  }
         | 
| 162 | 
            +
             | 
| 163 | 
            +
                  params[:intermediates] = intermediates if intermediates
         | 
| 164 | 
            +
                  params[:travelMode] = travel_mode if travel_mode
         | 
| 165 | 
            +
                  params[:routingPreference] = routing_preference if routing_preference
         | 
| 166 | 
            +
                  params[:polylineQuality] = polyline_quality if polyline_quality
         | 
| 167 | 
            +
                  params[:polylineEncoding] = polyline_encoding if polyline_encoding
         | 
| 168 | 
            +
                  params[:departureTime] = time_convert(departure_time) if departure_time
         | 
| 169 | 
            +
                  params[:arrivalTime] = time_convert(arrival_time) if arrival_time
         | 
| 170 | 
            +
                  params[:computeAlternativeRoutes] = compute_alternative_routes unless compute_alternative_routes.nil?
         | 
| 171 | 
            +
                  params[:routeModifiers] = route_modifiers if route_modifiers
         | 
| 172 | 
            +
                  params[:languageCode] = language_code if language_code
         | 
| 173 | 
            +
                  params[:regionCode] = region_code if region_code
         | 
| 174 | 
            +
                  params[:units] = units if units
         | 
| 175 | 
            +
                  params[:optimizeWaypointOrder] = optimize_waypoint_order unless optimize_waypoint_order.nil?
         | 
| 176 | 
            +
                  params[:requestedReferenceRoutes] = requested_reference_routes if requested_reference_routes
         | 
| 177 | 
            +
                  params[:extraComputations] = extra_computations if extra_computations
         | 
| 178 | 
            +
                  params[:trafficModel] = traffic_model if traffic_model
         | 
| 179 | 
            +
                  params[:transitPreferences] = transit_preferences if transit_preferences
         | 
| 180 | 
            +
             | 
| 181 | 
            +
                  field_mask ||= "*"
         | 
| 182 | 
            +
             | 
| 183 | 
            +
                  post("/directions/v2:computeRoutes", params,
         | 
| 184 | 
            +
                    base_url: ROUTES_BASE_URL,
         | 
| 185 | 
            +
                    custom_response_decoder: method(:extract_routes_body),
         | 
| 186 | 
            +
                    field_mask: field_mask)
         | 
| 187 | 
            +
                end
         | 
| 188 | 
            +
             | 
| 189 | 
            +
                private
         | 
| 190 | 
            +
             | 
| 191 | 
            +
                # Extracts a result from a Routes API HTTP response.
         | 
| 192 | 
            +
                def extract_routes_body(response)
         | 
| 193 | 
            +
                  begin
         | 
| 194 | 
            +
                    body = MultiJson.load(response.body, symbolize_keys: true)
         | 
| 195 | 
            +
                  rescue
         | 
| 196 | 
            +
                    raise GoogleMapsService::Error::ApiError.new(response), "Received a malformed response."
         | 
| 197 | 
            +
                  end
         | 
| 198 | 
            +
             | 
| 199 | 
            +
                  if response.code == "400"
         | 
| 200 | 
            +
                    message = body.is_a?(Array) ? body.first[:error][:message] : body[:error][:message]
         | 
| 201 | 
            +
                    raise GoogleMapsService::Error::ClientError.new(response), message
         | 
| 202 | 
            +
                  else
         | 
| 203 | 
            +
                    check_response_status_code(response)
         | 
| 204 | 
            +
                  end
         | 
| 205 | 
            +
             | 
| 206 | 
            +
                  body
         | 
| 207 | 
            +
                end
         | 
| 208 | 
            +
             | 
| 209 | 
            +
                def time_convert(value)
         | 
| 210 | 
            +
                  if value.is_a?(Time)
         | 
| 211 | 
            +
                    value.utc.iso8601
         | 
| 212 | 
            +
                  else
         | 
| 213 | 
            +
                    value
         | 
| 214 | 
            +
                  end
         | 
| 215 | 
            +
                end
         | 
| 216 | 
            +
              end
         | 
| 217 | 
            +
            end
         | 
| @@ -10,6 +10,7 @@ require "google_maps_service/apis/elevation" | |
| 10 10 | 
             
            require "google_maps_service/apis/geocoding"
         | 
| 11 11 | 
             
            require "google_maps_service/apis/places"
         | 
| 12 12 | 
             
            require "google_maps_service/apis/roads"
         | 
| 13 | 
            +
            require "google_maps_service/apis/routes"
         | 
| 13 14 | 
             
            require "google_maps_service/apis/time_zone"
         | 
| 14 15 |  | 
| 15 16 | 
             
            module GoogleMapsService
         | 
| @@ -28,6 +29,7 @@ module GoogleMapsService | |
| 28 29 | 
             
                include GoogleMapsService::Apis::Geocoding
         | 
| 29 30 | 
             
                include GoogleMapsService::Apis::Places
         | 
| 30 31 | 
             
                include GoogleMapsService::Apis::Roads
         | 
| 32 | 
            +
                include GoogleMapsService::Apis::Routes
         | 
| 31 33 | 
             
                include GoogleMapsService::Apis::TimeZone
         | 
| 32 34 |  | 
| 33 35 | 
             
                # Secret key for accessing Google Maps Web Service.
         | 
| @@ -80,7 +82,7 @@ module GoogleMapsService | |
| 80 82 | 
             
                def initialize(**options)
         | 
| 81 83 | 
             
                  [:key, :client_id, :client_secret,
         | 
| 82 84 | 
             
                    :retry_timeout, :queries_per_second].each do |key|
         | 
| 83 | 
            -
                    instance_variable_set("@#{key}" | 
| 85 | 
            +
                    instance_variable_set(:"@#{key}", options[key] || GoogleMapsService.instance_variable_get(:"@#{key}"))
         | 
| 84 86 | 
             
                  end
         | 
| 85 87 | 
             
                  [:request_options, :ssl_options, :connection].each do |key|
         | 
| 86 88 | 
             
                    if options.has_key?(key)
         | 
| @@ -152,6 +154,38 @@ module GoogleMapsService | |
| 152 154 | 
             
                  end
         | 
| 153 155 | 
             
                end
         | 
| 154 156 |  | 
| 157 | 
            +
                # Make API call using an http post.
         | 
| 158 | 
            +
                #
         | 
| 159 | 
            +
                # @param [String] path Url path.
         | 
| 160 | 
            +
                # @param [String] params Request parameters.
         | 
| 161 | 
            +
                # @param [String] base_url Base Google Maps Web Service API endpoint url.
         | 
| 162 | 
            +
                # @param [Boolean] accepts_client_id Sign the request using API {#keys} instead of {#client_id}.
         | 
| 163 | 
            +
                # @param [Method] custom_response_decoder Custom method to decode raw API response.
         | 
| 164 | 
            +
                #
         | 
| 165 | 
            +
                # @return [Object] Decoded response body.
         | 
| 166 | 
            +
                def post(path, params, base_url: DEFAULT_BASE_URL, accepts_client_id: true, custom_response_decoder: nil, field_mask: nil)
         | 
| 167 | 
            +
                  url = URI(base_url + generate_auth_url(path, {}, accepts_client_id))
         | 
| 168 | 
            +
             | 
| 169 | 
            +
                  Retriable.retriable timeout: @retry_timeout, on: RETRIABLE_ERRORS do |try|
         | 
| 170 | 
            +
                    begin
         | 
| 171 | 
            +
                      request_query_ticket
         | 
| 172 | 
            +
                      request = Net::HTTP::Post.new(url)
         | 
| 173 | 
            +
                      request["User-Agent"] = user_agent
         | 
| 174 | 
            +
                      request["X-Goog-FieldMask"] = field_mask if field_mask
         | 
| 175 | 
            +
                      request["Content-Type"] = "application/json"
         | 
| 176 | 
            +
                      request.body = MultiJson.dump(params)
         | 
| 177 | 
            +
                      response = Net::HTTP.start(url.hostname, url.port, use_ssl: url.scheme == "https") do |http|
         | 
| 178 | 
            +
                        http.request(request)
         | 
| 179 | 
            +
                      end
         | 
| 180 | 
            +
                    ensure
         | 
| 181 | 
            +
                      release_query_ticket
         | 
| 182 | 
            +
                    end
         | 
| 183 | 
            +
             | 
| 184 | 
            +
                    return custom_response_decoder.call(response) if custom_response_decoder
         | 
| 185 | 
            +
                    decode_response_body(response)
         | 
| 186 | 
            +
                  end
         | 
| 187 | 
            +
                end
         | 
| 188 | 
            +
             | 
| 155 189 | 
             
                # Get/wait the request "ticket" if QPS is configured.
         | 
| 156 190 | 
             
                # Check for previous request time, it must be more than a second ago before calling new request.
         | 
| 157 191 | 
             
                #
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: google_maps_service_ruby
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.7.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Lang Sharpe
         | 
| 8 | 
            -
            autorequire:
         | 
| 9 8 | 
             
            bindir: bin
         | 
| 10 9 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 10 | 
            +
            date: 2025-02-23 00:00:00.000000000 Z
         | 
| 12 11 | 
             
            dependencies:
         | 
| 13 12 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 13 | 
             
              name: multi_json
         | 
| @@ -38,6 +37,20 @@ dependencies: | |
| 38 37 | 
             
                - - "~>"
         | 
| 39 38 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 39 | 
             
                    version: '3.1'
         | 
| 40 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 41 | 
            +
              name: base64
         | 
| 42 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 43 | 
            +
                requirements:
         | 
| 44 | 
            +
                - - ">="
         | 
| 45 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 46 | 
            +
                    version: '0'
         | 
| 47 | 
            +
              type: :runtime
         | 
| 48 | 
            +
              prerelease: false
         | 
| 49 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 50 | 
            +
                requirements:
         | 
| 51 | 
            +
                - - ">="
         | 
| 52 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 53 | 
            +
                    version: '0'
         | 
| 41 54 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 55 | 
             
              name: coveralls_reborn
         | 
| 43 56 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -150,9 +163,37 @@ dependencies: | |
| 150 163 | 
             
                - - "~>"
         | 
| 151 164 | 
             
                  - !ruby/object:Gem::Version
         | 
| 152 165 | 
             
                    version: 0.9.28
         | 
| 153 | 
            -
             | 
| 154 | 
            -
               | 
| 155 | 
            -
               | 
| 166 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 167 | 
            +
              name: irb
         | 
| 168 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 169 | 
            +
                requirements:
         | 
| 170 | 
            +
                - - ">="
         | 
| 171 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 172 | 
            +
                    version: '0'
         | 
| 173 | 
            +
              type: :development
         | 
| 174 | 
            +
              prerelease: false
         | 
| 175 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 176 | 
            +
                requirements:
         | 
| 177 | 
            +
                - - ">="
         | 
| 178 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 179 | 
            +
                    version: '0'
         | 
| 180 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 181 | 
            +
              name: rdoc
         | 
| 182 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 183 | 
            +
                requirements:
         | 
| 184 | 
            +
                - - ">="
         | 
| 185 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 186 | 
            +
                    version: '0'
         | 
| 187 | 
            +
              type: :development
         | 
| 188 | 
            +
              prerelease: false
         | 
| 189 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 190 | 
            +
                requirements:
         | 
| 191 | 
            +
                - - ">="
         | 
| 192 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 193 | 
            +
                    version: '0'
         | 
| 194 | 
            +
            description: Google Maps API Client, including the Routes API, Directions API, Distance
         | 
| 195 | 
            +
              Matrix API, Geocoding API and Places API. google_maps_service_ruby is a fork of
         | 
| 196 | 
            +
              google_maps_service, which is a fork of google-maps-services-python.
         | 
| 156 197 | 
             
            email:
         | 
| 157 198 | 
             
            - langer8191@gmail.com
         | 
| 158 199 | 
             
            executables: []
         | 
| @@ -161,6 +202,7 @@ extra_rdoc_files: [] | |
| 161 202 | 
             
            files:
         | 
| 162 203 | 
             
            - CHANGELOG.md
         | 
| 163 204 | 
             
            - CODE_OF_CONDUCT.md
         | 
| 205 | 
            +
            - CONTRIBUTING.md
         | 
| 164 206 | 
             
            - LICENSE
         | 
| 165 207 | 
             
            - README.md
         | 
| 166 208 | 
             
            - lib/google_maps_service.rb
         | 
| @@ -171,6 +213,7 @@ files: | |
| 171 213 | 
             
            - lib/google_maps_service/apis/geocoding.rb
         | 
| 172 214 | 
             
            - lib/google_maps_service/apis/places.rb
         | 
| 173 215 | 
             
            - lib/google_maps_service/apis/roads.rb
         | 
| 216 | 
            +
            - lib/google_maps_service/apis/routes.rb
         | 
| 174 217 | 
             
            - lib/google_maps_service/apis/time_zone.rb
         | 
| 175 218 | 
             
            - lib/google_maps_service/client.rb
         | 
| 176 219 | 
             
            - lib/google_maps_service/convert.rb
         | 
| @@ -188,8 +231,6 @@ metadata: | |
| 188 231 | 
             
              changelog_uri: https://raw.githubusercontent.com/langsharpe/google-maps-services-ruby/master/CHANGELOG.md
         | 
| 189 232 | 
             
              documentation_uri: https://www.rubydoc.info/gems/google_maps_service_ruby
         | 
| 190 233 | 
             
              homepage_uri: https://github.com/langsharpe/google-maps-services-ruby
         | 
| 191 | 
            -
              source_code_uri: https://github.com/langsharpe/google-maps-services-ruby
         | 
| 192 | 
            -
            post_install_message:
         | 
| 193 234 | 
             
            rdoc_options: []
         | 
| 194 235 | 
             
            require_paths:
         | 
| 195 236 | 
             
            - lib
         | 
| @@ -204,8 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 204 245 | 
             
                - !ruby/object:Gem::Version
         | 
| 205 246 | 
             
                  version: '0'
         | 
| 206 247 | 
             
            requirements: []
         | 
| 207 | 
            -
            rubygems_version: 3. | 
| 208 | 
            -
            signing_key:
         | 
| 248 | 
            +
            rubygems_version: 3.6.2
         | 
| 209 249 | 
             
            specification_version: 4
         | 
| 210 250 | 
             
            summary: Google Maps API Client
         | 
| 211 251 | 
             
            test_files: []
         |