contentstack 0.6.3.1 → 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/.github/workflows/check-branch.yml +20 -0
 - data/.github/workflows/codeql-analysis.yml +68 -68
 - data/.github/workflows/jira.yml +28 -28
 - data/.github/workflows/release-gem.yml +30 -30
 - data/.github/workflows/sast-scan.yml +10 -10
 - data/.github/workflows/sca-scan.yml +15 -15
 - data/.github/workflows/secrets-scan.yml +10 -10
 - data/.gitignore +11 -11
 - data/.yardopts +6 -6
 - data/CHANGELOG.md +129 -114
 - data/CODEOWNERS +1 -1
 - data/CODE_OF_CONDUCT.md +73 -73
 - data/Gemfile +2 -2
 - data/Gemfile.lock +79 -76
 - data/LICENSE.txt +21 -21
 - data/README.md +197 -197
 - data/SECURITY.md +27 -27
 - data/contentstack.gemspec +29 -29
 - data/lib/contentstack/api.rb +191 -191
 - data/lib/contentstack/asset.rb +68 -68
 - data/lib/contentstack/asset_collection.rb +27 -27
 - data/lib/contentstack/client.rb +122 -91
 - data/lib/contentstack/content_type.rb +53 -53
 - data/lib/contentstack/entry.rb +235 -221
 - data/lib/contentstack/entry_collection.rb +44 -44
 - data/lib/contentstack/error.rb +6 -6
 - data/lib/contentstack/query.rb +665 -653
 - data/lib/contentstack/region.rb +13 -5
 - data/lib/contentstack/sync_result.rb +29 -29
 - data/lib/contentstack/version.rb +2 -2
 - data/lib/contentstack.rb +31 -31
 - data/lib/util.rb +110 -110
 - data/rakefile.rb +3 -3
 - data/spec/asset_collection_spec.rb +15 -15
 - data/spec/asset_spec.rb +47 -47
 - data/spec/content_type_spec.rb +80 -80
 - data/spec/contentstack_spec.rb +63 -38
 - data/spec/entry_collection_spec.rb +41 -41
 - data/spec/entry_spec.rb +116 -101
 - data/spec/fixtures/asset.json +1 -1
 - data/spec/fixtures/asset_collection.json +1 -1
 - data/spec/fixtures/category_content_type.json +1 -1
 - data/spec/fixtures/category_entry.json +1 -1
 - data/spec/fixtures/category_entry_collection.json +1 -1
 - data/spec/fixtures/category_entry_collection_without_count.json +1 -1
 - data/spec/fixtures/content_types.json +1 -1
 - data/spec/fixtures/product_entry.json +1 -1
 - data/spec/fixtures/product_entry_collection.json +1 -1
 - data/spec/fixtures/sync_init.json +2974 -2974
 - data/spec/query_spec.rb +210 -205
 - data/spec/spec_helper.rb +180 -180
 - data/spec/sync_spec.rb +26 -26
 - metadata +4 -3
 
    
        data/lib/contentstack/client.rb
    CHANGED
    
    | 
         @@ -1,92 +1,123 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'contentstack/api'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'contentstack/content_type'
         
     | 
| 
       3 
     | 
    
         
            -
            require 'contentstack/asset_collection'
         
     | 
| 
       4 
     | 
    
         
            -
            require 'contentstack/sync_result'
         
     | 
| 
       5 
     | 
    
         
            -
            require 'util'
         
     | 
| 
       6 
     | 
    
         
            -
            require 'contentstack/error'
         
     | 
| 
       7 
     | 
    
         
            -
            module Contentstack
         
     | 
| 
       8 
     | 
    
         
            -
              class Client
         
     | 
| 
       9 
     | 
    
         
            -
                using Utility
         
     | 
| 
       10 
     | 
    
         
            -
                attr_reader :region, :host
         
     | 
| 
       11 
     | 
    
         
            -
                # Initialize "Contentstack" Client instance
         
     | 
