Class: Moneybird::Client
- Inherits:
-
Object
- Object
- Moneybird::Client
- Defined in:
- lib/moneybird/client.rb
Instance Attribute Summary collapse
-
#bearer_token ⇒ Object
readonly
Returns the value of attribute bearer_token.
-
#errors ⇒ Object
Returns the value of attribute errors.
- #faraday_adapter ⇒ Object
- #http ⇒ Object
Instance Method Summary collapse
- #administrations ⇒ Object
- #base_url ⇒ Object
- #get_all_pages(path, options = {}) ⇒ Object
- #get_each_page(path, options = {}) ⇒ Object
-
#initialize(bearer_token) ⇒ Client
constructor
A new instance of Client.
- #version ⇒ Object
Constructor Details
#initialize(bearer_token) ⇒ Client
Returns a new instance of Client.
11 12 13 |
# File 'lib/moneybird/client.rb', line 11 def initialize(bearer_token) @bearer_token = bearer_token end |
Instance Attribute Details
#bearer_token ⇒ Object (readonly)
Returns the value of attribute bearer_token.
7 8 9 |
# File 'lib/moneybird/client.rb', line 7 def bearer_token @bearer_token end |
#errors ⇒ Object
Returns the value of attribute errors.
8 9 10 |
# File 'lib/moneybird/client.rb', line 8 def errors @errors end |
#faraday_adapter ⇒ Object
23 24 25 |
# File 'lib/moneybird/client.rb', line 23 def faraday_adapter @faraday_adapter ||= Faraday.default_adapter end |
#http ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/moneybird/client.rb', line 27 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 |
Instance Method Details
#administrations ⇒ Object
66 67 68 |
# File 'lib/moneybird/client.rb', line 66 def administrations Moneybird::Service::Administration.new(self).all end |
#base_url ⇒ Object
15 16 17 |
# File 'lib/moneybird/client.rb', line 15 def base_url "https://moneybird.com/" end |
#get_all_pages(path, options = {}) ⇒ Object
50 51 52 53 54 |
# File 'lib/moneybird/client.rb', line 50 def get_all_pages(path, = {}) get_each_page(path, ).inject([]) do |array, objects| array += objects end end |
#get_each_page(path, options = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/moneybird/client.rb', line 56 def get_each_page(path, = {}) return enum_for(:get_each_page, path, ) unless block_given? path = "/api/#{version}/#{path}" while path response = http.get(path, ) yield response.body path = (response[:pagination_links].next if response[:pagination_links]) end end |
#version ⇒ Object
19 20 21 |
# File 'lib/moneybird/client.rb', line 19 def version @version ||= 'v2' end |