class Moneybird::Client
Attributes
bearer_token[R]
errors[RW]
faraday_adapter[W]
http[W]
Public Class Methods
new(bearer_token)
click to toggle source
# File lib/moneybird/client.rb, line 9 def initialize(bearer_token) @bearer_token = bearer_token end
Public Instance Methods
administrations()
click to toggle source
# File lib/moneybird/client.rb, line 59 def administrations Moneybird::Service::Administration.new(self).all end
base_url()
click to toggle source
# File lib/moneybird/client.rb, line 13 def base_url "https://moneybird.com/" end
faraday_adapter()
click to toggle source
# File lib/moneybird/client.rb, line 21 def faraday_adapter @faraday_adapter ||= Faraday.default_adapter end
get_all_pages(path, options = {})
click to toggle source
# File lib/moneybird/client.rb, line 43 def get_all_pages(path, options = {}) get_each_page(path, options).inject([]) do |array, objects| array += objects end end
get_each_page(path, options = {}) { |body| ... }
click to toggle source
# File lib/moneybird/client.rb, line 49 def get_each_page(path, options = {}) return enum_for(:get_each_page, path, options) unless block_given? path = "/api/#{version}/#{path}" while path response = http.get(path, options) yield response.body path = (response[:pagination_links].next if response[:pagination_links]) end end
http()
click to toggle source
# File lib/moneybird/client.rb, line 25 def http @http ||= Faraday.new(url: base_url) do |faraday| faraday.headers = faraday_headers faraday.request :url_encoded faraday.response :json faraday.use Moneybird::Middleware::ErrorHandling faraday.use Moneybird::Middleware::Pagination faraday.adapter faraday_adapter end end
version()
click to toggle source
# File lib/moneybird/client.rb, line 17 def version @version ||= 'v2' end
Private Instance Methods
faraday_headers()
click to toggle source
# File lib/moneybird/client.rb, line 65 def faraday_headers { 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{bearer_token}" } end