gds-api-adapters 4.5.0 → 4.6.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.
    
        data/lib/gds_api/content_api.rb
    CHANGED
    
    | 
         @@ -94,7 +94,7 @@ class GdsApi::ContentApi < GdsApi::Base 
     | 
|
| 
       94 
94 
     | 
    
         
             
              end
         
     | 
| 
       95 
95 
     | 
    
         | 
| 
       96 
96 
     | 
    
         
             
              def countries
         
     | 
| 
       97 
     | 
    
         
            -
                get_json!("#{base_url}/travel-advice.json")
         
     | 
| 
      
 97 
     | 
    
         
            +
                parse_times(get_json!("#{base_url}/travel-advice.json"))
         
     | 
| 
       98 
98 
     | 
    
         
             
              end
         
     | 
| 
       99 
99 
     | 
    
         | 
| 
       100 
100 
     | 
    
         
             
              private
         
     | 
| 
         @@ -112,4 +112,13 @@ class GdsApi::ContentApi < GdsApi::Base 
     | 
|
| 
       112 
112 
     | 
    
         
             
                    batch_response
         
     | 
| 
       113 
113 
     | 
    
         
             
                  end
         
     | 
| 
       114 
114 
     | 
    
         
             
                end
         
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
                def parse_times(response)
         
     | 
| 
      
 117 
     | 
    
         
            +
                  response["results"].map do |result|
         
     | 
| 
      
 118 
     | 
    
         
            +
                    if result.has_key?("updated_at")
         
     | 
| 
      
 119 
     | 
    
         
            +
                      result["updated_at"] = Time.parse(result["updated_at"])
         
     | 
| 
      
 120 
     | 
    
         
            +
                    end
         
     | 
| 
      
 121 
     | 
    
         
            +
                  end
         
     | 
| 
      
 122 
     | 
    
         
            +
                  response
         
     | 
| 
      
 123 
     | 
    
         
            +
                end
         
     | 
| 
       115 
124 
     | 
    
         
             
            end
         
     | 
| 
         @@ -302,13 +302,14 @@ module GdsApi 
     | 
|
| 
       302 
302 
     | 
    
         | 
| 
       303 
303 
     | 
    
         
             
                  def content_api_has_countries(countries)
         
     | 
| 
       304 
304 
     | 
    
         
             
                    response = response_base.merge({
         
     | 
| 
       305 
     | 
    
         
            -
                      "results" => countries.map {| 
     | 
| 
      
 305 
     | 
    
         
            +
                      "results" => countries.map { |slug, values|
         
     | 
| 
      
 306 
     | 
    
         
            +
                        updated_at = values.has_key?(:updated_at) ? {"updated_at" => values[:updated_at]} : {}
         
     | 
| 
       306 
307 
     | 
    
         
             
                        {
         
     | 
| 
       307 
     | 
    
         
            -
                          "id" => "#{CONTENT_API_ENDPOINT}/travel-advice/#{ 
     | 
| 
       308 
     | 
    
         
            -
                          "name" => name,
         
     | 
| 
       309 
     | 
    
         
            -
                          "identifier" =>  
     | 
| 
       310 
     | 
    
         
            -
                          "web_url" => "http://www.test.gov.uk/travel-advice/#{ 
     | 
| 
       311 
     | 
    
         
            -
                        }
         
     | 
| 
      
 308 
     | 
    
         
            +
                          "id" => "#{CONTENT_API_ENDPOINT}/travel-advice/#{slug}.json",
         
     | 
| 
      
 309 
     | 
    
         
            +
                          "name" => values[:name],
         
     | 
| 
      
 310 
     | 
    
         
            +
                          "identifier" => slug,
         
     | 
| 
      
 311 
     | 
    
         
            +
                          "web_url" => "http://www.test.gov.uk/travel-advice/#{slug}",
         
     | 
| 
      
 312 
     | 
    
         
            +
                        }.merge(updated_at)
         
     | 
| 
       312 
313 
     | 
    
         
             
                      },
         
     | 
| 
       313 
314 
     | 
    
         
             
                      "total" => countries.length
         
     | 
| 
       314 
315 
     | 
    
         
             
                    })
         
     | 
| 
         @@ -11,7 +11,7 @@ module GdsApi 
     | 
|
| 
       11 
