Sha256: 15b497b85222f53de8ab118d0c7944fa2869ac5f2b279690486fb85c1d6ced15
Contents?: true
Size: 1.15 KB
Versions: 1
Compression:
Stored size: 1.15 KB
Contents
require 'virtus' require 'faraday' require 'faraday_middleware' module Firmapi class Company include Virtus.model attribute :siren, String attribute :nic, String attribute :commercial_name, String attribute :official_name, String attribute :name, String attribute :naf_code, String attribute :legal_form, String attribute :address, String attribute :postal_code, String attribute :city, String attribute :vat_number, String attribute :number_of_establishments, Integer attribute :registration_date, Date attribute :cessation_date, Date attribute :website, String def self.find_by_siren!(siren) conn = Faraday.new(url: 'https://firmapi.com') do |faraday| faraday.response :json, content_type: /\bjson$/ faraday.adapter Faraday.default_adapter end response = conn.get '/api/v1/company', { siren: siren, api_key: Firmapi.configuration.api_key} if response.status == 200 json = response.body self.new(json["result"]) elsif response.status == 404 raise NoCompanyFound, "No company was found with the siren '#{siren}'." end end class NoCompanyFound < StandardError ; end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
firmapi-0.1 | lib/firmapi/company.rb |