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.
9 10 11 |
# File 'lib/moneybird/client.rb', line 9 def initialize(bearer_token) @bearer_token = bearer_token end |
Instance Attribute Details
#bearer_token ⇒ Object (readonly)
Returns the value of attribute bearer_token.
5 6 7 |
# File 'lib/moneybird/client.rb', line 5 def bearer_token @bearer_token end |
#errors ⇒ Object
Returns the value of attribute errors.
6 7 8 |
# File 'lib/moneybird/client.rb', line 6 def errors @errors end |
#faraday_adapter ⇒ Object
21 22 23 |
# File 'lib/moneybird/client.rb', line 21 def faraday_adapter @faraday_adapter ||= Faraday.default_adapter end |
#http ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# 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 |
Instance Method Details
#administrations ⇒ Object
64 65 66 |
# File 'lib/moneybird/client.rb', line 64 def administrations Moneybird::Service::Administration.new(self).all end |
#base_url ⇒ Object
13 14 15 |
# File 'lib/moneybird/client.rb', line 13 def base_url "https://moneybird.com/" end |
#get_all_pages(path, options = {}) ⇒ Object
48 49 50 51 52 |
# File 'lib/moneybird/client.rb', line 48 def get_all_pages(path, = {}) get_each_page(path, ).inject([]) do |array, objects| array += objects end end |
#get_each_page(path, options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/moneybird/client.rb', line 54 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
17 18 19 |
# File 'lib/moneybird/client.rb', line 17 def version @version ||= 'v2' end |