class Contentstack::API

Public Class Methods

fetch_content_types(uid="") click to toggle source
# File lib/contentstack/api.rb, line 18
def self.fetch_content_types(uid="")
  if !uid.nil? && !uid.empty?
    path = "/content_types/#{uid}"
  else
    path = "/content_types"
  end
  send_request(path, {})
end
fetch_entries(content_type, query) click to toggle source
# File lib/contentstack/api.rb, line 27
def self.fetch_entries(content_type, query)
  path = "/content_types/#{content_type}/entries"
  send_request(path, query)
end
fetch_entry(content_type, entry_uid, query) click to toggle source
# File lib/contentstack/api.rb, line 32
def self.fetch_entry(content_type, entry_uid, query)
  path = "/content_types/#{content_type}/entries/#{entry_uid}"
  send_request(path, query)
end
get_assets(asset_uid=nil) click to toggle source
# File lib/contentstack/api.rb, line 37
def self.get_assets(asset_uid=nil)
  path = "/assets"
  path += "/#{asset_uid}" if !asset_uid.nil?
  send_request(path)
end
get_sync_items(query) click to toggle source
# File lib/contentstack/api.rb, line 43
def self.get_sync_items(query)
  path = "/stacks/sync"
  send_request(path, query)
end
init_api(api_key, delivery_token, environment,host) click to toggle source
# File lib/contentstack/api.rb, line 9
def self.init_api(api_key, delivery_token, environment,host)
  @host = host
  @api_version = '/v3'
  @environment = environment
  @api_key = api_key
  @access_token = delivery_token
  @headers = {environment: @environment}
end

Private Class Methods

send_request(path, q=nil) click to toggle source
# File lib/contentstack/api.rb, line 49
def self.send_request(path, q=nil)
  q ||= {}

  q.merge!(@headers)

  query = "?" + q.to_query
  # puts "Request URL:- #{@host}#{@api_version}#{path}#{query} \n\n"
  
  ActiveSupport::JSON.decode(URI.open("#{@host}#{@api_version}#{path}#{query}",
  "api_key" =>  @api_key,
  "access_token"=>  @access_token,
  "user_agent"=> "ruby-sdk/#{Contentstack::VERSION}",
  "x-user-agent" => "ruby-sdk/#{Contentstack::VERSION}").read)
end