| 
       12 
     | 
    
         
            -
                def initialize(api_key, delivery_token, environment, options={})
         
     | 
| 
       13 
     | 
    
         
            -
                  raise Contentstack::Error.new("Api Key is not valid") if api_key.class != String
         
     | 
| 
       14 
     | 
    
         
            -
                  raise Contentstack::Error.new("Api Key Field Should not be Empty") if api_key.empty?
         
     | 
| 
       15 
     | 
    
         
            -
                  raise Contentstack::Error.new("Delivery Token is not valid") if delivery_token.class != String
         
     | 
| 
       16 
     | 
    
         
            -
                  raise Contentstack::Error.new("Delivery Token Field Should not be Empty") if delivery_token.empty?
         
     | 
| 
       17 
     | 
    
         
            -
                  raise Contentstack::Error.new("Envirnoment Field is not valid") if environment.class != String
         
     | 
| 
       18 
     | 
    
         
            -
                  raise Contentstack::Error.new("Envirnoment Field Should not be Empty") if environment.empty?
         
     | 
| 
       19 
     | 
    
         
            -
                  @region = options[:region].nil? ? Contentstack::Region::US : options[:region]
         
     | 
| 
       20 
     | 
    
         
            -
                  @host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host]
         
     | 
| 
       21 
     | 
    
         
            -
                  @ 
     | 
| 
       22 
     | 
    
         
            -
                  @ 
     | 
| 
       23 
     | 
    
         
            -
                  @ 
     | 
| 
       24 
     | 
    
         
            -
                  @ 
     | 
| 
       25 
     | 
    
         
            -
                  @ 
     | 
| 
       26 
     | 
    
         
            -
                  @ 
     | 
| 
       27 
     | 
    
         
            -
                  @ 
     | 
| 
       28 
     | 
    
         
            -
                   
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
                    " 
     | 
| 
       31 
     | 
    
         
            -
                    " 
     | 
| 
       32 
     | 
    
         
            -
                    " 
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                   
     | 
