Class: Moneybird::Client
- Inherits:
-
Object
- Object
- Moneybird::Client
- Defined in:
- lib/moneybird/client.rb
Instance Attribute Summary collapse
-
#_last_response ⇒ Object
readonly
Returns the value of attribute _last_response.
-
#bearer_token ⇒ Object
readonly
Returns the value of attribute bearer_token.
-
#errors ⇒ Object
Returns the value of attribute errors.
- #http ⇒ Object
Instance Method Summary collapse
- #administrations ⇒ Object
- #base_url ⇒ Object
- #delete(path, headers = {}) ⇒ Object
- #get(path, headers = {}) ⇒ Object
- #headers ⇒ Object
-
#initialize(bearer_token) ⇒ Client
constructor
A new instance of Client.
- #patch(path, body = nil, headers = {}) ⇒ Object
- #post(path, body = nil, headers = {}) ⇒ Object
- #uri_for_path(path) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(bearer_token) ⇒ Client
Returns a new instance of Client.
7 8 9 |
# File 'lib/moneybird/client.rb', line 7 def initialize(bearer_token) @bearer_token = bearer_token end |
Instance Attribute Details
#_last_response ⇒ Object (readonly)
Returns the value of attribute _last_response.
3 4 5 |
# File 'lib/moneybird/client.rb', line 3 def _last_response @_last_response end |
#bearer_token ⇒ Object (readonly)
Returns the value of attribute bearer_token.
3 4 5 |
# File 'lib/moneybird/client.rb', line 3 def bearer_token @bearer_token end |
#errors ⇒ Object
Returns the value of attribute errors.
4 5 6 |
# File 'lib/moneybird/client.rb', line 4 def errors @errors end |
#http ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/moneybird/client.rb', line 19 def http @http ||= begin uri = uri_for_path(base_url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == 'https' http 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
11 12 13 |
# File 'lib/moneybird/client.rb', line 11 def base_url "https://moneybird.com/api/#{version}/" end |
#delete(path, headers = {}) ⇒ Object
60 61 62 63 64 |
# File 'lib/moneybird/client.rb', line 60 def delete(path, headers={}) uri = uri_for_path(path) http = Net::HTTP::Delete.new(uri.request_uri, self.headers.merge(headers)) perform(http) end |
#get(path, headers = {}) ⇒ Object
40 41 42 43 44 |
# File 'lib/moneybird/client.rb', line 40 def get(path, headers={}) uri = uri_for_path(path) http = Net::HTTP::Get.new(uri.request_uri, self.headers.merge(headers)) perform(http) end |
#headers ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/moneybird/client.rb', line 28 def headers { 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{bearer_token}" } end |
#patch(path, body = nil, headers = {}) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/moneybird/client.rb', line 46 def patch(path, body=nil, headers={}) uri = uri_for_path(path) http = Net::HTTP::Patch.new(uri.request_uri, self.headers.merge(headers)) http.body = body perform(http) end |
#post(path, body = nil, headers = {}) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/moneybird/client.rb', line 53 def post(path, body=nil, headers={}) uri = uri_for_path(path) http = Net::HTTP::Post.new(uri.request_uri, self.headers.merge(headers)) http.body = body perform(http) end |
#uri_for_path(path) ⇒ Object
36 37 38 |
# File 'lib/moneybird/client.rb', line 36 def uri_for_path(path) URI.parse(File.join(base_url, path)) end |
#version ⇒ Object
15 16 17 |
# File 'lib/moneybird/client.rb', line 15 def version @version ||= 'v2' end |