class DatoDump::Client
Public Class Methods
new(configuration)
click to toggle source
# File lib/dato_dump/client.rb, line 8 def initialize(configuration) @host = configuration.api_host @domain = configuration.domain @token = configuration.token end
Public Instance Methods
connection()
click to toggle source
# File lib/dato_dump/client.rb, line 34 def connection options = { url: @host, headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Space-Domain' => @domain, 'Authorization' => "Api-Key #{@token}" } } @connection ||= Faraday.new(options) do |c| c.request :json c.response :json, content_type: /\bjson$/ c.response :raise_error c.adapter :net_http end end
get(*args)
click to toggle source
# File lib/dato_dump/client.rb, line 26 def get(*args) connection.get(*args) rescue Faraday::ClientError => e body = JSON.parse(e.response[:body]) puts JSON.pretty_generate(body) raise e end
records()
click to toggle source
# File lib/dato_dump/client.rb, line 22 def records get('records', 'page[limit]' => 10_000).body.with_indifferent_access end
space()
click to toggle source
# File lib/dato_dump/client.rb, line 14 def space include = [ 'content_types', 'content_types.fields' ] get('space', include: include).body.with_indifferent_access end