transparent_data-rb 0.1.0 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +34 -22
- data/lib/transparent_data.rb +2 -0
- data/lib/transparent_data/actions/add.rb +28 -0
- data/lib/transparent_data/actions/result.rb +22 -0
- data/lib/transparent_data/actions/search.rb +40 -0
- data/lib/transparent_data/configurable.rb +1 -1
- data/lib/transparent_data/module_functions.rb +13 -2
- data/lib/transparent_data/request.rb +10 -19
- data/lib/transparent_data/response/struct.rb +7 -1
- data/lib/transparent_data/version.rb +1 -1
- data/transparent_data.gemspec +2 -2
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5af41cd1106275ad10b7ca0eafa1871651d4967ba1e1a6f00d04fa826ca01b9
|
4
|
+
data.tar.gz: 9d0a797a052a03d8cb57e4faba99fa094c3cc29017804d2a4f9d91e3095a5454
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 183407be095e12dee5d5fc0fd3a6a9357f1992f08bd6375d38e109e4f0523b8b6eed3fd069984712126c3bd3c4beb2ef5aceba7ae61dc864b8806960c2a88dd7
|
7
|
+
data.tar.gz: 2a7f1b56290e4a9331f32df1025acf481588cb5c7460714cb85035ac572807c43861a2aed8368ae9023c1d9a66ae56a37cfb41ed0504a26da55f4d32ac1949ed
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,44 +1,56 @@
|
|
1
|
-
# TransparentData
|
1
|
+
# TransparentData RB
|
2
|
+
[](https://badge.fury.io/rb/transparent_data-rb) [](https://travis-ci.com/sigmen/transparent_data-rb)
|
2
3
|
|
3
|
-
|
4
|
+
## Supports
|
4
5
|
|
5
|
-
|
6
|
+
Ruby `>= 2.4`.
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
9
10
|
Add this line to your application's Gemfile:
|
10
11
|
|
11
|
-
|
12
|
-
gem 'transparent_data-rb'
|
13
|
-
```
|
12
|
+
gem 'transparent_data-rb'
|
14
13
|
|
15
14
|
And then execute:
|
16
15
|
|
17
16
|
$ bundle install
|
18
17
|
|
19
|
-
Or install
|
18
|
+
Or install with:
|
20
19
|
|
21
20
|
$ gem install transparent_data-rb
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
22
|
+
### Usage
|
30
23
|
|
31
|
-
|
32
|
-
|
33
|
-
## Contributing
|
24
|
+
```ruby
|
25
|
+
response = TransparentData.search(country_name, query)
|
34
26
|
|
35
|
-
|
27
|
+
response.body # => [{...}]
|
28
|
+
response.status # => 200
|
29
|
+
response.headers # => {...}
|
30
|
+
```
|
36
31
|
|
32
|
+
#### Search options
|
33
|
+
* country_name - Any available country name (see Available countries)
|
34
|
+
* query - Search query
|
37
35
|
|
38
|
-
|
36
|
+
#### Available countries
|
37
|
+
Gem supports all available Transparentdata.eu countries:
|
38
|
+
* finland
|
39
|
+
* uk
|
40
|
+
* denmark
|
41
|
+
* norway
|
42
|
+
* slovakia
|
43
|
+
* czech
|
39
44
|
|
40
|
-
|
45
|
+
#### Configuration
|
41
46
|
|
42
|
-
|
47
|
+
Before using gem you need to configure some parameters:
|
43
48
|
|
44
|
-
|
49
|
+
```ruby
|
50
|
+
TransparentData.configure do |config|
|
51
|
+
config.url = 'https://transparentdata.eu/' # You can using any another url for test environment
|
52
|
+
config.user = 'user' # Username for HTTP Basic
|
53
|
+
config.password = 'password' # Password for HTTP Basic
|
54
|
+
config.key = 'key' # API Key
|
55
|
+
end
|
56
|
+
```
|
data/lib/transparent_data.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'faraday'
|
2
|
+
require 'json'
|
2
3
|
|
3
4
|
require 'transparent_data/version'
|
4
5
|
require 'transparent_data/exceptions'
|
5
6
|
require 'transparent_data/configurable'
|
7
|
+
require 'transparent_data/request'
|
6
8
|
require 'transparent_data/module_functions'
|
7
9
|
|
8
10
|
module TransparentData
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module TransparentData
|
2
|
+
module Actions
|
3
|
+
class Add
|
4
|
+
attr_reader :client, :source, :method, :parameters
|
5
|
+
|
6
|
+
def initialize(client, source, method, parameters)
|
7
|
+
@client = client
|
8
|
+
@source = source
|
9
|
+
@method = method
|
10
|
+
@parameters = parameters
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
TransparentData::Request.call(client, 'add', json: build_json)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def build_json
|
20
|
+
{
|
21
|
+
source: source,
|
22
|
+
method: method,
|
23
|
+
parameters: parameters
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module TransparentData
|
2
|
+
module Actions
|
3
|
+
class Result
|
4
|
+
attr_reader :client, :ident
|
5
|
+
|
6
|
+
def initialize(client, ident)
|
7
|
+
@client = client
|
8
|
+
@ident = ident
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
TransparentData::Request.call(client, 'result', query: build_query(ident))
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def build_query
|
18
|
+
{ ident: ident }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module TransparentData
|
2
|
+
module Actions
|
3
|
+
class Search
|
4
|
+
COUNTRY_TO_KEY_MAP = {
|
5
|
+
finland: :fi,
|
6
|
+
czech: :cz,
|
7
|
+
denmark: :dk,
|
8
|
+
norway: :no,
|
9
|
+
slovakia: :sk,
|
10
|
+
uk: :uk
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
attr_reader :client, :country, :query_str
|
14
|
+
|
15
|
+
def initialize(client, country, query_str)
|
16
|
+
@client = client
|
17
|
+
@country = country
|
18
|
+
@query_str = query_str
|
19
|
+
end
|
20
|
+
|
21
|
+
def call
|
22
|
+
search_method = "#{fetch_country_id(country)}Search"
|
23
|
+
|
24
|
+
TransparentData::Request.call(client, search_method, query: build_query(query_str))
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def build_query(query_str)
|
30
|
+
{ q: query_str }
|
31
|
+
end
|
32
|
+
|
33
|
+
def fetch_country_id(country)
|
34
|
+
COUNTRY_TO_KEY_MAP.fetch(country.to_s.downcase.to_sym) do
|
35
|
+
raise TransparentData::UnknownCountryError, "Unknown country: #{country.inspect}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,9 +1,20 @@
|
|
1
1
|
require 'transparent_data/request'
|
2
|
+
require 'transparent_data/actions/search'
|
3
|
+
require 'transparent_data/actions/add'
|
4
|
+
require 'transparent_data/actions/result'
|
2
5
|
|
3
6
|
module TransparentData
|
4
7
|
module ModuleFunctions
|
5
|
-
def search(country,
|
6
|
-
TransparentData::
|
8
|
+
def search(country, query_str)
|
9
|
+
TransparentData::Actions::Search.new(client, country, query_str).call
|
10
|
+
end
|
11
|
+
|
12
|
+
def add(source, method, parameters)
|
13
|
+
TransparentData::Actions::Add.new(client, source, method, parameters).call
|
14
|
+
end
|
15
|
+
|
16
|
+
def result(ident)
|
17
|
+
TransparentData::Actions::Result.new(client, ident).call
|
7
18
|
end
|
8
19
|
|
9
20
|
private
|
@@ -2,33 +2,24 @@ require 'transparent_data/response/struct'
|
|
2
2
|
|
3
3
|
module TransparentData
|
4
4
|
class Request
|
5
|
-
|
6
|
-
|
7
|
-
COUNTRY_TO_KEY_MAP = {
|
8
|
-
finland: :fi,
|
9
|
-
czech: :cz,
|
10
|
-
denmark: :dk,
|
11
|
-
norway: :no,
|
12
|
-
slovakia: :sk,
|
13
|
-
uk: :uk
|
14
|
-
}.freeze
|
15
|
-
|
16
|
-
def self.call(client, country, query)
|
17
|
-
response = client.post(build_path(country, query))
|
5
|
+
def self.call(client, method, query: {}, json: {})
|
6
|
+
response = client.post(build_path(method, query), json)
|
18
7
|
|
19
8
|
TransparentData::Response::Struct.new(response)
|
20
9
|
end
|
21
10
|
|
22
11
|
private
|
23
12
|
|
24
|
-
def build_path(
|
25
|
-
"/#{TransparentData.key}/#{
|
13
|
+
def build_path(method, query)
|
14
|
+
base_path = "/#{TransparentData.key}/#{method}"
|
15
|
+
|
16
|
+
return base_path unless query&.any?
|
17
|
+
|
18
|
+
base_path.concat("?#{convert_params_to_query(query)}")
|
26
19
|
end
|
27
20
|
|
28
|
-
def
|
29
|
-
|
30
|
-
raise TransparentData::UnknownCountryError, "Unknown country: #{country.inspect}"
|
31
|
-
end
|
21
|
+
def convert_params_to_query(params)
|
22
|
+
params.map { |pair| pair.join('=') }.join('&')
|
32
23
|
end
|
33
24
|
end
|
34
25
|
end
|
@@ -3,11 +3,17 @@ module TransparentData
|
|
3
3
|
class Struct
|
4
4
|
extend Forwardable
|
5
5
|
|
6
|
-
def_delegators :@response, :
|
6
|
+
def_delegators :@response, :headers, :status, :success?
|
7
7
|
|
8
8
|
def initialize(response)
|
9
9
|
@response = response
|
10
10
|
end
|
11
|
+
|
12
|
+
def body
|
13
|
+
JSON.parse(@response.body)
|
14
|
+
rescue JSON::ParserError
|
15
|
+
@response.body
|
16
|
+
end
|
11
17
|
end
|
12
18
|
end
|
13
19
|
end
|
data/transparent_data.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ['Roman Kakorin']
|
10
10
|
spec.email = ['romchky1@gmail.com']
|
11
11
|
|
12
|
-
spec.summary = '
|
13
|
-
spec.description = '
|
12
|
+
spec.summary = 'https://transparentdata.eu API client'
|
13
|
+
spec.description = 'https://transparentdata.eu API client'
|
14
14
|
spec.homepage = 'https://github.com/sigmen/transparent_data-rb'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
spec.required_ruby_version = '>= 2.4.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: transparent_data-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Kakorin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,7 +94,7 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description:
|
97
|
+
description: https://transparentdata.eu API client
|
98
98
|
email:
|
99
99
|
- romchky1@gmail.com
|
100
100
|
executables: []
|
@@ -114,6 +114,9 @@ files:
|
|
114
114
|
- bin/console
|
115
115
|
- bin/setup
|
116
116
|
- lib/transparent_data.rb
|
117
|
+
- lib/transparent_data/actions/add.rb
|
118
|
+
- lib/transparent_data/actions/result.rb
|
119
|
+
- lib/transparent_data/actions/search.rb
|
117
120
|
- lib/transparent_data/configurable.rb
|
118
121
|
- lib/transparent_data/exceptions.rb
|
119
122
|
- lib/transparent_data/module_functions.rb
|
@@ -146,5 +149,5 @@ requirements: []
|
|
146
149
|
rubygems_version: 3.1.4
|
147
150
|
signing_key:
|
148
151
|
specification_version: 4
|
149
|
-
summary:
|
152
|
+
summary: https://transparentdata.eu API client
|
150
153
|
test_files: []
|