11 
     | 
    
         
             
                      "postcode"  => postcode
         
     | 
| 
       12 
12 
     | 
    
         
             
                    }
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
                    stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode. 
     | 
| 
      
 14 
     | 
    
         
            +
                    stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.gsub(' ','+') + ".json")
         
     | 
| 
       15 
15 
     | 
    
         
             
                      .to_return(:body => response.to_json, :status => 200)
         
     | 
| 
       16 
16 
     | 
    
         
             
                    stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/partial/" + postcode.split(' ').first + ".json")
         
     | 
| 
       17 
17 
     | 
    
         
             
                      .to_return(:body => response.to_json, :status => 200)
         
     | 
| 
         @@ -35,19 +35,19 @@ module GdsApi 
     | 
|
| 
       35 
35 
     | 
    
         
             
                      }]
         
     | 
| 
       36 
36 
     | 
    
         
             
                    }]
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
                    stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode. 
     | 
| 
      
 38 
     | 
    
         
            +
                    stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.gsub(' ','+') + ".json")
         
     | 
| 
       39 
39 
     | 
    
         
             
                      .to_return(:body => response.merge({'areas' => area_response}).to_json, :status => 200)
         
     | 
| 
       40 
40 
     | 
    
         
             
                    stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/partial/" + postcode.split(' ').first + ".json")
         
     | 
| 
       41 
41 
     | 
    
         
             
                      .to_return(:body => response.to_json, :status => 200)
         
     | 
| 
       42 
42 
     | 
    
         
             
                  end
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
       44 
44 
     | 
    
         
             
                  def mapit_does_not_have_a_postcode(postcode)
         
     | 
| 
       45 
     | 
    
         
            -
                    stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode. 
     | 
| 
      
 45 
     | 
    
         
            +
                    stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.gsub(' ','+') + ".json")
         
     | 
| 
       46 
46 
     | 
    
         
             
                      .to_return(:body => { "code" => 404, "error" => "No Postcode matches the given query." }.to_json, :status => 404)
         
     | 
| 
       47 
47 
     | 
    
         
             
                  end
         
     | 
| 
       48 
48 
     | 
    
         | 
| 
       49 
49 
     | 
    
         
             
                  def mapit_does_not_have_a_bad_postcode(postcode)
         
     | 
| 
       50 
     | 
    
         
            -
                    stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode. 
     | 
| 
      
 50 
     | 
    
         
            +
                    stub_request(:get, "#{MAPIT_ENDPOINT}/postcode/" + postcode.gsub(' ','+') + ".json")
         
     | 
| 
       51 
51 
     | 
    
         
             
                      .to_return(:body => { "code" => 400, "error" => "Postcode '#{postcode}' is not valid." }.to_json, :status => 400)
         
     | 
| 
       52 
52 
     | 
    
         
             
                  end
         
     | 
| 
       53 
53 
     | 
    
         | 
    
        data/lib/gds_api/version.rb
    CHANGED
    
    
    
        data/test/content_api_test.rb
    CHANGED
    
    | 
         @@ -492,21 +492,30 @@ describe GdsApi::ContentApi do 
     | 
|
| 
       492 
492 
     | 
    
         
             
                end
         
     | 
| 
       493 
493 
     | 
    
         
             
              end
         
     | 
| 
       494 
494 
     | 
    
         | 
| 
       495 
     | 
    
         
            -
               
     | 
| 
       496 
     | 
    
         
            -
                 
     | 
| 
       497 
     | 
    
         
            -
                   
     | 
| 
       498 
     | 
    
         
            -
             
     | 
| 
       499 
     | 
    
         
            -
             
     | 
| 
       500 
     | 
    
         
            -
             
     | 
| 
      
 495 
     | 
    
         
            +
              describe "countries" do
         
     | 
| 
      
 496 
     | 
    
         
            +
                before(:each) do
         
     | 
| 
      
 497 
     | 
    
         
            +
                  content_api_has_countries({
         
     | 
| 
      
 498 
     | 
    
         
            +
                    'afghanistan' => {:name => 'Afghanistan', :updated_at => "2013-02-11T16:12:22+00:00" },
         
     | 
| 
      
 499 
     | 
    
         
            +
                    'albania' => {:name => 'Albania'},
         
     | 
| 
      
 500 
     | 
    
         
            +
                    'algeria' => {:name => 'Algeria'}
         
     | 
| 
      
 501 
     | 
    
         
            +
                  })
         
     | 
