lib/dato/account/client.rb in dato-0.1.3 vs lib/dato/account/client.rb in dato-0.1.4

- old
+ new

@@ -3,23 +3,24 @@ require 'json' require 'active_support/core_ext/hash/indifferent_access' require 'dato/account/repo/account' require 'dato/account/repo/site' +require 'dato/api_error' module Dato module Account class Client REPOS = { account: Repo::Account, sites: Repo::Site, } - attr_reader :token, :domain, :schema + attr_reader :token, :base_url, :schema - def initialize(token, domain: 'https://account-api.datocms.com') - @domain = domain + def initialize(token, base_url: 'https://account-api.datocms.com') + @base_url = base_url @token = token end REPOS.each do |method_name, repo_klass| define_method method_name do @@ -30,24 +31,19 @@ ) end end def request(*args) - begin - connection.send(*args).body.with_indifferent_access - rescue Faraday::ClientError => e - puts e.response - body = JSON.parse(e.response[:body]) - puts JSON.pretty_generate(body) - raise e - end + connection.send(*args).body.with_indifferent_access + rescue Faraday::ClientError => e + raise ApiError.new(e) end private def connection options = { - url: domain, + url: base_url, headers: { 'Accept' => "application/json", 'Content-Type' => "application/json", 'Authorization' => "Bearer #{@token}" }