Module: Beanie

Defined in:
lib/beanie/company.rb,
lib/beanie.rb,
lib/beanie/api.rb,
lib/beanie/journal.rb,
lib/beanie/product.rb,
lib/beanie/version.rb,
lib/beanie/billable.rb,
lib/beanie/bom_item.rb,
lib/beanie/customer.rb,
lib/beanie/document.rb,
lib/beanie/supplier.rb,
lib/beanie/stock_item.rb,
lib/beanie/vat_record.rb,
lib/beanie/vat_return.rb,
lib/beanie/config_type.rb,
lib/beanie/fixed_asset.rb,
lib/beanie/sales_order.rb,
lib/beanie/work_centre.rb,
lib/beanie/bank_account.rb,
lib/beanie/beanie_alert.rb,
lib/beanie/config_value.rb,
lib/beanie/journal_item.rb,
lib/beanie/customer_note.rb,
lib/beanie/product_price.rb,
lib/beanie/sales_invoice.rb,
lib/beanie/supplier_note.rb,
lib/beanie/bank_statement.rb,
lib/beanie/company_member.rb,
lib/beanie/purchase_order.rb,
lib/beanie/stock_category.rb,
lib/beanie/stock_location.rb,
lib/beanie/stock_supplier.rb,
lib/beanie/nominal_account.rb,
lib/beanie/bill_of_material.rb,
lib/beanie/customer_address.rb,
lib/beanie/product_category.rb,
lib/beanie/production_order.rb,
lib/beanie/purchase_invoice.rb,
lib/beanie/sales_order_item.rb,
lib/beanie/stock_adjustment.rb,
lib/beanie/supplier_address.rb,
lib/beanie/tax_registration.rb,
lib/beanie/work_centre_group.rb,
lib/beanie/sales_invoice_item.rb,
lib/beanie/bank_statement_data.rb,
lib/beanie/purchase_order_item.rb,
lib/beanie/nominal_account_category.rb

Overview

Copyright © 2017-2018, AltoYield Limited. All rights reserved.

This is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version.

It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this product; see the file COPYING. If not, write to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

THIS SOFTWARE IS PROVIDED BY ALTOYIELD LIMITED “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ALTOYIELD LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Defined Under Namespace

Classes: Api, BankAccount, BankStatement, BankStatementData, BeanieAlert, Billable, BomItem, Company, CompanyMember, ConfigType, ConfigValue, Customer, CustomerAddress, CustomerNote, Document, FixedAsset, Journal, JournalItem, NominalAccount, NominalAccountCategory, Product, ProductCategory, ProductPrice, ProductionOrder, PurchaseInvoice, PurchaseOrder, PurchaseOrderItem, SalesInvoice, SalesInvoiceItem, SalesOrder, SalesOrderItem, StockAdjustment, StockCategory, StockItem, StockLocation, StockSupplier, Supplier, SupplierAddress, SupplierNote, TaxRegistration, VatRecord, VatReturn, WorkCentre, WorkCentreGroup

Constant Summary collapse

VERSION =
"0.1.3"
@@token =
nil

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



86
87
88
# File 'lib/beanie.rb', line 86

def api_key
  @api_key
end

.api_versionObject

Returns the value of attribute api_version.



86
87
88
# File 'lib/beanie.rb', line 86

def api_version
  @api_version
end

.secret_keyObject

Returns the value of attribute secret_key.



86
87
88
# File 'lib/beanie.rb', line 86

def secret_key
  @secret_key
end

Class Method Details

.api_url(url = '', api_base_uri = nil) ⇒ Object



89
90
91
# File 'lib/beanie.rb', line 89

def self.api_url(url='', api_base_uri=nil)
  (api_base_uri || @base_uri) + url
end

.base_uriObject



121
122
123
# File 'lib/beanie.rb', line 121

def self.base_uri
  @base_uri
end

.connect(opts = {}) ⇒ Object



93
94
95
96
97
# File 'lib/beanie.rb', line 93

def self.connect(opts = {})
  @base_uri = opts[:base_uri] ? opts[:base_uri] : 'https://bean.ie'
  @api_key = opts[:api_key] if opts[:api_key]
  @secret_key = opts[:secret_key] if opts[:secret_key]
end

.get_tokenObject



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/beanie.rb', line 99

def self.get_token
  unless @@token
    #
    # We need to get an authentication token from the server
    unless @api_key and @secret_key
      raise AuthenticationError.new('No API Key / Secret Key provided.' \
                                    'Set your API Key using "Beanie.api_key = <API-KEY>". ' \
                                    'Set your Secret Key using "Beanie.secret_key = <SECRET>". ' \
                                    'You can generate API keys from the Beanie web interface. ' \
                                    'See https://bean.ie/help/api/key for details or email ' \
                                    '[email protected] for further assistance.')
    end
    url = "#{@base_uri}/api/authenticate"
    data = {:api_key => @api_key, :secret_key => @secret_key}
    response = RestClient.post(url, data.to_json, :content_type => :json, :accept => :json)
    raise AuthenticationError.new('Authentication failure.') unless response.code == 202
    data = JSON.parse(response.body)
    @@token = data['token']
  end
  @@token
end