Class: DatoDump::Client
- Inherits:
-
Object
- Object
- DatoDump::Client
- Defined in:
- lib/dato_dump/client.rb
Instance Method Summary collapse
- #connection ⇒ Object
- #get(*args) ⇒ Object
-
#initialize(configuration) ⇒ Client
constructor
A new instance of Client.
- #records ⇒ Object
- #space ⇒ Object
Constructor Details
#initialize(configuration) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 |
# File 'lib/dato_dump/client.rb', line 8 def initialize(configuration) @host = configuration.api_host @domain = configuration.domain @token = configuration.token end |
Instance Method Details
#connection ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/dato_dump/client.rb', line 34 def connection = { url: @host, headers: { 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'X-Space-Domain' => @domain, 'Authorization' => "Api-Key #{@token}" } } @connection ||= Faraday.new() do |c| c.request :json c.response :json, content_type: /\bjson$/ c.response :raise_error c.adapter :net_http end end |
#get(*args) ⇒ Object
26 27 28 29 30 31 32 |
# 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 ⇒ Object
22 23 24 |
# File 'lib/dato_dump/client.rb', line 22 def records get('records', 'page[limit]' => 10_000).body.with_indifferent_access end |
#space ⇒ Object
14 15 16 17 18 19 20 |
# 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 |