| 
      
 502 
     | 
    
         
            +
             
     | 
| 
      
 503 
     | 
    
         
            +
                  @results = @api.countries['results']
         
     | 
| 
      
 504 
     | 
    
         
            +
                end
         
     | 
| 
       501 
505 
     | 
    
         | 
| 
       502 
     | 
    
         
            -
                 
     | 
| 
       503 
     | 
    
         
            -
             
     | 
| 
      
 506 
     | 
    
         
            +
                it "should fetch the list of countries" do
         
     | 
| 
      
 507 
     | 
    
         
            +
                  assert_equal 3, @results.length
         
     | 
| 
       504 
508 
     | 
    
         | 
| 
       505 
     | 
    
         
            -
             
     | 
| 
       506 
     | 
    
         
            -
             
     | 
| 
      
 509 
     | 
    
         
            +
                  assert_equal ['afghanistan', 'albania', 'algeria'], @results.map {|c| c['identifier'] }
         
     | 
| 
      
 510 
     | 
    
         
            +
                  assert_equal ['Afghanistan', 'Albania', 'Algeria'], @results.map {|c| c['name'] }
         
     | 
| 
       507 
511 
     | 
    
         | 
| 
       508 
     | 
    
         
            -
             
     | 
| 
       509 
     | 
    
         
            -
             
     | 
| 
      
 512 
     | 
    
         
            +
                  assert_equal "#{@base_api_url}/travel-advice/afghanistan.json", @results.first['id']
         
     | 
| 
      
 513 
     | 
    
         
            +
                  assert_equal 'http://www.test.gov.uk/travel-advice/afghanistan', @results.first['web_url']
         
     | 
| 
      
 514 
     | 
    
         
            +
                end
         
     | 
| 
      
 515 
     | 
    
         
            +
             
     | 
| 
      
 516 
     | 
    
         
            +
                it "should parse all updated_at values to Time objects" do
         
     | 
| 
      
 517 
     | 
    
         
            +
                  assert_equal [Time.parse("2013-02-11T16:12:22+00:00"), nil, nil], @results.map {|c| c['updated_at'] }
         
     | 
| 
      
 518 
     | 
    
         
            +
                end
         
     | 
| 
       510 
519 
     | 
    
         
             
              end
         
     | 
| 
       511 
520 
     | 
    
         | 
| 
       512 
521 
     | 
    
         
             
              def api_response_for_results(results)
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -2,7 +2,7 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            name: gds-api-adapters
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
4 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       5 
     | 
    
         
            -
              version: 4. 
     | 
| 
      
 5 
     | 
    
         
            +
              version: 4.6.0
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors: 
         
     | 
| 
       8 
8 
     | 
    
         
             
            - James Stewart
         
     | 
| 
         @@ -239,7 +239,7 @@ required_ruby_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       239 
239 
     | 
    
         
             
              requirements: 
         
     | 
| 
       240 
240 
     | 
    
         
             
              - - ">="
         
     | 
| 
       241 
241 
     | 
    
         
             
                - !ruby/object:Gem::Version 
         
     | 
| 
       242 
     | 
    
         
            -
                  hash:  
     | 
| 
      
 242 
     | 
    
         
            +
                  hash: 4475864604503724645
         
     | 
| 
       243 
243 
     | 
    
         
             
                  segments: 
         
     | 
| 
       244 
244 
     | 
    
         
             
                  - 0
         
     | 
| 
       245 
245 
     | 
    
         
             
                  version: "0"
         
     | 
| 
         @@ -248,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       248 
248 
     | 
    
         
             
              requirements: 
         
     | 
| 
       249 
249 
     | 
    
         
             
              - - ">="
         
     | 
| 
       250 
250 
     | 
    
         
             
                - !ruby/object:Gem::Version 
         
     | 
| 
       251 
     | 
    
         
            -
                  hash:  
     | 
| 
      
 251 
     | 
    
         
            +
                  hash: 4475864604503724645
         
     | 
| 
       252 
252 
     | 
    
         
             
                  segments: 
         
     | 
| 
       253 
253 
     | 
    
         
             
                  - 0
         
     | 
| 
       254 
254 
     | 
    
         
             
                  version: "0"
         
     |