gds-api-adapters 2.7.2 → 2.8.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 +10 -2
- data/lib/gds_api/exceptions.rb +2 -0
- data/lib/gds_api/test_helpers/content_api.rb +5 -0
- data/lib/gds_api/version.rb +1 -1
- data/test/content_api_test.rb +22 -0
- metadata +4 -4
    
        data/lib/gds_api/content_api.rb
    CHANGED
    
    | @@ -20,8 +20,16 @@ class GdsApi::ContentApi < GdsApi::Base | |
| 20 20 | 
             
                get_json("#{base_url}/with_tag.json?tag=#{CGI.escape(tag)}&sort=curated")
         | 
| 21 21 | 
             
              end
         | 
| 22 22 |  | 
| 23 | 
            -
              def artefact(slug)
         | 
| 24 | 
            -
                 | 
| 23 | 
            +
              def artefact(slug, edition=nil)
         | 
| 24 | 
            +
                url = "#{base_url}/#{slug}.json"
         | 
| 25 | 
            +
                if edition
         | 
| 26 | 
            +
                  if options.include?(:bearer_token)
         | 
| 27 | 
            +
                    url += "?edition=#{edition}"
         | 
| 28 | 
            +
                  else
         | 
| 29 | 
            +
                    raise GdsApi::NoBearerToken
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
                get_json(url)
         | 
| 25 33 | 
             
              end
         | 
| 26 34 |  | 
| 27 35 | 
             
              def artefact_with_snac_code(slug, snac)
         | 
    
        data/lib/gds_api/exceptions.rb
    CHANGED
    
    
| @@ -34,6 +34,11 @@ module GdsApi | |
| 34 34 | 
             
                    stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
         | 
| 35 35 | 
             
                  end
         | 
| 36 36 |  | 
| 37 | 
            +
                  def content_api_has_unpublished_artefact(slug, edition, body = artefact_for_slug(slug))
         | 
| 38 | 
            +
                    url = "#{CONTENT_API_ENDPOINT}/#{slug}.json?edition=#{edition}"
         | 
| 39 | 
            +
                    stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
             | 
| 37 42 | 
             
                  def content_api_has_an_artefact_with_snac_code(slug, snac, body = artefact_for_slug(slug))
         | 
| 38 43 | 
             
                    url = "#{CONTENT_API_ENDPOINT}/#{slug}.json?snac=#{snac}"
         | 
| 39 44 | 
             
                    stub_request(:get, url).to_return(status: 200, body: body.to_json, headers: {})
         | 
    
        data/lib/gds_api/version.rb
    CHANGED
    
    
    
        data/test/content_api_test.rb
    CHANGED
    
    | @@ -19,6 +19,28 @@ describe GdsApi::ContentApi do | |
| 19 19 | 
             
                end
         | 
| 20 20 | 
             
              end
         | 
| 21 21 |  | 
| 22 | 
            +
              describe "artefact" do
         | 
| 23 | 
            +
                it "should show the artefact" do
         | 
| 24 | 
            +
                  content_api_has_an_artefact("devolution-uk")
         | 
| 25 | 
            +
                  response = @api.artefact("devolution-uk")
         | 
| 26 | 
            +
                  assert_equal "http://contentapi.test.gov.uk/devolution-uk.json", response["id"]
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                it "should be able to fetch unpublished editions when authenticated" do
         | 
| 30 | 
            +
                  api = GdsApi::ContentApi.new('test', { bearer_token: 'MY_BEARER_TOKEN' })
         | 
| 31 | 
            +
                  content_api_has_unpublished_artefact("devolution-uk", 3)
         | 
| 32 | 
            +
                  response = api.artefact("devolution-uk", 3)
         | 
| 33 | 
            +
                  assert_equal "http://contentapi.test.gov.uk/devolution-uk.json", response["id"]
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                it "should raise an exception if no bearer token is used when fetching unpublished editions" do
         | 
| 37 | 
            +
                  content_api_has_unpublished_artefact("devolution-uk", 3)
         | 
| 38 | 
            +
                  assert_raises GdsApi::NoBearerToken do
         | 
| 39 | 
            +
                    @api.artefact("devolution-uk", 3)
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
             | 
| 22 44 | 
             
              describe "tags" do
         | 
| 23 45 | 
             
                it "should produce an artefact with the provided tag" do
         | 
| 24 46 | 
             
                  tag = "crime-and-justice"
         | 
    
        metadata
    CHANGED
    
    | @@ -2,7 +2,7 @@ | |
| 2 2 | 
             
            name: gds-api-adapters
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 4 | 
             
              prerelease: 
         | 
| 5 | 
            -
              version: 2. | 
| 5 | 
            +
              version: 2.8.0
         | 
| 6 6 | 
             
            platform: ruby
         | 
| 7 7 | 
             
            authors: 
         | 
| 8 8 | 
             
            - James Stewart
         | 
| @@ -10,7 +10,7 @@ autorequire: | |
| 10 10 | 
             
            bindir: bin
         | 
| 11 11 | 
             
            cert_chain: []
         | 
| 12 12 |  | 
| 13 | 
            -
            date: 2012-09- | 
| 13 | 
            +
            date: 2012-09-26 00:00:00 Z
         | 
| 14 14 | 
             
            dependencies: 
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 16 16 | 
             
              name: plek
         | 
| @@ -205,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 205 205 | 
             
              requirements: 
         | 
| 206 206 | 
             
              - - ">="
         | 
| 207 207 | 
             
                - !ruby/object:Gem::Version 
         | 
| 208 | 
            -
                  hash: - | 
| 208 | 
            +
                  hash: -243511613045247910
         | 
| 209 209 | 
             
                  segments: 
         | 
| 210 210 | 
             
                  - 0
         | 
| 211 211 | 
             
                  version: "0"
         | 
| @@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 214 214 | 
             
              requirements: 
         | 
| 215 215 | 
             
              - - ">="
         | 
| 216 216 | 
             
                - !ruby/object:Gem::Version 
         | 
| 217 | 
            -
                  hash: - | 
| 217 | 
            +
                  hash: -243511613045247910
         | 
| 218 218 | 
             
                  segments: 
         | 
| 219 219 | 
             
                  - 0
         | 
| 220 220 | 
             
                  version: "0"
         |