| 
       35 
     | 
    
         
            -
                  raise Contentstack::Error.new("Proxy  
     | 
| 
       36 
     | 
    
         
            -
                   
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                
         
     | 
| 
       39 
     | 
    
         
            -
                 
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
                
         
     | 
| 
       59 
     | 
    
         
            -
                 
     | 
| 
       60 
     | 
    
         
            -
                # 
         
     | 
| 
       61 
     | 
    
         
            -
                # 
     | 
| 
       62 
     | 
    
         
            -
                # 
         
     | 
| 
       63 
     | 
    
         
            -
                # 
     | 
| 
       64 
     | 
    
         
            -
                # 
         
     | 
| 
       65 
     | 
    
         
            -
                # 
     | 
| 
       66 
     | 
    
         
            -
                # 
         
     | 
| 
       67 
     | 
    
         
            -
                # 
     | 
| 
       68 
     | 
    
         
            -
                # 
         
     | 
| 
       69 
     | 
    
         
            -
                # 
     | 
| 
       70 
     | 
    
         
            -
                # 
         
     | 
| 
       71 
     | 
    
         
            -
                # 
     | 
| 
       72 
     | 
    
         
            -
                # 
         
     | 
| 
       73 
     | 
    
         
            -
                # 
     | 
| 
       74 
     | 
    
         
            -
                #
         
     | 
| 
       75 
     | 
    
         
            -
                # 
     | 
| 
       76 
     | 
    
         
            -
                 
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
                   
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
                 
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
                   
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
                  when " 
     | 
| 
       87 
     | 
    
         
            -
                    host = " 
     | 
| 
       88 
     | 
    
         
            -
                   
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            require 'contentstack/api'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'contentstack/content_type'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'contentstack/asset_collection'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'contentstack/sync_result'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'util'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require 'contentstack/error'
         
     | 
| 
      
 7 
     | 
    
         
            +
            module Contentstack
         
     | 
| 
      
 8 
     | 
    
         
            +
              class Client
         
     | 
| 
      
 9 
     | 
    
         
            +
                using Utility
         
     | 
| 
      
 10 
     | 
    
         
            +
                attr_reader :region, :host
         
     | 
| 
      
 11 
     | 
    
         
            +
                # Initialize "Contentstack" Client instance
         
     | 
| 
      
 12 
     | 
    
         
            +
                def initialize(api_key, delivery_token, environment, options={})
         
     | 
| 
      
 13 
     | 
    
         
            +
                  raise Contentstack::Error.new("Api Key is not valid") if api_key.class != String
         
     | 
| 
      
 14 
     | 
    
         
            +
                  raise Contentstack::Error.new("Api Key Field Should not be Empty") if api_key.empty?
         
     | 
| 
      
 15 
     | 
    
         
            +
                  raise Contentstack::Error.new("Delivery Token is not valid") if delivery_token.class != String
         
     | 
| 
      
 16 
     | 
    
         
            +
                  raise Contentstack::Error.new("Delivery Token Field Should not be Empty") if delivery_token.empty?
         
     | 
| 
      
 17 
     | 
    
         
            +
                  raise Contentstack::Error.new("Envirnoment Field is not valid") if environment.class != String
         
     | 
| 
      
 18 
     | 
    
         
            +
                  raise Contentstack::Error.new("Envirnoment Field Should not be Empty") if environment.empty?
         
     | 
| 
      
 19 
     | 
    
         
            +
                  @region = options[:region].nil? ? Contentstack::Region::US : options[:region]
         
     | 
| 
      
 20 
     | 
    
         
            +
                  # @host = options[:host].nil? ? get_default_region_hosts(@region) : options[:host] #removed for not supporting custom host with regions
         
     | 
| 
      
 21 
     | 
    
         
            +
                  @host = get_host_by_region(@region, options) # Added new method for custom host support with different regions
         
     | 
| 
      
 22 
     | 
    
         
            +
                  @live_preview = !options.key?(:live_preview) ? {} : options[:live_preview]
         
     | 
| 
      
 23 
     | 
    
         
            +
                  @branch = options[:branch].nil? ? "" : options[:branch]
         
     | 
| 
      
 24 
     | 
    
         
            +
                  @proxy_details = options[:proxy].nil? ? "" : options[:proxy]
         
     | 
| 
      
 25 
     | 
    
         
            +
                  @timeout = options[:timeout].nil? ? 3000 : options[:timeout]
         
     | 
| 
      
 26 
     | 
    
         
            +
                  @retryDelay = options[:retryDelay].nil? ? 3000 : options[:retryDelay]
         
     | 
| 
      
 27 
     | 
    
         
            +
                  @retryLimit = options[:retryLimit].nil? ? 5 : options[:retryLimit]
         
     | 
| 
      
 28 
     | 
    
         
            +
                  @errorRetry = options[:errorRetry].nil? ? [408, 429] : options[:errorRetry]
         
     | 
| 
      
 29 
     | 
    
         
            +
                  retry_options = {
         
     | 
| 
      
 30 
     | 
    
         
            +
                    "timeout" =>  @timeout.to_s,
         
     | 
| 
      
 31 
     | 
    
         
            +
                    "retryDelay"=>  @retryDelay,
         
     | 
| 
      
 32 
     | 
    
         
            +
                    "retryLimit"=> @retryLimit,
         
     | 
| 
      
 33 
     | 
    
         
            +
                    "errorRetry" => @errorRetry
         
     | 
| 
      
 34 
     | 
    
         
            +
                  }
         
     | 
| 
      
 35 
     | 
    
         
            +
                  raise Contentstack::Error.new("Proxy URL Should not be Empty") if @proxy_details.present? && @proxy_details[:url].empty?
         
     | 
| 
      
 36 
     | 
    
         
            +
                  raise Contentstack::Error.new("Proxy Port Should not be Empty") if @proxy_details.present? && @proxy_details[:port].empty?
         
     | 
| 
      
 37 
     | 
    
         
            +
                  API.init_api(api_key, delivery_token, environment,  @host, @branch, @live_preview, @proxy_details, retry_options)
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
                
         
     | 
| 
      
 40 
     | 
    
         
            +
                def content_types
         
     | 
| 
      
 41 
     | 
    
         
            +
                  ContentType.all
         
     | 
| 
      
 42 
     | 
    
         
            +
                end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                def content_type(uid)
         
     | 
| 
      
 45 
     | 
    
         
            +
                  ContentType.new({uid: uid})
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                def assets
         
     | 
| 
      
 49 
     | 
    
         
            +
                  AssetCollection.new
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                def asset(uid)
         
     | 
| 
      
 53 
     | 
    
         
            +
                  Asset.new(uid)
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                def live_preview_query(query={})
         
     | 
| 
      
 57 
     | 
    
         
            +
                  API.live_preview_query(query)
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
                
         
     | 
| 
      
 60 
     | 
    
         
            +
                # Syncs your Contentstack data with your app and ensures that the data is always up-to-date by providing delta updates
         
     | 
| 
      
 61 
     | 
    
         
            +
                # 
         
     | 
| 
      
 62 
     | 
    
         
            +
                #   Stack.sync({'init': true})        // For initializing sync
         
     | 
| 
      
 63 
     | 
    
         
            +
                # 
         
     | 
| 
      
 64 
     | 
    
         
            +
                #   Stack.sync({'init': true, 'locale': 'en-us'})     //For initializing sync with entries of a specific locale
         
     | 
| 
      
 65 
     | 
    
         
            +
                # 
         
     | 
| 
      
 66 
     | 
    
         
            +
                #   Stack.sync({'init': true, 'start_date': '2018-10-22'})    //For initializing sync with entries published after a specific date
         
     | 
| 
      
 67 
     | 
    
         
            +
                # 
         
     | 
| 
      
 68 
     | 
    
         
            +
                #   Stack.sync({'init': true, 'content_type_uid': 'session'})   //For initializing sync with entries of a specific content type
         
     | 
| 
      
 69 
     | 
    
         
            +
                # 
         
     | 
| 
      
 70 
     | 
    
         
            +
                #   Stack.sync({'init': true, 'type': 'entry_published'})   // Use the type parameter to get a specific type of content.Supports 'asset_published', 'entry_published', 'asset_unpublished', 'entry_unpublished', 'asset_deleted', 'entry_deleted', 'content_type_deleted'.
         
     | 
| 
      
 71 
     | 
    
         
            +
                # 
         
     | 
| 
      
 72 
     | 
    
         
            +
                #   Stack.sync({'pagination_token': '<pagination>'})    // For fetching the next batch of entries using pagination token
         
     | 
| 
      
 73 
     | 
    
         
            +
                # 
         
     | 
| 
      
 74 
     | 
    
         
            +
                #   Stack.sync({'sync_token': '<sync>'})    // For performing subsequent sync after initial sync
         
     | 
| 
      
 75 
     | 
    
         
            +
                #
         
     | 
| 
      
 76 
     | 
    
         
            +
                # @param params [Hash] params is an object that supports ‘locale’, ‘start_date’, ‘content_type_uid’, and ‘type’ queries.
         
     | 
| 
      
 77 
     | 
    
         
            +
                def sync(params)
         
     | 
| 
      
 78 
     | 
    
         
            +
                  sync_result = API.get_sync_items(params)
         
     | 
| 
      
 79 
     | 
    
         
            +
                  SyncResult.new(sync_result)
         
     | 
| 
      
 80 
     | 
    
         
            +
                end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
                private
         
     | 
| 
      
 83 
     | 
    
         
            +
                def get_default_region_hosts(region='us')
         
     | 
| 
      
 84 
     | 
    
         
            +
                  host = "#{Contentstack::Host::PROTOCOL}#{Contentstack::Host::DEFAULT_HOST}" #set default host if region is nil
         
     | 
| 
      
 85 
     | 
    
         
            +
                  case region
         
     | 
| 
      
 86 
     | 
    
         
            +
                  when "us"
         
     | 
| 
      
 87 
     | 
    
         
            +
                    host = "#{Contentstack::Host::PROTOCOL}#{Contentstack::Host::DEFAULT_HOST}"
         
     | 
| 
      
 88 
     | 
    
         
            +
                  when "eu"
         
     | 
| 
      
 89 
     | 
    
         
            +
                    host = "#{Contentstack::Host::PROTOCOL}eu-cdn.#{Contentstack::Host::HOST}"
         
     | 
| 
      
 90 
     | 
    
         
            +
                  when "azure-na"
         
     | 
| 
      
 91 
     | 
    
         
            +
                    host = "#{Contentstack::Host::PROTOCOL}azure-na-cdn.#{Contentstack::Host::HOST}"
         
     | 
| 
      
 92 
     | 
    
         
            +
                  when "azure-eu"
         
     | 
| 
      
 93 
     | 
    
         
            +
                    host = "#{Contentstack::Host::PROTOCOL}azure-eu-cdn.#{Contentstack::Host::HOST}"
         
     | 
| 
      
 94 
     | 
    
         
            +
                  end
         
     | 
| 
      
 95 
     | 
    
         
            +
                  host
         
     | 
| 
      
 96 
     | 
    
         
            +
                end
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
                def get_host_by_region(region, options)
         
     | 
| 
      
 99 
     | 
    
         
            +
                  if options[:host].nil? && region.present?
         
     | 
| 
      
 100 
     | 
    
         
            +
                    host = get_default_region_hosts(region)
         
     | 
| 
      
 101 
     | 
    
         
            +
                  elsif options[:host].present? && region.present?
         
     | 
| 
      
 102 
     | 
    
         
            +
                    custom_host = options[:host]
         
     | 
| 
      
 103 
     | 
    
         
            +
                    case region
         
     | 
| 
      
 104 
     | 
    
         
            +
                    when "us"
         
     | 
| 
      
 105 
     | 
    
         
            +
                    host = "#{Contentstack::Host::PROTOCOL}cdn.#{custom_host}"
         
     | 
| 
      
 106 
     | 
    
         
            +
                    when "eu"
         
     | 
| 
      
 107 
     | 
    
         
            +
                      host = "#{Contentstack::Host::PROTOCOL}eu-cdn.#{custom_host}"
         
     | 
| 
      
 108 
     | 
    
         
            +
                    when "azure-na"
         
     | 
| 
      
 109 
     | 
    
         
            +
                      host = "#{Contentstack::Host::PROTOCOL}azure-na-cdn.#{custom_host}"
         
     | 
| 
      
 110 
     | 
    
         
            +
                    when "azure-eu"
         
     | 
| 
      
 111 
     | 
    
         
            +
                      host = "#{Contentstack::Host::PROTOCOL}azure-eu-cdn.#{custom_host}"
         
     | 
| 
      
 112 
     | 
    
         
            +
                    end
         
     | 
| 
      
 113 
     | 
    
         
            +
                  elsif options[:host].present? && region.empty?
         
     | 
| 
      
 114 
     | 
    
         
            +
                    custom_host = options[:host]
         
     | 
| 
      
 115 
     | 
    
         
            +
                    host = "#{Contentstack::Host::PROTOCOL}cdn.#{custom_host}"
         
     | 
| 
      
 116 
     | 
    
         
            +
                  else
         
     | 
| 
      
 117 
     | 
    
         
            +
                    host = "#{Contentstack::Host::PROTOCOL}#{Contentstack::Host::DEFAULT_HOST}" #set default host if region and host is empty  
         
     | 
| 
      
 118 
     | 
    
         
            +
                  end
         
     | 
| 
      
 119 
     | 
    
         
            +
                  host
         
     | 
| 
      
 120 
     | 
    
         
            +
                end
         
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
              end
         
     | 
| 
       92 
123 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,54 +1,54 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'contentstack/query'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'util'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            module Contentstack
         
     | 
| 
       5 
     | 
    
         
            -
              class ContentType
         
     | 
| 
       6 
     | 
    
         
            -
                using Utility
         
     | 
| 
       7 
     | 
    
         
            -
                [:title, :uid, :created_at, :updated_at, :attributes].each do |method_name|
         
     | 
| 
       8 
     | 
    
         
            -
                  if [:created_at, :updated_at].include?(method_name)
         
     | 
| 
       9 
     | 
    
         
            -
                    define_method method_name do
         
     | 
| 
       10 
     | 
    
         
            -
                      return Time.parse(@attributes[method_name]) if @attributes[method_name] && !@attributes[method_name].nil?
         
     | 
| 
       11 
     | 
    
         
            -
                    end
         
     | 
| 
       12 
     | 
    
         
            -
                  elsif :attributes == method_name
         
     | 
| 
       13 
     | 
    
         
            -
                    define_method :attributes do
         
     | 
| 
       14 
     | 
    
         
            -
                      {
         
     | 
| 
       15 
     | 
    
         
            -
                        title: self.title,
         
     | 
| 
       16 
     | 
    
         
            -
                        uid: self.uid,
         
     | 
| 
       17 
     | 
    
         
            -
                        created_at: self.created_at,
         
     | 
| 
       18 
     | 
    
         
            -
                        updated_at: self.updated_at,
         
     | 
| 
       19 
     | 
    
         
            -
                        schema: @attributes[:schema]
         
     | 
| 
       20 
     | 
    
         
            -
                      }
         
     | 
| 
       21 
     | 
    
         
            -
                    end 
         
     | 
| 
       22 
     | 
    
         
            -
                  else
         
     | 
| 
       23 
     | 
    
         
            -
                    define_method method_name do
         
     | 
| 
       24 
     | 
    
         
            -
                      return @attributes[method_name]
         
     | 
| 
       25 
     | 
    
         
            -
                    end
         
     | 
| 
       26 
     | 
    
         
            -
                  end
         
     | 
| 
       27 
     | 
    
         
            -
                end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                def initialize(object)
         
     | 
| 
       30 
     | 
    
         
            -
                  @attributes = object.symbolize_keys
         
     | 
| 
       31 
     | 
    
         
            -
                end
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
                def query
         
     | 
| 
       34 
     | 
    
         
            -
                  Query.new(self.uid)
         
     | 
| 
       35 
     | 
    
         
            -
                end
         
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
                def entry(entry_uid)
         
     | 
| 
       38 
     | 
    
         
            -
                  Entry.new({uid: entry_uid}, self.uid)
         
     | 
| 
       39 
     | 
    
         
            -
                end
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
                def self.all
         
     | 
| 
       43 
     | 
    
         
            -
                  content_types = API.fetch_content_types["content_types"]
         
     | 
| 
       44 
     | 
    
         
            -
                  content_types.map do |content_type|
         
     | 
| 
       45 
     | 
    
         
            -
                    ContentType.new(content_type.inject({}){|clone,(k,v)| clone[k.to_sym] = v; clone})
         
     | 
| 
       46 
     | 
    
         
            -
                  end
         
     | 
| 
       47 
     | 
    
         
            -
                end
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
                def fetch
         
     | 
| 
       50 
     | 
    
         
            -
                  content_type = API.fetch_content_types(uid)["content_type"]
         
     | 
| 
       51 
     | 
    
         
            -
                  ContentType.new(content_type.inject({}){|clone,(k,v)| clone[k.to_sym] = v; clone})
         
     | 
| 
       52 
     | 
    
         
            -
                end
         
     | 
| 
       53 
     | 
    
         
            -
              end
         
     | 
| 
      
 1 
     | 
    
         
            +
            require 'contentstack/query'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'util'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            module Contentstack
         
     | 
| 
      
 5 
     | 
    
         
            +
              class ContentType
         
     | 
| 
      
 6 
     | 
    
         
            +
                using Utility
         
     | 
| 
      
 7 
     | 
    
         
            +
                [:title, :uid, :created_at, :updated_at, :attributes].each do |method_name|
         
     | 
| 
      
 8 
     | 
    
         
            +
                  if [:created_at, :updated_at].include?(method_name)
         
     | 
| 
      
 9 
     | 
    
         
            +
                    define_method method_name do
         
     | 
| 
      
 10 
     | 
    
         
            +
                      return Time.parse(@attributes[method_name]) if @attributes[method_name] && !@attributes[method_name].nil?
         
     | 
| 
      
 11 
     | 
    
         
            +
                    end
         
     | 
| 
      
 12 
     | 
    
         
            +
                  elsif :attributes == method_name
         
     | 
| 
      
 13 
     | 
    
         
            +
                    define_method :attributes do
         
     | 
| 
      
 14 
     | 
    
         
            +
                      {
         
     | 
| 
      
 15 
     | 
    
         
            +
                        title: self.title,
         
     | 
| 
      
 16 
     | 
    
         
            +
                        uid: self.uid,
         
     | 
| 
      
 17 
     | 
    
         
            +
                        created_at: self.created_at,
         
     | 
| 
      
 18 
     | 
    
         
            +
                        updated_at: self.updated_at,
         
     | 
| 
      
 19 
     | 
    
         
            +
                        schema: @attributes[:schema]
         
     | 
| 
      
 20 
     | 
    
         
            +
                      }
         
     | 
| 
      
 21 
     | 
    
         
            +
                    end 
         
     | 
| 
      
 22 
     | 
    
         
            +
                  else
         
     | 
| 
      
 23 
     | 
    
         
            +
                    define_method method_name do
         
     | 
| 
      
 24 
     | 
    
         
            +
                      return @attributes[method_name]
         
     | 
| 
      
 25 
     | 
    
         
            +
                    end
         
     | 
| 
      
 26 
     | 
    
         
            +
                  end
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                def initialize(object)
         
     | 
| 
      
 30 
     | 
    
         
            +
                  @attributes = object.symbolize_keys
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                def query
         
     | 
| 
      
 34 
     | 
    
         
            +
                  Query.new(self.uid)
         
     | 
| 
      
 35 
     | 
    
         
            +
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
                def entry(entry_uid)
         
     | 
| 
      
 38 
     | 
    
         
            +
                  Entry.new({uid: entry_uid}, self.uid)
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                def self.all
         
     | 
| 
      
 43 
     | 
    
         
            +
                  content_types = API.fetch_content_types["content_types"]
         
     | 
| 
      
 44 
     | 
    
         
            +
                  content_types.map do |content_type|
         
     | 
| 
      
 45 
     | 
    
         
            +
                    ContentType.new(content_type.inject({}){|clone,(k,v)| clone[k.to_sym] = v; clone})
         
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                def fetch
         
     | 
| 
      
 50 
     | 
    
         
            +
                  content_type = API.fetch_content_types(uid)["content_type"]
         
     | 
| 
      
 51 
     | 
    
         
            +
                  ContentType.new(content_type.inject({}){|clone,(k,v)| clone[k.to_sym] = v; clone})
         
     | 
| 
      
 52 
     | 
    
         
            +
                end
         
     | 
| 
      
 53 
     | 
    
         
            +
              end
         
     | 
| 
       54 
54 
     | 
    
         
             
            end
         
     |