firmapi 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83b3f1632b676cb34fa0dd1d5e07d4b059becc66
4
+ data.tar.gz: 96d491c658248919a96171211f41dce4c4310a77
5
+ SHA512:
6
+ metadata.gz: caa57ef54818f727cefca381642e2c0fd60b2628300c79003955ef8393dcd367d56af7aedee41f56fc1830d19ee5e19043cd2fb0d404af055bc9bfc4ea258a01
7
+ data.tar.gz: f70f67e4a93bc604b627be92134b775e1b0296f97f6af893ee4a605b690da7d73091b50b7c0e510e16130708605a71460786280a90b3a4a8d14e8ed7092ae50a
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in firmapi.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Etienne Depaulis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,71 @@
1
+ # Firmapi
2
+
3
+ Firmapi is a ruby client for [Firmapi](https://firmapi.com/) JSON API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'firmapi'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install firmapi
18
+
19
+ ## Usage
20
+
21
+ ### Configuration
22
+
23
+ Firmapi can be configured (ideally inside an initializer) by
24
+ calling Firmapi.configure like so:
25
+
26
+ Firmapi.configure do |config|
27
+ # An api key is mandatory to use the service
28
+ config.api_key = "123456"
29
+ end
30
+
31
+ ### Gathering information about a company
32
+
33
+ #### Using the SIREN number
34
+
35
+ company = Firmapi::Company.find_by_siren!(480470152)
36
+ company.name # => "EVANGELINA"
37
+
38
+ Firmapi::Company.find_by_siren!("INVALID SIREN") # => Firmapi::Company::NoCompanyFound: 'No company was found with the siren 'INVALID SIREN'.'
39
+
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
48
+
49
+ ## License
50
+
51
+ The MIT License (MIT)
52
+
53
+ Copyright (c) 2014 Etienne Depaulis
54
+
55
+ Permission is hereby granted, free of charge, to any person obtaining a copy
56
+ of this software and associated documentation files (the "Software"), to deal
57
+ in the Software without restriction, including without limitation the rights
58
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
59
+ copies of the Software, and to permit persons to whom the Software is
60
+ furnished to do so, subject to the following conditions:
61
+
62
+ The above copyright notice and this permission notice shall be included in
63
+ all copies or substantial portions of the Software.
64
+
65
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
66
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
67
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
68
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
69
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
70
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
71
+ THE SOFTWARE.
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new('spec')
6
+
7
+ # If you want to make this the default task
8
+ task default: :spec
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'firmapi/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "firmapi"
7
+ spec.version = Firmapi::VERSION
8
+ spec.authors = ["Etienne Depaulis"]
9
+ spec.email = ["etienne.depaulis@gmail.com"]
10
+ spec.description = %q{Firmapi is a ruby client for www.firmapi.com}
11
+ spec.summary = %q{Firmapi is a ruby client for www.firmapi.com}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake", '~> 10.1.0'
22
+ spec.add_development_dependency "rspec", '~> 2.99'
23
+ spec.add_development_dependency "vcr", '~> 2.9'
24
+ spec.add_development_dependency "webmock", '~> 1.18'
25
+ spec.add_runtime_dependency "faraday", '~> 0.9'
26
+ spec.add_runtime_dependency "faraday_middleware", '~> 0.9'
27
+ spec.add_runtime_dependency "virtus", '~> 1.0'
28
+ end
@@ -0,0 +1,8 @@
1
+ require "firmapi/version"
2
+
3
+ module Firmapi
4
+
5
+ require 'firmapi/configuration'
6
+ require 'firmapi/company'
7
+
8
+ end
@@ -0,0 +1,43 @@
1
+ require 'virtus'
2
+ require 'faraday'
3
+ require 'faraday_middleware'
4
+
5
+ module Firmapi
6
+ class Company
7
+ include Virtus.model
8
+
9
+ attribute :siren, String
10
+ attribute :nic, String
11
+ attribute :commercial_name, String
12
+ attribute :official_name, String
13
+ attribute :name, String
14
+ attribute :naf_code, String
15
+ attribute :legal_form, String
16
+ attribute :address, String
17
+ attribute :postal_code, String
18
+ attribute :city, String
19
+ attribute :vat_number, String
20
+ attribute :number_of_establishments, Integer
21
+ attribute :registration_date, Date
22
+ attribute :cessation_date, Date
23
+ attribute :website, String
24
+
25
+ def self.find_by_siren!(siren)
26
+ conn = Faraday.new(url: 'https://firmapi.com') do |faraday|
27
+ faraday.response :json, content_type: /\bjson$/
28
+ faraday.adapter Faraday.default_adapter
29
+ end
30
+
31
+ response = conn.get '/api/v1/company', { siren: siren, api_key: Firmapi.configuration.api_key}
32
+
33
+ if response.status == 200
34
+ json = response.body
35
+ self.new(json["result"])
36
+ elsif response.status == 404
37
+ raise NoCompanyFound, "No company was found with the siren '#{siren}'."
38
+ end
39
+ end
40
+
41
+ class NoCompanyFound < StandardError ; end
42
+ end
43
+ end
@@ -0,0 +1,13 @@
1
+ module Firmapi
2
+ class Configuration
3
+ attr_accessor :api_key
4
+ end
5
+
6
+ def self.configuration
7
+ @configuration ||= Configuration.new
8
+ end
9
+
10
+ def self.configure
11
+ yield(configuration) if block_given?
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Firmapi
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,51 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://firmapi.com/api/v1/company?api_key=123456&siren=INVALID%20SIREN
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - '*/*'
16
+ response:
17
+ status:
18
+ code: 404
19
+ message: Not Found
20
+ headers:
21
+ Server:
22
+ - nginx/1.4.1 (Ubuntu)
23
+ Date:
24
+ - Fri, 06 Jun 2014 12:58:53 GMT
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ X-Frame-Options:
32
+ - SAMEORIGIN
33
+ X-Xss-Protection:
34
+ - 1; mode=block
35
+ X-Content-Type-Options:
36
+ - nosniff
37
+ Cache-Control:
38
+ - no-cache
39
+ Set-Cookie:
40
+ - request_method=GET; path=/
41
+ X-Request-Id:
42
+ - 21e616b5-5e88-46ef-8b80-cab5f520eb4a
43
+ X-Runtime:
44
+ - '0.073416'
45
+ body:
46
+ encoding: UTF-8
47
+ string: '{"input":{"siren":"INVALID SIREN"},"result":{"response":"fail","error":"Company
48
+ not found","description":"No company where found by this siren."}}'
49
+ http_version:
50
+ recorded_at: Fri, 06 Jun 2014 12:58:53 GMT
51
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://firmapi.com/api/v1/company?api_key=123456&siren=480470152
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - '*/*'
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx/1.4.1 (Ubuntu)
23
+ Date:
24
+ - Fri, 06 Jun 2014 12:43:33 GMT
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ X-Frame-Options:
32
+ - SAMEORIGIN
33
+ X-Xss-Protection:
34
+ - 1; mode=block
35
+ X-Content-Type-Options:
36
+ - nosniff
37
+ Etag:
38
+ - '"ef8fa7287179f2c5bbd81ec627358a0b"'
39
+ Cache-Control:
40
+ - max-age=0, private, must-revalidate
41
+ Set-Cookie:
42
+ - request_method=GET; path=/
43
+ X-Request-Id:
44
+ - d77bcb08-828e-4f56-8dbb-eb5fc2644a5d
45
+ X-Runtime:
46
+ - '0.042333'
47
+ body:
48
+ encoding: UTF-8
49
+ string: '{"input":{"siren":"480470152"},"result":{"siren":"480470152","name":"Norauto
50
+ France","nic":"00012","commercial_name":null,"official_name":"NORAUTO FRANCE","naf_code":"4532Z","legal_form":"SAS","address":"511
51
+ 589 R Des Seringats","postal_code":"59262","city":"Sainghin En Melantois","vat_number":"FR71480470152","number_of_establishments":230,"registration_date":"2005-01-20","cessation_date":null,"website":"http://centres.norauto.fr/110-norauto-leers?utm_source=google\u0026utm_medium=places\u0026utm_campaign=Norauto_20121219JC","financial_activity":[{"publication_year":2012,"turnover":null,"income":null,"workforce_count":null,"publication_date":"2012-09-29"},{"publication_year":2011,"turnover":null,"income":null,"workforce_count":null,"publication_date":"2011-09-29"},{"publication_year":2010,"turnover":null,"income":null,"workforce_count":null,"publication_date":"2010-09-29"},{"publication_year":2009,"turnover":null,"income":null,"workforce_count":null,"publication_date":"2009-09-29"}]}}'
52
+ http_version:
53
+ recorded_at: Fri, 06 Jun 2014 12:43:33 GMT
54
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Firmapi::Company do
4
+
5
+ before(:all) do
6
+ Firmapi.configure do |config|
7
+ config.api_key = "123456"
8
+ end
9
+ end
10
+
11
+ describe ":find_by_siren!" do
12
+
13
+ context 'with a valid siren' do
14
+
15
+ before(:each) do
16
+ VCR.use_cassette "find_single_company_with_valid_siren" do
17
+ @company = Firmapi::Company.find_by_siren!(480470152)
18
+ end
19
+ end
20
+
21
+ subject(:company) { @company }
22
+
23
+ it { expect(subject.name).to eq("Norauto France") }
24
+ it { expect(subject.siren).to eq("480470152") }
25
+ it { expect(subject.nic).to eq("00012") }
26
+ it { expect(subject.commercial_name).to be_nil }
27
+ it { expect(subject.official_name).to eq("NORAUTO FRANCE") }
28
+ it { expect(subject.naf_code).to eq("4532Z") }
29
+ it { expect(subject.legal_form).to eq("SAS") }
30
+ it { expect(subject.address).to eq("511 589 R Des Seringats") }
31
+ it { expect(subject.postal_code).to eq("59262") }
32
+ it { expect(subject.city).to eq("Sainghin En Melantois") }
33
+ it { expect(subject.vat_number).to eq("FR71480470152") }
34
+ it { expect(subject.number_of_establishments).to eq(230) }
35
+ it { expect(subject.registration_date).to eq(Date.new(2005, 1, 20)) }
36
+ it { expect(subject.cessation_date).to be_nil }
37
+ it { expect(subject.website).to eq("http://centres.norauto.fr/110-norauto-leers?utm_source=google\u0026utm_medium=places\u0026utm_campaign=Norauto_20121219JC") }
38
+
39
+ end
40
+
41
+ context 'with an invalid siren' do
42
+ it "raises an exception" do
43
+ VCR.use_cassette "find_single_company_with_invalid_siren" do
44
+ expect{
45
+ Firmapi::Company.find_by_siren!("INVALID SIREN")
46
+ }.to raise_error Firmapi::Company::NoCompanyFound
47
+ end
48
+ end
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,11 @@
1
+ require 'bundler/setup'
2
+ require 'webmock/rspec'
3
+ require 'VCR'
4
+
5
+ require_relative '../lib/firmapi.rb'
6
+
7
+ VCR.configure do |c|
8
+ c.cassette_library_dir = 'spec/cassettes'
9
+ c.hook_into :webmock
10
+ c.allow_http_connections_when_no_cassette = false
11
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: firmapi
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Etienne Depaulis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 10.1.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 10.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.99'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.99'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.18'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '1.18'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '0.9'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '0.9'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday_middleware
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '0.9'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '0.9'
111
+ - !ruby/object:Gem::Dependency
112
+ name: virtus
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '1.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '1.0'
125
+ description: Firmapi is a ruby client for www.firmapi.com
126
+ email:
127
+ - etienne.depaulis@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - .rspec
134
+ - Gemfile
135
+ - License.txt
136
+ - README.md
137
+ - Rakefile
138
+ - firmapi.gemspec
139
+ - lib/firmapi.rb
140
+ - lib/firmapi/company.rb
141
+ - lib/firmapi/configuration.rb
142
+ - lib/firmapi/version.rb
143
+ - spec/cassettes/find_single_company_with_invalid_siren.yml
144
+ - spec/cassettes/find_single_company_with_valid_siren.yml
145
+ - spec/company_spec.rb
146
+ - spec/spec_helper.rb
147
+ homepage: ''
148
+ licenses:
149
+ - MIT
150
+ metadata: {}
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.0.14
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Firmapi is a ruby client for www.firmapi.com
171
+ test_files:
172
+ - spec/cassettes/find_single_company_with_invalid_siren.yml
173
+ - spec/cassettes/find_single_company_with_valid_siren.yml
174
+ - spec/company_spec.rb
175
+ - spec/spec_helper.rb
176
+ has_rdoc: