Class: FsApi::Client
- Inherits:
-
Object
- Object
- FsApi::Client
- Defined in:
- lib/fs_api/client.rb
Instance Attribute Summary collapse
-
#_last_response ⇒ Object
readonly
Returns the value of attribute _last_response.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
- #base_url ⇒ Object
- #clients ⇒ Object
- #delete(path, headers = {}) ⇒ Object
- #get(path, headers = {}) ⇒ Object
- #headers ⇒ Object
- #http ⇒ Object
-
#initialize(username, password) ⇒ Client
constructor
A new instance of Client.
- #invoices ⇒ Object
- #invoices_payments ⇒ Object
- #post(path, body = nil, headers = {}) ⇒ Object
- #products ⇒ Object
- #put(path, body = nil, headers = {}) ⇒ Object
- #saved_invoices ⇒ Object
- #uri_for_path(path) ⇒ Object
Constructor Details
#initialize(username, password) ⇒ Client
Returns a new instance of Client.
6 7 8 9 |
# File 'lib/fs_api/client.rb', line 6 def initialize(username, password) @username = username @password = password end |
Instance Attribute Details
#_last_response ⇒ Object (readonly)
Returns the value of attribute _last_response.
3 4 5 |
# File 'lib/fs_api/client.rb', line 3 def _last_response @_last_response end |
#errors ⇒ Object
Returns the value of attribute errors.
4 5 6 |
# File 'lib/fs_api/client.rb', line 4 def errors @errors end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
3 4 5 |
# File 'lib/fs_api/client.rb', line 3 def password @password end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
3 4 5 |
# File 'lib/fs_api/client.rb', line 3 def username @username end |
Instance Method Details
#base_url ⇒ Object
11 12 13 |
# File 'lib/fs_api/client.rb', line 11 def base_url "https://www.factuursturen.nl:443/api/v1" end |
#clients ⇒ Object
66 67 68 |
# File 'lib/fs_api/client.rb', line 66 def clients FsApi::Service::Client.new(self) end |
#delete(path, headers = {}) ⇒ Object
56 57 58 59 60 |
# File 'lib/fs_api/client.rb', line 56 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
36 37 38 39 40 |
# File 'lib/fs_api/client.rb', line 36 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
25 26 27 28 29 30 |
# File 'lib/fs_api/client.rb', line 25 def headers { 'Accept' => 'application/json', 'Content-Type' => 'application/json' } end |
#http ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/fs_api/client.rb', line 15 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.verify_mode = OpenSSL::SSL::VERIFY_NONE http end end |
#invoices ⇒ Object
62 63 64 |
# File 'lib/fs_api/client.rb', line 62 def invoices FsApi::Service::Invoice.new(self) end |
#invoices_payments ⇒ Object
74 75 76 |
# File 'lib/fs_api/client.rb', line 74 def invoices_payments FsApi::Service::InvoicesPayment.new(self) end |
#post(path, body = nil, headers = {}) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/fs_api/client.rb', line 49 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 |
#products ⇒ Object
70 71 72 |
# File 'lib/fs_api/client.rb', line 70 def products FsApi::Service::Product.new(self) end |
#put(path, body = nil, headers = {}) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/fs_api/client.rb', line 42 def put(path, body=nil, headers={}) uri = uri_for_path(path) http = Net::HTTP::Put.new(uri.request_uri, self.headers.merge(headers)) http.body = body perform(http) end |
#saved_invoices ⇒ Object
78 79 80 |
# File 'lib/fs_api/client.rb', line 78 def saved_invoices FsApi::Service::InvoicesSaved.new(self) end |
#uri_for_path(path) ⇒ Object
32 33 34 |
# File 'lib/fs_api/client.rb', line 32 def uri_for_path(path) URI.parse(File.join(base_url, path)) end |