ytj_client 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/README.md +18 -0
- data/lib/ytj_client/version.rb +1 -1
- data/lib/ytj_client.rb +29 -1
- data/ytj_client.gemspec +2 -1
- metadata +24 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 455bb7b28b6be0a244f82d8be90a5a6d1dffa0d7
|
4
|
+
data.tar.gz: f268be3fd7806007f44600fb2d9e3fbb9fb4ab15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26734252f07e86bc96bc022b5b70f0b39d5186e245a6cd5d79e1a9fbaccd5355635c71e082f24fef18526174592f0c4506de40cd37d7e90412861605401a7569
|
7
|
+
data.tar.gz: bcacb0411072814d10fbea61cb6c8c6894a9ea2c84bccddb900a8f71822c06ee786ed27da71a1370ce675abb9b4495eca95b5b42467520e3fae44cd370a02393
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# ytj_client
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/ytj_client.svg)](https://badge.fury.io/rb/ytj_client)
|
4
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/jannewaren/ytj_client.svg)](https://gemnasium.com/github.com/jannewaren/ytj_client)
|
5
|
+
[![Build Status](https://travis-ci.org/jannewaren/ytj_client.svg?branch=master)](https://travis-ci.org/jannewaren/ytj_client)
|
6
|
+
|
7
|
+
[![Test Coverage](https://codeclimate.com/github/jannewaren/ytj_client/badges/coverage.svg)](https://codeclimate.com/github/jannewaren/ytj_client/coverage)
|
8
|
+
[![Code Climate](https://codeclimate.com/github/jannewaren/ytj_client/badges/gpa.svg)](https://codeclimate.com/github/jannewaren/ytj_client)
|
9
|
+
[![Issue Count](https://codeclimate.com/github/jannewaren/ytj_client/badges/issue_count.svg)](https://codeclimate.com/github/jannewaren/ytj_client)
|
10
|
+
|
11
|
+
|
3
12
|
A really small gem to fetch and parse data from the Finnish Patent and Registration Office's (PRH) YTJ-tiedot (business information system) API at http://avoindata.prh.fi/ytj.html
|
4
13
|
|
5
14
|
Makes the API call for you and parses the relevant (in my opinion) information to a convenient format (Ruby hash).
|
@@ -43,4 +52,13 @@ YtjClient.fetch_company('2331972-7')
|
|
43
52
|
# }
|
44
53
|
# }
|
45
54
|
```
|
55
|
+
## Version history
|
56
|
+
|
57
|
+
### 0.2.2
|
58
|
+
|
59
|
+
- fetch all Finnish companies from TR api
|
60
|
+
|
61
|
+
### 0.2.1
|
46
62
|
|
63
|
+
- first working Version
|
64
|
+
- fetching company details with business_id
|
data/lib/ytj_client/version.rb
CHANGED
data/lib/ytj_client.rb
CHANGED
@@ -1,9 +1,18 @@
|
|
1
|
-
require
|
1
|
+
require 'ytj_client/version'
|
2
2
|
require 'logger'
|
3
|
+
require 'restclient'
|
4
|
+
|
5
|
+
require 'active_support'
|
6
|
+
require 'active_support/core_ext/object/blank'
|
7
|
+
require 'active_support/core_ext/hash/slice'
|
8
|
+
require 'active_support/core_ext/hash/keys'
|
9
|
+
require 'active_support/core_ext/string/inflections'
|
3
10
|
|
4
11
|
module YtjClient
|
5
12
|
|
6
13
|
YTJ_API_URL = 'http://avoindata.prh.fi:80/bis/v1/'.freeze
|
14
|
+
TR_API_URL = 'http://avoindata.prh.fi:80/tr/v1?totalResults=false&maxResults=1000&resultsFrom=0&companyRegistrationFrom=
|
15
|
+
'.freeze
|
7
16
|
|
8
17
|
class << self
|
9
18
|
|
@@ -27,8 +36,27 @@ module YtjClient
|
|
27
36
|
logger.error "Error fetching data from YTJ: #{$!.message} - #{$!.backtrace}"
|
28
37
|
end
|
29
38
|
|
39
|
+
def fetch_all_companies(to_date = '1896-01-01')
|
40
|
+
all_companies = []
|
41
|
+
url = TR_API_URL+to_date
|
42
|
+
|
43
|
+
while true
|
44
|
+
companies, url = fetch_1000_companies(url)
|
45
|
+
companies.each do |result|
|
46
|
+
all_companies << result.slice("businessId", "name", "companyForm", "registrationDate").symbolize_keys
|
47
|
+
end
|
48
|
+
break if url.blank?
|
49
|
+
end
|
50
|
+
return all_companies
|
51
|
+
end
|
52
|
+
|
30
53
|
private
|
31
54
|
|
55
|
+
def fetch_1000_companies(url)
|
56
|
+
response = JSON.parse(RestClient.get(url).body)
|
57
|
+
return response["results"], response["nextResultsUri"]
|
58
|
+
end
|
59
|
+
|
32
60
|
# Returns a hash with all company data from YTJ
|
33
61
|
def api_call(business_id)
|
34
62
|
url = "#{YTJ_API_URL}#{business_id}"
|
data/ytj_client.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.13"
|
25
|
-
spec.add_development_dependency "rake", "~>
|
25
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.0"
|
27
27
|
spec.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
|
28
28
|
spec.add_development_dependency 'webmock', '~> 2.3', '>= 2.3.1'
|
@@ -30,4 +30,5 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency 'awesome_print', '~> 1.7', '>= 1.7.0'
|
31
31
|
|
32
32
|
spec.add_runtime_dependency 'rest-client', '~> 2.0', '>= 2.0.0'
|
33
|
+
spec.add_runtime_dependency 'activesupport', '~> 5.0', '>= 5.0.1'
|
33
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ytj_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janne Warén
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '12.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '12.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,6 +146,26 @@ dependencies:
|
|
146
146
|
- - ">="
|
147
147
|
- !ruby/object:Gem::Version
|
148
148
|
version: 2.0.0
|
149
|
+
- !ruby/object:Gem::Dependency
|
150
|
+
name: activesupport
|
151
|
+
requirement: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - "~>"
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '5.0'
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: 5.0.1
|
159
|
+
type: :runtime
|
160
|
+
prerelease: false
|
161
|
+
version_requirements: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - "~>"
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '5.0'
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: 5.0.1
|
149
169
|
description: Fetches data with business_id from the YTJ API at http://avoindata.prh.fi/ytj.html
|
150
170
|
email:
|
151
171
|
- janne.waren@iki.fi
|