Class: Be::Data::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/be-data-api.rb,
lib/be-data-api/version.rb

Defined Under Namespace

Classes: VatBasic, VatStatus

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Constructor Details

#initialize(api_id, api_key) ⇒ Api

Returns a new instance of Api.



9
10
11
# File 'lib/be-data-api.rb', line 9

def initialize(api_id, api_key)
  @conn = Excon.new("https://api.data.be", :query => { "api_id" => api_id, "api_key" => api_key })
end

Instance Method Details

#vat_basic(vat_number) ⇒ Object

Examples:

Be::Data::Api.new(...).vat_status "844044609"
Be::Data::Api.new(...).vat_status "0844.044.609"
Be::Data::Api.new(...).vat_status "BE-0844-044-609"


40
41
42
43
44
45
# File 'lib/be-data-api.rb', line 40

def vat_basic(vat_number)
  response = get("/1.0/vat/#{vat_number}/basic")
  return VatBasic.new(response['vat-clean'], response['vat-formatted'], !!response['active'], !!response['valid'],
                      response['company-name'], response['start-date'], response['language'], response['address-fr'],
                      response['address-nl'])
end

#vat_status(vat_number) ⇒ Object

Examples:

Be::Data::Api.new(...).vat_status "844044609"
Be::Data::Api.new(...).vat_status "0844.044.609"
Be::Data::Api.new(...).vat_status "BE-0844-044-609"


29
30
31
32
# File 'lib/be-data-api.rb', line 29

def vat_status(vat_number)
  response = get("/1.0/vat/#{vat_number}/status")
  return VatStatus.new(response['vat-clean'], response['vat-formatted'], !!response['active'], !!response['valid'])
end

#vat_valid?(vat_number) ⇒ Boolean

Examples:

Be::Data::Api.new(...).vat_valid? "844044609"
Be::Data::Api.new(...).vat_valid? "0844.044.609"
Be::Data::Api.new(...).vat_valid? "BE-0844-044-609"

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/be-data-api.rb', line 18

def vat_valid?(vat_number)
  response = get("/1.0/vat/#{vat_number}/validity")
  p response
  return !!response["valid"]
end