transparent_data-rb 0.1.2 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/Gemfile.lock +1 -1
- data/README.md +34 -22
- data/lib/transparent_data.rb +3 -2
- data/lib/transparent_data/actions.rb +28 -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/request.rb +13 -20
- data/lib/transparent_data/response/struct.rb +7 -1
- data/lib/transparent_data/version.rb +1 -1
- metadata +6 -3
- data/lib/transparent_data/module_functions.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4a8f55fa7433e0e315d2bbb74b17105bdbb26f547e68cd3e4e869d81a98b836
|
4
|
+
data.tar.gz: 710a59a70647472ac85a443af84a6f5a1fd21b5e9d657a562625c2f5e9d82f14
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8a93674569fbb5dddd85e95635beff0fbda36e8a3ccd380f89d27eda11c6e368bbf7b4c9fed0fab7335565c806ed1da198310860522e10fda9cde47e81a48af3
|
7
|
+
data.tar.gz: f6390304fb55dcfb2bccfe77a2f979606b3bd60d9e2efea44da569e3967192b9761498164d403c63222d933f4fde4d0d769eb4d2272ab7eb61f571d3b59c4b1f
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,44 +1,56 @@
|
|
1
|
-
# TransparentData
|
1
|
+
# TransparentData RB
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/transparent_data-rb.svg)](https://badge.fury.io/rb/transparent_data-rb) [![Build Status](https://travis-ci.com/sigmen/transparent_data-rb.svg?branch=master)](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,13 +1,14 @@
|
|
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'
|
6
|
-
require 'transparent_data/
|
7
|
+
require 'transparent_data/actions'
|
7
8
|
|
8
9
|
module TransparentData
|
9
10
|
extend TransparentData::Configurable
|
10
|
-
extend TransparentData::
|
11
|
+
extend TransparentData::Actions
|
11
12
|
|
12
13
|
initialize_config_accessors(:url, :user, :password, :key)
|
13
14
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'transparent_data/request'
|
2
|
+
require 'transparent_data/actions/search'
|
3
|
+
require 'transparent_data/actions/add'
|
4
|
+
require 'transparent_data/actions/result'
|
5
|
+
|
6
|
+
module TransparentData
|
7
|
+
module Actions
|
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
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def client
|
23
|
+
@client ||= Faraday.new(TransparentData.url) do |conn|
|
24
|
+
conn.basic_auth(TransparentData.user, TransparentData.password)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -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
|
@@ -2,32 +2,25 @@ require 'transparent_data/response/struct'
|
|
2
2
|
|
3
3
|
module TransparentData
|
4
4
|
class Request
|
5
|
-
|
5
|
+
class << self
|
6
|
+
def call(client, method, query: {}, json: {})
|
7
|
+
response = client.post(build_path(method, query), json.to_json)
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
czech: :cz,
|
10
|
-
denmark: :dk,
|
11
|
-
norway: :no,
|
12
|
-
slovakia: :sk,
|
13
|
-
uk: :uk
|
14
|
-
}.freeze
|
9
|
+
TransparentData::Response::Struct.new(response)
|
10
|
+
end
|
15
11
|
|
16
|
-
|
17
|
-
response = client.post(build_path(country, query))
|
12
|
+
private
|
18
13
|
|
19
|
-
|
20
|
-
|
14
|
+
def build_path(method, query)
|
15
|
+
base_path = "/#{TransparentData.key}/#{method}"
|
21
16
|
|
22
|
-
|
17
|
+
return base_path unless query&.any?
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
end
|
19
|
+
base_path.concat("?#{convert_params_to_query(query)}")
|
20
|
+
end
|
27
21
|
|
28
|
-
|
29
|
-
|
30
|
-
raise TransparentData::UnknownCountryError, "Unknown country: #{country.inspect}"
|
22
|
+
def convert_params_to_query(params)
|
23
|
+
params.map { |pair| pair.join('=') }.join('&')
|
31
24
|
end
|
32
25
|
end
|
33
26
|
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
|
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.7
|
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
|
@@ -114,9 +114,12 @@ files:
|
|
114
114
|
- bin/console
|
115
115
|
- bin/setup
|
116
116
|
- lib/transparent_data.rb
|
117
|
+
- lib/transparent_data/actions.rb
|
118
|
+
- lib/transparent_data/actions/add.rb
|
119
|
+
- lib/transparent_data/actions/result.rb
|
120
|
+
- lib/transparent_data/actions/search.rb
|
117
121
|
- lib/transparent_data/configurable.rb
|
118
122
|
- lib/transparent_data/exceptions.rb
|
119
|
-
- lib/transparent_data/module_functions.rb
|
120
123
|
- lib/transparent_data/request.rb
|
121
124
|
- lib/transparent_data/response/struct.rb
|
122
125
|
- lib/transparent_data/version.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'transparent_data/request'
|
2
|
-
|
3
|
-
module TransparentData
|
4
|
-
module ModuleFunctions
|
5
|
-
def search(country, query)
|
6
|
-
TransparentData::Request.call(client, country, query)
|
7
|
-
end
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
def client
|
12
|
-
@client ||= Faraday.new(TransparentData.url) do |conn|
|
13
|
-
conn.basic_auth(TransparentData.user, TransparentData.password)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|